Coupon Codes with Stripe using php

Coupon Codes with Stripe using php

In this post we will show you Coupon Codes with Stripe using php, hear for Coupon Codes with Stripe using php we will give you demo and example for implement.

hear we use curl for call Coupon Codes with Stripe using php, we need to pass YOUR_STRIPE_API_KEY, email, coupon


this is Stripe class file and we need to include it in you main php file.

// create class for Stripe
class Stripe
public $stripe_headers;
// set api url
public $url = '';

// set all array for fields data
public $fields = array();

function __construct ()
$this->stripe_headers = array('Authorization: Bearer YOUR_STRIPE_API_KEY');

// set PHP functions for curl call
function call ()
$get_output = "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->stripe_headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->fields));
// for https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$get_output = curl_exec($ch);
// stripe api response return here php array
return json_decode($get_output, true);


this is main file for execute Stripe api, Coupon Codes with Stripe.

// include Stripe.php file

$set_subscription = new Stripe();
$set_subscription->url .= 'customers';
$set_subscription->fields['email'] = '';
$customer = $set_subscription->call();

// create simple customer subscription with your credit card and simple plan
$set_subscription = new Stripe();
$set_subscription->url .= 'customers/'.$customer['id'].'/subscriptions';

//add your plan i.e. 'ULTIMATE'
$set_subscription->fields['plan'] = 'ULTIMATE';

//starter plan name of the simple stripe plan
//add your coupon i.e. 'ADD-YOUR-COUPON'

$set_subscription->fields['coupon'] = 'ADD-YOUR-COUPON';

//add trial end time
$set_trial_end  = date(strtotime("+28 day"));
$set_subscription->fields['trial_end'] = $set_trial_end;

$subscription_add = $set_subscription->call();
echo "Coupon Codes with Stripe using php <br><br>";
echo "<pre>";
echo "</pre>";

Hope this code and post will helped you for implement Coupon Codes with Stripe using 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 *

4  +  2  =  

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