use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialState.ACTIVE in project pay-connector by alphagov.
the class WorldpayRefundHandlerTest method test_refund_request_contains_reference.
@Test
void test_refund_request_contains_reference() throws Exception {
RefundEntity refundEntity = RefundEntityFixture.aValidRefundEntity().build();
GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of(CREDENTIALS_MERCHANT_ID, "MERCHANTCODE", CREDENTIALS_USERNAME, "worldpay-password", CREDENTIALS_PASSWORD, "password")).withGatewayAccountEntity(gatewayAccountEntity).withPaymentProvider(WORLDPAY.getName()).withState(ACTIVE).build();
ChargeEntity chargeEntity = chargeEntityFixture.withTransactionId("transaction-id").withGatewayAccountCredentialsEntity(credentialsEntity).withPaymentProvider(WORLDPAY.getName()).build();
gatewayAccountEntity.setGatewayAccountCredentials(List.of(credentialsEntity));
when(refundGatewayClient.postRequestFor(any(URI.class), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), anyMap())).thenThrow(new GatewayException.GatewayErrorException("Unexpected HTTP status code 400 from gateway"));
worldpayRefundHandler.refund(RefundGatewayRequest.valueOf(Charge.from(chargeEntity), refundEntity, gatewayAccountEntity, credentialsEntity));
String expectedRefundRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE paymentService PUBLIC \"-//WorldPay//DTD WorldPay PaymentService v1//EN\"\n" + " \"http://dtd.worldpay.com/paymentService_v1.dtd\">\n" + "<paymentService version=\"1.4\" merchantCode=\"MERCHANTCODE\">\n" + " <modify>\n" + " <orderModification orderCode=\"transaction-id\">\n" + " <refund reference=\"" + refundEntity.getExternalId() + "\">\n" + " <amount currencyCode=\"GBP\" exponent=\"2\" value=\"500\"/>\n" + " </refund>\n" + " </orderModification>\n" + " </modify>\n" + "</paymentService>\n" + "";
verify(refundGatewayClient).postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), argThat(argument -> argument.getPayload().equals(expectedRefundRequest) && argument.getOrderRequestType().equals(OrderRequestType.REFUND)), anyMap());
}
Aggregations