Paytm Payment gateway integration in PHP: A Step-by-Step Guide

Paytm Payment gateway integration

In the modern digital economy, accepting online payments is crucial for businesses of all sizes. One of India’s most trusted payment platforms, Paytm offers a secure and easy-to-use payment gateway that can be integrated into your website or app. In this blog, we will show you how to integrate the Paytm payment gateway using PHP.

Why Choose Paytm Payment Gateway?

Before diving into the integration steps, let’s look at why Paytm is a preferred choice:

  • Wide User Base: Millions of active users across India.
  • Multiple Payment Options: Supports UPI, Credit/Debit Cards, Wallet, and Net Banking.
  • Security: PCI-DSS compliant, SSL-secured transactions.
  • Fast Settlements: Quick and reliable fund transfers.

Prerequisites for Integration

To integrate Paytm with your PHP-based website, you’ll need the following:

  1. A Paytm Business Account.
  2. Merchant ID (MID) and Merchant Key, provided by Paytm.
  3. A working PHP environment (XAMPP/LAMP or live server).
  4. Basic knowledge of PHP and HTML.

Step-by-Step Integration Process

Step 1: Create a Paytm Business Account

Go to Paytm for Business and register as a merchant. Once approved, you’ll receive:

  • MID (Merchant ID)
  • Merchant Key
  • Website name

You’ll need these credentials for integrating the gateway.

Step 2: Download the Paytm PHP SDK

Paytm provides a developer kit (SDK) for easy integration.

Step 3: Create a Transaction Page

Create an HTML form where users can enter payment details.

<form method="post" action="pgRedirect.php">
  <input type="text" name="ORDER_ID" value="ORD123456" hidden>
  <input type="text" name="CUST_ID" value="CUST001" hidden>
  <input type="text" name="TXN_AMOUNT" value="100">
  <input type="submit" value="Pay Now">
</form>

This form sends data to the pgRedirect.php file, which handles request redirection to Paytm.

Step 4: Configure config_paytm.php

This file contains your merchant credentials. Make sure it’s included in your project and configured properly.

define('PAYTM_ENVIRONMENT', 'TEST'); // or 'PROD'
define('PAYTM_MERCHANT_KEY', 'Your_Merchant_Key');
define('PAYTM_MERCHANT_MID', 'Your_MID');
define('PAYTM_MERCHANT_WEBSITE', 'WEBSTAGING'); // or your live website name

Step 5: Handle the Callback with pgResponse.php

After payment, Paytm will redirect to your callback URL with the transaction response.

include("config_paytm.php");
include("encdec_paytm.php");

$paytmChecksum = "";
$paramList = $_POST;
$isValidChecksum = false;

$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";

$isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum);

if ($isValidChecksum && $_POST["STATUS"] == "TXN_SUCCESS") {
    echo "Transaction successful!";
    // Process order
} else {
    echo "Transaction failed!";
}

Testing the Integration

Paytm provides a sandbox environment for testing. Use the provided test credentials to simulate payments before going live.

Final Thoughts:-

Integrating Paytm Payment Gateway in PHP is a simple yet powerful way to enable digital payments on your platform. Whether you’re running an e-commerce store or a service-based website, the integration helps you accept payments securely and reliably.

Read also:-

For live implementation, make sure you switch to production credentials and follow all security guidelines.

Share this post :