use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST 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());
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.
the class ChargeServiceTest method shouldUpdateStateOrProvinceForChargeWhenCountryIsUs.
@Test
public void shouldUpdateStateOrProvinceForChargeWhenCountryIsUs() {
ChargeEntity chargeSpy = spy(ChargeEntityFixture.aValidChargeEntity().build());
ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
AuthCardDetails authCardDetails = new AuthCardDetails();
Address address = new Address();
address.setCountry("US");
address.setPostcode("20500");
authCardDetails.setAddress(address);
authCardDetails.setCardNo("1234567890");
when(chargeEvent.getStatus()).thenReturn(ENTERING_CARD_DETAILS);
when(chargeEvent.getUpdated()).thenReturn(now());
when(mockedChargeEventDao.persistChargeEventOf(chargeSpy, null)).thenReturn(chargeEvent);
when(mockedChargeDao.findByExternalId(chargeSpy.getExternalId())).thenReturn(Optional.of(chargeSpy));
when(mockNorthAmericanRegionMapper.getNorthAmericanRegionForCountry(any(Address.class))).thenAnswer((Answer<Optional<? extends NorthAmericaRegion>>) invocationOnMock -> Optional.of(UsState.WASHINGTON_DC));
when(chargeSpy.getEvents()).thenReturn(List.of(chargeEvent));
service.updateChargeAndEmitEventPostAuthorisation(chargeSpy.getExternalId(), ENTERING_CARD_DETAILS, authCardDetails, null, null, null, null, null);
assertThat(chargeSpy.getCardDetails().getBillingAddress().get().getStateOrProvince(), is("DC"));
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.
the class WorldpayPaymentProviderTest method should_retry_without_exemption_flag_when_authorising_with_exemption_flag_results_in_soft_decline.
@Test
void should_retry_without_exemption_flag_when_authorising_with_exemption_flag_results_in_soft_decline() throws Exception {
gatewayAccountEntity.setRequires3ds(true);
gatewayAccountEntity.setIntegrationVersion3ds(1);
gatewayAccountEntity.setWorldpay3dsFlexCredentialsEntity(aWorldpay3dsFlexCredentialsEntity().withExemptionEngine(true).build());
chargeEntityFixture.withGatewayAccountEntity(gatewayAccountEntity);
chargeEntityFixture.withStatus(ChargeStatus.AUTHORISATION_READY);
String gatewayTransactionId = randomUUID().toString();
chargeEntityFixture.withGatewayTransactionId(gatewayTransactionId);
ChargeEntity chargeEntity = chargeEntityFixture.build();
var cardAuthRequest = new CardAuthorisationGatewayRequest(chargeEntity, anAuthCardDetails().build());
when(worldpayAuthoriseHandler.authoriseWithExemption(cardAuthRequest)).thenReturn(getGatewayResponse(WORLDPAY_EXEMPTION_REQUEST_SOFT_DECLINE_RESULT_REJECTED_RESPONSE));
var secondResponse = getGatewayResponse(WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE);
when(worldpayAuthoriseHandler.authoriseWithoutExemption(cardAuthRequest)).thenReturn(secondResponse);
GatewayResponse<WorldpayOrderStatusResponse> response = worldpayPaymentProvider.authorise(cardAuthRequest);
assertTrue(response.getBaseResponse().isPresent());
assertEquals(secondResponse.getBaseResponse().get(), response.getBaseResponse().get());
assertNotEquals(cardAuthRequest.getCharge().getGatewayTransactionId(), gatewayTransactionId);
ArgumentCaptor<LoggingEvent> loggingEventArgumentCaptor = ArgumentCaptor.forClass(LoggingEvent.class);
verify(mockAppender, times(2)).doAppend(loggingEventArgumentCaptor.capture());
List<LoggingEvent> logs = loggingEventArgumentCaptor.getAllValues();
assertTrue(logs.stream().anyMatch(loggingEvent -> {
String log = format("Authorisation with billing address and with 3DS data and without device data " + "collection result for %s", chargeEntity.getExternalId());
return loggingEvent.getMessage().contains(log);
}));
assertTrue(logs.stream().anyMatch(loggingEvent -> {
String log = "Worldpay authorisation response (orderCode: transaction-id, lastEvent: REFUSED, " + "exemptionResponse result: REJECTED, exemptionResponse reason: HIGH_RISK)";
return loggingEvent.getMessage().contains(log);
}));
assertTrue(logs.stream().anyMatch(loggingEvent -> loggingEvent.getMessage().contains("AUTHORISATION READY -> AUTHORISATION READY")));
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType.TEST in project pay-connector by alphagov.
the class ChargeServiceTest method updateChargeAndEmitEventPostAuthorisation_shouldEmitEventWhenCountryIsInUnitedStates.
@Test
public void updateChargeAndEmitEventPostAuthorisation_shouldEmitEventWhenCountryIsInUnitedStates() {
ChargeEntity chargeSpy = spy(ChargeEntityFixture.aValidChargeEntity().build());
ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
AuthCardDetails authCardDetails = new AuthCardDetails();
Address address = new Address();
address.setCountry("US");
address.setPostcode("20500");
authCardDetails.setAddress(address);
authCardDetails.setCardNo("1234567890");
when(chargeEvent.getStatus()).thenReturn(ENTERING_CARD_DETAILS);
when(chargeEvent.getUpdated()).thenReturn(now());
when(mockedChargeEventDao.persistChargeEventOf(chargeSpy, null)).thenReturn(chargeEvent);
when(mockedChargeDao.findByExternalId(chargeSpy.getExternalId())).thenReturn(Optional.of(chargeSpy));
when(mockNorthAmericanRegionMapper.getNorthAmericanRegionForCountry(any(Address.class))).thenAnswer((Answer<Optional<? extends NorthAmericaRegion>>) invocationOnMock -> Optional.of(UsState.WASHINGTON_DC));
when(chargeSpy.getEvents()).thenReturn(List.of(chargeEvent));
service.updateChargeAndEmitEventPostAuthorisation(chargeSpy.getExternalId(), ENTERING_CARD_DETAILS, authCardDetails, null, null, null, null, null);
verify(mockEventService).emitAndRecordEvent(PaymentDetailsEntered.from(chargeSpy));
}
Aggregations