This is a sample android application to test Safaricom M-Pesa STK push using Twiga Engineering android-daraja-sdk library, android-daraja-sdk).
- Android Studio
- Kotlin
- Kotlin anko
- Create a developer account on the Safaricom Developer Portal (https://developer.safaricom.co.ke/)
- Create a Lipa na M-Pesa online app on the console
- Go to https://developer.safaricom.co.ke/test_credentials to get test credentials for transactions
- On your android studio start screen, go to 'Check out from version control'
- Paste the clone link (https://github.com/tirgei/MpesaDaraja.git) then press clone
- Open the project
You'll need to setup firebase which in this case will be used for authentication. We'll later use firebase to send confirmation notifications using Firebase functions once a transaction is successful.
- On your android studio, click on 'Tools' from the menu bar then Firebase.
- A firebase assistant pane will open from the right.
- Click on 'Authentication' then connect to firebase, the authentication dependency will be added
You can check the firebase functions repo here: MpesaDaraja-Functions
Create a Kotlin object named 'Constants' to hold the variables.
From the Safaricom test credentials page:
- PAYBILL (Lipa na M-Pesa Online Shortcode)
- PASSKEY (Lipa na M-Pesa Online Passkey)
- ACCOUNT_REF (Initiator name)
From the app you created in your developer console:
- CONSUMER_KEY
- CONSUMER_SECRET
You're now all set to tinker around, Happy Coding :)
- Daraja - https://github.com/twigaeng/android-daraja-sdk
- Mikepenz Iconics (FontAwesome) - https://github.com/mikepenz/Android-Iconics
- PinView - https://github.com/ChaosLeong/PinView