用于支付网关的 PHP 交易状态 API [英] Transaction Status API in PHP for Payment Gateway
问题描述
我正在研究 PayUMoney 支付网关.我已经成功集成了它.现在,在通过 PayUMoney 进行审核之前,他们突然告诉我,我必须在我的门户上集成交易状态 API.他们为我提供了 API.我也集成了它.以下是他们提供给我的代码.
I am working on PayUMoney payment gateway. I have integrated it successfully. Now before undergoing through audit process by PayUMoney suddenly they told me that I have to integrate transaction status API on my portal. They have provided me API for it. I have integrated that also. Following is the code they have provided me.
$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);
上面的代码给了我如下回复:
Above Code gives me response as follows :
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] =>
)
)
)
在此之后,我写了以下行来访问上述回复.
After this I have written following line to access above response.
$checkout_data = $o['transaction_details'][$var1];
但是在这行之后,它给了我以下错误.
But after this line it gives me following error.
Message: Illegal string offset 'transaction_details'
Message: Illegal string offset 'NPMM87334121'
我不明白我在哪里做错了.payu 给出的响应在数组中,所以如果我将它作为数组访问,仍然为什么它给我错误.
I don't understand where I am doing the mistake. The response given by payu is in array so if I am accessing it as array, Still why it gives me error.
推荐答案
它返回 pre 标签内数组的 print_r .响应不是数组,而是文本根据 manojit 我们必须使用
it is returning a print_r of the array within a pre tag . the response is not an array its a text as per manojit we have to use
$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2";
form=2 获取json格式<前>大批([状态] =>1[味精] =>1 个交易中的 1 个成功获取[交易详情] =>大批([0345b17744cc6e0bab66] =>大批([mihpayid] =>403993715521192567[request_id] =>[bank_ref_num] =>[amt] =>1.00[交易金额] =>1.00[txnid] =>0345b17744cc6e0bab66[additional_charges] =>0.00[产品信息] =>quot CartItemId quot quot 28729 quot CartId quot quot 1423 quot 产品Id quot[名字] =>达哈尔[银行代码] =>抄送[udf1] =>[{CartItemId":28729",CartId":1423",ProductId":58",BasePrice":890.00",数量":1","ItemPromoId":null,"ItemPromoDiscount":null[udf3] =>9007291400[udf4] =>12 md 路戈拉巴扎[udf5] =>0345b17744cc6e0bab66[字段 2] =>[field9] =>FSS0001-身份验证不可用.[错误代码] =>E501[附加] =>2020-06-26 10:49:43[payment_source] =>支付宝[卡片类型] =>签证[error_Message] =>银行无法验证.[net_amount_debit] =>0.00[光盘] =>0.00[模式] =>抄送[PG_TYPE] =>HDFCPG[card_no] =>401200XXXXXX1112[name_on_card] =>swarna sekhar dhar[udf2] =>xyx.9@gmail.com[状态] =>失败[未映射状态] =>失败的[Merchant_UTR] =>[Settled_At] =>)
form=2 to get json format
这篇关于用于支付网关的 PHP 交易状态 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!