Search in sources :

Example 1 with CaptureResponse

use of uk.gov.pay.connector.gateway.CaptureResponse in project pay-connector by alphagov.

the class CardCaptureService method doCapture.

public CaptureResponse doCapture(String externalId) {
    ChargeEntity charge;
    try {
        charge = prepareChargeForCapture(externalId);
    } catch (OptimisticLockException e) {
        LOG.info("OptimisticLockException in doCapture for charge external_id={}", externalId);
        throw new ConflictRuntimeException(externalId);
    }
    CaptureResponse operationResponse = capture(charge);
    processGatewayCaptureResponse(externalId, charge.getStatus(), operationResponse);
    return operationResponse;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) OptimisticLockException(javax.persistence.OptimisticLockException) ConflictRuntimeException(uk.gov.pay.connector.common.exception.ConflictRuntimeException)

Example 2 with CaptureResponse

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

use of uk.gov.pay.connector.gateway.CaptureResponse in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldSuccessfullySendACaptureRequest.

@Test
public void shouldSuccessfullySendACaptureRequest() throws Exception {
    PaymentProvider paymentProvider = getSmartpayPaymentProvider();
    CardAuthorisationGatewayRequest request = getCardAuthorisationRequest(chargeEntity);
    GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
    assertTrue(response.isSuccessful());
    assertThat(response.getBaseResponse().isPresent(), is(true));
    SmartpayAuthorisationResponse smartpayAuthorisationResponse = (SmartpayAuthorisationResponse) response.getBaseResponse().get();
    String transactionId = smartpayAuthorisationResponse.getPspReference();
    assertThat(transactionId, is(not(nullValue())));
    chargeEntity.setGatewayTransactionId(transactionId);
    CaptureResponse captureGatewayResponse = paymentProvider.capture(CaptureGatewayRequest.valueOf(chargeEntity));
    assertTrue(captureGatewayResponse.isSuccessful());
    assertThat(captureGatewayResponse.state(), is(CaptureResponse.ChargeState.PENDING));
}
Also used : PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SmartpayPaymentProvider(uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) SmartpayAuthorisationResponse(uk.gov.pay.connector.gateway.smartpay.SmartpayAuthorisationResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 4 with CaptureResponse

use of uk.gov.pay.connector.gateway.CaptureResponse in project pay-connector by alphagov.

the class WorldpayPaymentProviderTest method shouldBeAbleToSendCaptureRequestForMerchant.

/**
 * Worldpay does not care about a successful authorization reference to make a capture request.
 * It simply accepts anything as long as the request is well formed. (And ignores it silently)
 */
@Test
public void shouldBeAbleToSendCaptureRequestForMerchant() {
    WorldpayPaymentProvider paymentProvider = getValidWorldpayPaymentProvider();
    CaptureResponse response = paymentProvider.capture(CaptureGatewayRequest.valueOf(chargeEntity));
    assertTrue(response.isSuccessful());
}
Also used : WorldpayPaymentProvider(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) Test(org.junit.Test)

Example 5 with CaptureResponse

use of uk.gov.pay.connector.gateway.CaptureResponse in project pay-connector by alphagov.

the class WorldpayPaymentProviderTest method shouldBeAbleToSubmitAPartialRefundAfterACaptureHasBeenSubmitted.

@Test
public void shouldBeAbleToSubmitAPartialRefundAfterACaptureHasBeenSubmitted() {
    WorldpayPaymentProvider paymentProvider = getValidWorldpayPaymentProvider();
    AuthCardDetails authCardDetails = anAuthCardDetails().build();
    CardAuthorisationGatewayRequest request = getCardAuthorisationRequest(authCardDetails);
    GatewayResponse<WorldpayOrderStatusResponse> response = paymentProvider.authorise(request);
    String transactionId = response.getBaseResponse().get().getTransactionId();
    assertThat(response.getBaseResponse().isPresent(), is(true));
    assertThat(response.getBaseResponse().isPresent(), is(true));
    assertThat(transactionId, is(not(nullValue())));
    chargeEntity.setGatewayTransactionId(transactionId);
    CaptureResponse captureResponse = paymentProvider.capture(CaptureGatewayRequest.valueOf(chargeEntity));
    assertThat(captureResponse.isSuccessful(), is(true));
    RefundEntity refundEntity = new RefundEntity(1L, userExternalId, userEmail, chargeEntity.getExternalId());
    GatewayRefundResponse refundResponse = paymentProvider.refund(RefundGatewayRequest.valueOf(Charge.from(chargeEntity), refundEntity, validGatewayAccount, validGatewayAccountCredentialsEntity));
    assertTrue(refundResponse.isSuccessful());
}
Also used : WorldpayPaymentProvider(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) AuthCardDetailsFixture.anAuthCardDetails(uk.gov.pay.connector.model.domain.AuthCardDetailsFixture.anAuthCardDetails) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) Mockito.anyString(org.mockito.Mockito.anyString) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) WorldpayOrderStatusResponse(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderStatusResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Aggregations

CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)40 Test (org.junit.Test)34 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)18 StripeTransferOutRequest (uk.gov.pay.connector.gateway.stripe.request.StripeTransferOutRequest)11 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)10 CaptureGatewayRequest (uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest)10 URI (java.net.URI)7 Fee (uk.gov.pay.connector.fee.model.Fee)7 CaptureResponse.fromBaseCaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse)7 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)7 Mockito.anyString (org.mockito.Mockito.anyString)6 GatewayErrorException (uk.gov.pay.connector.gateway.GatewayException.GatewayErrorException)6 BaseCaptureResponse (uk.gov.pay.connector.gateway.model.response.BaseCaptureResponse)6 InOrder (org.mockito.InOrder)5 GatewayClient (uk.gov.pay.connector.gateway.GatewayClient)5 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)5 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)5 StripeCaptureRequest (uk.gov.pay.connector.gateway.stripe.request.StripeCaptureRequest)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 GatewayRefundResponse (uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse)3