#louislegourmet
1 messages · Page 1 of 1 (latest)
if ("checkout.session.completed".equals(event.getType())) {
System.out.println("Checkout Session Completed !");
Session session = (Session) event.getDataObjectDeserializer().getObject()
.orElseThrow(() -> new RuntimeException("Error deserializing session object"));
// System.out.println(session);
String sessionId = session.getId();
System.out.println("Checkout suceeded for session: " + sessionId);
StripeSessionInfo stripeSession = new StripeSessionInfo(sessionId);
stripeSession.fetchSessionInfo(YOUR_STRIPE_CLE_PRIVE);
paymentIntentPaiementId = stripeSession.getMetadata().get("paiementId");
// System.out.println(stripeSession.getMetadata().get("paiementId"));
return true;
} else if ("payment_intent.succeeded".equals(event.getType())) {
PaymentIntent paymentIntent = (PaymentIntent) event.getDataObjectDeserializer().getObject()
.orElseThrow(() -> new RuntimeException("Error deserializing payment intent object"));
System.out.println(paymentIntent);
String paymentIntentId = paymentIntent.getId();
System.out.println("Payment succeeded for payment intent: " + paymentIntentId);
// Mettre à jour la BDD dans la table paiement - IDSTRIPE = paymentIntentId
// Mettre à jour la BDD dans la table paiement - Etat = succeeded
System.out.println("PaiementID = " + paymentIntentPaiementId);
return true;
} else {...}
Here is a portion of the important code for better clarity
Hello 👋
We don't automatically copy the metadata over to the underlying PaymentIntent object when the session is completed.
You'd need to retrieve the session once you receive the webhook event and look at the metadata that way
However, I can't access the Session object when I receive the PaymentIntent.suceeded event right ?
Or if I can, can you enlighten me as to how to do so?
System.out.println(stripeSession.getMetadata().get("paiementId"));
This line in the checkout.session.completed section allows me to access what I want, but for that, I needed to access the Stripe Session object, which I did n't find how to do in the if eventype = PaymentIntent.suceeded if statement
Would this line work : Session session = Session.retrieve(paymentIntent.getObject().getCheckoutSession()); ?
You can use List all Checkout Session API endpoint and pass in the payment_intent ID as the parameter to find the relevant checkout session object
https://stripe.com/docs/api/checkout/sessions/list