#Fonseca - charge details on checkout success page
1 messages · Page 1 of 1 (latest)
You can get the Charge ID from a Checkout Session object, you just have to make a separate retrieve call to the Checkout Session API and expand the Checkout Session's payment_intent.charges hash to get Charges that were created by the Checkout Session's associated Payment Intent
here are some docs on expanding object fields:
I think i understand, thank you ima look into it
Sounds good! Feel free to come back with questions if you get confused
quick question,
do i retrieve the charge id from the payment intent or from the checkout session
You technically get it from the Payment Intent, but you can expand the Payment Intent from inside the Checkout Session object in order to get the Charge when you retrieve the Checkout Session
What language are you using?
python
checkout = stripe.checkout.Session.create(
success_url='https://nutreat.org',
cancel_url='https://nutreat.org',
currency="brl",
line_items=[{'price':'price_1LsVUFLVPYcWi3a5helJS4cK', 'quantity':1}],
mode="payment",
payment_intent_data={
'transfer_group': '{transfer1}'
},
)
charge = stripe.PaymentIntent.retireve(checkout.payment_intent, expand=['charges'])
thats my code
So you would do a separate API call to retrieve that Checkout Session using its ID. Something like:
stripe.checkout.Session.retrieve( "cs_test_abc123", "expand"=["payment_intent.charges"] )
That would give you the Charge object, which contains the Charge ID
It's just nested under checkout_session.payment_intent.charges
i understand, i would put that code to happen in the payment success page right?
because if not i would try to receive it right away after the checkout session was created and get null because the customer didnt even have time to finish the payment
It depends on what you're hoping to display on that page, but if you want to make sure that the success_url page has data about the Charge, then you would call the retrieve API (as we described above) after the customer was redirected. As long as they aren't using a delayed payment method (like ACH, SEPA Debit, etc.) then the Charge object will contain information about the successful charge
well actually i dont need to display nothing more than a success text
but
i need the charge id to create 2 transfers to receivers
thats why i thought i needed to place it in the success page, because i need the transfers to happen right after the charge
Okay, yeah. That should work just fine for you in the case of immediate payment, but if you want to integrate with ACH payments or SEPA, you'll want to build this whole workflow using webhooks instead
So the method for getting the Charge ID will be the same as above. The only difference will be that you will listen for checkout.session.completed in order to get the Checkout Session ID from the webhook's payload
Yes we recommend setting up webhooks for any fulfillment that needs to happen following Checkout:
https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler
Note that you can also opt-in to getting the checkout session in the success URL to aid in that data retrieval following redirect:
https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
Note that if you have an endpoint subscribed to checkout.session.completed, Checkout will wait (up to ten seconds) for you to respond to that event to ensure your systems are aware of the payment success prior to the customer being redirected
Fonseca - charge details on checkout success page