Razorpay Recurring Subscriptions

Collect recurring payments from your customers easily.

techhawa-razorpay-recurring-payment-home

Using Razorpay Subscriptions you can automatically charge customers based on a billing cycle that you control. You can easily create and manage recurring payments and get instant alerts on payment activity as well as the status of subscriptions. Razorpay handles all the complexities of managing recurring payments on your behalf.

Note: You can charge as per a fixed schedule and do not require any intervention on the customer’s end as it is automated.

#1.Define a plan

The first step to creating a subscription is to create a plan. A plan contains product details along with the amount and frequency of the billing cycles. Depending upon your business, you can create multiple plans with different billing cycles and pricing.To create a plan from the Dashboard:

  • Create an Razorpay Account.
  • Go to Subscriptions, click on getting started( if you are coming for first time) and choose plans tab.

  • techhawa_subsciption_create_plan
  • Click New Plan Button.
  • Enter the Plan Name,Plan Description, Billing Frequency, Billing Amount and Internal Notes details(optional) as shown below.

  • techhawa_subscription_create_plan_details

#2. Creating a Subscription

The next step is creating a subscription using the plan you created in Step 1. You have to define the following details when creating a subscription:

  • Copy and paste the code in your website to create automatic subscription.
  • <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://user-key-id:[email protected]/v1/subscriptions",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "plan_id=techhawa_user_plan_id&total_count=12&customer_notify=1",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded",
        "postman-token: 67d92778-3ca8-ffb4-9680-c384d115f95a"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
    
    ?>
    
  • Now replace the user-key-id, user-key-secret and plan-id.
  • Note: You can get key and secret from here and plan id from step-1.

  • You will get response as shown below when you run the above code.

  • techhawa_razorpay_subscription_json

#3. Creating Payment Button

  • Pass the response you got in step-2 to Subscriber_Response Variable
  • Below code helps to store the subscription id
  • Note: Subscription id is stored in GetSubscriberId_Basic Variable.

    <p class="text-center py-3"><button id="techhawa" class="btn btn-primary"
     style="background-color: #4abba9 !important;"
     href="https://www.techhawa.com"  >
    TechHawa Recurring Subscription Demo</button></p>
    
    <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
    
    <script>
    var options = {
        "key": "Your-key",
        "subscription_id": "<?php echo $GetSubscriberId_Basic ?>",
        "name": "TechHawa -Let's Grow Together ",
        "description": "TechHawa Recurring Demo",
        "image": "https://techhawa.com/images/logo.png",
        "handler": function (response){
           
        },
        
        "theme": {
            "color": "#00a1f1"
        }
    };
    var techhawa= new Razorpay(options);
    
    document.getElementById('techhawa').onclick = function(e){
        techhawa.open();
        e.preventDefault();
    }
    </script>
    

  • Now replace the your-key in the javascript variable key and save the file with .html.
  • You can see the demo below.
  • Note: For live change the mode in razorpay dashboard top nav bar and copy the LIVE KEY-ID .


    Live Demo