简体   繁体   中英

Stripe: Update subscription or cancel and create new one?

We have one product with 4 different prices(basic, middle etc). Let's say user bought basic package (payment session is created after payment completion subscription created),but after a while, user decided to change his package and upgrade to advanced package. In that case should i use update subscription?

This actually updates from X$ to the Y$ package

var service = new SubscriptionService();
Subscription subscription = service.Get("sub_49ty4767H20z6a");

var items = new List<SubscriptionItemOptions> {
    new SubscriptionItemOptions {
        Id = subscription.Items.Data[0].Id,
        Price = "price_CBb6IXqvTLXp3f",
    },
};

var options = new SubscriptionUpdateOptions {
  CancelAtPeriodEnd = false,
  ProrationBehavior = "create_prorations",
  Items = items,
};
subscription = service.Update("sub_49ty4767H20z6a", options);

or just cancel current subscription and create new one? Why am i asking this, because i chatted with support guys from Stripe, and got two different answers. One of them told me that i need to use update_subscripton, the another one told that i need to attach new subscription. I am confused.

The way that you've described this here, the update to upgrade the subscription makes more sense to me. Pay careful attention to the intended proration behaviour (do you want to credit the time left on the current plan) and whether you want to shift the billing period .

I'd also point out that you should consider switching to separate Products. A Product is a single good/service that you sell, while Prices represent different billing intervals and currencies. If you imagine some service with Silver, Gold and Platinum access levels, each of those is a different product -- they get more features! The Product is what gets shown on the invoice, too. So unless you use separate Products, the invoices would be indistinguishable aside from the rate paid.

Most of the time doing what you've done doesn't present any specific obsdtacles, but the Customer Portal enforces one price per product per interval. If you had two annual prices for the "same product" but different amount, why would anybody pay the higher price? It's because they're paying for something different, a different product.

Quick Answer

Upgrade (From Basic to Pro)

  1. Remove Basic
  2. Add Pro
  3. Prorate (Do not change billing cycle)
// subscriptionId -> your subscription id
// additionalStripePriceIds -> stripe price id you are going to add
// removalStripePriceIds -> stripe price id you are going to remove
var getService = new SubscriptionService();

var getServiceResult = await getService.GetAsync(subscriptionId);

var items = new List<SubscriptionItemOptions>();

if (removalStripePriceIds != null && removalStripePriceIds.Any())
{
  foreach (var removalStripePriceId in removalStripePriceIds)
  {
    var item = getServiceResult.Items.Data.FirstOrDefault(i => i.Price.Id == removalStripePriceId);

    if (item != null)
    {
      var subscriptionItemOption = new SubscriptionItemOptions
      {
        Id = item.Id,
        Deleted = true,
      };

      items.Add(subscriptionItemOption);
    }
  }
}

foreach (var additionalStripePriceId in additionalStripePriceIds)
{
  var subscriptionItemOption = new SubscriptionItemOptions
  {
    Price = additionalStripePriceId,
  };

  items.Add(subscriptionItemOption);
}

var updateService = new SubscriptionService();

var updateOptions = new SubscriptionUpdateOptions
{
  CancelAtPeriodEnd = false,
  ProrationBehavior = "create_prorations",
  Items = items,
};

await updateService.UpdateAsync(subscriptionId, updateOptions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM