Manage Recurring/Subscription Payments using Stripe billing in PHP

A subscription is a product or service which is paid for periodically, rather than all at once. Subscriptions fees are usually charged for a consistent time period, typically in weeks, months, or years. Stripe is a system to accept payments via credit cards. Instead of you handling all the security compliance and banking transactions. In this tutorial, We have share how to integrate Manage Recurring/Subscription Payments using Stripe billing in PHP. This is a very simple example, you can just copy paste and change according to your requirement.
Step-1: Create a Stripe account and get API keys
  • Create a Stripe account and login to the dashboard.
  • Navigate to the Developers » API keys page.
  • There is two type of standard API keys named secret key and publishable key.To show the Secret key, click on Reveal test key token button.
Before you get started, take a look at the folders and files structure of Manage Recurring/Subscription Payments using Stripe billing in PHP
  • manage-subscription-payments-using-stripe-billing-in-php
    • css
      • style.css
    • images
    • templates
      • header.php
      • footer.php
    • config.php
    • index.php
    • charge.php
Step 2. JavaScript
You add Stripe Javascript code on your page.
  
Step 3: Create Product and Subscription Plan
 [
          "name" => 'Name',
          "type" => "service"
      ],
      "nickname" => 'nick name',
      "interval" => 'year',
      "interval_count" => "1",
      "currency" => 'usd',
      "amount" => 100 ,
  ));
  ?>
Step 4: Create Customer
 ,
  'source'  => ,
]);
?>
Step 5: Create Subscription by Mapping the Plan to Customer
 '',
    'items' => [['plan' => '']],
]);
?>
So let’s add both variables inside our config.php, like this:
  
Step 6: Handles subscription process
index.php





 

Manage Recurring/Subscription Payments using Stripe billing in PHP

Price

No Hidden Costs

  • Custom Design
  • Choice of Layout
  • Number of Pages Included
  • Update and add pages (CMS)
  • Mobile Friendly Design
  • Homepage Banner Designs
  • Professional Logo Design
  • Search Engine Friendly
  • Search Engine Submission
  • Website Contact Form
  • Built on WordPress
  • Search Engine Optimisation
  • Website Visitor Statistics
  • Full Website Ownership
  • Google Maps Integration
  • 5GB SSD Disk Space
  • 5 Email Addresses
  • Free Domain Name for 1 year
  • Free Website hosting for 1 year
  • UK Email Support
  • Built in the UK, NO outsourcing
Starter Package
$399

  • Custom Design
  • Choice of Layout
  • 1 - 3 Pages
  • Update and add pages (CMS)
  • Mobile Friendly Design
  • Homepage Banner Designs 1
  • Professional Logo Design
  • Search Engine Friendly
  • Search Engine Submission
  • Website Contact Form
  • Built on WordPress
  • Search Engine Optimisation
  • Website Visitor Statistics
  • Full Website Ownership
  • Google Maps Integration
  • 5GB SSD Disk Space
  • 5 Email Addresses
  • Free Domain Name for 1 year
  • Free Website hosting for 1 year
  • UK Telephone/Email Support
  • Built in the UK, NO outsourcing
Advanced Package
$799

  • Custom Design
  • Choice of Layout
  • 3 - 6 Pages
  • Update and add pages (CMS)
  • Mobile Friendly Design
  • Homepage Banner Designs 1
  • Professional Logo Design
  • Search Engine Friendly
  • Search Engine Submission
  • Website Contact Form
  • Built on WordPress
  • Search Engine Optimisation
  • Website Visitor Statistics
  • Full Website Ownership
  • Google Maps Integration
  • 5GB SSD Disk Space
  • 5 Email Addresses
  • Free Domain Name for 1 year
  • Free Website hosting for 1 year
  • UK Telephone/Email Support
  • Built in the UK, NO outsourcing
Business Package
$999


  • Custom Design
  • Choice of Layout
  • 6 - 9 Pages
  • Update and add pages (CMS)
  • Mobile Friendly Design
  • Homepage Banner Designs 1
  • Professional Logo Design
  • Search Engine Friendly
  • Search Engine Submission
  • Website Contact Form
  • Built on WordPress
  • Search Engine Optimisation
  • Website Visitor Statistics
  • Full Website Ownership
  • Google Maps Integration
  • 5GB SSD Disk Space
  • 5 Email Addresses
  • Free Domain Name for 1 year
  • Free Website hosting for 1 year
  • UK Telephone/Email Support
  • Built in the UK, NO outsourcing
charge.php
 [
          "name" => $plan,
          "type" => "service"
      ],
      "nickname" => $plan,
      "interval" => $interval,
      "interval_count" => "1",
      "currency" => $currency,
      "amount" => ($price*100) ,
  ));

  $customer = \Stripe\Customer::create([
      'email' => $email,
      'source'  => $token,
  ]);

   $subscription = \Stripe\Subscription::create(array(
      "customer" => $customer->id,
      "items" => array(
          array(
              "plan" => $plan->id,
          ),
      ),
  ));
?>
  

Manage Recurring/Subscription Payments using Stripe billing in PHP

Thank You!

Successfully charged $!

Please check your email for further instructions on how to complete your account setup.


Having trouble? Contact us

Continue to homepage

Create header.php and footer.php section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header and footer section.
header.php



  
    
  
  
  
  
  
  
  
  
  Manage Recurring/Subscription Payments using Stripe billing in PHP | Web Haunt
  
  
  
  
  
  
  
   


  
    
footer.php