Pesapal.com

Forum

Welcome, Guest
Username
Password:
 

Re: Demo site, Not getting status while querying
(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: Re: Demo site, Not getting status while querying

Re: Demo site, Not getting status while querying 9 years, 7 months ago #1833

Hi Lazro,

Please see below the checkStatus class which i downloaded from
developer.pesapal.com/forum/2-pesapal-in...-pesapal-php-example

I have blacked out the consumer and secret keys.


Also see below the code which i am using to call the checkStatusByMerchantRef() function
which is defined in the CheckStatus class. I am including the OAuth as well as the checkStatus classes.

I have hard coded the reference no for which i want the status (2706528). Btw, on demo.pesapal.com. the transaction is indicated as completed.

require_once('OAuth.php');
require_once('checkStatus.php');


$checkStatus = new CheckStatus();

$checkStatus->check();

class CheckStatus
{
function check()
{
$checkStatus = new pesapalCheckStatus();

//----------------------------------------------------------------------
//check status

$status = $checkStatus->checkStatusByMerchantRef(2706528);

echo("<p> merchant reference 2706528, new status :$status</p>");

}//checkStatus()

}//CheckStatus













class pesapalCheckStatus {

var $token;
var $params;
var $signature_method;

var $QueryPaymentStatus;
var $QueryPaymentStatusByMerchantRef;
var $querypaymentdetails;

public function __construct(){

$this->token = $this->params = NULL;
//Kenyan Merchant
$consumer_key = "xxxxxxxxxxxxx BLACKED OUT xxxxxxxxxxxxxxxx";
$consumer_secret = "xxxxxxxxxxx BLACKED OUT xxxxxxxxxxxxxxxxxx";


$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);

$isDemo =true; // i confirm the key above belong to a DEMO merchant
if($isDemo)
$api = 'demo.pesapal.com';
else
$api = 'www.pesapal.com';

$this->QueryPaymentStatus = $api.'/api/querypaymentstatus';
$this->QueryPaymentStatusByMerchantRef= $api.'/API/QueryPaymentStatusByMerchantRef';
$this->querypaymentdetails = $api.'/API/querypaymentdetails';
}

function checkStatusUsingTrackingIdandMerchantRef($pesapalMerchantReference,$pesapalTrackingId){

//get transaction status
$request_status = OAuthRequest::from_consumer_and_token(
$this->consumer,
$this->token,
"GET",
$this->QueryPaymentStatus,
$this->params
);
$request_status->set_parameter("pesapal_merchant_reference", $pesapalMerchantReference);
$request_status->set_parameter("pesapal_transaction_tracking_id",$pesapalTrackingId);
$request_status->sign_request($this->signature_method, $this->consumer, $this->token);

$status = $this->curlRequest($request_status);

return $status;
}

function getTransactionDetails($pesapalMerchantReference,$pesapalTrackingId){

$request_status = OAuthRequest::from_consumer_and_token(
$this->consumer,
$this->token,
"GET",
$this->querypaymentdetails,
$this->params
);
$request_status->set_parameter("pesapal_merchant_reference", $pesapalMerchantReference);
$request_status->set_parameter("pesapal_transaction_tracking_id",$pesapalTrackingId);
$request_status->sign_request($this->signature_method, $this->consumer, $this->token);

$responseData = $this->curlRequest($request_status);

$pesapalResponse = explode(",", $responseData);
$pesapalResponseArray=array('pesapal_transaction_tracking_id'=>$pesapalResponse[0],
'payment_method'=>$pesapalResponse[1],
'status'=>$pesapalResponse[2],
'pesapal_merchant_reference'=>$pesapalResponse[3]);

return $pesapalResponseArray;
}
function checkStatusByMerchantRef($pesapalMerchantReference){

$request_status = OAuthRequest::from_consumer_and_token(
$this->consumer,
$this->token,
"GET",
$this->QueryPaymentStatusByMerchantRef,
$this->params
);
$request_status->set_parameter("pesapal_merchant_reference", $pesapalMerchantReference);
$request_status->sign_request($this->signature_method, $this->consumer, $this->token);

$status = $this->curlRequest($request_status);

return $status;
}

function curlRequest($request_status){

$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));
$pesapal_response_data = $elements[1];

return $pesapal_response_data;
}
}

Re: Demo site, Not getting status while querying 9 years, 7 months ago #1834

  • lazro
  • OFFLINE
  • Administrator
  • Pesapal
  • Posts: 404
Hi,

Try using HTTPS for all connections instead of HTTP as indicated on that example. There was a slight change on that. See below:

developer.pesapal.com/forum/6-announceme...-sandbox-application
Regards,

Lazaro Ong'ele
Web Developer

Skype: Lazrotep
+254-020-249-5438 ; +254-706-191-729
Dagoretti Lane, Off Naivasha Road.

Facebook: www.facebook.com/pesapal
Twitter: twitter.com/PesaPal
Helpdesk: support.pesapal.com
This e-mail address is being protected from spambots. You need JavaScript enabled to view it.
The following user(s) said Thank You: kentwillie

Re: Demo site, Not getting status while querying 9 years, 7 months ago #1835

I have read through that posting about the change from http to https.

I have indeed changed the url from using HTTP to using HTTPS and created a new MPESA transaction.

Everything works as expected, the call back gets called, and Pesapal calls my ipn with the tracking id as well as the reference, except that i still don't get the status.

I also don't get the status when i query.

Re: Demo site, Not getting status while querying 9 years, 7 months ago #1837

Ah, I figured out the problem.

I dug into the CheckStatus code and discovered that curl_exec() which is called in the curlRequest() function was failing. It was failing to execute and returning false.

After further investigation, i discovered that my web hosting service has blocked outgoing connections by default, thats why curl_exec() was failing.

So i had to log into my hosting account cpanel and whitelisted Pesapal's ip address.

That got me the expected results.


Thanks Lazro for your time helping me debug.

Re: Demo site, Not getting status while querying 9 years, 7 months ago #1838

  • lazro
  • OFFLINE
  • Administrator
  • Pesapal
  • Posts: 404
Great!
Regards,

Lazaro Ong'ele
Web Developer

Skype: Lazrotep
+254-020-249-5438 ; +254-706-191-729
Dagoretti Lane, Off Naivasha Road.

Facebook: www.facebook.com/pesapal
Twitter: twitter.com/PesaPal
Helpdesk: support.pesapal.com
This e-mail address is being protected from spambots. You need JavaScript enabled to view it.
  • Page:
  • 1