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));
}
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"));
}
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()));
}
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;
}
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;
}
Aggregations