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 https://api.stripe.com/v1/subscriptions/sub_49ty47958G5z6a \ -u sk_test_a12RX8g5E58fT659vg4Gd1fp: \ -d plan=pro-monthly
Stripe Upgrading-Downgrading Plans
class Stripe { public $headers; // set url public $url = 'https://api.stripe.com/v1/'; //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); curl_close($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>"; print_r($subscription_add); 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 onlincode.org