条纹结帐-创建会话-对订阅应用税率

jet*_*com 8 stripe-payments stripe-sca tax-rate stripe-subscriptions

我正在尝试设置新的Stripe Checkout Create session。我无法在会话创建过程中为订阅设置税率,因为该订阅是由Stripe自动创建的。

我在仪表板上设置了税率,默认税率为20%。我希望将其自动应用于所有订阅。有人可以指导我吗?

stripe.checkout.Session.create(
        payment_method_types=['card'],
        subscription_data={
            'items': [{
            'plan': plan.stripe_plan_name,
            'quantity': 1
            }],
        },
        customer_email = user.email,
        success_url='https://www.jetpackdata.com/success',
        cancel_url='https://www.jetpackdata.com/cancel'
    )
Run Code Online (Sandbox Code Playgroud)

stripe.redirectToCheckout在客户端选择。

我在听网络提要'checkout.session.completed'在后端升级帐户。

我正在听'invoice.created',当status=draft设置时,我设置了默认税率(因为我们有一个小时可以在创建后对其进行修改)。

我应该改为收听'customer.subscription.created'并直接在订阅上进行设置,而不是在每张发票上进行设置吗?

首次客户订购购买似乎未应用税率,因为状态不像订购周期那样在一个小时内保持在草稿中。是因为我处于测试模式吗?

任何帮助,将不胜感激。

jet*_*com 5

联系 Stripe 技术支持,我得到了这个:

“目前,我们目前无法通过 Checkout 设置税率,但这是我们路线图上的一项功能,将来会添加。”

因此,对于那些需要使用新的 Stripe Checkout Session 为订阅设置税费的人,这里有一个解决方法。以下大纲将帮助您从第一张发票和随后的订阅发票中为您的订阅添加税费!

  1. 创建一个新客户并将客户 ID 存储在您的后端:
new_customer = stripe.Customer.create(
    email = user.email
)
Run Code Online (Sandbox Code Playgroud)
  1. 在订阅计划上为您的税创建发票项目:(这将自动拉入第一个订阅计划)
new_tax_invoice = stripe.InvoiceItem.create(
    customer=new_customer['id'],
    amount=int(plan.price*20),
    currency="eur",
    description="VAT"
)
Run Code Online (Sandbox Code Playgroud)
  1. 创建一个 Stripe Session checkout 并将 stripe_session.id 移交给客户端的stripe.redirectToCheckout
stripe_session = stripe.checkout.Session.create(
    payment_method_types=['card'],
    subscription_data={
        'items': [{
        'plan': plan.stripe_plan_name,
        'quantity': 1
        }],
    },
    customer = new_customer['id'],
    success_url=app.config['STRIPE_SUCCESS_URL'],
    cancel_url=app.config['STRIPE_CANCEL_URL'],
)
Run Code Online (Sandbox Code Playgroud)
  1. 使用您的税率在 Stripe Dashboard 上创建一个税务对象

  2. 收听customer.subscription.created的 Stripe Webhook并使用您从步骤 4 中获得的默认税率 ID 更新订阅对象

if stripe_webhook['type'] == 'customer.subscription.created':
    stripe.Subscription.modify(
        stripe_webhook['data']['object']['id'],
        default_tax_rates = [app.config['STRIPE_TAX_RATE']]
    )
Run Code Online (Sandbox Code Playgroud)
  1. 收听 Stripe Webhook 的checkout.session.completed并使用 stripe_subscription_id 和 stripe_customer_id 在后端进行必要的内务处理