mpesa integration to website c2b tutorial php
Mpesa Integration to website c2b tutorial in php
This mpesa integration article guides you on how to integrate Mpesa with your website with mpesa api code c2b tutorial, you will learn how mpesa integration to website is easy.
Integrating MPesa Paybill or Lipa na Mpesa to any application system or Website Using Safaricom C2B M-Pesa API. The new Safaricom Daraja Mpesa API integration to website has so many advantages and many of website and web developers can take advantage of it thanks to Safaricom. Though Safaricom wont help you in developing the Lipa na Mpesa Integration to your website, we can take that burden by guiding you on how to integrate the Lipa na Mpesa API to your application, website, e-commerce, software android.
We make it easier to develop Mpesa integration to website then send Bulk SMS whenever a customer pays through the Lipa na Mpesa Till number or Paybill number. The mpesa website Integration is more to work on receiving the transaction details on database. It needs more logic developing the website to do automatic transaction like depositing in accounts, withdrawing money to Mpesa, buying credit.
In this mpesa api tutorial we will simply guide you on how to integrate your android application, web system or website with Mpesa API – C2B. For our Bulk SMS clients we help with free website integration to website only C2B integration in php. If unable to follow mpesa api tutorial for this mpesa c2b integration then we will help you on mpesa integration to website. If you have subscribed to our services then dont worry on how to integrate mpesa to a website as we will help you in mpesa integration in php.
Web developers and software Developers who needs to Lipa na M-pesa to website integration can follow just some few steps or Mpesa API tutorial assuming we are working with Mpesa integration in PHP.
Step guide on Mpesa integration to website
Tutorial Requirements for integrating mpesa to website or any other application – assuming you are doing the mpesa integration with php.
When you want to integrate Mpesa with Application your application or URL that is receiving the Mpesa transactions must be online.
Assuming we are integrating your website in php, you must have a domain name, hosting configured in Apache and PHP and MySql database, SSL,
You can either use the root domain or use a sub folder in your domain if its secure to use it in Mpesa to website integration. Like for us we will use www.movesms.co.ke . If you are starting you can buy a domain which only costs Ksh 700 at Move Host . The domain is supposed to come with hosting package to host your Mpesa API integration files and then for Mpesa Integration database.
If you hosting is configured well for mpesa to website integration in php then we can go to Safaricom Portal
Create an account at Safaricom Developer Portal
Enter details as requested on Safaricom Daraja API portal
After creating login to Safaricom API portal and access Menu My APPs
The next stage on the Mpesa API integration is to get Consumer Secret and Key
This is the stage for creating an app for mpesa integration to website.
Add your new app so that you can use it in Mpesa website intgration.Check on Sandbox for c2b, b2c, b2b. then allocate that app name e.g. MoveSMS. You can check this stage for Mpesa API integration to website stage below.
You can explore your app after creating them. Kindly note that for mpesa integration to website the app must be approved.
After clicking on your Mpesa integration app that you will use you will see consumer key and secret. You can save your detail on your email as you will require the consumer secret and key in mpesa integration to website later on Mpesa website API.
After that Mpesa website integration you can create a security password to ensure transactions are not compromised.
You can use any security password that will be unique but which hackers cant guess. As the Mpesa website API integration is online so many hackers will be trying those URL, so a password can be used as security on the Mpesa to website inetgration platform.
After that stage on Lipa na Mpesa to website integration, go ahead and get the Shortcode for testing.
This Mpesa API url will take you to Shortcode test generation
The Shortcode is a 6 numbers
Now you can go to PHPMYADMIN to create the database
All the Mpesa integration transaction codes will be saved in the integration database.
Go to Control Panel of your account,
- Creating a database eg movesms
- Creating a database username
- Giving your database user access to work with your database
Mpesa integration to website will be directing the mpesa transaction code on that database
Create a table on that database e.g movesms.
The details needed by Safaricom are
Number Auto Number
FName Varchar 25
MName Varchar 25
LName Varchar 25
TransactionType Varchar 40
TransID Varchar 40
TransTime Varchar 40
ShortCode Varchar 15
BillRefNumber Varchar 30
InvoiceNumber Varchar 30
ThirdPartyTransID Varchar 40
MSISDN Varchar 20
In this part of mpesa integration to website tutorial it will depend on where you want to store the needed URL by Safaricom. For Mpesa to website integration to occur we need two URL that is Validation and Confirmation pages. You can decide to put them straight on public html or on sub folder for mpesa integration to website..
In Mpesa Integration to website Validation URL is to receive the M-Pesa transaction once sent to your Lipa na Mpesa Paybill number or Till Number. This is so easier for mpesa integration in php. As I said earlier this Mpesa integration api website tutorial is for those who use php, but other languages the logic is all the same. Follow this mpesa api tutorial and you will learn how to easily do Lipa na Mpesa API online checkout
In this Mpesa integration to website Validation URL is where the Mpesa Transaction is sent first when client pays throuth Lipa na Mpesa. You can put the Validation and comfirmation on root folder or create a subfolder to put your 2 URLs, eg a folder like www.movesms.co.ke/mpesaapi/ .
Go direct to MPESA API github and download the 2 files validation and comfirmation https://github.com/safaricom/mpesa_c2b_php_confirmation_validation
Download those 2 URL and upload them on your public html/root or subfolder
The next stage in this Mpesa integration to website is to go to Safaricom API portal and register validation and confirmation call back urls.
Create another file called register.php and upload it on the folder. It will look like www.movesms.co.ke/mpesaapi/register.php
On this part of integration of APi we will use php to register the validation and confirmation URL’s.
Copy the contents of the register URL on this MPesa API Github here https://github.com/movetechke/mpesa
Now you can go to web browser to register your URL example we visit www.movesms.co.ke/mpesaapi/register.php so that our urls will be registered on Safricom API portal automatically.
If all goes well with this mpesa integration in php then you are good to go live.
Finish on all test cases, submit and let Safaricom approve. With that MPesa API integration in php you are ready to go to production.
Move Your System to Live after mpesa ecommerce integration
Now after finishing on logical Mpesa api integration you can move your system to live.
How to Develop Mpesa Integration to Website
You have seen how easy it is to integrate mpesa to a website, especially c2b integration in php. For those who have followed this online Mpesa API integration tutorial you can easily develop a C2B, B2C, B2B Mpesa Integration to your android application or website system. Safaricom MPESA API tutorials also offers guide on how to use all the Lipa na Mpesa API integration in so many languages from android, php, Java, Python. If unable then we can easily guide you on the Mpesa integration to website without hustle. We take few days for the integration of Mpesa to website to work. We can even offer Laravel Mpesa integration for free if you are buying bulk SMS from Us. You are welcome to learn more from our tutorials on mpesa api php, mpesa b2c api, lipa na mpesa online api, mpesa api android, lipa na mpesa online checkout.
We have realized so many people have encountered problems in mpesa integration to website, that is why we have developed a mpesa api portal. You can register on our mpesa api portal, register your URL, register Mpesa shortcode, get the easy API to use in your code. It will be simple to integrate any website using our Mpesa API and its so easy in mpesa ecommerce integration