Search in sources :

Example 1 with PaymentWebhookResult

use of alfio.manager.support.PaymentWebhookResult in project alf.io by alfio-event.

the class StripeWebhookPaymentManager method forceTransactionCheck.

@Override
public PaymentWebhookResult forceTransactionCheck(TicketReservation reservation, Transaction transaction, PaymentContext paymentContext) {
    Validate.isTrue(transaction.getPaymentProxy() == PaymentProxy.STRIPE, "invalid transaction");
    try {
        PurchaseContext purchaseContext = paymentContext.getPurchaseContext();
        var options = baseStripeManager.options(purchaseContext, builder -> builder.setIdempotencyKey(reservation.getId())).orElseThrow();
        var intent = PaymentIntent.retrieve(transaction.getPaymentId(), options);
        switch(intent.getStatus()) {
            case "processing":
            case "requires_action":
            case "requires_confirmation":
                return PaymentWebhookResult.pending();
            case "succeeded":
                return processSuccessfulPaymentIntent(transaction, intent, reservation, purchaseContext);
            case REQUIRES_PAYMENT_METHOD:
                // payment is failed.
                return processFailedPaymentIntent(transaction, reservation, purchaseContext);
            default:
                return null;
        }
    } catch (Exception ex) {
        log.error("Error trying to check PaymentIntent status", ex);
        return PaymentWebhookResult.error("failed");
    }
}
Also used : alfio.repository(alfio.repository) java.util(java.util) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) ZonedDateTime(java.time.ZonedDateTime) PaymentResult(alfio.manager.support.PaymentResult) PurchaseContext(alfio.model.PurchaseContext) ConfigurationManager(alfio.manager.system.ConfigurationManager) JsonParser(com.google.gson.JsonParser) PaymentInformation(alfio.model.PaymentInformation) Charge(com.stripe.model.Charge) alfio.model.transaction.capabilities(alfio.model.transaction.capabilities) PaymentIntent(com.stripe.model.PaymentIntent) alfio.model.transaction(alfio.model.transaction) StripeChargeTransactionWebhookPayload(alfio.model.transaction.webhook.StripeChargeTransactionWebhookPayload) StripePaymentIntentWebhookPayload(alfio.model.transaction.webhook.StripePaymentIntentWebhookPayload) StripeException(com.stripe.exception.StripeException) Stripe(com.stripe.Stripe) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) Audit(alfio.model.Audit) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) StringReader(java.io.StringReader) StripeSCACreditCardToken(alfio.model.transaction.token.StripeSCACreditCardToken) Environment(org.springframework.core.env.Environment) STRIPE_MANAGER_TYPE_KEY(alfio.manager.payment.BaseStripeManager.STRIPE_MANAGER_TYPE_KEY) TicketReservation(alfio.model.TicketReservation) Log4j2(lombok.extern.log4j.Log4j2) PaymentWebhookResult(alfio.manager.support.PaymentWebhookResult) StripeObject(com.stripe.model.StripeObject) ClockProvider(alfio.util.ClockProvider) EXTERNAL_PROCESSING_PAYMENT(alfio.model.TicketReservation.TicketReservationStatus.EXTERNAL_PROCESSING_PAYMENT) ConfigurationKeys(alfio.model.system.ConfigurationKeys) WAITING_EXTERNAL_CONFIRMATION(alfio.model.TicketReservation.TicketReservationStatus.WAITING_EXTERNAL_CONFIRMATION) BalanceTransaction(com.stripe.model.BalanceTransaction) Webhook(com.stripe.net.Webhook) Transactional(org.springframework.transaction.annotation.Transactional) PurchaseContext(alfio.model.PurchaseContext) StripeException(com.stripe.exception.StripeException)

Aggregations

STRIPE_MANAGER_TYPE_KEY (alfio.manager.payment.BaseStripeManager.STRIPE_MANAGER_TYPE_KEY)1 PaymentResult (alfio.manager.support.PaymentResult)1 PaymentWebhookResult (alfio.manager.support.PaymentWebhookResult)1 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 Audit (alfio.model.Audit)1 PaymentInformation (alfio.model.PaymentInformation)1 PurchaseContext (alfio.model.PurchaseContext)1 TicketReservation (alfio.model.TicketReservation)1 EXTERNAL_PROCESSING_PAYMENT (alfio.model.TicketReservation.TicketReservationStatus.EXTERNAL_PROCESSING_PAYMENT)1 WAITING_EXTERNAL_CONFIRMATION (alfio.model.TicketReservation.TicketReservationStatus.WAITING_EXTERNAL_CONFIRMATION)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 alfio.model.transaction (alfio.model.transaction)1 alfio.model.transaction.capabilities (alfio.model.transaction.capabilities)1 StripeSCACreditCardToken (alfio.model.transaction.token.StripeSCACreditCardToken)1 StripeChargeTransactionWebhookPayload (alfio.model.transaction.webhook.StripeChargeTransactionWebhookPayload)1 StripePaymentIntentWebhookPayload (alfio.model.transaction.webhook.StripePaymentIntentWebhookPayload)1 alfio.repository (alfio.repository)1 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)1 ClockProvider (alfio.util.ClockProvider)1