用于支付网关的 PHP 交易状态 API

问题描述 投票:0回答:4

我正在开发 PayUMoney 支付网关。我已经整合成功了。现在,在接受 PayUMoney 的审核流程之前,他们突然告诉我,我必须在我的门户上集成交易状态 API。他们为我提供了 API。我也已经整合了。以下是他们提供给我的代码。

$key = "gtKFFx";
$salt = "eCwWELxi";
$command = "verify_payment";
$var1 = "NPMM87334121";

//hash formaula
$hash_str = $key  . '|' . $command . '|' . $var1 . '|' . $salt ;
$hash = strtolower(hash('sha512', $hash_str));
$r = array('key' => $key , 'hash' =>$hash , 'var1' => $var1, 'command' => $command);
$qs= http_build_query($r);
$wsUrl = "https://test.payu.in/merchant/postservice.php?form=1";
//$wsUrl = "https://info.payu.in/merchant/postservice?form=1";

$c = curl_init();
curl_setopt($c, CURLOPT_URL, $wsUrl);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $qs);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
$o = curl_exec($c);
if (curl_errno($c)) {
  $sad = curl_error($c);
  throw new Exception($sad);
}
curl_close($c);

$valueSerialized = @unserialize($o);
if($o === 'b:0;' || $valueSerialized !== false) {
  print_r($valueSerialized);
}
print_r($o);

上面的代码给我的回应如下:

Array
(
    [status] => 1
    [msg] => 1 out of 1 Transactions Fetched Successfully
    [transaction_details] => Array
        (
            [NPMM87334121] => Array
                (
                    [mihpayid] => 403993715517090502
                    [request_id] => 
                    [bank_ref_num] => 
                    [amt] => 100813.00
                    [transaction_amount] => 100813.00
                    [txnid] => TRANS-2011-01-05-11-05-00
                    [additional_charges] => 0.00
                    [productinfo] => Test
                    [firstname] => Test User
                    [bankcode] => CC
                    [udf1] => 
                    [udf3] => 
                    [udf4] => 
                    [udf5] => 
                    [field2] => 
                    [field9] => FSS0001-Authentication Not Available
                    [error_code] => E500
                    [payment_source] => payu
                    [card_type] => VISA
                    [error_Message] => Bank failed to authenticate the customer
                    [net_amount_debit] => 0.00
                    [disc] => 0.00
                    [mode] => CC
                    [PG_TYPE] => HDFCPG
                    [card_no] => 411111XXXXXX1111
                    [name_on_card] => Demo
                    [udf2] => 
                    [addedon] => 2018-01-05 11:21:36
                    [status] => failure
                    [unmappedstatus] => failed
                    [Merchant_UTR] => 
                    [Settled_At] => 
                )

        )

)

在此之后,我编写了以下行来访问上述响应。

$checkout_data = $o['transaction_details'][$var1];

但是在这行之后它给了我以下错误。

Message: Illegal string offset 'transaction_details'
Message: Illegal string offset 'NPMM87334121'

我不明白我哪里做错了。 payu 给出的响应位于数组中,因此如果我将其作为数组访问,仍然会出现错误。

php payment-gateway payumoney
4个回答
2
投票

使用此 url 获取 Payu Status Api

$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2";

注意变量形式=2而不是1
此 url 返回 json 输出 而形式=1 返回难以操作的数组输出


2
投票

它返回 pre 标记内数组的 print_r 。响应不是数组而是文本 根据 manojit 我们必须使用

$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2";

form=2 获取json格式

数组
(
[状态] => 1
[msg] => 1 笔交易已成功获取
[transaction_details] => 数组
(
[0345b17744cc6e0bab66] => 数组
(
[mihpayid] => 403993715521192567
[请求 ID] =>
[银行参考编号] =>
[金额] => 1.00
[交易金额] => 1.00
[txnid] => 0345b17744cc6e0bab66
[额外费用] => 0.00
[productinfo] =>“CartItemId”“28729”“CartId”“1423”“ProductId”
[名字] => ss dhar
[银行代码] => CC
[udf1] => [{"CartItemId":"28729","CartId":"1423","ProductId":"58","BasePrice":"890.00","数量":"1","ItemPromoId" :null,"ItemPromoDiscount":null
[udf3] => 900xxxxx00
[udf4] => xx xx路戈拉巴扎尔
[udf5] => 0345b17744cc6e0bab66
[字段2] =>
[field9] => FSS0001 - 身份验证不可用。
[错误代码] => E501
[补充] => 2020-06-26 10:49:43
[ payment_source ] => 付款
[卡类型] => VISA
[error_Message] => 银行无法验证。
[净借额] => 0.00
[光盘] => 0.00
[模式] => CC
[PG_TYPE] => HDFCPG
[卡号] => 401200XXXXXX1112
[卡上姓名] => swarna xxxx dhar
[udf2] => [电子邮件受保护]
[状态] => 失败
[未映射状态] => 失败
[Merchant_UTR] =>
[已解决_At] =>
)

) ) </pre>

0
投票

更新代码的 Curl 部分,如下所示:

$wsUrl = "https://info.payu.in/merchant/postservice?form=2";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $wsUrl);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $qs);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
$o = curl_exec($c);
if (curl_errno($c)) {
  $sad = curl_error($c);
  throw new Exception($sad);
}
curl_close($c);

$valueSerialized = @unserialize($o);
if($o === 'b:0;' || $valueSerialized !== false) {
  print_r($valueSerialized);
} 
//print_r($o);

$o = json_decode($o);

foreach($o->transaction_details as $key => $val){
    if(($val->status=="success")&&($val->unmappedstatus=="captured")){
        // Update
    }
}

-1
投票
$valueSerialized = @unserialize($o);
if($o === 'b:0;' || $valueSerialized !== false) {
  print_r($valueSerialized);
}
print_r($o);

$checkout_data = $o['transaction_details'][$var1];

您正在访问(序列化的)字符串

$o
而不是未序列化的对象
$valueSerialized

所以应该是

$checkout_data = $valueSerialized['transaction_details'][$var1];

您的脚本中存在巨大问题:

  • 您关闭了安全性,您应该删除线路

    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);

  • 变量名称具有误导性(例如称为序列化的变量中的未序列化值)

  • 您没有对 HTTP 响应状态代码进行错误检查,并且您正在抑制

    @unserialize($o)
    中的错误。不要使用
    @

© www.soinside.com 2019 - 2024. All rights reserved.