我正在尝试设置新的 Stripe Checkout Create session
.我无法在 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
挑选在客户端。我正在网络 Hook 上收听
'checkout.session.completed'
在我的后端升级帐户。我在听
'invoice.created'
当 status=draft
,我设置了默认税率(因为我们有一个小时可以在创建后对其进行修改)。我应该听吗
'customer.subscription.created'
并直接在订阅上设置而不是在每张发票上设置?第一次客户订阅购买似乎没有应用税率,因为状态不会像订阅周期中那样在草稿中保持一个小时。是因为我处于测试模式吗?
任何帮助,将不胜感激。
最佳答案
联系 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 为订阅设置税费的人来说,这里有一个解决方法。以下大纲将帮助您从第一张发票和随后的订阅发票中为您的订阅添加税款!
- Create a new customer and store the customer id on your backend:
new_customer = stripe.Customer.create( email = user.email )
- 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" )
- 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'], )
Create a tax object on your Stripe Dashboard with your tax rate
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']] )
- 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
关于stripe-sca - Stripe Checkout - 创建 session - 对订阅应用税率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184491/