Stripe downgrade-upgrade plan using API in PHP

Stripe downgrade-upgrade plan using API in PHP

In this post we will show you Stripe downgrade-upgrade plan, hear for Stripe downgrade-upgrade plan we will give you demo and example for implement.

Syntex for Stripe downgrade-upgrade plan

this is Syntex for Stripe downgrade-upgrade plan, you need to change subscription id and STRIPE_API_KEY and plan hear.

// curl for Stripe downgrade-upgrade plan
curl \
-u sk_test_a12RX8g5E58fT659vg4Gd1fp: \
-d plan=pro-monthly

Stripe Upgrading-Downgrading Plans

class Stripe
public $headers;
// set url
public $url = '';

//all fields array
public $fields = array();

function __construct ()
$this->headers = array('Authorization: Bearer sk_test_STRIPE_API_KEY');
// ADD HERE STRIPE_API_KEY = your application stripe api key

// PHP functions to curl call
function call ()
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);

return json_decode($output, true); // return here php array with stripe api response

$subscription = new Stripe();
// add your subscription id hear
$subscription->url .= 'subscriptions/sub_B6N1qfu8XnGEZp';
// sub_B6N1qfu8XnGEZp is example
$subscription->fields['plan'] = 'your-new-plan';
// add your plan

$subscription_add = $subscription->call();
echo "<pre>";
echo "</pre>";

Hope this code and post will helped you for implement Stripe downgrade-upgrade using API in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  18  =  28

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US