在 django 中使用 stripe 分割付款

问题描述 投票:0回答:1

我正在开展一个项目,买方将付款,该付款应分为

  • 申请费
  • 卖家付款
  • 推荐付款 她是我的密码

        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}")

我试图在所有三个用户之间分摊付款

  • 申请费
  • 卖家收费
  • 介绍费

我尝试使用付款转账方式,但收到资金不足的错误

如果我现在付款。推荐金额转到推荐帐户,但卖家没有收到任何钱

请提供最佳解决方案 预先感谢

python django stripe-payments payment
1个回答
0
投票

您可以使用单独的费用和转账在多个关联帐户之间分摊付款。请注意

transfer_group
属性 的使用,它允许您指定转账的来源费用。它将帮助您避免资金不足的错误。这样,只有在原始收费成功后,转账才会执行。

© www.soinside.com 2019 - 2024. All rights reserved.