What is this article about?
Three years ago i did an internship at payleven when their first app came out. Now they launched their mPos SDK. I was curious and I tried it out in my free time between the semesters.
What does payleven do?
payleven allows you to accept card and cash payments with your smartphone or tablet. You don’t pay monthly fees and you don’t have a contract over years. You only pay a percentage of your charged amount. To accept credit and debit cards you need to buy a bluetooth terminal (~70€) once and with the payleven app you’re able to accept payments everywhere in your country. http://www.payleven.co.uk/
What’s about the payleven mPos SDK then?
Implementing the SDK, you can accept card payments in your own app using the same bluetooth terminal. The SDK lets you process payments seamlessly without swapping to the payleven app.
What can you do?
Of course the SDK does not have full functionality like the original app. Until now you can login and charge an amount. The SDK does all the magic in the background and when the payment is finished (you will see the amount on the terminal and after inserting your card it will ask you for your pin or an signature) it gives you a response if the payment was successful or not.
There is an official example on github: https://github.com/payleven/mPOS-SDK-Android.
The SDK comes with a comprehensive documention, making it very easy to work with.
It helped me a lot, but if you take a closer look, you will see that you need to pass around one instance of the payleven object. Since you do not create activities in Android by yourself it’s not that obvious how to handle it in a good way. In their example they used Fragments and DataFragments, but i want to use separated activities.
The idea is to have a SessionProvider which – as the name says – provides you your session. You inject it (dependency injection, i use dagger) to your activity where you call “getSessionData(pSessionListener)” which notifies your pSessionListener when SessionData is available. If there is no SessionData instance, it adds the pSessionListener to a list and starts asynchronously (on a different task) the LoginActivity which uses the LoginController. LoginController contains all the login logic (in this example it only communicates with paylevens SDK but for your own app you might call to your own backend). When the login is done, SessionProvider will be notified, which notifies all the listeners in the list passing the new SessionData instance.The sequencediagram below shows the flow.
What happens if the payleven session expires?
It’s an edge case, it should not expire. But with the flow above it’s easy to handle. After catching a “AuthorizationError” you call sessionProvider.invalidateSessionData(pSessionListener) which forces a relogin.
PaymentController and DeviceController should always be created with an valid payleven instance, so if you invalidate your SessionData you should recreate these controllers.
What’s about my example, what functionality does it have?
You can enter an amount in EUR/Cent and press the pay button. You have a device screen to choose your specific bluetooth terminal and you have a “pay” button. Additionally i added a “BoatRental” view to give you a little idea how the use-case could be. It calculates the amount to pay after choosing a boat to rent. When a payment is done it shows a “payment successful/denied view and optionally a receipt as a bitmap.
After playing around for a while i think the SDK works good and it opens a new world: accept card payments by yourself – awesome.