Search in sources :

Example 1 with GatewayRefundResponse

use of uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse 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)

Example 2 with GatewayRefundResponse

use of uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse in project pay-connector by alphagov.

the class RefundService method doRefund.

public ChargeRefundResponse doRefund(Long accountId, Charge charge, RefundRequest refundRequest) {
    GatewayAccountEntity gatewayAccountEntity = gatewayAccountDao.findById(accountId).orElseThrow(() -> new GatewayAccountNotFoundException(accountId));
    GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity = gatewayAccountCredentialsService.findCredentialFromCharge(charge, gatewayAccountEntity).orElseThrow(() -> new GatewayAccountCredentialsNotFoundException("Unable to find gateway account credentials to use to refund charge."));
    RefundEntity refundEntity = createRefund(charge, gatewayAccountEntity, refundRequest);
    GatewayRefundResponse gatewayRefundResponse = providers.byName(PaymentGatewayName.valueFrom(charge.getPaymentGatewayName())).refund(RefundGatewayRequest.valueOf(charge, refundEntity, gatewayAccountEntity, gatewayAccountCredentialsEntity));
    RefundEntity refund = processRefund(gatewayRefundResponse, refundEntity.getId(), gatewayAccountEntity, charge);
    return new ChargeRefundResponse(gatewayRefundResponse, refund);
}
Also used : RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) GatewayAccountNotFoundException(uk.gov.pay.connector.gatewayaccount.exception.GatewayAccountNotFoundException) GatewayAccountCredentialsNotFoundException(uk.gov.pay.connector.gatewayaccount.exception.GatewayAccountCredentialsNotFoundException) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)

Example 3 with GatewayRefundResponse

use of uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse in project pay-connector by alphagov.

the class RefundServiceTest method setupWorldpayMock.

private void setupWorldpayMock(String reference, String errorCode) {
    WorldpayRefundResponse worldpayResponse = mock(WorldpayRefundResponse.class);
    when(worldpayResponse.getReference()).thenReturn(Optional.ofNullable(reference));
    when(worldpayResponse.getErrorCode()).thenReturn(errorCode);
    when(worldpayResponse.stringify()).thenReturn("Randompay refund response (errorCode: " + errorCode + ")");
    GatewayRefundResponse.RefundState refundState;
    if (isNotBlank(errorCode)) {
        refundState = GatewayRefundResponse.RefundState.ERROR;
    } else {
        refundState = GatewayRefundResponse.RefundState.PENDING;
    }
    GatewayRefundResponse gatewayRefundResponse = GatewayRefundResponse.fromBaseRefundResponse(worldpayResponse, refundState);
    when(mockProvider.refund(any())).thenReturn(gatewayRefundResponse);
}
Also used : WorldpayRefundResponse(uk.gov.pay.connector.gateway.worldpay.WorldpayRefundResponse) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse)

Example 4 with GatewayRefundResponse

use of uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse in project pay-connector by alphagov.

the class StripeRefundHandlerTest method shouldNotRefund_whenStatusCode4xxOnTransfer.

@Test
public void shouldNotRefund_whenStatusCode4xxOnTransfer() throws Exception {
    mockRefundSuccess();
    mockTransfer4xxResponse();
    final GatewayRefundResponse refund = refundHandler.refund(refundRequest);
    assertNotNull(refund);
    assertTrue(refund.getError().isPresent());
    assertThat(refund.state(), is(GatewayRefundResponse.RefundState.ERROR));
    assertThat(refund.getError().get().getMessage(), Is.is("Stripe refund response (error code: resource_missing, error: No such charge: ch_123456 or something similar)"));
    assertThat(refund.getError().get().getErrorType(), Is.is(GENERIC_GATEWAY_ERROR));
}
Also used : GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) Test(org.junit.Test)

Example 5 with GatewayRefundResponse

use of uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse in project pay-connector by alphagov.

the class StripeRefundHandlerTest method shouldNotRefund_whenStatusCode4xxOnRefund.

@Test
public void shouldNotRefund_whenStatusCode4xxOnRefund() throws Exception {
    mockTransferSuccess();
    mockRefund4xxResponse();
    final GatewayRefundResponse refund = refundHandler.refund(refundRequest);
    assertNotNull(refund);
    assertTrue(refund.getError().isPresent());
    assertThat(refund.state(), is(GatewayRefundResponse.RefundState.ERROR));
    assertThat(refund.getError().get().getMessage(), Is.is("Stripe refund response (error code: resource_missing, error: No such charge: ch_123456 or something similar)"));
    assertThat(refund.getError().get().getErrorType(), Is.is(GENERIC_GATEWAY_ERROR));
}
Also used : GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) Test(org.junit.Test)

Aggregations

GatewayRefundResponse (uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse)23 Test (org.junit.Test)17 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)9 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)6 RefundGatewayRequest (uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest)6 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)6 CaptureGatewayRequest (uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest)5 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)3 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)3 GatewayError (uk.gov.pay.connector.gateway.model.GatewayError)2 List (java.util.List)1 Inject (javax.inject.Inject)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1