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());
}
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);
}
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);
}
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));
}
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));
}
Aggregations