Stripe Payment API – Create Monthly Subscription Plan, Create Customer & Assign Customer to the Plan

Stripe API request and response code to create monthly subscription plan, create customer and assign customer to the plan to be charged every month, posted by stripe checkout.js

API Installation Links:

API Usage Links

<?php require_once('vendor/autoload.php'); // check the link on github above on how to get it

// ****** One time charge, posted by stripe checkout.js
// charge card (not relevant for this topic)
$charge_response = \Stripe\Charge::create(array(
				"amount" 	=> 1000,
				"currency" 	=> "usd",
				"source"		=> $token,
				"description" => $email
// end of one time charge

// ***** Create monthly subscription plan, customer & 
// ***** assign customer to the plan to be charged every month
// ***** posted by stripe checkout.js

// create plan
$plan = \Stripe\Plan::create(array(
  "name" => "Xyz Monthly Plan",
  "id" => "xyz-monthly",
  "interval" => "month",
  "currency" => "usd",
  "amount" => 1000,

// create customer
$customer_response = \Stripe\Customer::create(array(
  "email" => $email,
  "source" => $token,

// response after customer is created
echo $customer_response;  // response
echo $customer_response->id; // customer id
echo $customer_response->email; // email
echo $customer_response->data->brand; // credit card type
echo $customer_response->data->last4; // credit card last 4 digits
echo $customer_response->data->exp_month; // expiry month
echo $customer_response->data->exp_year;  // expiry year

// assign customer to plan to be charged every month
$assign_response = \Stripe\Subscription::create(array(
  "customer" => $customer_response->id,
  "plan" => "xyz-monthly",


Please check the comments within the code for better understanding. In case you run into any problems please check the Events and/or Logs on the Stripe dashboard.

Hope it helps!