use of uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest in project pay-connector by alphagov.
the class CardCaptureServiceTest method doCapture_shouldCaptureAChargeForStripeAccountV2.
@Test
public void doCapture_shouldCaptureAChargeForStripeAccountV2() throws QueueException {
String gatewayTxId = "theTxId";
ChargeEntity charge = createNewChargeWithFees("stripe", 1L, AUTHORISATION_SUCCESS, gatewayTxId);
ChargeEntity chargeSpy = spy(charge);
mockChargeDaoOperations(chargeSpy);
stripeWillRespondWithSuccessAndAdditionalFees();
when(mockedProviders.byName(charge.getPaymentGatewayName())).thenReturn(mockedPaymentProvider);
CaptureResponse response = cardCaptureService.doCapture(charge.getExternalId());
assertThat(response.isSuccessful(), is(true));
InOrder inOrder = Mockito.inOrder(chargeSpy);
inOrder.verify(chargeSpy).setStatus(CAPTURE_READY);
inOrder.verify(chargeSpy).setStatus(CAPTURE_SUBMITTED);
ArgumentCaptor<ChargeEntity> chargeEntityCaptor = ArgumentCaptor.forClass(ChargeEntity.class);
verify(mockedChargeEventDao).persistChargeEventOf(chargeEntityCaptor.capture(), isNull());
assertThat(chargeEntityCaptor.getValue().getStatus(), is(CAPTURE_SUBMITTED.getValue()));
ArgumentCaptor<CaptureGatewayRequest> request = ArgumentCaptor.forClass(CaptureGatewayRequest.class);
verify(mockedPaymentProvider, times(1)).capture(request.capture());
assertThat(request.getValue().getTransactionId(), is(gatewayTxId));
verify(mockEventService, times(1)).emitAndRecordEvent(any());
verifyNoInteractions(mockUserNotificationService);
}
use of uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest in project pay-connector by alphagov.
the class EpdqPaymentProviderTest method shouldCaptureSuccessfully.
@Test
public void shouldCaptureSuccessfully() throws Exception {
setUpAndCheckThatEpdqIsUp();
var request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetailsFixture().build());
GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request, chargeEntity);
assertThat(response.isSuccessful(), is(true));
String transactionId = response.getBaseResponse().get().getTransactionId();
assertThat(transactionId, is(not(nullValue())));
CaptureGatewayRequest captureRequest = buildCaptureRequest(chargeEntity, transactionId);
CaptureResponse captureResponse = paymentProvider.capture(captureRequest);
assertThat(captureResponse.isSuccessful(), is(true));
assertThat(captureResponse.state(), Is.is(CaptureResponse.ChargeState.PENDING));
}
use of uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithFee_feeCalculationShouldAlwaysRoundUp.
@Test
public void shouldCaptureWithFee_feeCalculationShouldAlwaysRoundUp() throws Exception {
final String transactionId = "ch_1231231123123";
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(10001L).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).withState(ACTIVE).build()).build();
CaptureGatewayRequest captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
mockStripeCaptureAndTransfer();
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
assertTrue(captureResponse.isSuccessful());
assertThat(captureResponse.getFeeList(), hasSize(2));
assertThat(captureResponse.getFeeList().get(0).getFeeType(), is(TRANSACTION));
assertThat(captureResponse.getFeeList().get(0).getAmount(), is(59L));
assertThat(captureResponse.getFeeList().get(1).getFeeType(), is(RADAR));
assertThat(captureResponse.getFeeList().get(1).getAmount(), is(5L));
}
use of uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithFee_feeCalculationShouldRoundUpTo1.
@Test
public void shouldCaptureWithFee_feeCalculationShouldRoundUpTo1() throws Exception {
final String transactionId = "ch_1231231123123";
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(1L).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).withState(ACTIVE).build()).build();
CaptureGatewayRequest captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
mockStripeCaptureAndTransfer();
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
assertTrue(captureResponse.isSuccessful());
assertThat(captureResponse.getFeeList(), hasSize(2));
assertThat(captureResponse.getFeeList().get(0).getFeeType(), is(TRANSACTION));
assertThat(captureResponse.getFeeList().get(0).getAmount(), is(51L));
assertThat(captureResponse.getFeeList().get(1).getFeeType(), is(RADAR));
assertThat(captureResponse.getFeeList().get(1).getAmount(), is(5L));
}
use of uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest in project pay-connector by alphagov.
the class CardCaptureServiceTest method verifyChargeIsCapturedImmediatelyFromPaymentProvider.
public void verifyChargeIsCapturedImmediatelyFromPaymentProvider(ChargeEntity chargeSpy) {
mockChargeDaoOperations(chargeSpy);
when(mockedProviders.byName(chargeSpy.getPaymentGatewayName())).thenReturn(mockedPaymentProvider);
when(mockedPaymentProvider.capture(any())).thenReturn(CaptureResponse.fromBaseCaptureResponse(BaseCaptureResponse.fromTransactionId(randomUUID().toString(), SANDBOX), COMPLETE));
CaptureResponse response = cardCaptureService.doCapture(chargeSpy.getExternalId());
assertThat(response.isSuccessful(), is(true));
InOrder inOrder = Mockito.inOrder(chargeSpy);
inOrder.verify(chargeSpy).setStatus(CAPTURE_READY);
inOrder.verify(chargeSpy).setStatus(CAPTURE_SUBMITTED);
inOrder.verify(chargeSpy).setStatus(CAPTURED);
ArgumentCaptor<ChargeEntity> chargeEntityCaptor = ArgumentCaptor.forClass(ChargeEntity.class);
// charge progresses from CAPTURE_SUBMITTED to CAPTURED, so two calls
// first invocation will add a captured date
verify(mockedChargeEventDao, times(2)).persistChargeEventOf(chargeEntityCaptor.capture(), isNull());
// second invocation will NOT add a captured date
assertThat(chargeEntityCaptor.getValue().getStatus(), is(CAPTURED.getValue()));
// only the CAPTURED has a bookingDate, so there's only one value captured
ArgumentCaptor<CaptureGatewayRequest> request = ArgumentCaptor.forClass(CaptureGatewayRequest.class);
verify(mockedPaymentProvider, times(1)).capture(request.capture());
assertThat(request.getValue().getTransactionId(), is(chargeSpy.getGatewayTransactionId()));
}
Aggregations