use of com.stripe.model.PaymentIntent 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");
}
}
use of com.stripe.model.PaymentIntent 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();
}
}
Aggregations