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