Search in sources :

Example 1 with ChargeEntity

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;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity)

Example 2 with ChargeEntity

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");
}
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 3 with ChargeEntity

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;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) OptimisticLockException(javax.persistence.OptimisticLockException) ConflictRuntimeException(uk.gov.pay.connector.common.exception.ConflictRuntimeException)

Example 4 with ChargeEntity

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;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity)

Example 5 with ChargeEntity

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;
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity)

Aggregations

ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)320 Test (org.junit.Test)208 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)163 Test (org.junit.jupiter.api.Test)50 Charge (uk.gov.pay.connector.charge.model.domain.Charge)40 List (java.util.List)27 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)26 URI (java.net.URI)25 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)25 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)21 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)21 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)20 PaymentGatewayName (uk.gov.pay.connector.gateway.PaymentGatewayName)20 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)20 Mockito.anyString (org.mockito.Mockito.anyString)19 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)18 Parameters (junitparams.Parameters)16 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)16 ChargeQueryResponse (uk.gov.pay.connector.gateway.ChargeQueryResponse)15 Optional (java.util.Optional)14