Reputation: 19
I need a help in implementing of paytm payment gateway. i am implementing the gateway in android app and i have coded it correctly and i have no errors and the sandbox keys are working fine and i am getting the responses also but then paytm sent me a file naming 'check status API.php' and said this to me i m quoting my email
For Transaction Status API, kindly generate new checksum using MID and ORDER ID and pass it on below link https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData={"MID":"MID","ORDERID":"ORDERID","CHECKSUMHASH":"CHECKSUMHASH"}
Please do Url encoding for the CHECKSUMHASH after that pass checksumhash value to status API.
and i have a attachment this file
check status API.php
public function PaytmTransactionStatus($order_id){
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
require_once("lib/config_paytm.php");
require_once("lib/encdec_paytm.php");
$checkSum = "";
$data = array(
"MID"=>"DIY12386817555501617",// please use your own MID.
"ORDER_ID"=>$order_id,
);
$key = 'bKMfNxPPf_QdZppa';
$checkSum =getChecksumFromArray($data, $key);// Please use your own merchant key value.
$request=array("MID"=>'**************',
"ORDERID"=>$order_id,"CHECKSUMHASH"=>$checkSum);
$JsonData =json_encode($request);
$postData = 'JsonData='.urlencode($JsonData);
$url = "https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus";
$HEADER[] = "Content-Type: application/json";
$HEADER[] = "Accept: application/json";
$args['HEADER'] = $HEADER;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $args['HEADER']);
$server_output = curl_exec($ch);
return json_decode($server_output,true);
i modified MID and merchant key with mine and uploaded it to server but the api is not working it is returning me whole code written in the browser but it should return json.
Upvotes: 0
Views: 8499
Reputation: 3
Change Staging url
$url = "https://securegw-tage.paytm.in/order/status";
To
Production
$url = "https://securegw.paytm.in/order/status";
Upvotes: 0
Reputation: 512
There is an issue in the URL for staging and production URLs are different.
Staging
$url = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
LIVE
$url = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
Upvotes: 1
Reputation: 19
After some research work finally, i wrote something that works fine
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$order_id = $_POST['order_id'];
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
require_once("./lib/config_paytm.php");
require_once("./lib/encdec_paytm.php");
$checkSum = "";
$paramList = array();
$paramList["MID"] = 'YOUR MID'; //Provided by Paytm
$paramList["ORDER_ID"] = $order_id; //unique OrderId for every request
$checkSum = getChecksumFromArray($paramList,"YOUR KEY");
$paramList["CHECKSUMHASH"] = urlencode($checkSum);
$data_string = 'JsonData='.json_encode($paramList);
$ch = curl_init(); // initiate curl
$url = "https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus"; //
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); /
format
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
echo $output;
return json_decode($output, true);
}
?>
Upvotes: 0
Reputation: 1112
Use this code to check status:
<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
// following files need to be included
$raw_data = json_decode(file_get_contents('php://input'), true);
function pkcs5_unpad_e($text) {
$pad = ord($text{strlen($text) - 1});
if ($pad > strlen($text))
return false;
return substr($text, 0, -1 * $pad);
}
function pkcs5_pad_e($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function encrypt_e($input, $ky) {
$key = $ky;
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc');
$input = pkcs5_pad_e($input, $size);
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', '');
$iv = "@@@@&&&&####$$$$";
mcrypt_generic_init($td, $key, $iv);
$data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$data = base64_encode($data);
return $data;
}
function getChecksumFromArray($arrayList, $key, $sort=1) {
if ($sort != 0) {
ksort($arrayList);
}
$str = getArray2Str($arrayList);
$salt = generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = encrypt_e($hashString, $key);
return $checksum;
}
function getArray2Str($arrayList) {
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
if ($flag) {
$paramStr .= checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . checkString_e($value);
}
}
return $paramStr;
}
//Gaurav check
function generateSalt_e($length) {
$random = "";
srand((double) microtime() * 1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for ($i = 0; $i < $length; $i++) {
$random .= substr($data, (rand() % (strlen($data))), 1);
}
return $random;
}
function checkString_e($value) {
$myvalue = ltrim($value);
$myvalue = rtrim($myvalue);
if ($myvalue == 'null')
$myvalue = '';
return $myvalue;
}
//test code
$checkSum = "";
$paramList = array();
$paramList["MID"] = 'your_MID';
$paramList["ORDERID"] = $raw_data["order_id"];
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($paramList,"your_key");
$check=urlencode($checkSum);
$paramList["CHECKSUMHASH"]=$check;
$data_string = json_encode($paramList);
$ch = curl_init(); // initiate curl
$url = "https://secure.paytm.in/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData=".$data_string; // where you want to post data
$headers = array('Content-Type:application/json');
$ch = curl_init(); // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1); // tell curl you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); // define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
//print_r($info)."<br />";
echo ($output);
?>
Upvotes: 0