How to Integrate Paytm Payment Gateway with PHP

Sagarvermaitdeveloper
3 min readMay 21, 2020

--

Here we discuss the payTm payment gateway with our own PHP code.There are some steps to integrate payTm payment gateway with our application. so lets start.

  1. First go to the businesspayTm.com, also link is given below

Go and make a a account if you have an existing normal paytm account you may also use that account.

Go to developer options and click API keys once you click the API keys how you have got the screen like this .

Scroll down and go to the developer Integration guide… you will see the the payment solution block. in the payment solution block click the website integration -> standard checkOut. scroll the screen you will see this screen

You have to select the php from for web section this will redirect you to the github page . you need to download the zip file and you need to unzip in your application.

When you unzip the file you got payTm Kit. in this payTmKit there is folder lib in this folder you need to go config_paytm.php and edit this with you merchant_id and merchant_key with your account merchant_id and merchant_key just like this.

define('PAYTM_ENVIRONMENT', 'TEST'); //PROD 
define
('PAYTM_MERCHANT_KEY', 'YOUR_MERCHANT_KEY'); //Change this constant's value with Merchant key received from Paytm.
define
('PAYTM_MERCHANT_MID', 'YOUR_MERCHANT_ID'); //Change this constant's value with MID (Merchant ID) received from Paytm.
define
('PAYTM_MERCHANT_WEBSITE', 'WEBSTAGING'); //Change this constant's value with Website name received from Paytm.

Your configuration is done. now you need to connect with your checkout form. and that checkout form you need call pgRedirect which is present in your payTmKit folder.

<form method="post" action="paytmKit/pgRedirect.php">

this will redirect you to the this page

if apayment is done by paytm it gives a response in pgResponse.php which is present in PayTmkit you just need to uncomment the code in pgRedirect.php.edit with your site url.

$paramList["CALLBACK_URL"] = "http://localhost:84/paytm/pgResponse.php";

this will give you the response success and do whatever in this codeblock.

if($isValidChecksum == "TRUE") {
echo "<b>Checksum matched and following are the transaction details:</b>" . "<br/>";
if ($_POST["STATUS"] == "TXN_SUCCESS") {
echo "<b>Transaction status is success</b>" . "<br/>";
//Process your transaction here as success transaction.
//Verify amount & order id received from Payment gateway with your application's order id and amount.
}

if error comes in the else you can also call another page.

Thanks.,

Tech Sagar

--

--

No responses yet