Sunday, June 13, 2010

Creating a simple MPESA Payment System for your Website - Part 1

This post is meant for Kenyans or anyone familiar with the MPESA mobile payment system in kenya.

Intro
For some reason the folks at Safaricom have never thought of sharing their MPESA API with kenyan web developers. A public MPESA Api could open the door to all sorts of innovative home-made online payment solutions. Just as MPESA has made banks and ATMs irelevant, Credit cards & Paypal would fade away if a 'Pay By Mpesa' option was available at an E-Commerce site.

The MPESA advantage
Credit card and Paypal fail miserably when they are the sole payment systems. Most kenyans would rather use debit cards and have no use for credit cards While Paypal only works with a handful of banks. Actually The last time I checked only Corporative bank debit cards could work with paypal.

This only leaves MPESA as the only viable option.

The MPESA letdown
MPESA has a fabulous automated service for big corporations via the Pay Bill option in the MPESA menu. Unfortunately the requirements for being enrolled in the service simply cannot be met by small fish like you and me. The service was meant for mega-corporations that's why most kenyan sites stick to regular send money option on the mpesa menu.

The locking out of small fish from Pay Bill & the non-existance of an MPESA Api has led to manual & crude methods of accepting payments online. Take the kenyan online book store http://booksfirst.co.ke for example. Here is theer processTo make a purchase using Mpesa.
  1. Customer sends money to the provided number.
  2. An actual human Sales rep(probably holding a mobile phone) receives the money
  3. The customer calls the human sales rep to confirm the payment.
  4. The payment is linked to a partcular customer's purchase.
Wow! The process is long enough to put off any 1st time buyer to your site.

Automating the process - Importance of Identifying the sender.
Back to http://booksfirst.co.ke  let us examine the typical message the sales rep will receive. i.e :

XYZ2B17 confirmed. You have received ksh 2000 from 0723000111.

It is important to note that MPESA outputs the sender's name only when he/she is registered. Otherwise the text would have looked like this :

XYZ2B17 confirmed. You have received ksh 2000 from  Mary Wanjiku 0723000111.

In order to track and link payments, the senders will need to be identified using a unique ID.  As you can see the sender's phone number is the best candidate for a unique Identifying field. The sender's name is not a good candidate as there could be multiple people with the same name.

Also Important to note is that the Receipt or Transaction Id(XYZ2B1) is always unique and received by both parties.

Automating Payment
My solution - Send & Claim
In an online store scenario payments need to be marched to a particular order. Just identifying the sender doesn't help much. So usually a human cashier links the two by calling the sender.
 
The idea is to remove the human cashier at the other end of the transaction. The 'cashier' will be replaced by GSM modem connected to a computer with an internet connection. Whenever an MPESA payment is received, it will be recorded on the site to be claimed by the sender.

The sender will then 'claim' the payment by simply entering the MPESA receipt together with his order. This will be equivalent to entering your credit card number at the checkout page in an online store. Thus an order and a payment can be linked in only 2 simple steps.

1) SEND :
The user sends money using MPESA to the seller's number. This payment is recorded in a database table with the following columns :

MpesaReceiptAmountTimeStampSenderMobileNumberStatus
XYZ2B150014/6/2010 2:45pm?0723000111Un-Claimed

2) CLAIM :
Remember that the MPESA receipt in the confirmation text sent to the user is the same as the one sent to the seller. So now the same user 'claims' the payment entering the Receipt together with his order at the checkout i,e



My Order


Product 1

200/=

Product 2

100/=

Product 3

200/=

Total

500/=


Your Name * If you are not registered.

 


Enter MPESA Receipt





if the receipt submitted matches any un-claimed payment, the matching amount recorded  is used to make the purchase. i.e

MpesaReceiptAmountTimeStampSenderMobileNumberStatus
XYZ2B150014/6/2010 2:45pmMary Wanjiku0723000111Claimed

500/= is claimed by the user & used to make purchase

Putting it all together
As you can see our payment model works. Fully automate the recording of incoming payments and you got a super MPESA payment system.

The Automatic Cashier
Remember the whole idea is removing the human at the other end of an online transaction using MPESA. For this to work, an icoming MPESA payment needs to be automatically recorded on the site. An SMS gateway dedicated to receiving texts on our site would easily solve our problems. But our 'small fish' puts this out of the question.

We will need to come up with a system that any startup can afford. We will exploit the ever affordable GSM modem so common in the market today. Using clever software that we will write, a safaricom modem & an internet connection we will implement a simple, cheap but affordable MPESA payment gateway.


In part two we will create this gateway then later on test it on a mock online bookstore. As always I will be using the ever tasteful combination of C# & AspNet.

See you then. Cheers.

Free Online Huawei Modem Unlock Code Calculator

This is my attempt to deal with couple of things I can't stand at the same time.
  1. Mobile Network providers locking Modems to their network and denying their customers their freedom of choice.
  2. Commercial websites charging mobile users to unlock their modems.
My solution
I have coded an online unlock code calculator for Huawei modems. Why Huawei ? - Because this is the most common modem where I come from. Basically all modems in the kenyan market(safaricom, zain, orange and Yu ) and beyond can be successfully unlocked using just a code.
I initialy created a seperate blog for the calculator at http://freemodemunlocker.blogspot.com/2010/06/free-online-huawei-modem-unlock-code.html

But the calculator itself(written in C#) is seperately hosted at a quick site I put up here http://aspspider.net/coderhalisi/huawei/myhuaweiunlocker.aspx This means It can be embedded anywhere using an iframe like so :

<iframe src="http://aspspider.net/coderhalisi/huawei/myhuaweiunlocker.aspx" frameborder="0" height="184px" scrolling="no" width="300px"></iframe>

Which results in the calculator appearing on a page like this :




Using A Mobile Phone?
Your handset may not support Iframes so just Click Here. Should work.

Supported Models :

E1762, E180, E182E, E196, E226, E270, E271, E272, E510, E612, E618, E620, E630, E630+,
E660, E660A, E800, E870, E880, EG162, E880, EG162, EG162G, EG602, EG602G
E156, E155, E1550, E1552, E156G, E160, E160G, E161, E166, E169, E169G, E170, E172, E176,

So you could pretty much unlock every modem from safaricom, zain & Orange. Enjoy