#anoch-jeyakanthan_connect-sct-currencies

1 messages ยท Page 1 of 1 (latest)

hearty shoalBOT
#

๐Ÿ‘‹ 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.

lyric wigeon
#

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

lethal hollow
#

Hello

lyric wigeon
#

Hey

lethal hollow
#

So to clarify, you are attempting to create Transfers to multiple Connected Accounts after a successful transaction?

lyric wigeon
#

yeah

lethal hollow
lyric wigeon
#

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?

hearty shoalBOT
lethal hollow
#

Yep that all looks good but the error is pretty self-explanatory, no?

lyric wigeon
#

yup

#

i fixed it thanks i was just a dumbass

#

just to clarify, the checkout session can be in any currency tho right?

lethal hollow
#

Well you control that but yes

lyric wigeon
#

okay thanks for the help appreciate it

lethal hollow
#

Sure thing

lyric wigeon
#

quick question, if i were to charge fees would I subtract it directly from the amount?

wispy ledge
#

Hi ๐Ÿ‘‹

My colleaguea had to go so I'm stepping in.

This sounds like a separate charges & transfers funds flow, correct?

lyric wigeon
#

alr np, yup your correct

wispy ledge
#

Okay in that case you retain whatever funds you want by reducing the amount you transfer to the Connected accounts.

lyric wigeon
#

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?

wispy ledge
#

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

lyric wigeon
#

ok no problem, thank you

#

have a good day

wispy ledge
#

You too ๐Ÿ‘‹