Search in sources :

Example 1 with AddressEntity

use of uk.gov.pay.connector.charge.model.AddressEntity in project pay-connector by alphagov.

the class ChargeDaoCardDetailsIT method persist_shouldStoreNullCardTypeDetails.

@Test
public void persist_shouldStoreNullCardTypeDetails() {
    GatewayAccountEntity testAccount = new GatewayAccountEntity(GatewayAccountType.TEST);
    testAccount.setExternalId(randomUuid());
    gatewayAccountDao.persist(testAccount);
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("username", "theUsername", "password", "thePassword", "merchant_id", "theMerchantCode")).withGatewayAccountEntity(testAccount).withPaymentProvider(SANDBOX.getName()).withState(ACTIVE).withExternalId(randomUuid()).build();
    gatewayAccountCredentialsDao.persist(credentialsEntity);
    Address billingAddress = AddressFixture.anAddress().build();
    ChargeEntity chargeEntity = ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(credentialsEntity).build();
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity(FirstDigitsCardNumber.of("123456"), LastDigitsCardNumber.of("1258"), "Mr. Pay Mc Payment", CardExpiryDate.valueOf("03/09"), "VISA", null, new AddressEntity(billingAddress));
    chargeEntity.setCardDetails(cardDetailsEntity);
    chargeDao.persist(chargeEntity);
    Map<String, Object> cardDetailsSaved = databaseTestHelper.getChargeCardDetails(chargeEntity.getId());
    assertThat(cardDetailsSaved, hasEntry("card_type", null));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Address(uk.gov.pay.connector.common.model.domain.Address) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Test(org.junit.Test)

Example 2 with AddressEntity

use of uk.gov.pay.connector.charge.model.AddressEntity in project pay-connector by alphagov.

the class ChargeDaoCardDetailsIT method persist_shouldStoreCardDetails.

@Test
public void persist_shouldStoreCardDetails() {
    GatewayAccountEntity testAccount = new GatewayAccountEntity(GatewayAccountType.TEST);
    testAccount.setExternalId(randomUuid());
    gatewayAccountDao.persist(testAccount);
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of()).withGatewayAccountEntity(testAccount).withPaymentProvider(SANDBOX.getName()).withState(ACTIVE).build();
    credentialsEntity.setExternalId(randomUuid());
    gatewayAccountCredentialsDao.persist(credentialsEntity);
    Address billingAddress = AddressFixture.anAddress().build();
    ChargeEntity chargeEntity = ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(credentialsEntity).build();
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity(FirstDigitsCardNumber.of("123456"), LastDigitsCardNumber.of("1258"), "Mr. Pay Mc Payment", CardExpiryDate.valueOf("03/09"), "VISA", CardType.DEBIT, new AddressEntity(billingAddress));
    chargeEntity.setCardDetails(cardDetailsEntity);
    chargeDao.persist(chargeEntity);
    Map<String, Object> cardDetailsSaved = databaseTestHelper.getChargeCardDetails(chargeEntity.getId());
    assertThat(cardDetailsSaved, hasEntry("card_type", "DEBIT"));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Address(uk.gov.pay.connector.common.model.domain.Address) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) Test(org.junit.Test)

Example 3 with AddressEntity

use of uk.gov.pay.connector.charge.model.AddressEntity in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateAChargeWithNoCountryWhenPrefilledAddressCountryIsMoreThanTwoCharacters.

@Test
public void shouldCreateAChargeWithNoCountryWhenPrefilledAddressCountryIsMoreThanTwoCharacters() {
    doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
    when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
    when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
    when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
    when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    var cardHolderDetails = new PrefilledCardHolderDetails();
    cardHolderDetails.setCardHolderName("Joe Bogs");
    var address = new PrefilledAddress("Line1", "Line2", "AB1 CD2", "London", "county", "123");
    cardHolderDetails.setAddress(address);
    ChargeCreateRequest request = requestBuilder.withPrefilledCardHolderDetails(cardHolderDetails).build();
    service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getCardDetails(), is(notNullValue()));
    assertThat(createdChargeEntity.getCardDetails().getBillingAddress().isPresent(), is(true));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Joe Bogs"));
    AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
    assertThat(addressEntity.getLine1(), is("Line1"));
    assertThat(addressEntity.getLine2(), is("Line2"));
    assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
    assertThat(addressEntity.getCity(), is("London"));
    assertThat(addressEntity.getCounty(), is("county"));
    assertThat(addressEntity.getCountry(), is(nullValue()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeCreateRequest(uk.gov.pay.connector.charge.model.ChargeCreateRequest) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PrefilledAddress(uk.gov.pay.connector.common.model.domain.PrefilledAddress) Charge(uk.gov.pay.connector.charge.model.domain.Charge) List(java.util.List) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) PrefilledCardHolderDetails(uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails) Test(org.junit.Test)

Example 4 with AddressEntity

use of uk.gov.pay.connector.charge.model.AddressEntity in project pay-connector by alphagov.

the class ChargeService method buildCardDetailsEntity.

private CardDetailsEntity buildCardDetailsEntity(AuthCardDetails authCardDetails) {
    CardDetailsEntity detailsEntity = new CardDetailsEntity();
    detailsEntity.setCardBrand(sanitize(authCardDetails.getCardBrand()));
    detailsEntity.setCardHolderName(sanitize(authCardDetails.getCardHolder()));
    detailsEntity.setExpiryDate(authCardDetails.getEndDate());
    if (hasFullCardNumber(authCardDetails)) {
        // Apple Pay etc. don’t give us a full card number, just the last four digits here
        detailsEntity.setFirstDigitsCardNumber(FirstDigitsCardNumber.of(StringUtils.left(authCardDetails.getCardNo(), 6)));
    }
    if (hasLastFourCharactersCardNumber(authCardDetails)) {
        detailsEntity.setLastDigitsCardNumber(LastDigitsCardNumber.of(StringUtils.right(authCardDetails.getCardNo(), 4)));
    }
    authCardDetails.getAddress().ifPresent(address -> {
        var addressEntity = new AddressEntity(address);
        northAmericanRegionMapper.getNorthAmericanRegionForCountry(address).map(NorthAmericaRegion::getAbbreviation).ifPresent(stateOrProvinceAbbreviation -> {
            addressEntity.setStateOrProvince(stateOrProvinceAbbreviation);
        });
        detailsEntity.setBillingAddress(addressEntity);
    });
    detailsEntity.setCardType(PayersCardType.toCardType(authCardDetails.getPayersCardType()));
    return detailsEntity;
}
Also used : AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity)

Example 5 with AddressEntity

use of uk.gov.pay.connector.charge.model.AddressEntity in project pay-connector by alphagov.

the class AuthCardDetailsFixture method getCardDetailsEntity.

public CardDetailsEntity getCardDetailsEntity() {
    CardDetailsEntity cardDetailsEntity = new CardDetailsEntity();
    cardDetailsEntity.setCardBrand(cardBrand);
    cardDetailsEntity.setCardHolderName(cardHolder);
    cardDetailsEntity.setExpiryDate(endDate);
    if (cardNo.length() > 6) {
        cardDetailsEntity.setFirstDigitsCardNumber(FirstDigitsCardNumber.of(StringUtils.left(cardNo, 6)));
    }
    cardDetailsEntity.setLastDigitsCardNumber(LastDigitsCardNumber.of(StringUtils.right(cardNo, 4)));
    if (address != null) {
        cardDetailsEntity.setBillingAddress(new AddressEntity(address));
    }
    cardDetailsEntity.setCardType(PayersCardType.toCardType(payersCardType));
    CardBrandLabelEntity cardTypeDetails = new CardBrandLabelEntity();
    cardTypeDetails.setBrand("visa");
    cardTypeDetails.setLabel("Visa");
    cardDetailsEntity.setCardTypeDetails(cardTypeDetails);
    return cardDetailsEntity;
}
Also used : CardBrandLabelEntity(uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity) AddressEntity(uk.gov.pay.connector.charge.model.AddressEntity) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity)

Aggregations

AddressEntity (uk.gov.pay.connector.charge.model.AddressEntity)9 Test (org.junit.Test)6 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)6 List (java.util.List)4 CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)4 ChargeCreateRequest (uk.gov.pay.connector.charge.model.ChargeCreateRequest)4 PrefilledCardHolderDetails (uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails)4 Charge (uk.gov.pay.connector.charge.model.domain.Charge)4 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)4 PrefilledAddress (uk.gov.pay.connector.common.model.domain.PrefilledAddress)4 PaymentGatewayName (uk.gov.pay.connector.gateway.PaymentGatewayName)4 Address (uk.gov.pay.connector.common.model.domain.Address)2 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)2 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)2 GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity)2 CardBrandLabelEntity (uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity)1