Uncategorized

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?”.

Mike Pedersen, The Application Developer behind PesaPi, the Open Source API for Safaricom's M-Pesa in Kenya

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.

PesaPi can be downloaded here>

PesaPi Podcast with Mike Pedersen can be downloaded here>

Previous post

Mobile Internet identified as a major Internet Governance issue for the 6th IGF in Nairobi, Kenya.

Next post

Interview with Joseck Mudiri, Country Manager for Kenya at Kalahari.co.ke [Video]

38 Comments

  1. Jason
    May 25, 2011 at 6:54 am — Reply

    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

    • Michael Pedersen
      May 25, 2011 at 11:46 am — Reply

      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

      • Mike
        June 15, 2011 at 12:43 am — Reply

        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.

      • June 17, 2011 at 2:55 am — Reply

        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.

      • MAK
        September 28, 2011 at 7:22 am — Reply

        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

      • Scott hardiman
        January 18, 2015 at 11:20 am — Reply

        Hi Michael,

        Can the api be used to make cyrpto coin payments, send and recieve? Would would be required?

  2. May 25, 2011 at 7:46 am — Reply

    Site coming soon and will require this! Thats a great step ahead. I will contact you for more info.

    Geof

  3. andrew
    May 25, 2011 at 8:22 am — Reply

    This is pretty cool you know……nice one Mike

  4. May 27, 2011 at 9:15 am — Reply

    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.

    • Michael Pedersen
      May 29, 2011 at 3:20 am — Reply

      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.

  5. May 28, 2011 at 9:03 am — Reply

    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.

  6. […] 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/&#039;;Check 今回は、サファリコムがM-PESAのアプリを発表した… ではなく、アプリディベロッパーがサファリコムによる公式のM-PESAアプリの発表を待たず、独自に「M-PESA  Pi」というアプリを開発、なんとそれをオープンソースにして公開してしまったというコラムの紹介だ。 今回の面白いこところは、サファリコムがM-PESAのアプリを発表したのではなく、アプリディベロッパーがM-PESAの機能の穴埋めをするオープンソースアプリを開発したということだ。開発者のマイク・ピダーソン(Mike Pederson)は「ギークの中のギーク」として知られ、寝ているときだってコードの夢を見ているといっても過言じゃないそうだ。 彼はアプリを開発しただけでなく、そのコードを全てオープンソースとして公開してしまった。これによって、アプリディベロッパーならだれでも簡単にM-PESAのサービスにつなげるアプリの開発ができるようになった。マイクは、これは自分の本業じゃないし、お金を取るつもりもない。オープンソースにしてみんなが勝手に改良できるようにした方がいいと思った、と話している。そう、彼にとって今回のアプリ開発のターゲットはM-PESAユーザーではなく、今後このオープンソースを使って新たなアプリを開発していくディベロッパー達なのだ。(彼のインタビューがこちらからダウンロードできる) アプリ開発はこうしたオープンイノベーションの視点を持っているが、今回のM-PESA Piはその最たる例と言えるだろう。マイクの生み出したものを土台に今後どんなアプリが生まれてくるのか、非常に楽しみだ。 参照: http://www.moseskemibaro.com/2011/05/25/m-pesapi-an-open-source-api-for-safaricoms-m-pesa-in-kenya/ […]

  7. N-able Systems Geek
    June 6, 2011 at 9:08 am — Reply

    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!

  8. ruth deshy
    June 6, 2011 at 10:12 am — Reply

    good stuff!

  9. June 8, 2011 at 8:10 am — Reply

    This is fantastic information about MPESA. Am intending to use it for purposes of my site.

  10. Fredrick
    June 14, 2011 at 5:56 am — Reply

    this is great Mike

  11. Martin Mbogo
    June 17, 2011 at 4:06 am — Reply

    Great stuff.

  12. Maurice Oduor
    June 19, 2011 at 3:11 pm — Reply

    Moses could you please update the download link. It is broken.

  13. June 24, 2011 at 1:36 pm — Reply

    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.

  14. mogz
    June 28, 2011 at 3:36 am — Reply

    Has saved me lots of work. Awesome.

  15. July 8, 2011 at 5:29 am — Reply

    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.

  16. des
    September 15, 2011 at 4:29 pm — Reply

    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…

    • BL Pancholi
      January 6, 2012 at 9:48 am — Reply

      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.

  17. […] 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 […]

  18. Artur
    December 4, 2011 at 5:56 pm — Reply

    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

  19. January 9, 2012 at 7:47 pm — Reply

    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

  20. […] User here's links to info on an mpesa API called pesapi http://www.moseskemibaro.com/201http://www.moseskemibaro.com/201…i think they should set you on the right track. Hope it helpsVia Kalina Zografska.Comment Loading… […]

  21. November 19, 2012 at 7:24 am — Reply

    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!

  22. January 25, 2013 at 1:37 am — Reply

    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

  23. Dedan
    February 18, 2013 at 2:34 am — Reply

    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

    • Phil
      March 16, 2013 at 2:08 pm — Reply

      I also got the same problem as you Dedan. Did you get a solution?

  24. Nomis Kafuko Wilson
    October 27, 2014 at 7:29 pm — Reply

    Does Pesapi work with some networks in Ugand?

    • October 31, 2014 at 12:43 pm — Reply

      @nomis I have no idea. Check with the developer?

  25. November 4, 2014 at 12:16 am — Reply

    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

  26. Michael Maina
    November 27, 2014 at 2:07 pm — Reply

    Hello Moses, and how can one integrate the M-Pesa API to the android platform? please assist…

    • December 1, 2014 at 8:11 pm — Reply

      @michael I am not the developer of PesaPI. Please get in touch with them directly.

  27. Scott hardiman
    January 18, 2015 at 11:18 am — Reply

    Hi

    Can the api be used to assist in making crypto currency payments like bitcoin or my own hybrid coin soon to be launched?

  28. February 21, 2015 at 5:45 am — Reply

    For a beginner facing any problem, visit
    http://goo.gl/tdGaU0

Leave a reply

Your email address will not be published. Required fields are marked *

fourteen + 2 =