Search in sources :

Example 1 with ProviderSessionIdentifier

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;
    });
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) GatewayErrorException(uk.gov.pay.connector.gateway.GatewayException.GatewayErrorException) ProviderSessionIdentifier(uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier) GatewayException(uk.gov.pay.connector.gateway.GatewayException) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)

Example 2 with ProviderSessionIdentifier

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

Example 3 with ProviderSessionIdentifier

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);
    });
}
Also used : AuthorisationResponse(uk.gov.pay.connector.paymentprocessor.api.AuthorisationResponse) ProviderSessionIdentifier(uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) GatewayException(uk.gov.pay.connector.gateway.GatewayException)

Aggregations

ProviderSessionIdentifier (uk.gov.pay.connector.gateway.model.ProviderSessionIdentifier)3 Auth3dsRequiredEntity (uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)2 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)2 ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)2 GatewayException (uk.gov.pay.connector.gateway.GatewayException)2 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)2 Test (org.junit.Test)1 GatewayErrorException (uk.gov.pay.connector.gateway.GatewayException.GatewayErrorException)1 Auth3dsResult (uk.gov.pay.connector.gateway.model.Auth3dsResult)1 Auth3dsResponseGatewayRequest (uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest)1 AuthorisationResponse (uk.gov.pay.connector.paymentprocessor.api.AuthorisationResponse)1