Integrate Paytm Payment Gateway for Subscriptions and Recurring Billing in Laravel

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now
Featurepaytm/paytm-pgpaytm/paytmchecksumanandsiddharth/laravel-paytm-wallet
PurposeFull Paytm Payment Gateway API SDKOnly for checksum signing/verificationLaravel package for simple Wallet/PG payments (old)
Recurring Payment Support✅ Yes❌ No❌ No
Subscription Creation/Management✅ Yes❌ No❌ No
UPI Autopay✅ Yes❌ No❌ No
Card Tokenization (required for Recurring)✅ Yes❌ No❌ No
Wallet Payments✅ Yes❌ No✅ Yes
Laravel Integration❌ Raw PHP SDK, you write controller manually❌ Only PHP helper library✅ Pre-built Laravel support (but for old APIs only)
Maintenance✅ Official, regularly updated✅ Official, regularly updated❌ Unofficial, rarely updated
Dependency on Paytm Docs✅ High, because raw API handling✅ Used for checksum calculation in all types✅ Minimal, because handled internally (but outdated logic)
Security (Signature Handling)Manual handling with checksum libNeeded for secure callsInternal checksum handling (but old method)
Good ForFull latest Subscription, UPI, Recurring, Wallet, Card paymentsOnly checksum signing/verifyingOnly simple one-time wallet payments
Bad ForIf you don’t want to manage API manuallyIf you think it’s a full SDK (it’s not)Recurring/Subscription, UPI autopay

🔥 Conclusion (Real World):

NeedWhat to use
Full Professional Paytm Gateway integration (Subscription, Recurring, UPI Autopay)paytm/paytm-pg + paytm/paytmchecksum
Only simple Wallet payment (no recurring, no subscription)anandsiddharth/laravel-paytm-wallet

✅ Full Tutorial: Paytm Subscription & Recurring Payments (Laravel)


Step 1: Install Paytm Official Packages

composer require paytm/paytm-pg
composer require paytm/paytmchecksum

✅ This will install the latest versions.


Step 2: Set Paytm Credentials in .env

PAYTM_ENVIRONMENT=PROD
PAYTM_MERCHANT_ID=YOUR_MERCHANT_ID
PAYTM_MERCHANT_KEY=YOUR_MERCHANT_KEY
PAYTM_WEBSITE=YOUR_WEBSITE_NAME
PAYTM_CALLBACK_URL=https://yourdomain.com/paytm/subscription/callback

✅ (Get all these from your Paytm Dashboard)


Step 3: Create Subscription Request API (Laravel Controller)

Create SubscriptionController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Paytm\pg\MerchantProperty;
use Paytm\pg\RefundApi;
use Paytm\pg\SubscriptionApi;
use Paytm\pg\TransactionApi;
use Paytm\pg\utility\Config;
use Paytm\pg\utility\PaytmHelper;
use PaytmChecksum;

class SubscriptionController extends Controller
{
    public function createSubscription(Request $request)
    {
        // Step 1: Set Paytm environment properties
        MerchantProperty::setMerchantId(env('PAYTM_MERCHANT_ID'));
        MerchantProperty::setMerchantKey(env('PAYTM_MERCHANT_KEY'));
        MerchantProperty::setMerchantWebsite(env('PAYTM_WEBSITE'));
        MerchantProperty::setIndustryTypeId('Retail');
        MerchantProperty::setChannelId('WEB');

        // Step 2: Prepare subscription body
        $body = [
            "requestType"   => "NATIVE_SUBSCRIPTION",
            "mid"           => env('PAYTM_MERCHANT_ID'),
            "websiteName"   => env('PAYTM_WEBSITE'),
            "subscriptionRequest" => [
                "subscriptionAmountType" => "FIX",
                "subscriptionAmount" => "100.00",
                "subscriptionFrequency" => "MONTHLY",
                "subscriptionFrequencyUnit" => "MONTH",
                "subscriptionStartDate" => now()->addMinutes(5)->format('Y-m-d'), // Start after 5 mins
                "subscriptionGraceDays" => 3,
                "subscriptionExpiryDate" => now()->addYear(1)->format('Y-m-d'),
                "paymentInstrument" => [
                    "paymentMode" => "CARD",
                ],
                "payerInfo" => [
                    "name" => "John Doe",
                    "email" => "john@example.com",
                    "mobile" => "7777777777",
                ],
            ]
        ];

        // Step 3: Generate Checksum
        $checksum = PaytmChecksum::generateSignature(json_encode($body), env('PAYTM_MERCHANT_KEY'));

        // Step 4: Prepare final request
        $header = [
            "signature" => $checksum
        ];

        $paytmParams = [
            "head" => $header,
            "body" => $body
        ];

        // Step 5: Send the Subscription Request
        $url = "https://securegw.paytm.in/subscription/create";

        $response = $this->callNewApi($url, $paytmParams);

        return response()->json(json_decode($response, true));
    }

    private function callNewApi($url, $params)
    {
        $data_string = json_encode($params);

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, [ 
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string)
        ]);

        $response = curl_exec($ch);

        return $response;
    }
}

Step 4: Setup Route in web.php

use App\Http\Controllers\SubscriptionController;

Route::post('/paytm/subscription', [SubscriptionController::class, 'createSubscription']);

Step 5: Handle Callback/Webhook after Subscription

Create another function:

public function subscriptionCallback(Request $request)
{
    // Paytm will POST data here
    $payload = $request->all();

    // Validate signature
    $isValidChecksum = PaytmChecksum::verifySignature(
        json_encode($payload['body']), 
        env('PAYTM_MERCHANT_KEY'), 
        $payload['head']['signature']
    );

    if ($isValidChecksum) {
        // Update your database subscription status
        return response('Callback handled successfully.', 200);
    } else {
        return response('Invalid checksum', 400);
    }
}

Your Flow Will Be:

  1. Frontend → Call /paytm/subscription → Start Subscription
  2. Paytm → Redirect/Callback → /paytm/subscription/callback
  3. Laravel backend → Capture and validate → Update Subscription table.

Tip:

Paytm also provides Webhook URLs (for subscription renewal, payment failures, etc.).
✅ Make sure to listen to webhook events and handle renewals or failures properly in production!


✅ Final Recommendation:

SituationWhat to Use
Professional Subscription + Recurring Payment Handlingpaytm/paytm-pg + paytm/paytmchecksum
Old Style Wallet Payment Onlyanandsiddharth/laravel-paytm-wallet

Senior Software Development Engineer at Cotocus

Related Posts

How We Fixed a Stubborn Laravel MeiliSearch Bulk Indexing Failure (16,000+ Records)

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now If…

Read More

Laravel Search Without Docker, Queues, or Horizon

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Modern…

Read More

Laravel Scout with Typesense vs Meilisearch

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Modern…

Read More

SESSION_DRIVER=file vs SESSION_DRIVER=database in Laravel

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Which…

Read More

Laravel Logging: Complete Step-by-Step Guide to Enable, Debug, Verify, and Master Logs in Any Laravel Project

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Logging…

Read More

Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now This…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments