我如何在结帐时获得 stripe 的申请费以反映可调整的数量?

How do I get stripe's application fee to reflect the adjustable quantity during checkout?

我为 Stripe 的结帐会话调用添加了可调整的数量。我了解到费用对象是在付款后创建的。

我正在查看 stripe 文档中的申请费用对象,它说它的上限为最终费用金额。我如何在结帐会话期间检索收费金额或更好的数量?

    checkout_session = stripe.checkout.Session.create(
                success_url=domain_url + 'success?session_id={CHECKOUT_SESSION_ID}',
                cancel_url=domain_url + 'cancelled/',
                payment_method_types=['card'],
                customer=customer.id,
                payment_intent_data={
                    'application_fee_amount': int(stripe_price * fee_percentage),
                    'transfer_data': {
                    'destination': seller.stripe_user_id,
                    },
                },
                line_items=[
                {
                    'price_data': {
                        'currency': currency,
                        'unit_amount': price,
                        'product_data': {
                            'name': title
                        },
                    },
                    'adjustable_quantity': {
                    'enabled': True,
                    'minimum': 0,
                    'maximum': available_quantity,
                  },
                  'quantity': 1,
                },
                ],
                metadata={
                    "product_id": product.id,
                    "client_reference_id": user.id,
                },
                mode='payment',

            )
            return JsonResponse({'sessionId': checkout_session['id']})
        except Exception as e:
            return JsonResponse({'error': str(e)})

目前最好的选择是执行以下操作:

  1. 在结帐会话中将 payment_method_data.capture_method 设置为 manual
  2. 结帐会话完成时set an application_fee_amount when capturing the funds

这将您限制为支持单独授权和捕获的付款方式,但它允许您在结帐会话完成后设置application_fee_amount