Home > OS >  Stripe Subscription update the plan immediately with full amount
Stripe Subscription update the plan immediately with full amount

Time:08-30

I'm looking to update the customer's subscription, and the new plan price will be deducted immediately.

Consider the following scenario:

User is on Plan A($15 per month) and wants to update to Plan B($25 per month) in the middle of the month.

I want the user to charge $25 right away rather than prorate - I don't want the difference will be charged to the customer.

I also try with proration_behavior='always_invoice' However, it is charge $10. I need $25 charged right away.

 subscription = Stripe::Subscription.retrieve('sub_49ty4767H20z6a')
      Stripe::Subscription.update(
        subscription.id,
        {
          cancel_at_period_end: false,
          proration_behavior: 'none',
          items: [
            {
              id: subscription.items.data[0].id,
              price: 'price_1LcBtVHhBkzUOaGo0gvFmaMS'
            }
          ]
        }
      )

CodePudding user response:

I see you’re looking to update a subscription without any prorations and to immediately charge for the upgraded price. The way to achieve this would be by specifically passing proration_behavior: ‘none’ and billing_cycle_anchor: ‘now’. Your code will look something like this:

Stripe::Subscription.update(
  subscription.id,
  {
    cancel_at_period_end: false,
    billing_cycle_anchor: ‘now’,
    proration_behavior: ‘none’,
    items: [
      {
        id: subscription.items.data[0].id,
        price: 'price_xxxxxxx'
      }
    ]
  }
)

Please note that this changes the billing cycle of the subscription and to learn more about billing_cycle_anchor please visit here.

CodePudding user response:

You can achieve it with proration_behavior and billing_cycle_anchor.

You only need to pass these two properties while updating your subscription details using stripe API.

 subscription = Stripe::Subscription.retrieve('sub_49ty4767H20z6a')
 Stripe::Subscription.update(
        subscription.id,
        {
          cancel_at_period_end: false,
          proration_behavior: 'none',
          billing_cycle_anchor: 'now',
          items: [
            {
              id: subscription.items.data[0].id,
              price: 'price_1LcBtVHhBkzUOaGo0gvFmaMS'
            }
          ]
        }
      )
  • Related