use of uk.gov.pay.connector.charge.model.domain.ChargeEntity in project pay-connector by alphagov.
the class DiscrepancyService method resolve.
private GatewayStatusComparison resolve(GatewayStatusComparison gatewayStatusComparison) {
if (canBeCancelled(gatewayStatusComparison)) {
ChargeEntity chargeEntity = chargeService.findChargeByExternalId(gatewayStatusComparison.getCharge().getExternalId());
boolean cancelSuccess = expiryService.forceCancelWithGateway(chargeEntity);
if (cancelSuccess) {
LOGGER.info("Successfully resolved discrepancy for charge {} ", gatewayStatusComparison.getChargeId());
gatewayStatusComparison.setProcessed(true);
} else {
LOGGER.info("Failed to resolve discrepancy for charge {} ", gatewayStatusComparison.getChargeId());
}
} else {
LOGGER.info("Could not resolve discrepancy for charge {} ", gatewayStatusComparison.getChargeId());
}
return gatewayStatusComparison;
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntity 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.ChargeEntity in project pay-connector by alphagov.
the class CardCaptureService method doCapture.
public CaptureResponse doCapture(String externalId) {
ChargeEntity charge;
try {
charge = prepareChargeForCapture(externalId);
} catch (OptimisticLockException e) {
LOG.info("OptimisticLockException in doCapture for charge external_id={}", externalId);
throw new ConflictRuntimeException(externalId);
}
CaptureResponse operationResponse = capture(charge);
processGatewayCaptureResponse(externalId, charge.getStatus(), operationResponse);
return operationResponse;
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntity in project pay-connector by alphagov.
the class CardCaptureService method markChargeAsEligibleForCapture.
public ChargeEntity markChargeAsEligibleForCapture(String externalId) {
ChargeEntity charge = chargeService.markChargeAsEligibleForCapture(externalId);
if (!charge.isDelayedCapture()) {
addChargeToCaptureQueue(charge);
userNotificationService.sendPaymentConfirmedEmail(charge, charge.getGatewayAccount());
}
return charge;
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntity in project pay-connector by alphagov.
the class CardCaptureService method markDelayedCaptureChargeAsCaptureApproved.
public ChargeEntity markDelayedCaptureChargeAsCaptureApproved(String externalId) {
ChargeEntity charge = chargeService.markDelayedCaptureChargeAsCaptureApproved(externalId);
addChargeToCaptureQueue(charge);
return charge;
}
Aggregations