#anoch-jeyakanthan_connect-sct-currencies
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/1272577511972143107
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
this is my entire function:
// Handler for checkout.session.async_payment_succeeded event
async function handleSuccessfulPayment(session: Stripe.Checkout.Session) {
console.log("Received successful payment");
const { transferGroupId, vendorsInTransaction } = session.metadata as { transferGroupId: string, vendorsInTransaction: string };
const vendors = JSON.parse(vendorsInTransaction) as { price: number, stripeAccountId: string }[];
for await (const { price, stripeAccountId } of vendors) {
try {
console.log("values", session.payment_intent)
const transfer = await stripe.transfers.create({
amount: price,
currency: 'usd',
destination: stripeAccountId,
transfer_group: transferGroupId,
source_transaction: session.payment_intent as string,
});
console.log(`Transfer created successfully: ${transfer.id}`);
} catch (error) {
console.error(`Error creating transfer for vendor ${stripeAccountId}:`, error);
}
}
return new Response("Transfers processed successfully", { status: 200 });
}
also I'm unsure which webhook event I should use, checkout.session.async_payment_succeeded or checkout.session.completed
Hello
Hey
So to clarify, you are attempting to create Transfers to multiple Connected Accounts after a successful transaction?
yeah
Gotcha, then you want to listen to both of those Event types and when you receive one of them you retrieve the Checkout Session and expand the PaymentIntent: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-payment_intent -- from that you look at latest_charge (https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge) and that is the ID that you pass as the source_transaction for your Transfer
If you aren't familiar with Expansion then take a look at: https://docs.stripe.com/expand
okay 1 sec i'm just trying to implement that rq
I'm getting this error now:
Error creating transfer for vendor acct_1PmjLAIARny5XvyV: StripeInvalidRequestError: The currency of source_transaction's balance transaction (cad) must be the same as the transfer currency (usd)
also I did this:
const paymentIntent = (await stripe.checkout.sessions.retrieve(session.id, {
expand: ["payment_intent"]
})).payment_intent as Stripe.PaymentIntent;
and for the source transaction I put source_transaction: paymentIntent.latest_charge as string,
this is what you meant right?
Yep that all looks good but the error is pretty self-explanatory, no?
yup
i fixed it thanks i was just a dumbass
just to clarify, the checkout session can be in any currency tho right?
Well you control that but yes
okay thanks for the help appreciate it
Sure thing
quick question, if i were to charge fees would I subtract it directly from the amount?
Hi ๐
My colleaguea had to go so I'm stepping in.
This sounds like a separate charges & transfers funds flow, correct?
alr np, yup your correct
Okay in that case you retain whatever funds you want by reducing the amount you transfer to the Connected accounts.
ok thanks that's what i was wondering thanks
also this is my first bigger solo project, what would be the best practice for storing the fee % rate? env vars?
Unfortunately that would be up to you to determine. I don't know enough about your system architecture to advise and it's outside the scope of my area of expertise
You too ๐