Paytm Payment Gateway Integration with PHP

Today, We want to share with you Paytm Payment Gateway Integration with PHP.In this post we will show you wordpress plugin require another plugin, hear for callback url in paytm integration we will give you demo and example for implement.In this post, we will learn about paytm payment gateway integration in android with an example.

Paytm Payment Gateway Integration with PHP

There are the Following The simple About paytm gratification api Full Information With Example and source code.

As I will cover this Post with live Working example to develop How we can integrate Paytm payment gateway using PHP, so the Laravel 6 Paytm Payment Gateway Integration Using PHP is used for this example is following below.

Simple Paytm is a very famous and best way to make payments these some days. To step by step here explain into php Paytm source code integrate Paytm in our popular blog website we need to follow the simple below steps –

Step 1. Paytm create an account

First of all, we need to make an account devloper Like as at Sign Up/Register Paytm Account as well as here retrive our main merchant ID as well Secret Key.

and then we can start PHP source coding in our site to use the Paytm. First of all, we will setting / configure the Paytm with mode of the test credentials to test our source code.

Step 2. configure the Paytm with test credentials

(filename – config.php)
[php]
define(‘PAYTM_ENVIRONMENT’, ‘TEST’); // PROD for live payment
define(‘PAYTM_MERCHANT_KEY’, ‘xxxxxxxxxxxxxxx’);
define(‘PAYTM_MERCHANT_MID’, xxxxxxxxxxxxxxxx);
define(‘PAYTM_MERCHANT_WEBSITE’, “WEBSTAGING”);
define(‘PAYTM_REDIRECT_URL’, “http://localhost/paytm/Response.php”);
$PAYTM_TXN_URL=’https://securegw-stage.paytm.in/theia/processTransaction’;
if (PAYTM_ENVIRONMENT == ‘PROD’) {
$PAYTM_TXN_URL=’https://securegw.paytm.in/theia/processTransaction’;
}
define(‘PAYTM_TXN_URL’, $PAYTM_TXN_URL);
[/php]

READ :  VueJS Directory Application Structure Example

Step 3. create the payment form

Now I shall make a new file(index.php) to make the payment form which will have the amount to be payment/paid as well as other more useful needed details –

[php]



Here Merchant Check Out Page


Merchant Check Out Page

	

S.No Label Value
Step : 1 “>
Step : 2
Step : 3
Step : 4
Step : 5

* – Mandatory Fields



[/php]

Step 4. Redirect.php

Here in this simple HTML form, I have set the form the action=”Redirect.php”, then we will make a new file with this name –

[php]



pakainfo.com – Merchant Check Out Page


Please do not refresh this page…

$value) {
echo ‘‘;
}
?>
document.f1.submit();



[/php]

To handle the response of return call from paytm we need another file(Response.php) –

[php]
Checksum matched and following are the transaction Information:” . “
“;
if ($_POST[“STATUS”] == “TXN_SUCCESS”) {
echo “Transaction status is success” . “
“;
}
else {
echo “Transaction status is failure” . “
“;
}

if (isset($_POST) && count($_POST)>0 )
{
foreach($_POST as $paramName => $paramValue) {
echo “
” . $paramName . ” = ” . $paramValue;
}
}

}
else {
echo “Checksum mismatched.“;
}

?>
[/php]

Some Important Notes – Paytm Payment Gateway Integration with PHP

1. When I make an account for paytm payment gatway using PHP it asks us for a redirect URL where paytm will send the output. By default it will redirect to that URL, we can not change that.

If I want to pass the dynamic URL then I will need to contact support as well as ask them to enable the dynamic URL for our MERCHANT_ID for Paytm Payment Gateway Integration with PHP.

2. I can also pass some additional data while making a simple curl PHP call to paytm payment API as well as paytm will return that data in the output. But the name of that parameter can only be “MERC_UNQ_REF”. We can not pass user-defined parameter name.

3. SignIN data credentials for test MODE payment –

[php]
Mobile number – 9898989898
Password – 895689
[/php]

encdec_paytm.php

All the functions of the (encdec_paytm.php) file are below –

[php]
$value) {
$pos = strpos($value, $findme);
$pospipe = strpos($value, $findmepipe);
if ($pos !== false || $pospipe !== false)
{
continue;
}

if ($flag) {
$argQry .= liveStrCheck($value);
$flag = 0;
} else {
$argQry .= “|” . liveStrCheck($value);
}
}
return $argQry;
}

function convertArrTwoStringForVerify($dataVolumeList) {
$argQry = “”;
$flag = 1;
foreach ($dataVolumeList as $key => $value) {
if ($flag) {
$argQry .= liveStrCheck($value);
$flag = 0;
} else {
$argQry .= “|” . liveStrCheck($value);
}
}
return $argQry;
}

function redirect2PG($arguments, $key) {
$hashString = getchecksumFromArray($arguments);
$liveCurlecksum = encrypt_e($hashString, $key);
}

function removeCheckSumParam($dataVolumeList) {
if (isset($dataVolumeList[“PAYTMSUMDATAHASH”])) {
unset($dataVolumeList[“PAYTMSUMDATAHASH”]);
}
return $dataVolumeList;
}

function getTxnStatus($callServiceDataAPI) {
return callServicesMain(PAYTM_STATUS_QUERY_URL, $callServiceDataAPI);
}

function getTxnStatusNew($callServiceDataAPI) {
return paytmCallServices(PAYTM_STATUS_QUERY_NEW_URL, $callServiceDataAPI);
}

function initiateTxnRefund($callServiceDataAPI) {
$CHECKSUM = getRefundChecksumFromArray($callServiceDataAPI,PAYTM_MERCHANT_KEY,0);
$callServiceDataAPI[“CHECKSUM”] = $CHECKSUM;
return callServicesMain(PAYTM_REFUND_URL, $callServiceDataAPI);
}

function callServicesMain($paytmApiURI, $callServiceDataAPI) {
$dataJsonOutput = “”;
$outputArguments = array();
$JsonData =json_encode($callServiceDataAPI);
$requestArg = ‘JsonData=’.urlencode($JsonData);
$liveCurl = curl_init($paytmApiURI);
curl_setopt($liveCurl, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($liveCurl, CURLOPT_POSTFIELDS, $requestArg);
curl_setopt($liveCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($liveCurl, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($requestArg))
);
$dataJsonOutput = curl_exec($liveCurl);
$outputArguments = json_decode($dataJsonOutput,true);
return $outputArguments;
}

function paytmCallServices($paytmApiURI, $callServiceDataAPI) {
$dataJsonOutput = “”;
$outputArguments = array();
$JsonData =json_encode($callServiceDataAPI);
$requestArg = ‘JsonData=’.urlencode($JsonData);
$liveCurl = curl_init($paytmApiURI);
curl_setopt($liveCurl, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($liveCurl, CURLOPT_POSTFIELDS, $requestArg);
curl_setopt($liveCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($liveCurl, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($requestArg))
);
$dataJsonOutput = curl_exec($liveCurl);
$outputArguments = json_decode($dataJsonOutput,true);
return $outputArguments;
}
function getRefundChecksumFromArray($dataVolumeList, $key, $sort=1) {
if ($sort != 0) {
ksort($dataVolumeList);
}
$param = getRefundArray2Str($dataVolumeList);
$flag = generateCallBack_e(4);
$startdStr = $param . “|” . $flag;
$hash = hash(“sha256”, $startdStr);
$hashString = $hash . $flag;
$liveCurlecksum = encrypt_e($hashString, $key);
return $liveCurlecksum;
}
function getRefundArray2Str($dataVolumeList) {
$findmepipe = ‘|’;
$argQry = “”;
$flag = 1;
foreach ($dataVolumeList as $key => $value) {
$pospipe = strpos($value, $findmepipe);
if ($pospipe !== false)
{
continue;
}

if ($flag) {
$argQry .= liveStrCheck($value);
$flag = 0;
} else {
$argQry .= “|” . liveStrCheck($value);
}
}
return $argQry;
}
function callRefundAPI($refundApiURL, $callServiceDataAPI) {
$dataJsonOutput = “”;
$outputArguments = array();
$JsonData =json_encode($callServiceDataAPI);
$requestArg = ‘JsonData=’.urlencode($JsonData);
$liveCurl = curl_init($paytmApiURI);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($liveCurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($liveCurl, CURLOPT_URL, $refundApiURL);
curl_setopt($liveCurl, CURLOPT_POST, true);
curl_setopt($liveCurl, CURLOPT_POSTFIELDS, $requestArg);
curl_setopt($liveCurl, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = ‘Content-Type: application/json’;
curl_setopt($liveCurl, CURLOPT_HTTPHEADER, $headers);
$dataJsonOutput = curl_exec($liveCurl);
$outputArguments = json_decode($dataJsonOutput,true);
return $outputArguments;
}
[/php]

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Paytm Payment Gateway Integration with PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment