Search in sources :

Example 1 with CREDENTIALS_MERCHANT_ID

use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CREDENTIALS_MERCHANT_ID(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Charge(uk.gov.pay.connector.charge.model.domain.Charge) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) URI(java.net.URI) CREDENTIALS_PASSWORD(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_PASSWORD) OrderRequestType(uk.gov.pay.connector.gateway.model.OrderRequestType) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TEST(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) Mockito.when(org.mockito.Mockito.when) ACTIVE(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialState.ACTIVE) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CREDENTIALS_USERNAME(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_USERNAME) List(java.util.List) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) RefundEntityFixture(uk.gov.pay.connector.model.domain.RefundEntityFixture) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) URI(java.net.URI) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test)

Aggregations

URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 Mock (org.mockito.Mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1 Charge (uk.gov.pay.connector.charge.model.domain.Charge)1 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)1 ChargeEntityFixture (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture)1 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)1 GatewayClient (uk.gov.pay.connector.gateway.GatewayClient)1 GatewayException (uk.gov.pay.connector.gateway.GatewayException)1