在Django中使用Stripe进行分账支付
我正在做一个项目,买家会进行支付,这笔支付需要分成以下几部分:
- 申请费用
- 卖家付款
- 推荐人付款
这是我的代码:
if buyer_address.state.lower() == 'alabama' or buyer_address.state.lower() == 'al':
taxes = int(round(float(price * 0.08)))
shipping_charges = courier.price
total_charges = price + taxes
# if referrals:
admin_amount = int((total_charges - shipping_charges) * 0.2)
seller_amount = total_charges - admin_amount
referral_amount = int(admin_amount * 0.02)
payment_info = {
"amount": total_charges, # Amount in cents
"currency": "usd",
"connected_accounts": [
{"account_id": 'acct_1OoODQIbLDChIvG2', "amount": seller_amount},
{"account_id": "acct_1OrzPRI5g3KKKWKv", "amount": referral_amount},
]
}
stripe.api_key = "sk_test_EI5Kddsg2MCELde0vbX2cDGw"
try:
for account_info in payment_info["connected_accounts"]:
# Set up transfer amount and destination separately
transfer_amount = account_info["amount"]
destination_account = account_info["account_id"]
print("=======================================================", destination_account)
session = stripe.checkout.Session.create(
success_url=my_domain + '/payment_success/' + str(auction_id) + '/' + courier_id + "?mode=" + mode,
cancel_url=my_domain + '/payment_failed/' + str(auction_id) + '/' + courier_id + "?mode=" + mode,
payment_method_types=['card'],
mode = 'payment',
line_items=[{
'price_data': {
'currency': 'usd',
'product_data': {
'name': 'NailSent Nails',
},
'unit_amount': int(total_charges), # amount should be in cents
},
'quantity': 1,
}],
payment_intent_data={
'transfer_data': {
'destination': destination_account,
'amount': transfer_amount, # amount should be in cents
}
},
)
except stripe.error.StripeError as e:
return HttpResponse(f"Error: {e}")
我试着把这笔支付分给这三个人。
- 申请费用
- 卖家费用
- 推荐费用
我尝试使用支付转账的方法,但出现了资金不足的错误。
现在,如果我进行支付,推荐人的金额会转到推荐人账户,但卖家却没有收到任何钱。
请提供一个好的解决方案。谢谢!