Stripe : Update customer’s subscription from basic to pro

Customers will often want to change to a new plan, e.g. by upgrading to the Pro plan in our examples. Stripe’s API provides a simple mechanism for switching the customer’s plan and automatically calculating the details like pro-rating for you.

require "stripe"
Stripe.api_key = "sk_test_OB7XXXXQKjKdmGkXXXXYtFJr"

customer = Stripe::Customer.retrieve("cus_7gXXXXuffmmtrs")
subscription = customer.subscriptions.retrieve("sub_7gaXXXXf0yRXM9")
subscription.plan = "gold_plan"


To give you a concrete example of what this might look like, let’s say a customer signs up on April 1 for the Basic plan at $10 a month. Half way through April, the customer decides to switch to the Pro plan for $20 a month. She’ll be charged $10 on April 1, the day she signed up, and then $25 on May 1: $20 for May 1 to June 1, minus $5 for the unused portion of the Basic plan, plus $10 for the 1/2 month on the more expensive Pro plan.


You can disable pro-rating if you like by passing an additional prorate option to the API request:

subscription.plan = "gold_plan"

# Flag telling us whether to prorate switching 
#   plans during a billing cycle.
# optional, default is true.
subscription.prorate = true

# optional, default is the current time
#   accepted format is unix timestamp
subscription.proration_date = true


For more details about proration visit this link; very useful



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s