Obromios
Obromios

Reputation: 16373

Stripe update of subscription generating error

I am using the gem stripe v4.0.3. If I retrieve a subscription, then I can cancel it using:

subscription.cancel_at_period_end = true
subscription.save

According to the stripe documentation, I should also be able to do this with the command:

subscription.update(cancel_at_period_end: true)

but this generates an error:

Failure/Error: subscription.update(cancel_at_period_end: true)

     NoMethodError:
       undefined method `update' for #<Stripe::Subscription:0x00007fcda95efd20>

Why is this?

Upvotes: 1

Views: 477

Answers (2)

Obromios
Obromios

Reputation: 16373

Stripe support confirmed that there is an error in the documentation example. They also stated there were two ways to do this

sub = Stripe::Subscription.retrieve("sub_xxxyyyzz")
sub.cancel_at_period_end = true
sub.save

Or

Stripe::Subscription.update("sub_xxxyyzz",{:cancel_at_period_end => true})

Upvotes: 2

Hari Kumar
Hari Kumar

Reputation: 31

There is no method as update for subscription object. If you want to cancel the subscription on period end, you need to call the subscription services cancel method. You will need to pass that your customer and subscription id, and then use the cancelAtPeriodEnd flag (set it to true).

Upvotes: 1

Related Questions