#steven_webhooks
1 messages · Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- steven_webhooks, 22 hours ago, 50 messages
👋 Welcome to your new thread!
⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1260410093757792328
📝 Have more to share? Add details, code, screenshots, videos, etc. below.
hello! how can I help?
Hi alex, got some proble with web_hook
case 'payment_intent.succeeded':
{
try {
const srcToken = event.data.object.id;
const paymentIntent = await stripe.paymentIntents.retrieve(
srcToken,
{
expand: ['latest_charge.balance_transaction'],
}
);
// Calculate net and fee
const balanceTrans = paymentIntent.latest_charge.balance_transaction;
const fee = balanceTrans.fee;
const netAmount = balanceTrans.net;
I have code like above, if I set break point before retrieve, step by step, in balanceTrans
I will get the expected value, if I set BP after that, when step into the balanceTrans, balance_transaction will be null
what might be the problem?
this is a public channel, please don't share your webhook secret here even if it is a test secret
you'll want to go through this section to understand how to get the balance transaction for a charge : https://docs.stripe.com/payments/payment-intents/asynchronous-capture#listen-webhooks
I see, I updated it
I added capture_method: 'automatic_async' and it didn't help,
how do I subscribe the additional balanceTransaction?
by default, if you are on API v 2024-04-10 [0] or later, you are using capture_method:"automatic_async" already. The key point to note here is that if you are using capture_method:"automatic_async"
For all payments, the balance_transaction is null on the following objects. For Connect payments, the transfer and application_fee are also null on the following objects:
attached Charge object of the API response
charge.succeeded webhook
payment_intent.succeeded webhook
and
You can listen to webhooks to check the status of objects that are initially null when using asynchronous capture.
To get the balance_transaction, subscribe to the charge.updated webhook event.
Does that mean I should do
const paymentIntent = await stripe.paymentIntents.retrieve(
srcToken,
{
expand: ['latest_charge.balance_transaction'],
}
);
// Calculate net and fee
const balanceTrans = paymentIntent.latest_charge.balance_transaction;
on
case 'charge.updated'
instead of
case 'py succeeded'?
you can just directly retrieve the balance transaction (https://docs.stripe.com/api/balance_transactions/retrieve) when you receive the charge.updated event since it's id is already in this event : https://docs.stripe.com/api/charges/object#charge_object-balance_transaction
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
but pretty much yes, you should retrieve the balance transaction on charge.updated
will charge.updated always be after pyi_ succeeded?
aka, it only happens with pyi_succeeded
Stripe doesn’t guarantee delivery of events in the order in which they’re generated : https://docs.stripe.com/webhooks#event-ordering. You should be prepared to handle a situation whereby charge.updated occurs before payment_intent.succeeded (although that should be rare). If that occurs, you should make a request to retrieve the corresponding PaymentIntent to process / handle first
I see, thanks