use of uk.gov.pay.connector.charge.model.ChargeCreateRequest in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateChargeWithZeroAmountIfGatewayAccountAllowsIt.
@Test
public void shouldCreateChargeWithZeroAmountIfGatewayAccountAllowsIt() {
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);
gatewayAccount.setAllowZeroAmount(true);
final ChargeCreateRequest request = requestBuilder.withAmount(0).build();
service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
assertThat(createdChargeEntity.getAmount(), is(0L));
}
use of uk.gov.pay.connector.charge.model.ChargeCreateRequest in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWithBlankEmailAddress.
@Test
public void shouldCreateAChargeWithBlankEmailAddress() {
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);
final ChargeCreateRequest request = requestBuilder.withEmail("").build();
service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
assertThat(createdChargeEntity.getEmail(), is(nullValue()));
}
use of uk.gov.pay.connector.charge.model.ChargeCreateRequest 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.ChargeCreateRequest in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWithDelayedCaptureTrue.
@Test
public void shouldCreateAChargeWithDelayedCaptureTrue() {
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);
final ChargeCreateRequest request = requestBuilder.withDelayedCapture(true).build();
service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
}
use of uk.gov.pay.connector.charge.model.ChargeCreateRequest in project pay-connector by alphagov.
the class ChargeServiceCreateTest method shouldCreateAChargeWhenPrefilledCardHolderDetailsAreNotPresent.
@Test
public void shouldCreateAChargeWhenPrefilledCardHolderDetailsAreNotPresent() {
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);
ChargeCreateRequest request = requestBuilder.build();
service.create(request, GATEWAY_ACCOUNT_ID, mockedUriInfo);
verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
assertThat(createdChargeEntity.getCardDetails(), is(nullValue()));
}
Aggregations