To use this site please enable javascript on your browser! Bryce Andy | Integrate MPesa or Tigopesa on your Laravel Website including other Payment Gateways

Integrate MPesa or Tigopesa on your Laravel Website including other Payment Gateways

Bryce on Feb 2, 2019


Disclaimer: This guide is for the old version 1 of the package, for version 2 and above read the documentation on Github

Over the last decade, Eastern African countries saw a transition in the way day-to day payments are transacted. Mobile and telecommunication companies have made this possible using mobile money services such as MPesa, AirtelMoney, TigoPesa just to mention a few.

Pesapal Payment Gateway

For web applications it hasn't been easy to integrate mobile money systems as the direct APIs have been expensive and or difficult to use. The emergence of Pesapal has filled this void and made it easier to integrate using their simple API. I have managed to compile the PHP API for Pesapal and created a package that can be used with Laravel.



If you are not sure you have cURL installed, go to the root of your project and add the following lines inside your composer.json file,

"require": {
        "ext-curl": "*"


Install the package

The Laravel package for Pesapal can be found in its github repository on here. To install it inside the root of you project run the following in the terminal;

composer require bryceandy/laravel_pesapal


Files and Configuration

After composer has downloaded all files successfully, inside your config/app.php file, add the following in the providers array

'providers' => [
         * Application Service Providers...

Then we can publish the package into our project using the command;

php artisan vendor:publish --provider="Bryceandy\Laravel_Pesapal\PesapalServiceProvider"

When it runs successfully, you will now have the following in your project;

NOTE: In order for this migration to work smoothly, make sure you have first_name, last_name and email fields in your users migration and password field be nullable. Lastly in the User model, create a $fillable array and add the previous 3 fields aforementioned.

But now since you have all these files you can modify them however you want to suit your project. Finally you can migrate your tables;

php artisan migrate


Your Routes

The 3 new routes you now have under resources/views/pesapal/ all have an important role. 

details.blade.php view will display details that your user will input, and its URL is


iframe.blade.php view will display payment options as seen below,  to arrive to this view a user needs to fill the details above correctly in the details view. Also try to make the 'reference' detail auto-generated in the controller depending on your project needs.

payment options

lastly, the callback_example.blade.php view will be the page which displays the payment status after a user makes a transaction.


Head over to demo if you want a testing environment or live for a live integration and create a business account. You will easily obtain a key-secret pair for your integration.

Then inside your .env file, create these environment variables;



Configure Pesapal Settings

For live accounts, in order to receive notifications for every payment from Pesapal, we need to set our IPN listener URL. On your Pesapal dashboard, go to Account Settings and click IPN Settings. Fill in your domain, example, then the IPN listener URL as

Thats all there is to it, you can now visit the details page and start making payments!



  • user 0 10 months ago

    Problem: signature_invalid | Advice: > |
    • user Bryce  10 months ago

      Hi, there has been an update on this package. Read the documentation on the latest version at

  • user Elson 2 years ago

    Sorry, an error occurred while processing your request. We are working to fix it as soon as we can. sory bro i get this error
    • user Bryce  2 years ago

      Hi Elson, if you reached here it is a good sign that it works. Just change your account from demo to live

  • user Elson 2 years ago

    how to change from demo to live?
    • user Bryce  2 years ago

      When you created a Pesapal account you used but now you have to create another one using, and do not forget to change your new PESPAL_KEY & PESAPAL_SECRET values in .env

  • user Elson 2 years ago

    second Mr Bryce what you are doing is so good, especially to Tanzania ICT. Its good to see tz developer make simple and easy library for another developer to use their skills and knowledge.

  • user Elson 2 years ago

    also, thank you for making this tutorial free to use and easy to use. god bless you
    • user Bryce  2 years ago

      You are welcome, I am glad I could help!

  • user Jay 1 year ago

    What I have to set in action of form in details.blade.php file.. I have default "/iframe" set in form action. Please help.
    • user Bryce  1 year ago

      The action is the default "pesapal/iframe.php", you have to leave it that way so you can make your payments

  • user Jere 1 year ago

    does it work in kenya ..mpesa to mpesa
    • user Bryce  1 year ago

      Yes it works

  • user Ochieng 1 year ago

    I get an object not found error after submitting the details form. I think it is an issue with iframe. How can i solve it?
    • user Bryce  1 year ago

      Do you have the first_name, last_name attributes in your create_users_table migration and User model? And the password set to nullable() in the same migration ?

  • user 0 1 year ago

    hey brandy igot an error of Problem: consumer_key_unknown | Advice: > |when i integrate with live API
    • user Bryce  1 year ago

      You have entered the wrong consumer key or secret values

  • user 0 1 year ago

    mr bryce you must check this bug your code works fine when developer go the vendor folder functions but the function the view dont work
    • user Bryce  1 year ago

      As per the documentation, you can use or edit the views that you have published. If you published then you will have the views inside "resources/views/pesapal"

  • user MUSA 1 year ago

    Undefined index: scheme

Bryce is a web developer based in Dar. Apart from writing code, you can find him in the gym, writing informative articles or playing football.

Copyright © Bryce Andy 2018