Stripe Checkout - 创建会话 - 对订阅应用税率

Stripe Checkout - Create Session - Apply Tax Rates on 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'
    )

并由 stripe.redirectToCheckout 在客户端选择。

我正在监听 'checkout.session.completed' 的 webhooks 以升级我后端的帐户。

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

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

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

如有任何帮助,我们将不胜感激。

您暂时无法为使用会话创建的订阅设置税率。这是 Stripe 正在做的事情,但现在你必须通过 API.

创建带有税率的订阅。

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

"At the present moment, we don't currently have the ability to set a tax rate through Checkout, but it is a feature that is on our roadmap to be added in the future."

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

  1. Create a new customer and store the customer id on your backend:
new_customer = stripe.Customer.create(
    email = user.email
)
  1. Create an invoice items for your Tax on the subscription plan: (This will be automatically pulled into the first subscription plan)
new_tax_invoice = stripe.InvoiceItem.create(
    customer=new_customer['id'],
    amount=int(plan.price*20),
    currency="eur",
    description="VAT"
)
  1. Create a Stripe Session checkout and handover the stripe_session.id to stripe.redirectToCheckout on the client side
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'],
)
  1. Create a tax object on your Stripe Dashboard with your tax rate

  2. Listen to the Stripe Webhook for customer.subscription.created and update the subscription object with the default tax rates id that you got from step 4

if stripe_webhook['type'] == 'customer.subscription.created':
    stripe.Subscription.modify(
        stripe_webhook['data']['object']['id'],
        default_tax_rates = [app.config['STRIPE_TAX_RATE']]
    )
  1. Listen to the Stripe Webhook for checkout.session.completed and do the necessary housekeeping on your backend with the stripe_subscription_id and stripe_customer_id