Search in sources :

Example 1 with CaptureGatewayRequest

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);
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) InOrder(org.mockito.InOrder) CaptureResponse.fromBaseCaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse) BaseCaptureResponse(uk.gov.pay.connector.gateway.model.response.BaseCaptureResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 2 with CaptureGatewayRequest

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));
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 3 with CaptureGatewayRequest

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));
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) 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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with CaptureGatewayRequest

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));
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) 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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 5 with CaptureGatewayRequest

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()));
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) InOrder(org.mockito.InOrder) CaptureResponse.fromBaseCaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse) BaseCaptureResponse(uk.gov.pay.connector.gateway.model.response.BaseCaptureResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse)

Aggregations

CaptureGatewayRequest (uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest)15 Test (org.junit.Test)13 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)11 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)10 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)7 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)6 InOrder (org.mockito.InOrder)5 CaptureResponse.fromBaseCaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse)5 RefundGatewayRequest (uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest)5 BaseCaptureResponse (uk.gov.pay.connector.gateway.model.response.BaseCaptureResponse)5 GatewayRefundResponse (uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse)5 Mockito.anyString (org.mockito.Mockito.anyString)4 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)2 Before (org.junit.Before)1