use of uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails 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.PrefilledCardHolderDetails in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWithPrefilledCardHolderDetailsCardholderNameOnly.
@Test
public void shouldCreateAChargeWithPrefilledCardHolderDetailsCardholderNameOnly() {
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);
PrefilledCardHolderDetails cardHolderDetails = new PrefilledCardHolderDetails();
cardHolderDetails.setCardHolderName("Joe Bogs");
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(false));
assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Joe Bogs"));
}
use of uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWithAllPrefilledCardHolderDetails.
@Test
public void shouldCreateAChargeWithAllPrefilledCardHolderDetails() {
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", null, "GB");
cardHolderDetails.setAddress(address);
final 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.getCity(), is("London"));
assertThat(addressEntity.getCountry(), is("GB"));
assertThat(addressEntity.getLine1(), is("Line1"));
assertThat(addressEntity.getLine2(), is("Line2"));
assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
assertThat(addressEntity.getCounty(), is(nullValue()));
}
use of uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWithPrefilledCardHolderDetailsAndSomeAddressMissing.
@Test
public void shouldCreateAChargeWithPrefilledCardHolderDetailsAndSomeAddressMissing() {
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", null, "AB1 CD2", "London", null, null);
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(nullValue()));
assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
assertThat(addressEntity.getCity(), is("London"));
assertThat(addressEntity.getCounty(), is(nullValue()));
assertThat(addressEntity.getCountry(), is(nullValue()));
}
use of uk.gov.pay.connector.charge.model.PrefilledCardHolderDetails in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWhenPrefilledCardHolderDetailsCardholderNameAndSomeAddressNotPresent.
@Test
public void shouldCreateAChargeWhenPrefilledCardHolderDetailsCardholderNameAndSomeAddressNotPresent() {
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();
var address = new PrefilledAddress("Line1", null, "AB1 CD2", "London", null, null);
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(nullValue()));
AddressEntity addressEntity = createdChargeEntity.getCardDetails().getBillingAddress().get();
assertThat(addressEntity.getLine1(), is("Line1"));
assertThat(addressEntity.getLine2(), is(nullValue()));
assertThat(addressEntity.getPostcode(), is("AB1 CD2"));
assertThat(addressEntity.getCity(), is("London"));
assertThat(addressEntity.getCounty(), is(nullValue()));
assertThat(addressEntity.getCountry(), is(nullValue()));
}
Aggregations