What is instamojo?
Instamojo provides free payment gateway in India. Trusted by 600000+ Indian Businesses, 100% Secure, No setup cost, No maintenance cost.
This SDK allows you to integrate payments via Instamojo into your Android app. It currently supports following modes of payments:
1.Credit / Debit Cards
2.EMI
3.Net Banking
4.Wallets
5.UPI
This SDK also comes pre-integrated with Juspay Safe Browser, which makes payments on mobile easier, resulting in faster transaction time and improvement in conversions.
1. 1-click OTP: Auto-processing Bank SMS OTP for 1-Click experience.
2. Network optimizations: Smart 2G connection handling to reduce page load times.
3. Input & Keyboard Enhancements: Displays right keyboard with password viewing option.
4. Smooth User Experience: Aids the natural flow of users with features like Automatic Focus, Scroll/Zoom, Navigation buttons.
Payment flow using SDK
The section describes how the payment flow probably looks like, when you integrate with this SDK. Note that, this is just for reference and you are free to make changes to this flow that works well for you.
When the buyer clicks on Buy button, your app makes a call to your backend to initiate a transaction in your system.
Your backend systems creates a payment order and returns the orderID to the app.
The app then initiates a payment via Instamojo SDK using the orderID.
If orderID is valid, the user is shown the available payment modes. This will take him via the payment process as per mode selected.
Once a payment is completed, a callback is received in your android activity with the payment_id, transaction_id and payment_status.
Your app shows the success / failure screen based on the payment status (either Credit or Failure).
For more details on the payment, your app may make a request to your backend servers with the transaction_id, which then returns the details after fetching the same from Instamojo servers.
SDK Dependency
The SDK currently supports Android Version >= ICS 4.0.3 (15). Just add the following to your application’s build.gradle file, inside the dependencies section.
1 2 3 4 5 6 7 8 9 10 |
repositories { mavenCentral() maven { url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/" } } dependencies { compile 'com.instamojo:android-sdk:+' } |
SDK Permissions
The following are the minimum set of permissions required by the SDK. Add the following set of permissions in the application’s manifest file above the <application> tag.
1 2 3 4 5 6 7 8 |
//General permissions <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> //required for Juspay to read the OTP from the SMS sent to the device <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> |
Proguard rules
If you are using Proguard for code obfuscation, add following rules in the proguard configuration file proguard-rules.pro.
# Rules for Instamojo SDK
1 |
-keep class com.instamojo.android.**{*;} |
Fetch Order ID from backend server
For initiating a payment, you should first create a payment order in your backend server and send the orderID to the app. Please check this documentation on how to create a payment order on your backend server using your Instamojo client credentials.
Android Integartion
Initializing SDK
Add the following code snippet inside the onCreate() method of your activity class.
1 2 3 4 5 6 |
@Override public void onCreate() { super.onCreate(); Instamojo.getInstance().initialize(this, Instamojo.Environment.TEST); ... } |
Implement the callback interface
Implement the Instamojo.InstamojoPaymentCallback callback interface in your activity class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class MainActivity extends AppCompatActivity implements Instamojo.InstamojoPaymentCallback { ... @Override public void onInstamojoPaymentComplete(String orderID, String transactionID, String paymentID, String paymentStatus) { ... } @Override public void onPaymentCancelled() { ... } @Override public void onInitiatePaymentFailure(String errorMessage) { ... } } |
Initiating Payment
Now you can simply call initiatePayment with the orderID and the callback instance (which is the activity itself) to initiate a payment.
1 |
Instamojo.getInstance().initiatePayment(this, orderID, this); |
Receiving response from the SDK
Once the payment is initiated from your activity, it can receive the various SDK responses in the callback methods.
1.Payment through SDK is complete. The payment can be either a success or a failure
1 2 3 4 5 |
@Override public void onInstamojoPaymentComplete(String orderID, String transactionID, String paymentID, String paymentStatus) { Log.d(TAG, "Payment complete. Order ID: " + orderID + ", Transaction ID: " + transactionID + ", Payment ID:" + paymentID + ", Status: " + paymentStatus); } |
2.Payment is cancelled by the user
1 2 3 4 |
@Override public void onPaymentCancelled() { Log.d(TAG, "Payment cancelled"); } |
3.There was a error while initiating a payment (eg: the orderID is invalid)
1 2 3 4 5 |
@Override public void onInitiatePaymentFailure(String errorMessage) { Log.d(TAG, "Initiate payment failed"); showToast("Initiating payment failed. Error: " + errorMessage); } |
Using Custom UI
We know that every application is unique. If you choose to create your own UI to collect payment information, Instamojo SDK has the necessary APIs to achieve this. Check out the CustomUIActivity activity with in the sample app to find out how this can be achieved.
Thanks for reading!!