Pesapal.com

Forum

Welcome, Guest
Username
Password:
 

$status returning a link instead of actual status
(1 viewing) (1) Guest
Welcome to the Pesapal integration forum!

This forum discusses everything about Pesapal integration on your web site. Having any problems? This is the right place to post a question and we are sure you will get an answer
  • Page:
  • 1

TOPIC: $status returning a link instead of actual status

$status returning a link instead of actual status 6 months ago #2138

Hi, I am testing pesapal ipn listener in php using my sandbox account but the value that I'm getting for $status which I want to store in the database is a link ("demo.pesapal.com/api/querypaymentstatus?oauth_consumer_key) instead of something like completed, pending or failed. What I'm I doing wrong or is it an error with the sandbox test site. Any help help would be greatly appreciated. Thanks in advance. Here is the code
NB: I could not include my actual merchant key or secret for security reasons

<?php
include_once('oauth.php');
$consumer_key="xxxxxxxxxxxxxxxxxx";//Register a merchant account >set_parameter("pesapal_merchant_reference", $pesapal_merchant_reference);
$request_status->set_parameter("pesapal_transaction_tracking_id",$pesapalTrackingId);
$request_status->sign_request($signature_method, $consumer, $token);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_status);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if(defined('CURL_PROXY_REQUIRED')) if (CURL_PROXY_REQUIRED == 'True')
{
$proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
}

$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$raw_header = substr($response, 0, $header_size - 4);
$headerArray = explode("\r\n\r\n", $raw_header);
$header = $headerArray[count($headerArray) - 1];

//transaction status
$elements = preg_split("/=/",substr($response, $header_size));
$status = $elements[1];

curl_close ($ch);

//UPDATE YOUR DB TABLE WITH NEW STATUS FOR TRANSACTION WITH pesapal_transaction_tracking_id $pesapalTrackingId

$db_update_successful = $con->query(" UPDATE `pesapal_payments` SET `status`='$status' WHERE `pesapal_transaction_tracking_id`='$pesapalTrackingId' ");

if($db_update_successful && $status != "PENDING")
{
$resp="pesapal_notification_type=$pesapalNotification&pesapal_transaction_tracking_id=$pesapalTrackingId&pesapal_merchant_reference=$pesapal_merchant_reference";
ob_start();
echo $resp;
ob_flush();
exit;
}
}
?>
Last Edit: 6 months ago by slimfresh.

Re: $status returning a link instead of actual status 6 months ago #2139

  • ovicko
  • OFFLINE
  • Fresh Boarder
  • Contact me for OpenCart 2 Pesapal integration
  • Posts: 10
Try to echo $status and see the string returned

Re: $status returning a link instead of actual status 5 months, 4 weeks ago #2140

Hi slimfresh

did you manage to get the actual value of status instead of link ?


Am also getting link instead of status.., please shed some light if you've figured it out.
call me +255 787 133 559

whats app +255 713 884 130

This e-mail address is being protected from spambots. You need JavaScript enabled to view it.

Re: $status returning a link instead of actual status 5 months, 4 weeks ago #2141

@Ovicko

First of all thanks for the interest

Since the script is being executed in the backend, I emailed myself the value for $status and this is what I got

" demo.pesapal.com/api/querypaymentstatus?oauth_consumer_key
Last Edit: 5 months, 4 weeks ago by slimfresh.

Re: $status returning a link instead of actual status 5 months, 4 weeks ago #2143

Hi @slimfresh

I managed to get an actual status message...

What is happening is that pesapal is returning a redirection to a different url and STATUS is found in the final url location.


Add this line below the curl options and you should be able to get valid response,,

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);


this is how your final curl block should look like

 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_status);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
$response = curl_exec($ch);


That statement tells curl to follow each redirect and process the last effective url. We then parse the final url location to get status..

status will be COMPLETED or PENDING

I hope this helps.
call me +255 787 133 559

whats app +255 713 884 130

This e-mail address is being protected from spambots. You need JavaScript enabled to view it.

Re: $status returning a link instead of actual status 5 months, 4 weeks ago #2144

@salimsaid

It worked for me too!! Thanks man you just saved me a lot time. If there is any site administrator reading this thread please update the ipn sample code provided in the downloads section. Thanks again Salim.

Re: $status returning a link instead of actual status 5 months, 3 weeks ago #2153

  • gummy123
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
You may echo $status and see the string returned
  • Page:
  • 1