Search in sources :

Example 1 with ChargeStatus

use of uk.gov.pay.connector.charge.model.domain.ChargeStatus 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");
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) StructuredArgument(net.logstash.logback.argument.StructuredArgument) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Gateway3dsRequiredParams(uk.gov.pay.connector.gateway.model.Gateway3dsRequiredParams)

Example 2 with ChargeStatus

use of uk.gov.pay.connector.charge.model.domain.ChargeStatus in project pay-connector by alphagov.

the class ChargingITestBase method addChargeAndCardDetails.

protected String addChargeAndCardDetails(Long chargeId, ChargeStatus status, ServicePaymentReference reference, Instant fromDate, String cardBrand) {
    String externalChargeId = "charge" + chargeId;
    ChargeStatus chargeStatus = status != null ? status : AUTHORISATION_SUCCESS;
    addCharge(chargeId, externalChargeId, chargeStatus, reference, fromDate, null, paymentProvider);
    databaseTestHelper.addToken(chargeId, "tokenId");
    databaseTestHelper.addEvent(chargeId, chargeStatus.getValue());
    databaseTestHelper.updateChargeCardDetails(chargeId, cardBrand, "1234", "123456", "Mr. McPayment", CardExpiryDate.valueOf("03/18"), null, "line1", null, "postcode", "city", null, "country");
    return externalChargeId;
}
Also used : ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString)

Example 3 with ChargeStatus

use of uk.gov.pay.connector.charge.model.domain.ChargeStatus in project pay-connector by alphagov.

the class ChargingITestBase method addCharge.

protected String addCharge(ChargeStatus status, String reference, Instant fromDate, String transactionId) {
    long chargeId = RandomUtils.nextInt();
    String externalChargeId = "charge" + chargeId;
    ChargeStatus chargeStatus = status != null ? status : AUTHORISATION_SUCCESS;
    addCharge(chargeId, externalChargeId, status, ServicePaymentReference.of(reference), fromDate, transactionId, paymentProvider);
    databaseTestHelper.addToken(chargeId, "tokenId");
    databaseTestHelper.addEvent(chargeId, chargeStatus.getValue());
    databaseTestHelper.updateChargeCardDetails(chargeId, AuthCardDetailsFixture.anAuthCardDetails().build());
    return externalChargeId;
}
Also used : ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString)

Example 4 with ChargeStatus

use of uk.gov.pay.connector.charge.model.domain.ChargeStatus in project pay-connector by alphagov.

the class ChargeDaoIT method testFindByDate_status_findsValidChargeForStatus.

@Test
public void testFindByDate_status_findsValidChargeForStatus() {
    TestCharge charge = DatabaseFixtures.withDatabaseTestHelper(databaseTestHelper).aTestCharge().withTestAccount(defaultTestAccount).withChargeId(nextLong()).withExternalChargeId(RandomIdGenerator.newId()).withCreatedDate(Instant.now().minus(Duration.ofHours(2))).insert();
    ArrayList<ChargeStatus> chargeStatuses = Lists.newArrayList(CREATED, ENTERING_CARD_DETAILS, AUTHORISATION_SUCCESS);
    List<ChargeEntity> charges = chargeDao.findBeforeDateWithStatusIn(Instant.now().minus(Duration.ofHours(1)), chargeStatuses);
    assertThat(charges.size(), is(1));
    assertEquals(charges.get(0).getId(), charge.getChargeId());
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) TestCharge(uk.gov.pay.connector.it.dao.DatabaseFixtures.TestCharge) Test(org.junit.Test)

Example 5 with ChargeStatus

use of uk.gov.pay.connector.charge.model.domain.ChargeStatus in project pay-connector by alphagov.

the class ChargeService method transitionChargeState.

@Transactional
public ChargeEntity transitionChargeState(ChargeEntity charge, ChargeStatus targetChargeState, ZonedDateTime gatewayEventTime) {
    ChargeStatus fromChargeState = ChargeStatus.fromString(charge.getStatus());
    charge.setStatus(targetChargeState);
    ChargeEventEntity chargeEventEntity = chargeEventDao.persistChargeEventOf(charge, gatewayEventTime);
    if (shouldEmitPaymentStateTransitionEvents) {
        stateTransitionService.offerPaymentStateTransition(charge.getExternalId(), fromChargeState, targetChargeState, chargeEventEntity);
    }
    taskQueueService.offerTasksOnStateTransition(charge);
    return charge;
}
Also used : ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Transactional(com.google.inject.persist.Transactional)

Aggregations

ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)23 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)12 ExpirableChargeStatus (uk.gov.pay.connector.charge.model.domain.ExpirableChargeStatus)6 GatewayException (uk.gov.pay.connector.gateway.GatewayException)6 Charge (uk.gov.pay.connector.charge.model.domain.Charge)5 Transactional (com.google.inject.persist.Transactional)4 ChargeQueryGatewayRequest (uk.gov.pay.connector.gateway.ChargeQueryGatewayRequest)4 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)4 String.format (java.lang.String.format)3 List (java.util.List)3 Optional (java.util.Optional)3 Inject (javax.inject.Inject)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)3 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)3 ChargeQueryResponse (uk.gov.pay.connector.gateway.ChargeQueryResponse)3 BaseCancelResponse (uk.gov.pay.connector.gateway.model.response.BaseCancelResponse)3 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)3