Search in sources :

Example 1 with CaptureResponse.fromBaseCaptureResponse

use of uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse 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

InOrder (org.mockito.InOrder)1 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)1 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)1 CaptureResponse.fromBaseCaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse)1 CaptureGatewayRequest (uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest)1 BaseCaptureResponse (uk.gov.pay.connector.gateway.model.response.BaseCaptureResponse)1