use of uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams in project pay-connector by alphagov.
the class Card3dsResponseAuthService method processGateway3DSecureResponse.
private void processGateway3DSecureResponse(String chargeExternalId, ChargeStatus oldChargeStatus, Gateway3DSAuthorisationResponse operationResponse, Auth3dsResult auth3dsResult) {
Optional<String> transactionId = operationResponse.getTransactionId();
ChargeStatus newStatus = operationResponse.getMappedChargeStatus();
if (newStatus == AUTHORISATION_3DS_REQUIRED) {
int numberOf3dsRequiredEventsRecorded = chargeService.count3dsRequiredEvents(chargeExternalId);
if (numberOf3dsRequiredEventsRecorded < authorisation3dsConfig.getMaximumNumberOfTimesToAllowUserToAttempt3ds()) {
LOGGER.info("Gateway instructed us to send the user through 3DS again for {} — this will be attempt {} of {}", chargeExternalId, numberOf3dsRequiredEventsRecorded + 1, authorisation3dsConfig.getMaximumNumberOfTimesToAllowUserToAttempt3ds());
} else {
newStatus = AUTHORISATION_REJECTED;
LOGGER.info("Gateway instructed us to send the user through 3DS again for {} but there have already been {} attempts in total, " + "so treating authorisation as rejected", chargeExternalId, numberOf3dsRequiredEventsRecorded);
}
}
LOGGER.info("3DS response authorisation for {} - {} .'. about to attempt charge update from {} -> {}", chargeExternalId, operationResponse, oldChargeStatus, newStatus);
ChargeEntity updatedCharge = chargeService.updateChargePost3dsAuthorisation(chargeExternalId, newStatus, AUTHORISATION_3DS, transactionId.orElse(null), operationResponse.getGateway3dsRequiredParams().map(Gateway3dsRequiredParams::toAuth3dsRequiredEntity).orElse(null), operationResponse.getProviderSessionIdentifier().orElse(null));
var worldPay3dsOrFlexLogMessage = integration3dsType(auth3dsResult, updatedCharge);
var structuredLoggingArguments = updatedCharge.getStructuredLoggingArgs();
if (worldPay3dsOrFlexLogMessage == WORLDPAY_3DS_CLASSIC) {
structuredLoggingArguments = ArrayUtils.addAll(structuredLoggingArguments, new StructuredArgument[] { kv(INTEGRATION_3DS_VERSION, "3DS") });
} else if (worldPay3dsOrFlexLogMessage == WORLDPAY_3DS_FLEX) {
structuredLoggingArguments = ArrayUtils.addAll(structuredLoggingArguments, new StructuredArgument[] { kv(INTEGRATION_3DS_VERSION, "3DS Flex") });
}
var logMessage = String.format(Locale.UK, "3DS authentication result%s authorisation for %s (%s %s) for %s (%s) - %s .'. %s -> %s", worldPay3dsOrFlexLogMessage.getLogMessage(), updatedCharge.getExternalId(), updatedCharge.getPaymentGatewayName().getName(), updatedCharge.getGatewayTransactionId(), updatedCharge.getGatewayAccount().getAnalyticsId(), updatedCharge.getGatewayAccount().getId(), operationResponse, oldChargeStatus, updatedCharge.getStatus());
LOGGER.info(logMessage, structuredLoggingArguments);
authorisationService.emitAuthorisationMetric(updatedCharge, "authorise-3ds");
}
use of uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams 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.Gateway3dsRequiredParams in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldSetStatusToAuthorisation3dsRequiredIfMaxAttemptsNotExceeded.
@Test
public void process3DSecureAuthorisation_shouldSetStatusToAuthorisation3dsRequiredIfMaxAttemptsNotExceeded() {
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(2);
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_3DS_REQUIRED.getValue()));
}
use of uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldStoreWorldpay3dsFlexRequiredParams.
@Test
public void process3DSecureAuthorisation_shouldStoreWorldpay3dsFlexRequiredParams() {
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);
Gateway3dsRequiredParams gateway3dsRequiredParams = new Worldpay3dsFlexRequiredParams(REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_ACS_URL, REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_TRANSACTION_ID, REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_PAYLOAD, REQUIRES_3DS_WORLDPAY_3DS_FLEX_3DS_VERSION);
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_3DS_REQUIRED.getValue()));
assertThat(charge.getGatewayTransactionId(), is(GENERATED_TRANSACTION_ID));
assertThat(charge.get3dsRequiredDetails().getWorldpayChallengeAcsUrl(), is(REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_ACS_URL));
assertThat(charge.get3dsRequiredDetails().getWorldpayChallengeTransactionId(), is(REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_TRANSACTION_ID));
assertThat(charge.get3dsRequiredDetails().getWorldpayChallengePayload(), is(REQUIRES_3DS_WORLDPAY_3DS_FLEX_CHALLENGE_PAYLOAD));
assertThat(charge.get3dsRequiredDetails().getThreeDsVersion(), is(REQUIRES_3DS_WORLDPAY_3DS_FLEX_3DS_VERSION));
assertThat(charge.getProviderSessionId(), is("provider-session-identifier"));
assertTrue(argumentCaptor.getValue().getTransactionId().isPresent());
assertThat(argumentCaptor.getValue().getTransactionId().get(), is(GENERATED_TRANSACTION_ID));
}
use of uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldStoreWorldpay3dsRequiredParams.
@Test
public void process3DSecureAuthorisation_shouldStoreWorldpay3dsRequiredParams() {
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);
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_3DS_REQUIRED.getValue()));
assertThat(charge.getGatewayTransactionId(), is(GENERATED_TRANSACTION_ID));
assertThat(charge.get3dsRequiredDetails().getIssuerUrl(), is(REQUIRES_3DS_ISSUER_URL));
assertThat(charge.get3dsRequiredDetails().getPaRequest(), is(REQUIRES_3DS_PA_REQUEST));
assertThat(charge.getProviderSessionId(), is("provider-session-identifier"));
assertTrue(argumentCaptor.getValue().getTransactionId().isPresent());
assertThat(argumentCaptor.getValue().getTransactionId().get(), is(GENERATED_TRANSACTION_ID));
}
Aggregations