#ahmad-naeem_code

1 messages ยท Page 1 of 1 (latest)

cerulean cypressBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

deft laurelBOT
vapid badger
#

case "checkout.session.completed":
const checkoutSessionCompleted = event.data.object;
const payment_intent = await this.stripe.paymentIntents.retrieve(checkoutSessionCompleted.payment_intent)
console.log(payment_intent.latest_charge)
// const charge = await this.stripe.charges.retrieve(chargeId)
if (checkoutSessionCompleted.metadata.vendorsData) {
console.log(checkoutSessionCompleted.metadata.vendorsData)
let totalAmount = checkoutSessionCompleted.amount_total
let vendorsData = checkoutSessionCompleted.metadata.vendorsData
let transferGroup = checkoutSessionCompleted.metadata.transferGroup
const sourceCharge = payment_intent.latest_charge
console.log(sourceCharge)
await this.createPaymentSession(vendorsData, totalAmount, transferGroup, sourceCharge)
}
break;

#

for (const vendor of vendorsArray) {
const { accountId, percentage } = vendor
const vendorCollectionAmount = (percentage/100) * netAmountCents
console.log("vendor collect", vendorCollectionAmount)

  try {
    const transfer = await this.stripe.transfers.create({
        currency: 'usd',
        amount: vendorCollectionAmount,
        destination: accountId,
        source_transaction:sourceCharge,
    });
    return transfer
} catch (error) {
    console.error("Error creating transfer for vendor:", error);
}
}
calm marsh
#

๐Ÿ‘‹ happy to help

vapid badger
#

hey please have been stuck for more than 2 days

calm marsh
#

you don't need to wait

#

to avoid waiting for available balance

vapid badger
#

From where we will get this charge it

#

You can see i have tried to do so

#

Can you please explain the flow step by step

#

I have read this docmentation

calm marsh
#

yes sure

#

when you receive the event checkout.session.completed you can then retrieve the PaymentIntent and get the latest_charge on the PI object

vapid badger
#

Okay what let say we have got the latest_charge

#

What do next ?

#

Pass it to the transfer object with destination id

calm marsh
#

yes

#

you pass it as source_transaction

vapid badger
#

Okay got cha

#

So it will be transferred to vendors connected account

calm marsh
#

yes

vapid badger
#

When funds will be available

calm marsh
#

no

#

directly

vapid badger
#

Let me try that

#

I'll update you on it