use of uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithFeeAndTransferCorrectAmountToConnectAccount.
@Test
public void shouldCaptureWithFeeAndTransferCorrectAmountToConnectAccount() throws Exception {
mockStripeCaptureAndTransfer();
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
ArgumentCaptor<StripeTransferOutRequest> transferRequestCaptor = ArgumentCaptor.forClass(StripeTransferOutRequest.class);
verify(gatewayClient, times(2)).postRequestFor(transferRequestCaptor.capture());
assertThat(transferRequestCaptor.getValue().getGatewayOrder().getPayload(), containsString("amount=9942"));
assertTrue(captureResponse.isSuccessful());
assertThat(captureResponse.state(), is(CaptureResponse.ChargeState.COMPLETE));
assertThat(captureResponse.getTransactionId().isPresent(), is(true));
assertThat(captureResponse.getTransactionId().get(), is(captureGatewayRequest.getTransactionId()));
assertThat(captureResponse.getFeeList(), hasSize(1));
assertThat(captureResponse.getFeeList().get(0).getFeeType(), is(nullValue()));
assertThat(captureResponse.getFeeList().get(0).getAmount(), is(58L));
}
use of uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithV2RadarAnd3dsFeesAndTransferCorrectAmountToConnectAccount.
@Test
public void shouldCaptureWithV2RadarAnd3dsFeesAndTransferCorrectAmountToConnectAccount() throws Exception {
mockStripeCaptureAndTransfer();
// 26Aug2021
int chargeCreatedDate = 1629936000;
// 25Aug2021
int feeV2DateAfterChargeCreatedDate = 1629849600;
when(stripeGatewayConfig.getFeePercentageV2Date()).thenReturn(Instant.ofEpochSecond(feeV2DateAfterChargeCreatedDate));
when(stripeGatewayConfig.getFeePercentageV2()).thenReturn(0.50);
when(stripeGatewayConfig.getRadarFeeInPence()).thenReturn(5);
when(stripeGatewayConfig.getThreeDsFeeInPence()).thenReturn(10);
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(10000L).withCreatedDate(Instant.ofEpochSecond(chargeCreatedDate)).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).build()).withEvents(List.of(aChargeEventEntity().withStatus(AUTHORISATION_3DS_REQUIRED).build(), aChargeEventEntity().withStatus(CREATED).build())).build();
captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
ArgumentCaptor<StripeTransferOutRequest> transferRequestCaptor = ArgumentCaptor.forClass(StripeTransferOutRequest.class);
verify(gatewayClient, times(2)).postRequestFor(transferRequestCaptor.capture());
assertThat(transferRequestCaptor.getValue().getGatewayOrder().getPayload(), containsString("amount=9885"));
assertTrue(captureResponse.isSuccessful());
List<Fee> feeList = captureResponse.getFeeList();
assertThat(feeList.size(), is(3));
assertThat(captureResponse.getFeeList(), containsInAnyOrder(Fee.of(FeeType.TRANSACTION, 100L), Fee.of(FeeType.RADAR, 5L), Fee.of(FeeType.THREE_D_S, 10L)));
}
use of uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithNewFeePercentageForChargesCreatedAfterConfiguredFeePercentageV2Date.
@Test
public void shouldCaptureWithNewFeePercentageForChargesCreatedAfterConfiguredFeePercentageV2Date() throws Exception {
mockStripeCaptureAndTransfer();
// 26Aug2021
int chargeCreatedDate = 1629936000;
// 25Aug2021 ;
int feeV2DateBeforeChargeCreatedDate = 1629849600;
when(stripeGatewayConfig.getFeePercentageV2Date()).thenReturn(Instant.ofEpochSecond(feeV2DateBeforeChargeCreatedDate));
when(stripeGatewayConfig.getFeePercentageV2()).thenReturn(0.20);
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(10000L).withCreatedDate(Instant.ofEpochSecond(chargeCreatedDate)).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).build()).build();
captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
ArgumentCaptor<StripeTransferOutRequest> transferRequestCaptor = ArgumentCaptor.forClass(StripeTransferOutRequest.class);
verify(gatewayClient, times(2)).postRequestFor(transferRequestCaptor.capture());
assertThat(transferRequestCaptor.getValue().getGatewayOrder().getPayload(), containsString("amount=9930"));
assertTrue(captureResponse.isSuccessful());
assertThat(captureResponse.getFeeList(), hasSize(2));
assertThat(captureResponse.getFeeList(), containsInAnyOrder(Fee.of(FeeType.TRANSACTION, 70L), Fee.of(FeeType.RADAR, 0L)));
}
use of uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithV2RadarAnd3dsFeesWhenTestAccountsAreEnabled.
@Test
public void shouldCaptureWithV2RadarAnd3dsFeesWhenTestAccountsAreEnabled() throws Exception {
mockStripeCaptureAndTransfer();
// 25Aug2021
int chargeCreatedDate = 1629849600;
// 26Aug2021
int feeV2DateAfterChargeCreatedDate = 1629936000;
when(stripeGatewayConfig.getFeePercentageV2Date()).thenReturn(Instant.ofEpochSecond(feeV2DateAfterChargeCreatedDate));
when(stripeGatewayConfig.getFeePercentageV2()).thenReturn(0.50);
when(stripeGatewayConfig.getRadarFeeInPence()).thenReturn(5);
when(stripeGatewayConfig.getThreeDsFeeInPence()).thenReturn(10);
when(stripeGatewayConfig.isEnableTransactionFeeV2ForTestAccounts()).thenReturn(true);
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(10000L).withCreatedDate(Instant.ofEpochSecond(chargeCreatedDate)).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).build()).withEvents(List.of(aChargeEventEntity().withStatus(AUTHORISATION_3DS_REQUIRED).build(), aChargeEventEntity().withStatus(CREATED).build())).build();
captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
ArgumentCaptor<StripeTransferOutRequest> transferRequestCaptor = ArgumentCaptor.forClass(StripeTransferOutRequest.class);
verify(gatewayClient, times(2)).postRequestFor(transferRequestCaptor.capture());
assertThat(transferRequestCaptor.getValue().getGatewayOrder().getPayload(), containsString("amount=9885"));
assertTrue(captureResponse.isSuccessful());
List<Fee> feeList = captureResponse.getFeeList();
assertThat(feeList.size(), is(3));
assertThat(captureResponse.getFeeList(), containsInAnyOrder(Fee.of(FeeType.TRANSACTION, 100L), Fee.of(FeeType.RADAR, 5L), Fee.of(FeeType.THREE_D_S, 10L)));
}
use of uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest in project pay-connector by alphagov.
the class StripeCaptureHandlerTest method shouldCaptureWithV1FeeAndTransferCorrectAmountToConnectAccount.
@Test
public void shouldCaptureWithV1FeeAndTransferCorrectAmountToConnectAccount() throws Exception {
mockStripeCaptureAndTransfer();
// 25Aug2021
int chargeCreatedDate = 1629849600;
// 26Aug2021 ;
int feeV2DateAfterChargeCreatedDate = 1629936000;
when(stripeGatewayConfig.getFeePercentageV2Date()).thenReturn(Instant.ofEpochSecond(feeV2DateAfterChargeCreatedDate));
when(stripeGatewayConfig.getFeePercentage()).thenReturn(0.50);
ChargeEntity chargeEntity = aValidChargeEntity().withGatewayAccountEntity(gatewayAccount).withTransactionId(transactionId).withAmount(10000L).withCreatedDate(Instant.ofEpochSecond(chargeCreatedDate)).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withPaymentProvider(STRIPE.getName()).build()).build();
captureGatewayRequest = CaptureGatewayRequest.valueOf(chargeEntity);
CaptureResponse captureResponse = stripeCaptureHandler.capture(captureGatewayRequest);
ArgumentCaptor<StripeTransferOutRequest> transferRequestCaptor = ArgumentCaptor.forClass(StripeTransferOutRequest.class);
verify(gatewayClient, times(2)).postRequestFor(transferRequestCaptor.capture());
assertThat(transferRequestCaptor.getValue().getGatewayOrder().getPayload(), containsString("amount=9900"));
assertTrue(captureResponse.isSuccessful());
assertThat(captureResponse.getFeeList(), hasSize(1));
assertThat(captureResponse.getFeeList().get(0).getFeeType(), is(nullValue()));
assertThat(captureResponse.getFeeList().get(0).getAmount(), is(100L));
}
Aggregations