Paytm 支付网关交易 API 不工作
Paytm payment gateway transaction API not working
我在实施 paytm 支付网关方面需要帮助。我在 android 应用程序中实现了网关,我已经正确编码,没有错误,沙箱密钥工作正常,我也收到了回复,但 paytm 给我发送了一个文件命名 'check status API.php'并且对我说了这句话,我引用了我的电子邮件
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.
我有这个文件的附件
查看状态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);
我用我的修改了 MID 和商家密钥并将其上传到服务器但是 api 不工作它是 return 把整个代码写在浏览器中但它应该 return json.
使用此代码检查状态:
<?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);
?>
经过一些研究工作,我终于写了一些很好用的东西
<?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);
}
?>
暂存和生产 URL 中存在问题 URL 不同。
分期
$url = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
直播
$url = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
改变
分期url
$url = "https://securegw-tage.paytm.in/order/status";
到
生产
$url = "https://securegw.paytm.in/order/status";
我在实施 paytm 支付网关方面需要帮助。我在 android 应用程序中实现了网关,我已经正确编码,没有错误,沙箱密钥工作正常,我也收到了回复,但 paytm 给我发送了一个文件命名 'check status API.php'并且对我说了这句话,我引用了我的电子邮件
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.
我有这个文件的附件
查看状态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);
我用我的修改了 MID 和商家密钥并将其上传到服务器但是 api 不工作它是 return 把整个代码写在浏览器中但它应该 return json.
使用此代码检查状态:
<?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);
?>
经过一些研究工作,我终于写了一些很好用的东西
<?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);
}
?>
暂存和生产 URL 中存在问题 URL 不同。
分期
$url = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
直播
$url = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
改变 分期url
$url = "https://securegw-tage.paytm.in/order/status";
到
生产
$url = "https://securegw.paytm.in/order/status";