#steven_paymentintent-fees
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/1288168254409408595
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
steven_paymentintent-fees
@strange tiger Can I ask to clarify exactly what is not working? That PaymentIntent was confirmed successfully and then later the charge.updated Event was triggered and you received it https://dashboard.stripe.com/events/evt_3Q0ZsAH4UK1ezOVR1DRCmOh2
How do I paste my code here?
It supposed to trig the module which doing the job for calculating the commission before forward the money to the connect account
I don't really need your code right now. I need you to explain your issue as a developer
but it didn't happen due to webhook didn't receive paymentIntent.succeed event
when receive this charge.updated
Was it racing?
case 'payment_intent.succeeded':
{
try {
const srcToken = event.data.object.id;
let trans = await Transaction.findOne({srcToken: srcToken});
if (trans)
{
trans.srcEvt = event.type;
trans.ums = Date.now();
await trans.save();
}
return;
} catch (error) {
utils2021.logMsg('system', 'webhook', `webhook event 'source.canceled': error:${error.message}`);
}
break;
}
There's nothing "racing". The same exact Events happen in Test mode the same way. The order of Events is never guaranteed
case 'charge.updated':
{
const srcToken = event.data.object.payment_intent;
let trans = await Transaction.findOne({srcToken: srcToken});
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;
if (trans.srcEvt === 'payment_intent.succeeded') {
if (trans)
{
trans.stripeFee = `${fee}`;
trans.afterStripeNet = `${netAmount}`;
trans.srcType = event.type;
trans.ums = Date.now();
await trans.save();
}
completePaymentIntentSucceed(trans, event.data.object);
}
break;
Sorry you're just dumping code with no context. I can't really just debug your code right now without understanding your issue.
My advice is to add real logs to your webhook handler and figure out what's missing
If the order not guarranted, the above code won't work due to it assume paymentIntent_succeed happen first
The problem didn't happen with StripeCli and it was always working
Gotcha, see https://docs.stripe.com/webhooks#event-ordering which explains order is not guaranteed.
In that case, if people want to calculate the StripeFee, what's the suggested logic?
when I using source, it worked great, not sure why you guys depprecated that
I used to calculate the StripeFee by my estimation, and I just need PaymentIntent.succeed, it didn't have this ordering issue, but the fee I calculated is not accurate
I mean the ordering issue will happen for most of your code in a webhook handler really. You more got luck that it didn't affect you until now.
My advice is to debug your code really and handle Events out of order
But if you want a quick fix, pass capture_method: 'automatic' so that the fee is calculated synchronously like it used to
do you mean in PaymentIntent.succeed?
yes
for the Quik fix
no
When I debug, it was alway correct as mentioned last time
When you create the PaymentIntent, you can pass the capture_method parameter set to automatic. Doing this means that you will get the BalanceTransaction created at the same time as the Charge and not asynchronously later.
I see, oh, it seems I tried that, it has other problem, let me double check
Do you mean here:
const pyInt = await stripe.paymentIntents.create({
amount,
currency,
description,
payment_method_types,
metadata: meta,
})
?
yes
I'm confused, I linked you to the exact API Reference for that parameter.
I see,
automatic_payment_methods: {
enabled: true,
},
Actually, it is not about wrapping atest_charge.balance_transaction, it is only about auto support card, alipay or wechat pay, I tried that before
It is just replace payment_method_types, right?
I'm sorry but you are passing a parameter that has nothing to do with what I said ๐
The parameter is named capture_method. I put the link above but to be sure: https://docs.stripe.com/api/payment_intents/create#create_payment_intent-capture_method
That's what the link showing, any sample code of that if it is not?
Yeah sorry you're mixing up the list of parameters and the basic example code on how to use the API overall. The example code is not for that specific parameter
Did you write that code you took a picture of? Are you the developer of the whole integration?
okay so if you wrote that code you likely understand that you are passing various parameters to the Create PaymentIntent API https://docs.stripe.com/api/payment_intents/create such as the amount and currency to charge, a description for the payment in the email receipt, etc. right?
see what I said above
okay so if you wrote that code you likely understand that you are passing various parameters to the Create PaymentIntent API https://docs.stripe.com/api/payment_intents/create such as the amount and currency to charge, a description for the payment in the email receipt, etc. right?
That's correct, but how do I make the capture_method to sync instead of async?
current is:
const pyInt = await stripe.paymentIntents.create({
amount,
currency,
description,
payment_method_types,
metadata: meta
})
I'm trying to teach you to fish here ๐
You clearly understand the parameters. You passed them as you needed, you found specific ones such as description and metadata
Now what is the parameter I told you to use earlier in the thread?
like this?
const pyInt = await stripe.paymentIntents.create({
amount,
currency,
description,
payment_method_types,
capture_method: automatic,
metadata: meta
})
I see, thanks, I'll try it out
it's a string so capture_method: 'automatic' but yes
I wished you were the people who told me to capture charged.updated.
anyway, thanks a lot
I mean using charge.updated is the right way. That's what I tell dozens of developers here. But you are clearly quite lost with the integration and your code overall so that alternative works, it's just not the best one