英文:
Splitting Payments Between Users Using Stripe Connect and PaymentIntents - Insufficient Balance Error
问题
我正在为一个电商平台开发一个联盟营销功能,允许卖家创建联盟计划。我目前正在使用Stripe Connect和PaymentIntents API。
当客户通过联盟链接购买产品时,我们希望将付款分成卖家(产品所有者)和联盟成员之间。我尝试通过创建带有transfer_data的PaymentIntent来实现这一目标,其中目的地是卖家的Stripe帐户ID,然后在payment_intent.succeeded webhook中,将一部分付款转给联盟成员的帐户。
问题是,即使支付意向成功,资金似乎也不会立即可用于平台帐户。这在我尝试将部分付款转至联盟成员的Stripe帐户时会导致“余额不足”错误。
以下是创建PaymentIntent的代码片段:
const paymentIntent = await stripe.paymentIntents.create({
amount: adjustedPrice * 100,
currency: "usd",
transfer_data: {
destination: sellerStripeAccountId,
},
application_fee_amount: affiliateCut * 100,
metadata: {
affiliate: affiliate || "",
affiliateCut,
affiliateAccountId,
},
});
以下是在webhook中转移联盟成员的份额的代码:
if(paymentIntent.metadata.affiliate) {
const affiliateTransfer = await stripe.transfers.create({
amount: paymentIntent.metadata.affiliateCut * 100,
currency: "usd",
destination: paymentIntent.metadata.affiliateAccountId,
});
}
我尝试在创建转移之前检查可用余额,但如前所述,来自PaymentIntent的资金似乎不会立即可用。
非常感谢您提供的任何见解或备选方法来解决这个问题。我如何确保在成功的PaymentIntent后立即拥有足够的余额来转账给联盟成员?
提前谢谢您!
英文:
I am developing an affiliate marketing feature for an e-commerce platform, where we allow our sellers to create affiliate programs. I am currently using Stripe Connect with the PaymentIntents API.
When a customer purchases a product through an affiliate link, we want to split the payment between the seller (product owner) and the affiliate. I am attempting to achieve this by creating a PaymentIntent with transfer_data where the destination is the seller's Stripe account ID and then in the payment_intent.succeeded webhook, make a transfer to the affiliate's account.
The problem is that, even when the payment intent is successful, the funds aren't immediately available in the platform account. This causes an "Insufficient Balance" error when I try to transfer part of the payment to the affiliate's Stripe account.
Here's a snippet of the code for creating the PaymentIntent:
const paymentIntent = await stripe.paymentIntents.create({
amount: adjustedPrice * 100,
currency: "usd",
transfer_data: {
destination: sellerStripeAccountId,
},
application_fee_amount: affiliateCut * 100,
metadata: {
affiliate: affiliate || "",
affiliateCut,
affiliateAccountId,
},
});
And here's the code for transferring the affiliate's cut (in the webhook):
if(paymentIntent.metadata.affiliate) {
const affiliateTransfer = await stripe.transfers.create({
amount: paymentIntent.metadata.affiliateCut * 100,
currency: "usd",
destination: paymentIntent.metadata.affiliateAccountId,
});
}
I've tried checking the available balance before creating the transfer, but as mentioned earlier, the funds from the PaymentIntent don't seem to be available immediately.
Any insights or alternate approaches to this problem would be greatly appreciated. How can I ensure that I have enough balance in my Stripe platform account to transfer to the affiliate immediately after a successful PaymentIntent?
Thank you in advance!
答案1
得分: 1
请参考以下翻译内容:
"Instead of using Destination Charges via the transfer_data
parameter (which is meant for a one-to-one seller/buyer relationship) you want to use Separate Charges & Transfers (meant for a many-to-one seller/buyer relationship) to create multiple transfers -- one to the seller and one to the affiliate. When you do so, you want to use the source_transaction
parameter (docs) when creating your transfer to tie the Transfers to the original Charge and allow you to create these transfers instantly. The funds still won't be available until the normal delay, but this will solve your 'insufficient funds' issue.
英文:
Instead of using Destination Charges via the transfer_data
parameter (which is meant for a one-to-one seller/buyer relationship) you want to use Separate Charges & Transfers (meant for a many-to-one seller/buyer relationship) to create multiple transfers -- one to the seller and one to the affiliate. When you do so, you want to use the source_transaction
parameter (docs) when creating your transfer to tie the Transfers to the original Charge and allow you to create these transfers instantly. The funds still won't be available until the normal delay, but this will solve your "insufficient funds" issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论