#k-nicholas_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1465632516638507098
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
here's how we create our checkout session
const session = await stripe.checkout.sessions.create(
{
client_reference_id: cartId,
metadata: {
...
},
line_items: [
...
],
payment_intent_data: {
application_fee_amount: calculateApplicationFee(
...
),
metadata: {
...
},
},
mode: "payment",
ui_mode: "custom",
return_url: ...,
},
{
stripeAccount: connectedAccStripeAccId,
},
);
๐ Hi there! Let me take a look
opsss forgot to mentioned. we cant find the value in the following webhook event:
- checkout.session.async_payment_failed
- checkout.session.async_payment_succeeded
- checkout.session.completed
- checkout.session.expired
Yeah, I don't believe you will be able to get charge information from those webhook event types.
You would have to listen to other event types, like payment_intent.succeeded. Though there you should be aware that the fee information won't be available immediately by default, due to asynchronous capture: https://docs.stripe.com/payments/payment-intents/asynchronous-capture
yeap, we are happy to listen to a different event to get the fees info. we dont need this information immediately, as it more for daily reporting.
But even there, you would still need to look up the Balance Transaction object associated with the payment. This isn't something that's included directly in webhook events
If you want to do daily reporting, you could also consider listing all Balance Transactions in the desired time period, to see all the fees: https://docs.stripe.com/api/balance_transactions/list
yea, you are right. i just had a look at "payment_intent.succeeded" event and i dont see the card processing fee.
i can see the "application_fee_amount": 375 only. but the main thing we need is actually the card processing fee
Yeah, that's contained in a Balance Transaction object, which is mentioned here: https://docs.stripe.com/expand/use-cases#stripe-fee-for-payment
Let me find you an example
So if I use the Stripe CLI to make an API call, looking up a particular Payment Intent, I can see the balance_transaction object (txn_โฆ) which contains the fee details:
stripe get pi_3Su88A6oEAX7HoXL17swNCM4 --expand latest_charge.balance_transaction
"balance_transaction": {
"id": "txn_3Su88A6oEAX7HoXL1CSYFUbE",
"object": "balance_transaction",
"amount": 3000,
"available_on": 1770076800,
"balance_type": "payments",
"created": 1769504415,
"currency": "eur",
"description": "Subscription creation",
"exchange_rate": null,
"fee": 123,
"fee_details": [
{
"amount": 123,
"application": null,
"currency": "eur",
"description": "Stripe processing fees",
"type": "stripe_fee"
}
],
"net": 2877,
"reporting_category": "charge",
"source": "ch_3Su88A6oEAX7HoXL11P6NxPq",
"status": "pending",
"type": "charge"
},
Balance Transactions just aren't included in any webhook payloads, I believe. So you need to fetch them via the API, based on a Payment Intent or Charge ID
thanks! btw, is there any api limit that we can hit this stripe.paymentIntents.retrieve() API? we just want to make sure we dont cause outage for our normal using thats trying to pay.
we will make sure to store the fees value in DB, once we retrieve it. (so will only be calling once per payment_intent)
The usual rate limits apply, which are 100 requests per second by default: https://docs.stripe.com/rate-limits
But if you are interested in just grabbing this data daily, you can consider listing all the Balance Transactions and specifying the created timeframe: https://docs.stripe.com/api/balance_transactions/list
But either approach is fine ๐
btw, if we want to use the balance transactions list API. what value do we use to correlate back to the transaction?
the example is showing
"id": "txn_1MiN3gLkdIwHu7ixxapQrznl"
"source": "tr_1MiN3gLkdIwHu7ixNCZvFdgA",
but i dont see those value in checkout_session / paymetn_intent webhook
Yeah, it's the source field, like in my example above you can see the associated Charge. Your example looks like that was a balance transaction for an application fee, rather than the actual payment. You can differentiate based on the Balance Transaction type.
ohh yea. i took the example above from directly from this URL https://docs.stripe.com/api/balance_transactions/list
ohh okay so we will get the ch_ value back in source field
Something like this would get you Balance Transactions for payments, while also including the Charge, with its Payment Method ID:
stripe balance_transactions list --type charge --expand data.source
nice. yea that works too
btw, when we call --expand. is that two API call or one? like in term of rate limits
It's a single API call ๐
nice. and also doesnt matter how many transactions was returned. is count as one API call right? (main thing, im trying to work out here, is there any other limits i should know)
and how many transactions can it return? is there pagination on this that we need to call for next page?
Yup, it's one API call. By default the limit is 10 results, but you can set it to 100. There is then pagination: https://docs.stripe.com/pagination
If you're using a Stripe SDK, I recommend using auto-pagination
You're welcome! ๐