#ahmad-naeem_code
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/1233333964274401313
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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);
}
}
const session = await this.stripe.checkout.sessions.create({
mode: "payment",
line_items: lineItems,
payment_intent_data: {
transfer_group: transferGroup,
},
metadata: {
vendorsData: JSON.stringify(vendorPayouts),
transferGroup
},
success_url:
"http://localhost:5050/inspect-session-details/success?session_id={CHECKOUT_SESSION_ID}&source=stripe",
cancel_url: "http://localhost:5050/cancel",
});
๐ happy to help
hey please have been stuck for more than 2 days
you don't need to wait
to avoid waiting for available balance
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
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Okay what let say we have got the latest_charge
What do next ?
Pass it to the transfer object with destination id
yes
When funds will be available