Search in sources :

Example 1 with StripeTransferOutRequest

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));
}
Also used : CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) StripeTransferOutRequest(uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest) Test(org.junit.Test)

Example 2 with StripeTransferOutRequest

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)));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) StripeTransferOutRequest(uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest) Fee(uk.gov.pay.connector.fee.model.Fee) Test(org.junit.Test)

Example 3 with StripeTransferOutRequest

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)));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) StripeTransferOutRequest(uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest) Test(org.junit.Test)

Example 4 with StripeTransferOutRequest

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)));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) StripeTransferOutRequest(uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest) Fee(uk.gov.pay.connector.fee.model.Fee) Test(org.junit.Test)

Example 5 with StripeTransferOutRequest

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));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) StripeTransferOutRequest(uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)7 StripeTransferOutRequest (uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest)7 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)6 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)6 Fee (uk.gov.pay.connector.fee.model.Fee)4