#steven_webhooks

1 messages · Page 1 of 1 (latest)

young perchBOT
limpid yokeBOT
#

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.

young perchBOT
#

👋 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.

distant urchin
#

hello! how can I help?

solid mist
#

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?

distant urchin
#

this is a public channel, please don't share your webhook secret here even if it is a test secret

solid mist
#

I see, I updated it

solid mist
#

I added capture_method: 'automatic_async' and it didn't help,

#

how do I subscribe the additional balanceTransaction?

distant urchin
#

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.

[0] https://docs.stripe.com/upgrades#2024-04-10

Keep track of changes and upgrades to the Stripe API.

solid mist
#

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'?

distant urchin
#

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

#

but pretty much yes, you should retrieve the balance transaction on charge.updated

solid mist
#

will charge.updated always be after pyi_ succeeded?

#

aka, it only happens with pyi_succeeded

distant urchin
#

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

Listen to events in your Stripe account on your webhook endpoint so your integration can automatically trigger reactions.

solid mist
#

I see, thanks