{"__v":0,"_id":"574671018138bd0e00cb2b05","initVersion":{"_id":"56a1c9c23845200d0066d701","version":"1.1"},"project":"56a1c9c13845200d0066d6fe","user":{"_id":"56a1c959842b650d0088899c","username":"","name":"Instamojo"},"hidden":false,"createdAt":"2016-05-26T03:44:01.839Z","fullscreen":false,"htmlmode":false,"html":"","body":"# Instamojo SDK Integration Documentation \n\nTable of Contents\n=================\n\n   * [Overview](#section-overview)\n   * [Payment flow Via SDK](#section-payment-flow-via-sdk)\n   * [Sample Application](#section-sample-application)\n   * [Installation](#section-installation-----)\n     * [Include SDK](#section-include-sdk)\n     * [SDK Permissions](#section-sdk-permissions)\n     * [Proguard rules](#section-proguard-rules)\n   * [Generating Access Token](#section-generating-access-token)\n   * [What is Transaction ID](#section-what-is-transaction-id)\n   * [Simple Integration](#section-simple-integration)\n     * [Initializing SDK](#section-initializing-sdk)\n     * [Fetching an Order](#section-fetching-an-order)\n         * [Creating the Payment Request](#section-creating-the-payment-request)\n         * [Creating the Order](#section-creating-the-order)\n         * [Using OrderID in the SDK](#section-using-orderid-in-the-sdk)\n     * [Initiating Order](#section-initiating-order)\n     * [Displaying Payment Forms](#section-displaying-payment-forms)\n     * [Receiving Payment result in the main activity](#section-receiving-payment-result-in-the-main-activity)\n   * [Integration with Test Environment](#section-integration-with-test-environment)\n   * [Verbose logging](#section-verbose-logging)\n   \n\n##Overview\nThis SDK allows you to integrate payments via Instamojo into your Android app. It currently supports following modes of payments:\n\n1. Credit / Debit Cards\n2. EMI \n3. Netbanking\n4. Wallets\n5. UPI\n\nThis SDK also comes pre-integrated with Juspay Safe Browser, which makes payments on mobile easier, resulting in faster transaction time and improvement in conversions.\n\n1. 1-click OTP: Auto-processing Bank SMS OTP for a 1-Click experience.\n2. Network optimizations: Smart 2G connection handling to reduce page load times.\n3. Input & Keyboard Enhancements: Displays right keyboard with password viewing option.\n4. Smooth User Experience: Aids the natural flow of users with features like Automatic Focus, Scroll/Zoom, Navigation buttons.\n\nThis SDK has two modes of integration.\n1. Simple Integration:\n    With Simple Integration, you can use the pre-created SDK's UI to collect payment information from the user.\n2. Custom UI Integration:\n    The SDK has necessary APIs available to create a custom UI to collect payment information from the user. More on this [here](https://docs.instamojo.com/v1.1/page/android-sdk-custom-ui).\n    ####**Note: Please contact a qualified security assessor to determine your PCI-DSS incidence and liability if you’re implementing a custom interface that collects cardholder information.**\n\n##Payment flow Via SDK\nThe 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.\n\n- When the buyer clicks on the Buy button, your app makes a call to your backend to initiate a transaction in your system.\n- Your backend systems create a transaction (uniquely identified by transaction_id). If required, it also obtains an access token from Instamojo servers. It passes back order details (like buyer details, amount, transaction id etc.) and a valid Instamojo’s access token.\n- Your Android app creates a new Order (from the SDK), by passing it order details and access token.\n- If the order is valid, the user is shown the payment modes, which will take him via the payment process as per mode selected.\n- Once a payment is completed, a callback is called in your Android app with your transaction_id.\n- Your Android app makes a request to your backend servers with the transaction_id.\n- Your backend server checks the status of the transaction by making a request to Instamojo’ server. - Your backend server updates the status in the database and passes back the result (successful / failure) to your app.\n- Your app shows the success/failure screen based on the result if received from your backend.\n\n## Sample Application \nYes, we have a Sample app that is integrated with SDK. You can either use it as a base for your project or have a look at the integration in action.\nCheck out the documentation of the Sample App [here](https://github.com/Instamojo/android-sdk-sample-app/blob/master/ReadMe.md).\n\n## Installation   [ ![Download](https://api.bintray.com/packages/dev-accounts/maven/sdks/images/download.svg) ](https://bintray.com/dev-accounts/maven/sdks/_latestVersion)\n### Include SDK\nThe SDK currently supports Android Version >= ICS 4.0.3(14). Just add the following to your application’s `build.gradle` file, inside the dependencies section.\n```\nrepositories {\n    mavenCentral()\n    maven {\n        url \"https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/\"\n    }\n}\n\ndependencies {\n    compile 'com.instamojo:android-sdk:+'\n}\n\n```\n\n### SDK Permissions\nThe 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.\n```\n//General permissions \n<uses-permission android:name=\"android.permission.INTERNET\" />\n<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />\n\n//required for Juspay to read the OTP from the SMS sent to the device\n<uses-permission android:name=\"android.permission.READ_PHONE_STATE\" />\n<uses-permission android:name=\"android.permission.READ_SMS\" />\n<uses-permission android:name=\"android.permission.RECEIVE_SMS\" />\n```\n\n### Proguard rules\nIf you are using Proguard for code obfuscation, add following rules in the proguard configuration file `proguard-rules.pro`\n```\n# Rules for Instamojo SDK\nkeep class com.instamojo.android.**{*;}\n```\n\n## Generating Access Token\nA valid access token should be generated on your server using your `Client ID` and `Client Secret`.\n\nGenerate CLIENT_ID and CLIENT_SECRET for specific environments from the following links.\n - [Test Environment](https://test.instamojo.com/integrations)\n - [Production Environment](https://www.instamojo.com/integrations)\n\nRelated support article: [How Do I Get My Client ID And Client Secret?](https://support.instamojo.com/hc/en-us/articles/212214265-How-do-I-get-my-Client-ID-and-Client-Secret-)\n\nAccess token should be generated using CLIENT_ID and CLIENT_SECRET and will be valid for 10 hours after generation. Please check this [documentation](https://github.com/Instamojo/sample-sdk-server#generating-access-token) \non how to generate Access Token using the credentials.\n\n## What is Transaction ID\nWell, transaction ID is a unique ID for an Order. Using this transaction ID, you can fetch Order status, get order details, and even initiate a refund for the Order attached to that transaction ID.\n\nThe transaction ID should be unique for every Order.\n\n## Simple Integration\n### Initializing SDK\nAdd the following `android:name=\"com.instamojo.android.InstamojoApplication\"` key to `<application>` tag in manifest tag\n```XML\n\n    <application\n            android:name=\"com.instamojo.android.InstamojoApplication\"\n            ..... >\n    </application>        \n```\n\nWhat if there is a custom `Application` class already?\nThen, add the following code snippet inside the `onCreate()` method of that custom application class.\n```Java\n    @Override\n        public void onCreate() {\n            super.onCreate();\n            Instamojo.initialize(this);\n            ...\n        }\n```\n\n### Fetching an Order\nThis step is for those who are looking for MarketPlace integration. If not, please move on to next [step](#section-initiating-order).\n\n### Creating the Payment Request\nPlease create a payment request using the [Payment Request API](https://docs.instamojo.com/v2/docs/create-a-payment-request) on your backend.\n\n***Note: Ensure that you send the following redirect URL in the Payment Request payload for SDK to function properly.***\nTest - https://test.instamojo.com/integrations/android/redirect/\nProduction - https://www.instamojo.com/integrations/android/redirect/\n\nOnce the payment request is created, collect payment request id from the field `id` from the response.\n\n### Creating the Order\nOnce the `id` from Payment Request API response is collected, you should create the order for this request using [Create Order API](https://docs.instamojo.com/v2/docs/create-an-order-using-payment-request-id) on your backend.\n\nOnce the Order is created, collect the Order ID from the field `order_id` from the response.\n\n### Using OrderID in the SDK\nOnce the `order_id` is collected, send it back to the app.\n\nOn the app, you can fetch the Order by passing the `access_token` and `order_id` to the SDK.\n```Java\n// Good time to show dialog\nRequest request = new Request(accessToken, orderID, new OrderRequestCallBack() {\n            @Override\n            public void onFinish(final Order order, final Exception error) {\n                runOnUiThread(new Runnable() {\n                    @Override\n                    public void run() {\n                        dialog.dismiss();\n                        if (error != null) {\n                            if (error instanceof Errors.ConnectionError) {\n                                showToast(\"No internet connection\");\n                            } else if (error instanceof Errors.ServerError) {\n                                showToast(\"Server Error. Try again\");\n                            } else if (error instanceof Errors.AuthenticationError) {\n                                showToast(\"Access token is invalid or expired. Please Update the token!!\");\n                            } else {\n                                showToast(error.toString());\n                            }\n                            return;\n                        }\n\n                        startPreCreatedUI(order);\n                    }\n                });\n\n            }\n        });\nrequest.execute();\n```\nOnce the order is fetched, please proceed to next [step](#section-displaying-payment-forms).\n\n### Initiating Order\nTo initiate an Order, the following fields are mandatory.\n\n1. Name of the buyer (Max 100 characters)&nbsp;\n2. Email of the buyer (Max 75 characters)&nbsp;\n3. Purpose of the transaction (Max 255 characters)&nbsp;\n4. Phone number of the buyer &nbsp;\n5. Transaction amount (Min of Rs. 9 and limited to 2 decimal points)&nbsp;\n6. Access Token &nbsp;\n7. Transaction ID (Max 64 characters)&nbsp;\n\nWith all the mandatory fields mentioned above, an `Order` object can be created.\n``` Java\nOrder order = new Order(accessToken, transactionID, name, email, phone, amount, purpose);\n```\n\nYou can also set webhook for this particular order using the following code snippet\n```Java\norder.setWebhook(\"http://your.server.com/webhook/\");\n```\n\n`Order` object must be validated locally before creating Order with Instamojo.\nAdd the following code snippet to validate the `Order` object.\n```Java\n//Validate the Order\n        if (!order.isValid()){\n            //oops order validation failed. Pinpoint the issue(s).\n\n            if (!order.isValidName()){\n                Log.e(\"App\", \"Buyer name is invalid\");\n            }\n\n            if (!order.isValidEmail()){\n                Log.e(\"App\", \"Buyer email is invalid\");\n            }\n\n            if (!order.isValidPhone()){\n                Log.e(\"App\", \"Buyer phone is invalid\");\n            }\n\n            if (!order.isValidAmount()){\n                Log.e(\"App\", \"Amount is invalid\");\n            }\n\n            if (!order.isValidDescription()){\n                Log.e(\"App\", \"description is invalid\");\n            }\n\n            if (!order.isValidTransactionID()){\n                Log.e(\"App\", \"Transaction ID is invalid\");\n            }\n\n            if (!order.isValidRedirectURL()){\n                Log.e(\"App\", \"Redirection URL is invalid\");\n            }\n\n            if (!order.isValidWebhook()) {\n                 showToast(\"Webhook URL is invalid\");\n            }\n\n            return;\n        }\n\n        //Validation is successful. Proceed\n```\n\nOnce `Order` is validated. Add the following code snippet to create an order with Instamojo.\n``` Java\n// Good time to show progress dialog to user\nRequest request = new Request(order, new OrderRequestCallBack() {\n                    @Override\n                    public void onFinish(Order order, Exception error) {\n                        //dismiss the dialog if showed\n                        \n                        // Make sure the follwoing code is called on UI thread to show Toasts or to \n                        //update UI elements \n                        if (error != null) {\n                            if (error instanceof Errors.ConnectionError) {\n                                  Log.e(\"App\", \"No internet connection\");\n                            } else if (error instanceof Errors.ServerError) {\n                                  Log.e(\"App\", \"Server Error. Try again\");\n                            } else if (error instanceof Errors.AuthenticationError){\n                                  Log.e(\"App\", \"Access token is invalid or expired\");\n                            } else if (error instanceof Errors.ValidationError){\n                                  // Cast object to validation to pinpoint the issue\n                                  Errors.ValidationError validationError = (Errors.ValidationError) error;\n                                  if (!validationError.isValidTransactionID()) {\n                                         Log.e(\"App\", \"Transaction ID is not Unique\");\n                                         return;\n                                  }\n                                  if (!validationError.isValidRedirectURL()) {\n                                         Log.e(\"App\", \"Redirect url is invalid\");\n                                         return;\n                                  }\n    \n\n                                  if (!validationError.isValidWebhook()) {\n                                          showToast(\"Webhook url is invalid\");\n                                          return;\n                                  }\n\n                                  if (!validationError.isValidPhone()) {\n                                         Log.e(\"App\", \"Buyer's Phone Number is invalid/empty\");\n                                         return;\n                                  }\n                                  if (!validationError.isValidEmail()) {\n                                         Log.e(\"App\", \"Buyer's Email is invalid/empty\");\n                                         return;\n                                  }\n                                  if (!validationError.isValidAmount()) {\n                                         Log.e(\"App\", \"Amount is either less than Rs.9 or has more than two decimal places\");\n                                         return;\n                                  }\n                                  if (!validationError.isValidName()) {\n                                         Log.e(\"App\", \"Buyer's Name is required\");\n                                         return;\n                                  }\n                            } else {\n                                  Log.e(\"App\", error.getMessage());\n                            }\n                        return;\n                        }\n\n                        startPreCreatedUI(order);\n                    }\n                });\n\n                request.execute();\n            }\n        });\n```\n\n### Displaying Payment Forms\nThis SDK comes by default with payment forms (Cards and Netbanking) that can be used to collect payment details from the buyer.\n\nAdd the following code snippet to your application's activity/fragment to use Pre-created UI.\n``` Java\nprivate void startPreCreatedUI(Order order){\n        //Using Pre created UI\n        Intent intent = new Intent(getBaseContext(), PaymentDetailsActivity.class);\n        intent.putExtra(Constants.ORDER, order);\n        startActivityForResult(intent, Constants.REQUEST_CODE);\n}\n```\n\nAnd you can call this once the order is created and validated, as per the above step:\n```Java\nstartPreCreatedUI(order);\n```\n\n### Receiving Payment result in the main activity\nAdd the following code snippet in the main activity.\nNote that TransactionID, OrderID, and paymentID maybe null. Please do a null check before proceeding.\n``` Java\n@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\n        super.onActivityResult(requestCode, resultCode, data);\n        if (requestCode == Constants.REQUEST_CODE && data != null) {\n                    String orderID = data.getStringExtra(Constants.ORDER_ID);\n                    String transactionID = data.getStringExtra(Constants.TRANSACTION_ID);\n                    String paymentID = data.getStringExtra(Constants.PAYMENT_ID);\n        \n                    // Check transactionID, orderID, and orderID for null before using them to check the Payment status.\n                    if (orderID != null && transactionID != null && paymentID != null) {\n                         //Check for Payment status with Order ID or Transaction ID\n                    } else {\n                         //Oops!! Payment was cancelled\n                    }\n        }\n}\n```\n\n## Integration with Test Environment\nTo do the integration in a test environment, add the following code snippet at any point in the code.\n```Java\nInstamojo.setBaseUrl(\"https://test.instamojo.com/\");\n```\nYou can remove this line to use production environment, before releasing the app.\n\n## Verbose logging\nDetailed logs can very useful during SDK Integration, especially while debugging any issues in integration. To enable verbose logging, add the following code snippet at any point in the code:\n``` Java\nInstamojo.setLogLevel(Log.DEBUG);\n```\nLog level defaults to `Log.WARN`.\n\nOnce the application is ready to be pushed to the Play Store, simply remove the line of code.","slug":"android-sdk","title":"Android SDK"}

Android SDK


# Instamojo SDK Integration Documentation Table of Contents ================= * [Overview](#section-overview) * [Payment flow Via SDK](#section-payment-flow-via-sdk) * [Sample Application](#section-sample-application) * [Installation](#section-installation-----) * [Include SDK](#section-include-sdk) * [SDK Permissions](#section-sdk-permissions) * [Proguard rules](#section-proguard-rules) * [Generating Access Token](#section-generating-access-token) * [What is Transaction ID](#section-what-is-transaction-id) * [Simple Integration](#section-simple-integration) * [Initializing SDK](#section-initializing-sdk) * [Fetching an Order](#section-fetching-an-order) * [Creating the Payment Request](#section-creating-the-payment-request) * [Creating the Order](#section-creating-the-order) * [Using OrderID in the SDK](#section-using-orderid-in-the-sdk) * [Initiating Order](#section-initiating-order) * [Displaying Payment Forms](#section-displaying-payment-forms) * [Receiving Payment result in the main activity](#section-receiving-payment-result-in-the-main-activity) * [Integration with Test Environment](#section-integration-with-test-environment) * [Verbose logging](#section-verbose-logging) ##Overview 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. Netbanking 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 a 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. This SDK has two modes of integration. 1. Simple Integration: With Simple Integration, you can use the pre-created SDK's UI to collect payment information from the user. 2. Custom UI Integration: The SDK has necessary APIs available to create a custom UI to collect payment information from the user. More on this [here](https://docs.instamojo.com/v1.1/page/android-sdk-custom-ui). ####**Note: Please contact a qualified security assessor to determine your PCI-DSS incidence and liability if you’re implementing a custom interface that collects cardholder information.** ##Payment flow Via 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 the Buy button, your app makes a call to your backend to initiate a transaction in your system. - Your backend systems create a transaction (uniquely identified by transaction_id). If required, it also obtains an access token from Instamojo servers. It passes back order details (like buyer details, amount, transaction id etc.) and a valid Instamojo’s access token. - Your Android app creates a new Order (from the SDK), by passing it order details and access token. - If the order is valid, the user is shown the payment modes, which will take him via the payment process as per mode selected. - Once a payment is completed, a callback is called in your Android app with your transaction_id. - Your Android app makes a request to your backend servers with the transaction_id. - Your backend server checks the status of the transaction by making a request to Instamojo’ server. - Your backend server updates the status in the database and passes back the result (successful / failure) to your app. - Your app shows the success/failure screen based on the result if received from your backend. ## Sample Application Yes, we have a Sample app that is integrated with SDK. 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](https://github.com/Instamojo/android-sdk-sample-app/blob/master/ReadMe.md). ## Installation [ ![Download](https://api.bintray.com/packages/dev-accounts/maven/sdks/images/download.svg) ](https://bintray.com/dev-accounts/maven/sdks/_latestVersion) ### Include SDK The SDK currently supports Android Version >= ICS 4.0.3(14). 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:+' } ``` ### 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. ``` //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 keep class com.instamojo.android.**{*;} ``` ## Generating Access Token A valid access token should be generated on your server using your `Client ID` and `Client Secret`. Generate CLIENT_ID and CLIENT_SECRET for specific environments from the following links. - [Test Environment](https://test.instamojo.com/integrations) - [Production Environment](https://www.instamojo.com/integrations) Related support article: [How Do I Get My Client ID And Client Secret?](https://support.instamojo.com/hc/en-us/articles/212214265-How-do-I-get-my-Client-ID-and-Client-Secret-) Access token should be generated using CLIENT_ID and CLIENT_SECRET and will be valid for 10 hours after generation. Please check this [documentation](https://github.com/Instamojo/sample-sdk-server#generating-access-token) on how to generate Access Token using the credentials. ## What is Transaction ID Well, transaction ID is a unique ID for an Order. Using this transaction ID, you can fetch Order status, get order details, and even initiate a refund for the Order attached to that transaction ID. The transaction ID should be unique for every Order. ## Simple Integration ### Initializing SDK Add the following `android:name="com.instamojo.android.InstamojoApplication"` key to `<application>` tag in manifest tag ```XML <application android:name="com.instamojo.android.InstamojoApplication" ..... > </application> ``` What if there is a custom `Application` class already? Then, add the following code snippet inside the `onCreate()` method of that custom application class. ```Java @Override public void onCreate() { super.onCreate(); Instamojo.initialize(this); ... } ``` ### Fetching an Order This step is for those who are looking for MarketPlace integration. If not, please move on to next [step](#section-initiating-order). ### Creating the Payment Request Please create a payment request using the [Payment Request API](https://docs.instamojo.com/v2/docs/create-a-payment-request) on your backend. ***Note: Ensure that you send the following redirect URL in the Payment Request payload for SDK to function properly.*** Test - https://test.instamojo.com/integrations/android/redirect/ Production - https://www.instamojo.com/integrations/android/redirect/ Once the payment request is created, collect payment request id from the field `id` from the response. ### Creating the Order Once the `id` from Payment Request API response is collected, you should create the order for this request using [Create Order API](https://docs.instamojo.com/v2/docs/create-an-order-using-payment-request-id) on your backend. Once the Order is created, collect the Order ID from the field `order_id` from the response. ### Using OrderID in the SDK Once the `order_id` is collected, send it back to the app. On the app, you can fetch the Order by passing the `access_token` and `order_id` to the SDK. ```Java // Good time to show dialog Request request = new Request(accessToken, orderID, new OrderRequestCallBack() { @Override public void onFinish(final Order order, final Exception error) { runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); if (error != null) { if (error instanceof Errors.ConnectionError) { showToast("No internet connection"); } else if (error instanceof Errors.ServerError) { showToast("Server Error. Try again"); } else if (error instanceof Errors.AuthenticationError) { showToast("Access token is invalid or expired. Please Update the token!!"); } else { showToast(error.toString()); } return; } startPreCreatedUI(order); } }); } }); request.execute(); ``` Once the order is fetched, please proceed to next [step](#section-displaying-payment-forms). ### Initiating Order To initiate an Order, the following fields are mandatory. 1. Name of the buyer (Max 100 characters)&nbsp; 2. Email of the buyer (Max 75 characters)&nbsp; 3. Purpose of the transaction (Max 255 characters)&nbsp; 4. Phone number of the buyer &nbsp; 5. Transaction amount (Min of Rs. 9 and limited to 2 decimal points)&nbsp; 6. Access Token &nbsp; 7. Transaction ID (Max 64 characters)&nbsp; With all the mandatory fields mentioned above, an `Order` object can be created. ``` Java Order order = new Order(accessToken, transactionID, name, email, phone, amount, purpose); ``` You can also set webhook for this particular order using the following code snippet ```Java order.setWebhook("http://your.server.com/webhook/"); ``` `Order` object must be validated locally before creating Order with Instamojo. Add the following code snippet to validate the `Order` object. ```Java //Validate the Order if (!order.isValid()){ //oops order validation failed. Pinpoint the issue(s). if (!order.isValidName()){ Log.e("App", "Buyer name is invalid"); } if (!order.isValidEmail()){ Log.e("App", "Buyer email is invalid"); } if (!order.isValidPhone()){ Log.e("App", "Buyer phone is invalid"); } if (!order.isValidAmount()){ Log.e("App", "Amount is invalid"); } if (!order.isValidDescription()){ Log.e("App", "description is invalid"); } if (!order.isValidTransactionID()){ Log.e("App", "Transaction ID is invalid"); } if (!order.isValidRedirectURL()){ Log.e("App", "Redirection URL is invalid"); } if (!order.isValidWebhook()) { showToast("Webhook URL is invalid"); } return; } //Validation is successful. Proceed ``` Once `Order` is validated. Add the following code snippet to create an order with Instamojo. ``` Java // Good time to show progress dialog to user Request request = new Request(order, new OrderRequestCallBack() { @Override public void onFinish(Order order, Exception error) { //dismiss the dialog if showed // Make sure the follwoing code is called on UI thread to show Toasts or to //update UI elements if (error != null) { if (error instanceof Errors.ConnectionError) { Log.e("App", "No internet connection"); } else if (error instanceof Errors.ServerError) { Log.e("App", "Server Error. Try again"); } else if (error instanceof Errors.AuthenticationError){ Log.e("App", "Access token is invalid or expired"); } else if (error instanceof Errors.ValidationError){ // Cast object to validation to pinpoint the issue Errors.ValidationError validationError = (Errors.ValidationError) error; if (!validationError.isValidTransactionID()) { Log.e("App", "Transaction ID is not Unique"); return; } if (!validationError.isValidRedirectURL()) { Log.e("App", "Redirect url is invalid"); return; } if (!validationError.isValidWebhook()) { showToast("Webhook url is invalid"); return; } if (!validationError.isValidPhone()) { Log.e("App", "Buyer's Phone Number is invalid/empty"); return; } if (!validationError.isValidEmail()) { Log.e("App", "Buyer's Email is invalid/empty"); return; } if (!validationError.isValidAmount()) { Log.e("App", "Amount is either less than Rs.9 or has more than two decimal places"); return; } if (!validationError.isValidName()) { Log.e("App", "Buyer's Name is required"); return; } } else { Log.e("App", error.getMessage()); } return; } startPreCreatedUI(order); } }); request.execute(); } }); ``` ### Displaying Payment Forms This SDK comes by default with payment forms (Cards and Netbanking) that can be used to collect payment details from the buyer. Add the following code snippet to your application's activity/fragment to use Pre-created UI. ``` Java private void startPreCreatedUI(Order order){ //Using Pre created UI Intent intent = new Intent(getBaseContext(), PaymentDetailsActivity.class); intent.putExtra(Constants.ORDER, order); startActivityForResult(intent, Constants.REQUEST_CODE); } ``` And you can call this once the order is created and validated, as per the above step: ```Java startPreCreatedUI(order); ``` ### Receiving Payment result in the main activity Add the following code snippet in the main activity. Note that TransactionID, OrderID, and paymentID maybe null. Please do a null check before proceeding. ``` Java @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constants.REQUEST_CODE && data != null) { String orderID = data.getStringExtra(Constants.ORDER_ID); String transactionID = data.getStringExtra(Constants.TRANSACTION_ID); String paymentID = data.getStringExtra(Constants.PAYMENT_ID); // Check transactionID, orderID, and orderID for null before using them to check the Payment status. if (orderID != null && transactionID != null && paymentID != null) { //Check for Payment status with Order ID or Transaction ID } else { //Oops!! Payment was cancelled } } } ``` ## Integration with Test Environment To do the integration in a test environment, add the following code snippet at any point in the code. ```Java Instamojo.setBaseUrl("https://test.instamojo.com/"); ``` You can remove this line to use production environment, before releasing the app. ## Verbose logging Detailed logs can very useful during SDK Integration, especially while debugging any issues in integration. To enable verbose logging, add the following code snippet at any point in the code: ``` Java Instamojo.setLogLevel(Log.DEBUG); ``` Log level defaults to `Log.WARN`. Once the application is ready to be pushed to the Play Store, simply remove the line of code.