I am fairly new to programming and was trying to create a marketplace checkout using stripe. I implemented stripe checkout already, however, to make it fully functional, I have to send multiple different accounts different amounts of money based on what products the customer has bought. I was wondering what is the best way to accomplish this was. I currently have the code below which only pays the seller of the first product the full amount:
router.post('/create-checkout-session', async(req, res) => {
const {cartItems} = req.body
const cartPriceArray = (cartItems.map((item) => {
return {price: item.stripePriceId, quantity: 1}
}))
const session = await stripe.checkout.sessions.create({
line_items: cartPriceArray,
mode: 'payment',
success_url: `${process.env.CLIENT_URL}checkout-success`,
cancel_url: `${process.env.CLIENT_URL}cart`,
payment_intent_data: {
application_fee_amount: 1, // change to percentage in future
transfer_data: {
destination: cartItems[0].stripeAccountId,
},
},
});
console.log(session)
res.json({url: session.url});
});
I was wondering if I can create an array of payment intents within the destination or after that send the stripe price Id of each item to the stripe acc id of the seller who is selling each item(attached to the cart items being passed in). If this is not possible, what is the best and easiest way to achieve this? (The accounts are express accounts)
Thank you!