Ad Code

Transaction Status API in PHP for PayU Payment Gateway

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'

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.

 

Use this url for Payu Status Api

 

$wsUrl = "https://test.payu.in/merchant/postservice.php?form=2"
$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
    }
} 
OR Single record
$checkout_data = $o->transaction_details->$var1->mihpayid;

 

Post a Comment

0 Comments