我正在使用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给出的响应是在数组中,所以如果我作为数组访问它,仍然为什么它给我错误。
答案 0 :(得分:1)
它在pre标签内返回数组的print_r。响应不是数组,而是文本 根据manojit,我们必须使用
$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2";
form = 2 获取json格式
Array
(
[status] => 1
[msg] => 1 out of 1 Transactions Fetched Successfully
[transaction_details] => Array
(
[0345b17744cc6e0bab66] => Array
(
[mihpayid] => 403993715521192567
[request_id] =>
[bank_ref_num] =>
[amt] => 1.00
[transaction_amount] => 1.00
[txnid] => 0345b17744cc6e0bab66
[additional_charges] => 0.00
[productinfo] => quot CartItemId quot quot 28729 quot quot CartId quot quot 1423 quot quot ProductId quot
[firstname] => ss dhar
[bankcode] => CC
[udf1] => [{"CartItemId":"28729","CartId":"1423","ProductId":"58","BasePrice":"890.00","Quantity":"1","ItemPromoId":null,"ItemPromoDiscount":null
[udf3] => 9007291400
[udf4] => 12 md road gorabazar
[udf5] => 0345b17744cc6e0bab66
[field2] =>
[field9] => FSS0001-Authentication Not Available.
[error_code] => E501
[addedon] => 2020-06-26 10:49:43
[payment_source] => payu
[card_type] => VISA
[error_Message] => Bank was unable to authenticate.
[net_amount_debit] => 0.00
[disc] => 0.00
[mode] => CC
[PG_TYPE] => HDFCPG
[card_no] => 401200XXXXXX1112
[name_on_card] => swarna sekhar dhar
[udf2] => xyx.9@gmail.com
[status] => failure
[unmappedstatus] => failed
[Merchant_UTR] =>
[Settled_At] =>
)
)
)
</pre>
答案 1 :(得分:0)
将此网址用于Payu Status Api
$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2";
注意变量形式= 2而不是1
此url返回json输出
而形式= 1
返回难以操作的数组输出
答案 2 :(得分:-1)
更新代码的卷曲部分,如下所示:
$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
}
}
答案 3 :(得分:-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)
中的错误。请勿使用@
。