#Fonseca - charge details on checkout success page

1 messages · Page 1 of 1 (latest)

inner sentinelBOT
rocky scaffold
#

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:

Learn how to reduce the number of requests you make to the Stripe API by expanding objects in responses.

sudden ibex
#

I think i understand, thank you ima look into it

rocky scaffold
#

Sounds good! Feel free to come back with questions if you get confused

sudden ibex
#

quick question,

#

do i retrieve the charge id from the payment intent or from the checkout session

rocky scaffold
#

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?

sudden ibex
#

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

rocky scaffold
#

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"] )

sudden ibex
#

ok

#

and that would retrieve the charge id?

rocky scaffold
#

That would give you the Charge object, which contains the Charge ID

#

It's just nested under checkout_session.payment_intent.charges

sudden ibex
#

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

rocky scaffold
#

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

sudden ibex
#

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

rocky scaffold
#

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

sudden ibex
#

i see

#

ima need the webhooks than

rocky scaffold
#

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

ember briar
#

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

sudden ibex
#

Ok ok understand

#

Im looking into it rn

#

ty

ember briar
#

Fonseca - charge details on checkout success page