PesaPi – An Open Source API for Safaricom’s M-Pesa in Kenya.
Its been a long time coming. Everyone in the Application Developer community in Kenya has been awaiting for ages for Safaricom to release an M-Pesa API that would enable them to build value-added services on the service. Sadly, this has not yet happened to-date although we keep hearing rumours that this could happen at anytime. M-Pesa is a big deal since it has around 13 million users the last time I checked. This means that almost all of Safaricom’s subscribers use the mobile money service making it a truly popular service that ensures customer “lock-in”. In many ways, M-Pesa has become the metaphor for mobile money in Kenya when you hear people utter statements like “Do you have the M-Pesa for <- insert competitor mobile network name here -> for me to send or receive money?”.

Therefore, the big news this week is not that Safaricom has released an M-Pesa API but rather an Application Developer has created a stop gap solution in the form of an open source M-Pesa API. I have known Mike Pedersen for the better part of four years. He is what you would call a “Geek’s Geek” in the sense he is one of the people I know who probably codes in his sleep! Yes, Mike has been in Kenya for the past year or so tinkering around with all sorts of code and he decided why not build an M-Pesa API. The product he has built is called PesaPi and it enables Application Developers to easily connect to M-Pesa services at Safaricom without needing an official API.
Mike insists that PesaPi is NOT a really “new” solution. He says that the same has already been done by the likes of PesaPal and iPay who offer commercial M-Pesa API solutions that are quite similar. In addition, PesaPi has been developed so that other Application Developers can take full advantage of the platform without having to figure out how to do it themselves. They simply “plug-in” to it and use it out of the box. For this very reason, PesaPi is actually targeted to Application Developers who can build their offerings around it for their clients. I asked Mike in the interview podcast below why he opted for an open source model instead of going commercial and he said he was not interested in getting into all the logistics of doing so. I would say he is being quite generous and could potentially disrupt the incumbents in this space.
41 Comments
This API does not seem to allow us to do the basic MPesa payment, or am i missing something here, all it allows is to get balances, not to much use….. Please clarify this for me
Let me try and clarify.
The API is not an “out of the box e-commerce solution” – it does however provide a way to “automatically” detect when someone have made a payment to you.
If you want to build an e-commerce solution – you need to build your own website, as well as a “basket” and whatever checkout procedure you require.
Then the user needs to transfer the payment to you (though your pay bill number).
Finally in order to confirm towards the user that you have received the payment – and thereby authorize the release of whatever service/product you are selling. This is where the API is useful since it allows you to automate this step.
Hereby you remove the need for having a human to confirm incoming payments, and then take the appropriate action – this can be automated…
However if you are in a situation where you want to “automatically” send money from your Mpesa account to someone (i.e. automated payroll payment) then this API will currently not help you – However I do encourage you to extend the API with this functionality and send me a patch with the functionality, so that it can be incorporated.
Bottom line: If you want to build an e-commerce solution whereby customers can pay though Mpesa then this will be of great help to you – However you still need to build your own e-commerce solution 😉
If instead you want to have a system disbursing payments (raises all kinds of security thoughts) – then you are out of luck so far – maybe someday it will be added.
Enjoy
Hey Mike… wont the power of ssl/tsl be enough?am thinking of a proposal. Safaricom should just have a take out and bring out similar services to Paypal & pesapal. Security might not really be an issue, the evidence is there. Maybe its just one of those opportunities they have given us to show them what to do. Payment is actually possible in reference to Oranges internet modem payment procedures through their portal which is quite secure.The online account should just share the user id details so that people may transact online.
Dont you think their databases are somewhat linkeable or exportable for that?or dont you think they are technical enough to include it?i think it is on the way eventually.Thanks a bunch for taking the leap to see how to fill this gap.
I paid shs 20,000 for java code that cannot do half of what this says it can do.
I’ll download a copy and with good luck will be the first large online to incorporate it.
HI Mike,
Its a great thing you guys are developing. I have a few queries.
1. The site reads it is a alpha version and the api should not be used for production. Has the status changed?
2. I would like to use these api for checking the mobile number of all users who pay for my service. is it possible?
3. Is it possible to check balance of all of my existing users and inform them?
Rgds
MAK
Hi Michael,
Can the api be used to make cyrpto coin payments, send and recieve? Would would be required?
Site coming soon and will require this! Thats a great step ahead. I will contact you for more info.
Geof
This is pretty cool you know……nice one Mike
This is very interesting,am sure all of us in web applications will have much to benefit from this.When are you coming up with a full ayatem with check out….? we will be waiting.
its ready when its ready 😉
Open source project has the luxery of not having a (fixed) deadline – the more people that contribute the sooner it will be ready.
Do note that the goal of the project is to create an API, not to create a fully-fledged e-commerce system, plenty of good systems already exists for this.
When I read this I know M-Pesa will still be here to stay. I also think that Africa has woken up to the reality of putting together technology, entertainment, banking services etc together in the palms of consumers…and I don’t think there is any provider doing it better than Safaricom.
Safaricom, get the praise from me and other consumers but don’t sleep. Competition is so stiff nowadays. You got to be more creative and innovative – and please involve the consumers as much when creating or improving new services.
[…] var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym tweetmeme_style = 'compact';tweetmeme_url='http://www.rising-africa.com/ictandmobile/2011/1034/';Check 今回ã¯ã€ã‚µãƒ•ァリコムãŒM-PESAã®ã‚¢ãƒ—リを発表ã—ãŸâ€¦ ã§ã¯ãªãã€ã‚¢ãƒ—リディベãƒãƒƒãƒ‘ーãŒã‚µãƒ•ァリコムã«ã‚ˆã‚‹å…¬å¼ã®M-PESAアプリã®ç™ºè¡¨ã‚’å¾…ãŸãšã€ç‹¬è‡ªã«ã€ŒM-PESA  Piã€ã¨ã„ã†ã‚¢ãƒ—リを開発ã€ãªã‚“ã¨ãれをオープンソースã«ã—ã¦å…¬é–‹ã—ã¦ã—ã¾ã£ãŸã¨ã„ã†ã‚³ãƒ©ãƒ ã®ç´¹ä»‹ã 。 今回ã®é¢ç™½ã„ã“ã¨ã“ã‚ã¯ã€ã‚µãƒ•ァリコムãŒM-PESAã®ã‚¢ãƒ—リを発表ã—ãŸã®ã§ã¯ãªãã€ã‚¢ãƒ—リディベãƒãƒƒãƒ‘ーãŒM-PESAã®æ©Ÿèƒ½ã®ç©´åŸ‹ã‚ã‚’ã™ã‚‹ã‚ªãƒ¼ãƒ—ンソースアプリを開発ã—ãŸã¨ã„ã†ã“ã¨ã 。開発者ã®ãƒžã‚¤ã‚¯ãƒ»ãƒ”ダーソン(Mike Pederson)ã¯ã€Œã‚®ãƒ¼ã‚¯ã®ä¸ã®ã‚®ãƒ¼ã‚¯ã€ã¨ã—ã¦çŸ¥ã‚‰ã‚Œã€å¯ã¦ã„ã‚‹ã¨ãã ã£ã¦ã‚³ãƒ¼ãƒ‰ã®å¤¢ã‚’見ã¦ã„ã‚‹ã¨ã„ã£ã¦ã‚‚éŽè¨€ã˜ã‚ƒãªã„ãã†ã 。 å½¼ã¯ã‚¢ãƒ—リを開発ã—ãŸã ã‘ã§ãªãã€ãã®ã‚³ãƒ¼ãƒ‰ã‚’å…¨ã¦ã‚ªãƒ¼ãƒ—ンソースã¨ã—ã¦å…¬é–‹ã—ã¦ã—ã¾ã£ãŸã€‚ã“れã«ã‚ˆã£ã¦ã€ã‚¢ãƒ—リディベãƒãƒƒãƒ‘ーãªã‚‰ã れã§ã‚‚ç°¡å˜ã«M-PESAã®ã‚µãƒ¼ãƒ“スã«ã¤ãªã’るアプリã®é–‹ç™ºãŒã§ãるよã†ã«ãªã£ãŸã€‚マイクã¯ã€ã“れã¯è‡ªåˆ†ã®æœ¬æ¥ã˜ã‚ƒãªã„ã—ã€ãŠé‡‘ã‚’å–ã‚‹ã¤ã‚‚りもãªã„。オープンソースã«ã—ã¦ã¿ã‚“ãªãŒå‹æ‰‹ã«æ”¹è‰¯ã§ãるよã†ã«ã—ãŸæ–¹ãŒã„ã„ã¨æ€ã£ãŸã€ã¨è©±ã—ã¦ã„る。ãã†ã€å½¼ã«ã¨ã£ã¦ä»Šå›žã®ã‚¢ãƒ—リ開発ã®ã‚¿ãƒ¼ã‚²ãƒƒãƒˆã¯M-PESAユーザーã§ã¯ãªãã€ä»Šå¾Œã“ã®ã‚ªãƒ¼ãƒ—ンソースを使ã£ã¦æ–°ãŸãªã‚¢ãƒ—リを開発ã—ã¦ã„ãディベãƒãƒƒãƒ‘ーé”ãªã®ã 。(å½¼ã®ã‚¤ãƒ³ã‚¿ãƒ“ューãŒã“ã¡ã‚‰ã‹ã‚‰ãƒ€ã‚¦ãƒ³ãƒãƒ¼ãƒ‰ã§ãã‚‹) アプリ開発ã¯ã“ã†ã—ãŸã‚ªãƒ¼ãƒ—ンイノベーションã®è¦–点をæŒã£ã¦ã„ã‚‹ãŒã€ä»Šå›žã®M-PESA Piã¯ãã®æœ€ãŸã‚‹ä¾‹ã¨è¨€ãˆã‚‹ã ã‚ã†ã€‚マイクã®ç”Ÿã¿å‡ºã—ãŸã‚‚ã®ã‚’土å°ã«ä»Šå¾Œã©ã‚“ãªã‚¢ãƒ—リãŒç”Ÿã¾ã‚Œã¦ãã‚‹ã®ã‹ã€éžå¸¸ã«æ¥½ã—ã¿ã 。 å‚照: https://moseskemibaro.com/2011/05/25/m-pesapi-an-open-source-api-for-safaricoms-m-pesa-in-kenya/ […]
Great stuff.was intuitively thinking about creating something like this for a while.Saved me alot of time.Good job.looking forward to enriching this API!
good stuff!
This is fantastic information about MPESA. Am intending to use it for purposes of my site.
this is great Mike
Great stuff.
Moses could you please update the download link. It is broken.
Great stuff. In Uganda, there is no single API available for developers from telecos offering mobile money. It’s really frustrating. Hope they learn from Kenya.
Has saved me lots of work. Awesome.
Samson you didnot do that much research, In Uganda we have a very easy to use API payments.yo.co.ug provided by Yo! Uganda.It is a thirdparty like MpesaPI/Pesapal but i does payouts and payins. I have integrated it in 3 sites and it works fine for me.
Hi Mike,
Thank for the source code.. I am looking @ incorporating mpesa as a payment method for a client. Am I correct in saying that the mpesa servers will do a callback to a user defined url with transaction information? amount, customer etc… Much the same as PAYPAL does. And secondly is this functionality available to all mpesa customers or just corporate clients?
Many thanks and keep up the good work…
Hi Mike,
In addition to above query , i also want to know that all the payment transactions are pushed from the MPesa to our server or we need to pull the same using provided PHP code ( like all trancation between two time or after a specific time).
I get confused as in configuration file i saw one config line PaymentReceivedUrl=”” ; So just want to confirming that if we add an URL here then can PesaPi server automatically call our URL?
An early reply will be highly appreciated.
[…] the Internet using M-Pesa, Zap and Credit Cards and PesaPi which is an open-source API built by Michael Pedersen who explains that; The API is not an “out of the box e-commerce solution” – it does however provide a way to […]
being a Pythonista,methinks i can contribute some code for the python port that integrates with Django and NoSQL db’s:python is much more efficient and easier to secure.
@ Mike,ever checked out sslstrip on github? SSL isn’t as secure as most people think but patches fix the vulnerabilities as they get detected
great stuff… im going to test it with an application im developing … i’ll keep you wonderful people posted with it once im game..cheers!! and HAPPY NEW YEAR
[…] User here's links to info on an mpesa API called pesapi https://moseskemibaro.com/201…https://moseskemibaro.com/201…i think they should set you on the right track. Hope it helpsVia Kalina Zografska.Comment Loading… […]
It’s a great start and the first step for mobile users to adapt to e-cash particularly mobile e-payments easily and globally. I’d like to motivate for the perfection of the app by suggesting few upgrades.
a) the invoice should state form of payment used,
b) it should also redirect to a second page that would basically capture return info in the case of mobile cash payment details such as the ticket id generated for that particular transaction and the returning names which could also be integrated with the sms api to just like how the financial institutions operate user accounts.
c) If shipping product isn’t necessary, like perhaps paying for a service should only be shortened to capture the users official details only and perhaps this would appear before any transaction details are presented- perhaps in stages?
Lastly, I am interested in putting this particular api into use.
Thanks for the generosity and thoughtfulness you have put into this project.Where can anyone find a guy today who doesn’t think of getting more money but rather how to embark in fulfilling purpose and putting others needs in mind? Keep up the great work and God bless! You’ll be surprised with rewards that await you in life for such trends my friend!
Hi Mike –
Bloody incredible. You are ahead of your time and if you can build a payment gateway you are set for life.
Are you for hire? I’d like to get help doing a mpesa gateway using wordpress jigoshop with http://www.mamaafricakenya.com
Thanks
Tim
Am i the only one who encountered a problem following Mike’s youtube tutorial? i got a message similar to:
Warning: require_once(PLUSPEOPLE.php) [function.require-once]: failed to open stream: No such file or directory in /homepath/include/PLUSPEOPLE/autoload.php on line 37
Fatal error: require_once() [function.require]: Failed opening required ‘PLUSPEOPLE.php’ (include_path=’../include:.:/usr/lib/php:/usr/local/lib/php’) in /homepath/include/PLUSPEOPLE/autoload.php on line 37
I also got the same problem as you Dedan. Did you get a solution?
Does Pesapi work with some networks in Ugand?
@nomis I have no idea. Check with the developer?
Found this to be interesting, in the recent past I have seen the use of LIPA NA M-PESA ONLINE to be more useful for quick development without having to mess with code too much ..:)
Check it out : http://www.safaricom.co.ke/personal/m-pesa/m-pesa-services-tariffs/paybill/lipa-na-m-pesa-online
Hello Moses, and how can one integrate the M-Pesa API to the android platform? please assist…
@michael I am not the developer of PesaPI. Please get in touch with them directly.
Hi
Can the api be used to assist in making crypto currency payments like bitcoin or my own hybrid coin soon to be launched?
For a beginner facing any problem, visit
http://goo.gl/tdGaU0
plas is there a guide to intergrate mpesa with woocommerce for wordpress
Hi Mike,
I think it is really great work. I want to use this on server side and get response in android app from server that payment done.But i don’t understand the process, how money will deduct and where we get that.
This is amazing .