Paytm 支付网关交易 API 不起作用

Paytm payment gateway transaction API not working

提问人:vips singh 提问时间:3/14/2018 最后编辑:Deepak Raivips singh 更新时间:7/30/2021 访问量:8097

问:

我需要帮助来实施 paytm 支付网关。我正在 Android 应用程序中实现网关,我已经正确编码了它,我没有错误,沙盒键工作正常,我也收到了回复,但随后 Paytm 向我发送了一个名为“检查状态API.php”的文件,并对我说了这句话,我引用了我的电子邮件

对于交易状态 API,请使用 MID 和 ORDER ID 并将其传递到下面的链接 https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData={“MID”:“MID”,“ORDERID”:“ORDERID”,“CHECKSUMHASH”:“CHECKSUMHASH”}

请在通过后对 CHECKSUMHASH 进行 Url 编码 checksumhash 值设置为状态 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 不起作用,它返回给我在浏览器中编写的整个代码,但它应该返回 json。

PHP Android 支付网关 Paytm

评论


答:

0赞 Insane Developer 3/14/2018 #1

使用以下代码检查状态:

<?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);
?>

评论

0赞 vips singh 3/14/2018
{“ErrorCode”:“CMER-IP101”,“ErrorMsg”:“内部处理错误”} 我在运行脚本后得到的响应,我在代码中更改了我的 MID,我们不需要更改密钥吗很好,但我在代码中找不到密钥......
0赞 Insane Developer 3/14/2018
您是否在代码中编辑了 MID 和密钥?
0赞 Insane Developer 3/14/2018
这里的校验和字符串将由 getChecksumFromArray() 函数返回。$checkSum = getChecksumFromArray($paramList,“your_key”);
0赞 vips singh 3/14/2018
是的,现在我用我的密钥更新了密钥,但错误保持不变
0赞 Insane Developer 3/14/2018
这就是对我有用的东西。你有库文件config_paytm.php和encdec_paytm.php吗?
0赞 vips singh 3/15/2018 #2

经过一些研究工作,我终于写了一些效果很好的东西

<?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);

     }

     ?>
1赞 ajmirani 4/19/2020 #3

暂存和生产 URL 的 URL 存在问题。

分期
$url = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';


$url = 'https://securegw.paytm.in/merchant-status/getTxnStatus';

0赞 sunil mehra 7/30/2021 #4

更改暂存网址

$url = "https://securegw-tage.paytm.in/order/status";

生产

$url = "https://securegw.paytm.in/order/status";