Pesapal.com

Forum

Welcome, Guest
Username
Password:
 

PesaPal PHP Example
(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
  • 2

TOPIC: PesaPal PHP Example

PesaPal PHP Example 6 years, 11 months ago #579

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

We decided to come up with a simplified PHP example for you guys. All you need to do is:
  1. Copy the files on an online server. (Make sure the server is publicly available)
  2. Open top[dot]php replace [domain] with your domain name eg. www.mysite.com
  3. Create a new database for the site and import the file db/pesapalPHPExample.sql
  4. Open db/dbconnector.php and edit the database name,username,host and paasword to give the application access to the new db created.
  5. Open pesapal/checkStatus.php and pesapal/iframe.php and add your consumer key and secret. In your checkStatus.php file if the key belong to a demo merchant set $isDemo = true otherwise set it to false.
  6. In the pesapal/iframe.php replace [sitelink] with the correct site URL
  7. Go to your merchant account and set up the IPN link: [sitelink]/pesapalPHPExample/ipn.php
  8. Open ipn.php and enter your email address in the "TO" fields. This is to help you monitor the IPN. (In your final application you need not to have the email section)
  9. Test the application.


If all goes well, you'll need to have a look at the codes and ensure you understand them line by line before you think about implementing the same on your application.

Your feedback is highly appreciated.

File Attachment:

File Name: PesaPalPHPExampleCode.zip
File Size: 208 KB
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.
Last Edit: 2 years, 3 months ago by lazro.

Re: PesaPal PHP Example 6 years, 10 months ago #639

Any security implications about leaving the file dbconnector.php in a public place?

Re: PesaPal PHP Example 5 years, 10 months ago #1184

  • kevin258
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
It is bringing this error when i run it: Could not enter transaction details: Field 'trackingId' doesn't have a default value

Re: PesaPal PHP Example 5 years, 10 months ago #1185

Hi,

The trackingId is the order id you are supposed to generate then send to Pesapal. Please ensure you are generating it and sending it in your API call.

This is a demo entirely for learning purposes after which you can implement the integration securely.

Re: PesaPal Opencart Intergration 5 years, 6 months ago #1323

Can someone please assist me on how i can integrate pesapal to my open cart...am using version 2.0.0.0

Re: PesaPal Opencart Intergration 5 years, 5 months ago #1333

  • komujohn
  • OFFLINE
  • Senior Boarder
  • Posts: 51
Hi Infomallnet,
I have the plugin you are looking for on www.opencart.com/index.php?route=extensi...p;extension_id=12674

Re: PesaPal PHP Example 4 years, 3 months ago #1894

  • asopia
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi
Is it possible to use the example code provided here in a local server like localhost and if not, how can I modify it to run in my local environment?

Thanks in advance

Re: PesaPal PHP Example 4 years, 3 months ago #1897

  • Odhiambo
  • OFFLINE
  • Administrator
  • Posts: 72
Hi Asopia,

Yes it is possible.

Re: PesaPal PHP Example 4 years, 3 months ago #1899

  • asopia
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi Odhiambo,
Kindly give me a guide of how to do that.

I'll appreciate

Re: PesaPal PHP Example 4 years, 2 months ago #1923

Okay in Tanzania every Mpesa user has a secret code they have to insert when making any kind of payment.. see what I dont get is how does this one work I did everything inserted everything in the right place but still when I try to make payments, which I am not even sure how to, it takes me to a page Iframe that has two links business and personal... where do I insert my security code the four number code for making payments how do I do that.

Re: PesaPal PHP Example 4 years, 2 months ago #1924

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

Share the link to your system. I would like to see what you have.
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: muddyjeff12

Re: PesaPal PHP Example 4 years, 2 months ago #1925

eefaster.us

Re: PesaPal PHP Example 4 years, 2 months ago #1926

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

Something is off in your iframe.php file. Please attach it (do not include your key and secret)

CSS issues : Why do you have the $sitelink variable as eefaster.us/pesapalPHPExample yet you do not have the pesapalPHPEaxmple folder, you've extracted the files in your root...?
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.
Last Edit: 4 years, 2 months ago by lazro.

Re: PesaPal PHP Example 4 years, 2 months ago #1927

My Iframe is here

<?php
include_once('../top.php');
require_once('OAuth.php');
require_once('../db/dbconnector.php');

if($_POST['api'])
$api = 'demo.pesapal.com';
else
$api = 'www.pesapal.com';

$token = $params = NULL;
$iframelink = $api.'/api/PostPesapalDirectOrderV4';

//Kenyan keys
$consumer_key = "";
$consumer_secret = "";

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

//get form details
if(!$_POST['reference']){
$ref = str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5);
$_POST['reference'] = substr(str_shuffle($ref),0,10);
}

$amount = str_replace(',','',$_POST['amount']); // remove thousands seperator if included
$amount = number_format($amount, 2); //format amount to 2 decimal places
$desc = $_POST['description'];
$type = 'MERCHANT';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phonenumber = $_POST['phone_number'];
$currency = $_POST['currency'];
$reference = $_POST['reference']; //unique transaction id, generated by merchant.
$callback_url = '[domain]/pesapalPHPExample/redirect.php'; //URL user to be redirected to after payment

//Record order in your database.
$database = new pesapalDatabase();
$database->store($_POST);

$post_xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<PesapalDirectOrderInfo
>";
$post_xml = htmlentities($post_xml);

//post transaction to pesapal
$iframe_src = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $iframelink, $params);
$iframe_src->set_parameter("oauth_callback", $callback_url);
$iframe_src->set_parameter("pesapal_request_data", $post_xml);
$iframe_src->sign_request($signature_method, $consumer, $token);

include('../pay.php');
include_once('../top.php');
?>

Re: PesaPal PHP Example 4 years, 2 months ago #1929

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

Kindly sort the css issue first. The iframe code seems to be fine but there is a disconnect.

Let your page look like staging.verviant.com/pesapalPHPExample
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
  • 2