Note: SDK currently does not support MarketPlace Integration. MarketPlace API Documentation is available here
This SDK allows you to integrate payments via Instamojo into your Android app. It currently supports following modes of payments:
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.
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.
orderID
to the app. See the sample app and sample backend for more details.orderID
.orderID
is valid, the user is shown the available payment modes. This will take him via the payment process as per mode selected.payment_id
, transaction_id
and payment_status
.Credit
or Failure
).transaction_id
, which then returns the details after fetching the same from Instamojo servers.A sample app that uses the latest SDK code is provided under /sample-app
folder. You can either use it as a base for your project or have a look at the integration in action.
Check out the documentation of the sample app here.
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.
repositories {
mavenCentral()
maven {
url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/"
}
}
dependencies {
compile 'com.instamojo:android-sdk:+'
}
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.
//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" />
If you are using Proguard for code obfuscation, add following rules in the proguard configuration file proguard-rules.pro
.
# Rules for Instamojo SDK
-keep class com.instamojo.android.**{*;}
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.
Add the following code snippet inside the onCreate()
method of your activity class.
@Override
public void onCreate() {
super.onCreate();
Instamojo.getInstance().initialize(this, Instamojo.Environment.TEST);
...
}
Implement the Instamojo.InstamojoPaymentCallback
callback interface in your activity class.
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) {
...
}
}
Now you can simply call initiatePayment
with the orderID
and the callback instance (which is the activity itself) to initiate a payment.
Instamojo.getInstance().initiatePayment(this, orderID, this);
Once the payment is initiated from your activity, it can receive the various SDK responses in the callback methods.
Payment through SDK is complete. The payment can be either a success or a failure
@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);
}
Payment is cancelled by the user
@Override
public void onPaymentCancelled() {
Log.d(TAG, "Payment cancelled");
}
There was a error while initiating a payment (eg: the orderID is invalid)
@Override
public void onInitiatePaymentFailure(String errorMessage) {
Log.d(TAG, "Initiate payment failed");
showToast("Initiating payment failed. Error: " + errorMessage);
}
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.
Find the integration documentation for SDK v1.2.6 using DevsupportAI here.
If you still have queries regarding SDK integration, please send a mail to our support id: support@instamojo.com. We will respond ASAP.