use of uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse in project pay-connector by alphagov.
the class WorldpayPaymentProvider method authorise3dsResponse.
@Override
public Gateway3DSAuthorisationResponse authorise3dsResponse(Auth3dsResponseGatewayRequest request) {
try {
List<HttpCookie> cookies = request.getProviderSessionId().map(providerSessionId -> singletonList(new HttpCookie(WORLDPAY_MACHINE_COOKIE_NAME, providerSessionId.toString()))).orElse(emptyList());
GatewayClient.Response response = authoriseClient.postRequestFor(gatewayUrlMap.get(request.getGatewayAccount().getType()), WORLDPAY, request.getGatewayAccount().getType(), build3dsResponseAuthOrder(request), cookies, getGatewayAccountCredentialsAsAuthHeader(request.getGatewayCredentials()));
GatewayResponse<WorldpayOrderStatusResponse> gatewayResponse = getWorldpayGatewayResponse(response);
calculateAndStoreExemption(request.getCharge(), gatewayResponse);
LOGGER.info(format("Worldpay 3ds authorisation response for %s : %s", request.getChargeExternalId(), sanitiseMessage(response.getEntity())));
if (gatewayResponse.getBaseResponse().isEmpty()) {
gatewayResponse.throwGatewayError();
}
BaseAuthoriseResponse authoriseResponse = gatewayResponse.getBaseResponse().get();
return Gateway3DSAuthorisationResponse.of(gatewayResponse.toString(), authoriseResponse.authoriseStatus(), authoriseResponse.getTransactionId(), authoriseResponse.getGatewayParamsFor3ds().orElse(null), gatewayResponse.getSessionIdentifier().orElse(null));
} catch (GatewayException e) {
return Gateway3DSAuthorisationResponse.of(e.getMessage(), BaseAuthoriseResponse.AuthoriseStatus.EXCEPTION);
}
}
use of uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse in project pay-connector by alphagov.
the class EpdqPaymentProviderTest method shouldCheckAuthorisationStatusSuccessfully.
@Test
public void shouldCheckAuthorisationStatusSuccessfully() throws Exception {
setUpAndCheckThatEpdqIsUp();
var request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetailsFixture().build());
GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
assertThat(response.isSuccessful(), is(true));
assertThat(response.getBaseResponse().get().authoriseStatus(), is(BaseAuthoriseResponse.AuthoriseStatus.AUTHORISED));
Gateway3DSAuthorisationResponse queryResponse = paymentProvider.authorise3dsResponse(buildQueryRequest(chargeEntity, Auth3dsResult.Auth3dsResultOutcome.AUTHORISED.name()));
assertThat(queryResponse.isSuccessful(), is(true));
assertThat(response.getBaseResponse().get().authoriseStatus(), is(BaseAuthoriseResponse.AuthoriseStatus.AUTHORISED));
}
use of uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse in project pay-connector by alphagov.
the class WorldpayPaymentProviderTest method should_construct_gateway_3DS_authorisation_response_with_paRequest_issuerUrl_and_machine_cookie_if_worldpay_asks_us_to_do_3ds_again.
@Test
void should_construct_gateway_3DS_authorisation_response_with_paRequest_issuerUrl_and_machine_cookie_if_worldpay_asks_us_to_do_3ds_again() throws Exception {
ChargeEntity chargeEntity = chargeEntityFixture.withProviderSessionId("original-machine-cookie").build();
when(response.getEntity()).thenReturn(load(WORLDPAY_3DS_RESPONSE));
when(response.getResponseCookies()).thenReturn(Map.of(WORLDPAY_MACHINE_COOKIE_NAME, "new-machine-cookie-value"));
when(authoriseClient.postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), eq(List.of(new HttpCookie(WORLDPAY_MACHINE_COOKIE_NAME, "original-machine-cookie"))), anyMap())).thenReturn(response);
var auth3dsResult = new Auth3dsResult();
auth3dsResult.setPaResponse("pa-response");
var auth3dsResponseGatewayRequest = new Auth3dsResponseGatewayRequest(chargeEntity, auth3dsResult);
Gateway3DSAuthorisationResponse result = worldpayPaymentProvider.authorise3dsResponse(auth3dsResponseGatewayRequest);
assertThat(result.getGateway3dsRequiredParams().isPresent(), is(true));
assertThat(result.getGateway3dsRequiredParams().get().toAuth3dsRequiredEntity().getPaRequest(), is("eJxVUsFuwjAM/ZWK80aSUgpFJogNpHEo2hjTzl"));
assertThat(result.getGateway3dsRequiredParams().get().toAuth3dsRequiredEntity().getIssuerUrl(), is("https://secure-test.worldpay.com/jsp/test/shopper/ThreeDResponseSimulator.jsp"));
assertThat(result.getProviderSessionIdentifier().isPresent(), is(true));
assertThat(result.getProviderSessionIdentifier().get(), is(ProviderSessionIdentifier.of("new-machine-cookie-value")));
}
use of uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldSetStatusToAuthorisationRejectedIfMaxAttemptsExceeded.
@Test
public void process3DSecureAuthorisation_shouldSetStatusToAuthorisationRejectedIfMaxAttemptsExceeded() {
Auth3dsResult auth3dsResult = AuthUtils.buildAuth3dsResult();
ArgumentCaptor<Auth3dsResponseGatewayRequest> argumentCaptor = ArgumentCaptor.forClass(Auth3dsResponseGatewayRequest.class);
when(mockedChargeDao.findByExternalId(charge.getExternalId())).thenReturn(Optional.of(charge));
when(mockAuthorisation3dsConfig.getMaximumNumberOfTimesToAllowUserToAttempt3ds()).thenReturn(3);
when(mockedChargeDao.count3dsRequiredEventsForChargeExternalId(charge.getExternalId())).thenReturn(3);
Gateway3dsRequiredParams gateway3dsRequiredParams = new Worldpay3dsRequiredParams(REQUIRES_3DS_ISSUER_URL, REQUIRES_3DS_PA_REQUEST);
setupMockExecutorServiceMock();
setupPaymentProviderMock(charge.getGatewayTransactionId(), AuthoriseStatus.REQUIRES_3DS, gateway3dsRequiredParams, ProviderSessionIdentifier.of("provider-session-identifier"), argumentCaptor);
when(mockedProviders.byName(charge.getPaymentGatewayName())).thenReturn(mockedPaymentProvider);
Gateway3DSAuthorisationResponse response = card3dsResponseAuthService.process3DSecureAuthorisation(charge.getExternalId(), auth3dsResult);
assertThat(response.isSuccessful(), is(false));
assertThat(charge.getStatus(), is(AUTHORISATION_REJECTED.getValue()));
}
use of uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldRespondAuthorisationSuccess.
@Test
public void process3DSecureAuthorisation_shouldRespondAuthorisationSuccess() {
Auth3dsResult auth3dsResult = AuthUtils.buildAuth3dsResult();
ArgumentCaptor<Auth3dsResponseGatewayRequest> argumentCaptor = ArgumentCaptor.forClass(Auth3dsResponseGatewayRequest.class);
when(mockedChargeDao.findByExternalId(charge.getExternalId())).thenReturn(Optional.of(charge));
setupMockExecutorServiceMock();
setupPaymentProviderMock(charge.getGatewayTransactionId(), AuthoriseStatus.AUTHORISED, null, null, argumentCaptor);
when(mockedProviders.byName(charge.getPaymentGatewayName())).thenReturn(mockedPaymentProvider);
Gateway3DSAuthorisationResponse response = card3dsResponseAuthService.process3DSecureAuthorisation(charge.getExternalId(), auth3dsResult);
assertThat(response.isSuccessful(), is(true));
assertThat(charge.getStatus(), is(AUTHORISATION_SUCCESS.getValue()));
assertThat(charge.getGatewayTransactionId(), is(GENERATED_TRANSACTION_ID));
assertTrue(argumentCaptor.getValue().getTransactionId().isPresent());
assertThat(argumentCaptor.getValue().getTransactionId().get(), is(GENERATED_TRANSACTION_ID));
}
Aggregations