Search in sources :

Example 1 with Gateway3DSAuthorisationResponse

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);
    }
}
Also used : WorldpayWalletAuthorisationHandler(uk.gov.pay.connector.gateway.worldpay.wallets.WorldpayWalletAuthorisationHandler) DefaultExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.DefaultExternalRefundAvailabilityCalculator) WorldpayOrderRequestBuilder.aWorldpayCancelOrderRequestBuilder(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderRequestBuilder.aWorldpayCancelOrderRequestBuilder) Worldpay3dsFlexCredentials(uk.gov.pay.connector.gatewayaccount.model.Worldpay3dsFlexCredentials) LoggerFactory(org.slf4j.LoggerFactory) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CREDENTIALS_MERCHANT_ID(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID) Transactional(com.google.inject.persist.Transactional) Collections.singletonList(java.util.Collections.singletonList) HttpCookie(java.net.HttpCookie) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) EXEMPTION_OUT_OF_SCOPE(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_OUT_OF_SCOPE) Map(java.util.Map) ChargeQueryGatewayRequest(uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest) URI(java.net.URI) Exemption3ds(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds) Gateway3dsExemptionResultObtained(uk.gov.pay.connector.events.model.charge.Gateway3dsExemptionResultObtained) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) EXEMPTION_REJECTED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_REJECTED) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) Collections.emptyList(java.util.Collections.emptyList) ChargeQueryResponse(uk.gov.pay.connector.gateway.ChargeQueryResponse) String.format(java.lang.String.format) WorldpayOrderRequestBuilder.aWorldpayInquiryRequestBuilder(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderRequestBuilder.aWorldpayInquiryRequestBuilder) List(java.util.List) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) UTC(java.time.ZoneOffset.UTC) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) EXEMPTION_HONOURED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_HONOURED) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) AuthorisationService(uk.gov.pay.connector.paymentprocessor.service.AuthorisationService) EventService(uk.gov.pay.connector.events.EventService) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Inject(javax.inject.Inject) Charge(uk.gov.pay.connector.charge.model.domain.Charge) Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) AuthorisationLogger(uk.gov.pay.connector.logging.AuthorisationLogger) ExternalChargeRefundAvailability(uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability) WalletAuthorisationGatewayRequest(uk.gov.pay.connector.wallets.WalletAuthorisationGatewayRequest) Named(javax.inject.Named) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) Logger(org.slf4j.Logger) ExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.ExternalRefundAvailabilityCalculator) AuthUtil.getGatewayAccountCredentialsAsAuthHeader(uk.gov.pay.connector.gateway.util.AuthUtil.getGatewayAccountCredentialsAsAuthHeader) BaseCancelResponse(uk.gov.pay.connector.gateway.model.response.BaseCancelResponse) ChargeDao(uk.gov.pay.connector.charge.dao.ChargeDao) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) WorldpayOrderRequestBuilder.aWorldpay3dsResponseAuthOrderRequestBuilder(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderRequestBuilder.aWorldpay3dsResponseAuthOrderRequestBuilder) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) UUID.randomUUID(java.util.UUID.randomUUID) EXEMPTION_NOT_REQUESTED(uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_NOT_REQUESTED) Refund(uk.gov.pay.connector.refund.model.domain.Refund) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) CancelGatewayRequest(uk.gov.pay.connector.gateway.model.request.CancelGatewayRequest) GatewayResponse(uk.gov.pay.connector.gateway.model.response.GatewayResponse) ZonedDateTime.now(java.time.ZonedDateTime.now) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) GatewayException(uk.gov.pay.connector.gateway.GatewayException) HttpCookie(java.net.HttpCookie)

Example 2 with Gateway3DSAuthorisationResponse

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));
}
Also used : BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 3 with Gateway3DSAuthorisationResponse

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")));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) Auth3dsResult(uk.gov.pay.connector.gateway.model.Auth3dsResult) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) HttpCookie(java.net.HttpCookie) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) Test(org.junit.jupiter.api.Test)

Example 4 with Gateway3DSAuthorisationResponse

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()));
}
Also used : Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) Auth3dsResult(uk.gov.pay.connector.gateway.model.Auth3dsResult) Worldpay3dsRequiredParams(uk.gov.pay.connector.gateway.worldpay.Worldpay3dsRequiredParams) Gateway3dsRequiredParams(uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) Test(org.junit.Test)

Example 5 with Gateway3DSAuthorisationResponse

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));
}
Also used : Auth3dsResponseGatewayRequest(uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest) Auth3dsResult(uk.gov.pay.connector.gateway.model.Auth3dsResult) Gateway3DSAuthorisationResponse(uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse) Test(org.junit.Test)

Aggregations

Gateway3DSAuthorisationResponse (uk.gov.pay.connector.gateway.model.response.Gateway3DSAuthorisationResponse)25 Test (org.junit.Test)21 Auth3dsResponseGatewayRequest (uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest)21 Auth3dsResult (uk.gov.pay.connector.gateway.model.Auth3dsResult)7 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)5 Gateway3dsRequiredParams (uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams)3 HttpCookie (java.net.HttpCookie)2 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)2 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)2 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)2 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)2 Worldpay3dsRequiredParams (uk.gov.pay.connector.gateway.worldpay.Worldpay3dsRequiredParams)2 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)2 Transactional (com.google.inject.persist.Transactional)1 String.format (java.lang.String.format)1 URI (java.net.URI)1 UTC (java.time.ZoneOffset.UTC)1 ZonedDateTime.now (java.time.ZonedDateTime.now)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1