Search in sources :

Example 1 with StripePaymentIntentWebhookPayload

use of alfio.model.transaction.webhook.StripePaymentIntentWebhookPayload in project alf.io by alfio-event.

the class StripeWebhookPaymentManager method parseTransactionPayload.

@Override
public Optional<TransactionWebhookPayload> parseTransactionPayload(String body, String signature, Map<String, String> additionalInfo, PaymentContext paymentContext) {
    try {
        var stripeEvent = Webhook.constructEvent(body, signature, getWebhookSignatureKey(paymentContext.getConfigurationLevel()));
        String eventType = stripeEvent.getType();
        if (eventType.startsWith("charge.")) {
            return deserializeObject(stripeEvent).map(obj -> new StripeChargeTransactionWebhookPayload(eventType, (Charge) obj));
        } else if (eventType.startsWith("payment_intent.")) {
            return deserializeObject(stripeEvent).map(obj -> new StripePaymentIntentWebhookPayload(eventType, (PaymentIntent) obj));
        }
        return Optional.empty();
    } catch (Exception e) {
        log.error("got exception while handling stripe webhook", e);
        return Optional.empty();
    }
}
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) StripeChargeTransactionWebhookPayload(alfio.model.transaction.webhook.StripeChargeTransactionWebhookPayload) StripePaymentIntentWebhookPayload(alfio.model.transaction.webhook.StripePaymentIntentWebhookPayload) Charge(com.stripe.model.Charge) 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