#Dan Judge

1 messages · Page 1 of 1 (latest)

silver cloakBOT
uneven cobalt
#

You just want to calculate what the amount would be after fees?

faint phoenix
#

Yeah, is there not a solid total in the checkout session response which has the total paid minus fees?

uneven cobalt
#

No not in the checkout session response. Do you need the fees before the payment is completed? There's a way to retrieve the fees after a payment has been completed. If you need the fees prior to payment, you'll need to attempt to calculate them yourself.

faint phoenix
#

After the payment is completed, is fine, how do I get that total amount from a checkout session please?

uneven cobalt
#

So there will be a payment intent on the checkout session: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent. You'll need to retrieve that: https://stripe.com/docs/api/payment_intents/retrieve and expand latest_charge: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-latest_charge. Within that charge object, you'll have a balance transaction: https://stripe.com/docs/api/charges/object#charge_object-balance_transaction. If you retrieve that: https://stripe.com/docs/api/balance_transactions/retrieve then you can calculate amount - fee since the balance transaction object has the fee details: https://stripe.com/docs/api/balance_transactions/object#balance_transaction_object-fee

faint phoenix
#

The patment_intent always seems to be null, I tried going down that route, any idea why it would be null?

uneven cobalt
#

Was the checkout session completed and paid?

faint phoenix
#

Yes

#

cs_test_b1kfssl7VKjbJBV5H1ITVMIzZ8RrgT1Lg3mq3JkNla6WxbZsynXij607sb

silver cloakBOT
uneven cobalt
#

Ah it's in subscription mode

#

So in that case you'll need to go to the subscription object -> latest_invoice -> payment_intent

faint phoenix
#

Got you, okay that's brilliant, thanks very much for your help

uneven cobalt
#

No problem

faint phoenix
#

Can I use expansion on the invoice for the payment intent and also the balance transaction?

#

To get it all in one request

uneven cobalt
#

Expansions have a maximum depth of four levels. Meaning that an expand string can contain no more than four properties: property1.property2.property3.property4.

faint phoenix
#

Okay thank you

uneven cobalt
#

No problem