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");
}
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;
}
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;
}
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());
}
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;
}
Aggregations