17

我正在尝试设置新的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在客户端挑选。

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

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

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

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

任何帮助,将不胜感激。

4

2 回答 2

5

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

“目前,我们目前无法通过 Checkout 设置税率,但这是我们未来计划添加的一项功能。”

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

  1. 创建一个新客户并将客户 ID 存储在您的后端:
new_customer = stripe.Customer.create(
    email = user.email
)
  1. 在订阅计划中为您的税创建发票项目:(这将自动拉入第一个订阅计划)
new_tax_invoice = stripe.InvoiceItem.create(
    customer=new_customer['id'],
    amount=int(plan.price*20),
    currency="eur",
    description="VAT"
)
  1. 创建一个 Stripe Session 结账并将 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'],
)
  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']]
    )
  1. 收听 Checkout.session.completed 的 Stripe Webhook使用 stripe_subscription_id 和 stripe_customer_id 在您的后端进行必要的内务管理
于 2019-08-06T23:02:45.350 回答
2

您目前无法为使用 Sessions 创建的订阅设置税率。这是 Stripe 正在做的事情,但现在您必须通过 API 创建带有税率的订阅。

于 2019-07-25T09:29:43.173 回答