如何处理重新订阅有试用期的 Stripe 计划?

How to handle re-subscription to a Stripe plan with a trial period?

如果客户重新订阅具有试用期的计划会怎样?

更准确地说:

  1. 一位客户订阅了一个有 30 天试用期的计划。
  2. 试用期结束后,客户决定取消 订阅。
  3. 客户稍后重新订阅该计划。

他们还能再次享受试用期吗?

我如何确定用户是否已经过了试用期,以便我可以在没有试用期的情况下处理他们的重新订阅?

我的解决方案:

我检查客户是否取消了该计划的订阅。如果是这样,我创建一个订阅 trial_end'now':

if len(stripe.Subscription.list(status='canceled', customer=stripe_customer_id, plan=plan_id)['data']) > 0:
    stripe.Subscription.create(
        customer=stripe_customer_id,
        plan=plan_id,
        trial_end='now')     
else:                
    stripe.Subscription.create(
        customer=stripe_customer_id,
        plan=plan_id)