use of uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier in project pay-connector by alphagov.
the class WalletAuthoriseService method doAuthorise.
public GatewayResponse<BaseAuthoriseResponse> doAuthorise(String chargeId, WalletAuthorisationData walletAuthorisationData) {
return authorisationService.executeAuthorise(chargeId, () -> {
final ChargeEntity charge = prepareChargeForAuthorisation(chargeId);
GatewayResponse<BaseAuthoriseResponse> operationResponse;
ChargeStatus chargeStatus = null;
String requestStatus = "failure";
try {
operationResponse = authorise(charge, walletAuthorisationData);
if (operationResponse.getBaseResponse().isPresent()) {
requestStatus = "success";
chargeStatus = operationResponse.getBaseResponse().get().authoriseStatus().getMappedChargeStatus();
} else {
operationResponse.throwGatewayError();
}
} catch (GatewayException e) {
LOGGER.error("Error occurred authorising charge. Charge external id: {}; message: {}", charge.getExternalId(), e.getMessage());
if (e instanceof GatewayErrorException) {
LOGGER.error("Response from gateway: {}", ((GatewayErrorException) e).getResponseFromGateway());
}
chargeStatus = AuthorisationService.mapFromGatewayErrorException(e);
operationResponse = GatewayResponse.GatewayResponseBuilder.responseBuilder().withGatewayError(e.toGatewayError()).build();
}
Optional<String> transactionId = authorisationService.extractTransactionId(charge.getExternalId(), operationResponse);
Optional<ProviderSessionIdentifier> sessionIdentifier = operationResponse.getSessionIdentifier();
Optional<Auth3dsRequiredEntity> auth3dsDetailsEntity = operationResponse.getBaseResponse().flatMap(BaseAuthoriseResponse::extractAuth3dsRequiredDetails);
logMetrics(charge, operationResponse, requestStatus, walletAuthorisationData.getWalletType());
processGatewayAuthorisationResponse(charge.getExternalId(), walletAuthorisationData, transactionId.orElse(null), sessionIdentifier.orElse(null), chargeStatus, auth3dsDetailsEntity);
authorisationLogger.logChargeAuthorisation(LOGGER, charge, transactionId.orElse("missing transaction ID"), operationResponse, charge.getChargeStatus(), chargeStatus);
return operationResponse;
});
}
use of uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier in project pay-connector by alphagov.
the class Card3dsResponseAuthServiceTest method process3DSecureAuthorisation_shouldPopulateTheProviderSessionId.
@Test
public void process3DSecureAuthorisation_shouldPopulateTheProviderSessionId() {
Auth3dsResult auth3dsResult = AuthUtils.buildAuth3dsResult();
ProviderSessionIdentifier providerSessionId = ProviderSessionIdentifier.of("provider-session-id");
charge.setProviderSessionId(providerSessionId.toString());
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);
card3dsResponseAuthService.process3DSecureAuthorisation(charge.getExternalId(), auth3dsResult);
assertTrue(argumentCaptor.getValue().getProviderSessionId().isPresent());
assertThat(argumentCaptor.getValue().getProviderSessionId().get(), is(providerSessionId));
}
use of uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier in project pay-connector by alphagov.
the class CardAuthoriseService method doAuthorise.
public AuthorisationResponse doAuthorise(String chargeId, AuthCardDetails authCardDetails) {
return authorisationService.executeAuthorise(chargeId, () -> {
final ChargeEntity charge = prepareChargeForAuthorisation(chargeId, authCardDetails);
GatewayResponse<BaseAuthoriseResponse> operationResponse;
ChargeStatus newStatus;
try {
operationResponse = authorise(charge, authCardDetails);
if (operationResponse.getBaseResponse().isEmpty()) {
operationResponse.throwGatewayError();
}
newStatus = operationResponse.getBaseResponse().get().authoriseStatus().getMappedChargeStatus();
} catch (GatewayException e) {
newStatus = AuthorisationService.mapFromGatewayErrorException(e);
operationResponse = GatewayResponse.GatewayResponseBuilder.responseBuilder().withGatewayError(e.toGatewayError()).build();
}
Optional<String> transactionId = authorisationService.extractTransactionId(charge.getExternalId(), operationResponse);
Optional<ProviderSessionIdentifier> sessionIdentifier = operationResponse.getSessionIdentifier();
Optional<Auth3dsRequiredEntity> auth3dsDetailsEntity = operationResponse.getBaseResponse().flatMap(BaseAuthoriseResponse::extractAuth3dsRequiredDetails);
ChargeEntity updatedCharge = chargeService.updateChargePostCardAuthorisation(charge.getExternalId(), newStatus, transactionId.orElse(null), auth3dsDetailsEntity.orElse(null), sessionIdentifier.orElse(null), authCardDetails);
var authorisationRequestSummary = generateAuthorisationRequestSummary(charge, authCardDetails);
authorisationLogger.logChargeAuthorisation(LOGGER, authorisationRequestSummary, updatedCharge, transactionId.orElse("missing transaction ID"), operationResponse, charge.getChargeStatus(), newStatus);
metricRegistry.counter(String.format("gateway-operations.%s.%s.authorise.%s.result.%s", updatedCharge.getPaymentProvider(), updatedCharge.getGatewayAccount().getType(), authorisationRequestSummary.billingAddress() == PRESENT ? "with-billing-address" : "without-billing-address", newStatus.toString())).inc();
return new AuthorisationResponse(operationResponse);
});
}
Aggregations