I am working on a project where, buyer will make the payment and that payment should be split into
- application-fee
- seller payment
- referral payment her is my code
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}")
i was trying to split the payment between all three user
- application-fee
- seller charges
- referral charges
i tried to user payment transfer method but got the error of insufficient funds
Right now if i make the payment. referral amount goes to the referral account but seller doesn't receive any money
please provide any best solution Thanks in advance
You can use separate Charges and Transfers to split payments between multiple Connected Accounts. Notice the use of the
transfer_groupproperty, which allows you to specify the source Charge for the Transfers. It will help you avoid the Insufficient funds error. This way the Transfers will only be executed when the original Charge succeeds.