{"_id":"59caa4843c0c2d00108bcffa","project":"56a1c9c13845200d0066d6fe","initVersion":{"_id":"56a1c9c23845200d0066d701","version":"1.1"},"user":{"_id":"56a1c959842b650d0088899c","username":"","name":"Instamojo"},"__v":0,"hidden":false,"createdAt":"2017-09-26T19:03:32.354Z","fullscreen":false,"htmlmode":false,"html":"","body":"[block:api-header]\n{\n  \"title\": \"Overview\"\n}\n[/block]\nAt Instamojo, we have always strived to make our integration kits simple and developer friendly. \n\nDevsupport AI is a bot programmer that will inject the Instamojo code in your project and get the payments working in minutes. \n\n## What all can I expect?\nWith this SDK, your customers would be able to pay using: \n1. Credit / Debit Cards\n2. EMI\n3. Netbanking\n4. Wallets\n5. UPI\n\n## What do I need? \n1. Back end server (We currently support PHP and are adding more technologies as we write this.)\n2. Client Id, Client Secret and Salt from dashboard. Note that sandbox and production credentials are different. \n3. Android Studio Project\n\n**Before proceeding further, have the above requisites up and ready.\n**\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Production integration\",\n  \"body\": \"At the end of this integration, you will be able to make payments on your production environment. Ensure to get your credentials from [Instamojo Dashboard](https://www.instamojo.com)\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Not Using PHP?\",\n  \"body\": \"The tool will give you a readymade file for PHP. If you are using other languages, take a look at this section: [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/android-integration-devsupport-ai#other-back-end-technologies)\"\n}\n[/block]\n## Step 1: \nDownload Devsupport AI from [here](https://github.com/artpar/devsupport/releases/latest). Install the .exe if you are on Windows, mac.zip if you are on Mac and .deb if you are on Linux. After the installation, you should see this screen:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/45036be-Screen_Shot_2017-09-27_at_12.47.58_AM.png\",\n        \"Screen Shot 2017-09-27 at 12.47.58 AM.png\",\n        2558,\n        1442,\n        \"#e3e2e3\"\n      ],\n      \"border\": true,\n      \"sizing\": \"80\",\n      \"caption\": \"\"\n    }\n  ]\n}\n[/block]\n## Step 2:\nLink your Android Project. You should see this screen:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ca86bdb-Screen_Shot_2017-09-27_at_12.50.36_AM.png\",\n        \"Screen Shot 2017-09-27 at 12.50.36 AM.png\",\n        2566,\n        1442,\n        \"#e1dfe0\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n## Step 3:\nClick on Integrate and complete your PHP integration first. \n\na. The tool will give you 2 files - handle_redirect.php and new_transaction.php\nb. These files already have your credentials - DO NOT modify these files. \nc. Host them on your PHP server and provide the publicly available URLs to these 2 files.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/f87f9ed-Webp.net-gifmaker.gif\",\n        \"Webp.net-gifmaker.gif\",\n        1100,\n        618,\n        \"#eff1f4\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n**If you are using some other technology on the back end, please refer to [other back end technology section below](https://docs.instamojo.com/v1.1/page/android-integration-devsupport-ai#other-back-end-technologies)** \n\nWe run test cases to see if you have hosted PHP correctly or not. You should see a success message as below:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/bc88ebc-Screen_Shot_2017-09-27_at_2.03.34_AM.png\",\n        \"Screen Shot 2017-09-27 at 2.03.34 AM.png\",\n        2560,\n        1438,\n        \"#e0dfe1\"\n      ]\n    }\n  ]\n}\n[/block]\n## Step 4:\nKeep your new_transaction.php URL handy. Proceed to Android integration and paste the URL. If everything went well, you should see a success screen:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/6ffd1cd-Screen_Shot_2017-10-05_at_11.12.44_AM.png\",\n        \"Screen Shot 2017-10-05 at 11.12.44 AM.png\",\n        2550,\n        1432,\n        \"#e1e0e2\"\n      ]\n    }\n  ]\n}\n[/block]\nGo to the activity you selected and just call InstamojoPay as shown below:\n\n```\ncallInstamojoPay(\"tester@gmail.com\", \"7875432991\", \"20\", \"official\", \"buyername\");\n\n```\n\nYou will receive a call back on the below function:\n\n```\nprivate void initListener() {\n   listener = new InstapayListener() {\n       @Override\n       public void onSuccess(String response) {\n           Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG)\n                   .show();\n       }\n\n       @Override\n       public void onFailure(int code, String reason) {\n           Toast.makeText(getApplicationContext(), \"Failed: \" + reason, Toast.LENGTH_LONG)\n                   .show();\n       }\n   };\n}\n\n```\n\n## Response Format:\n\nSuccess Response: \n\n**status=success:orderId=a089f02724ed4a8db6c069f6d30b3245:txnId=None:paymentId=MOJO7918005A76494611**\n\nFailure Response:\n**code - Failure Code\nReason - Reason in String\n**\n[block:api-header]\n{\n  \"title\": \"Other Back end Technologies\"\n}\n[/block]\nIf you are using Java, Go, Ruby, Python or NodeJS - here's what you need to do.\n\n1. Get an Access Token using [Oauth 2.0 API](https://docs.instamojo.com/v2/docs/application-based-authentication) \n\n*Note that the API is called with x-www-form-urlencoded, as shown below* \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9d510c1-Screen_Shot_2017-10-13_at_5.16.42_PM.png\",\n        \"Screen Shot 2017-10-13 at 5.16.42 PM.png\",\n        1952,\n        594,\n        \"#f6f6f6\"\n      ]\n    }\n  ]\n}\n[/block]\n2. Pass the access token and create a Payment Request using [Payment Request API](https://docs.instamojo.com/v2/docs/create-a-payment-request)\n3. Get Payment Request Id and create a Order using [Create Order API](https://docs.instamojo.com/v2/docs/create-an-order-using-payment-request-id)\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Setting Redirect URL\",\n  \"body\": \"While creating payment request, use the below Redirect URL\\nhttps://www.instamojo.com/integrations/android/redirect/\"\n}\n[/block]\nWrite this code in your back end and host it on your back end server. \n\nYour API URL should look something like this:\n\nhttps://mywebsite.com/instamojo.py\n\nIt should accept GET parameters like this:\n\nhttps://mywebsite.com/instamojo.py?action=new_transaction&amount=20&name=parth&purpose=testapi&email=test@gmail.com&phone=8888888888\n\nResponse should look like this\n\n```\n\n{\n\"transaction_id\":\"36e47df0-f0c3-4930-9888-74d003553f0e\",\n\"payment_request\":{\n\"id\":\"ec0bbe3d27df428fa3e86ff8b518ee18\",\n\"user\":\"https://api.instamojo.com/v2/users/92f7f8dfe5f248eaa332861d61d30e90/\",\n\"phone\":\"+918888888888\",\n\"email\":\"test@gmail.com\",\n\"buyer_name\":\"parth\",\n\"amount\":\"20.00\",\n\"purpose\":\"testapi\",\n\"status\":\"Pending\",\n\"expires_at\":null,\n\"payments\":{\n},\n\"send_sms\":false,\n\"send_email\":false,\n\"sms_status\":null,\n\"email_status\":null,\n\"shorturl\":null,\n\"longurl\":\"https://www.instamojo.com/@artpar/ec0bbe3d27df428fa3e86ff8b518ee18\",\n\"redirect_url\":\"https://www.instamojo.com/integrations/android/redirect/\",\n\"webhook\":\"YOUR_WEBHOOK_URL\",\n\"scheduled_at\":null,\n\"created_at\":\"2017-10-05T04:43:26.348492Z\",\n\"modified_at\":\"2017-10-05T04:43:26.348523Z\",\n\"resource_uri\":\"https://api.instamojo.com/v2/payment_requests/ec0bbe3d27df428fa3e86ff8b518ee18/\",\n\"allow_repeated_payments\":false,\n\"mark_fulfilled\":true\n},\n\"order\":{\n\"order_id\":\"72b8cfd4-3a52-4c4a-adaf-cec596fb380c\",\n\"name\":\"parth\",\n\"email\":\"test@gmail.com\",\n\"phone\":\"+918888888888\",\n\"amount\":\"20.00\"\n},\n\"token\":\"P3XEAQ7ab3TlGD7iBENRhIOzUZTeBo\"\n}\n\n```\n\nTest your API with [Postman](https://www.getpostman.com) and check if it's giving this output.\n\nIf yes, congrats! Open devsupport AI tool and proceed for Instamojo Android integration and enter the URL (e.g. https://mywebsite.com/instamojo.py) to your API when asked.\n\n## Want to test on Sandbox/Testing Environment? \n1. Login and get your credentials from [Instamojo Sandbox Dashboard](https://test.instamojo.com/).\n2. Update a. Client Id b. Client Secret c. URL in your back end code to get sandbox access token, order id and request id.\n3. Change the redirect URL in your backend code to https://test.instamojo.com/integrations/android/redirect/\n3. In your Android code, update the env param inside callInstamojo function to Config.TEST\n\nRun your build and test it.\n\n## Need help?\nDrop us an email at support@instamojo.com or support@devsupport.ai with the exact problem you are facing. We will help you out.","slug":"android-integration-devsupport-ai","title":"Android Integration - Devsupport AI"}

Android Integration - Devsupport AI


[block:api-header] { "title": "Overview" } [/block] At Instamojo, we have always strived to make our integration kits simple and developer friendly. Devsupport AI is a bot programmer that will inject the Instamojo code in your project and get the payments working in minutes. ## What all can I expect? With this SDK, your customers would be able to pay using: 1. Credit / Debit Cards 2. EMI 3. Netbanking 4. Wallets 5. UPI ## What do I need? 1. Back end server (We currently support PHP and are adding more technologies as we write this.) 2. Client Id, Client Secret and Salt from dashboard. Note that sandbox and production credentials are different. 3. Android Studio Project **Before proceeding further, have the above requisites up and ready. ** [block:callout] { "type": "success", "title": "Production integration", "body": "At the end of this integration, you will be able to make payments on your production environment. Ensure to get your credentials from [Instamojo Dashboard](https://www.instamojo.com)" } [/block] [block:callout] { "type": "info", "title": "Not Using PHP?", "body": "The tool will give you a readymade file for PHP. If you are using other languages, take a look at this section: [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/android-integration-devsupport-ai#other-back-end-technologies)" } [/block] ## Step 1: Download Devsupport AI from [here](https://github.com/artpar/devsupport/releases/latest). Install the .exe if you are on Windows, mac.zip if you are on Mac and .deb if you are on Linux. After the installation, you should see this screen: [block:image] { "images": [ { "image": [ "https://files.readme.io/45036be-Screen_Shot_2017-09-27_at_12.47.58_AM.png", "Screen Shot 2017-09-27 at 12.47.58 AM.png", 2558, 1442, "#e3e2e3" ], "border": true, "sizing": "80", "caption": "" } ] } [/block] ## Step 2: Link your Android Project. You should see this screen: [block:image] { "images": [ { "image": [ "https://files.readme.io/ca86bdb-Screen_Shot_2017-09-27_at_12.50.36_AM.png", "Screen Shot 2017-09-27 at 12.50.36 AM.png", 2566, 1442, "#e1dfe0" ], "sizing": "80" } ] } [/block] ## Step 3: Click on Integrate and complete your PHP integration first. a. The tool will give you 2 files - handle_redirect.php and new_transaction.php b. These files already have your credentials - DO NOT modify these files. c. Host them on your PHP server and provide the publicly available URLs to these 2 files. [block:image] { "images": [ { "image": [ "https://files.readme.io/f87f9ed-Webp.net-gifmaker.gif", "Webp.net-gifmaker.gif", 1100, 618, "#eff1f4" ], "sizing": "80" } ] } [/block] **If you are using some other technology on the back end, please refer to [other back end technology section below](https://docs.instamojo.com/v1.1/page/android-integration-devsupport-ai#other-back-end-technologies)** We run test cases to see if you have hosted PHP correctly or not. You should see a success message as below: [block:image] { "images": [ { "image": [ "https://files.readme.io/bc88ebc-Screen_Shot_2017-09-27_at_2.03.34_AM.png", "Screen Shot 2017-09-27 at 2.03.34 AM.png", 2560, 1438, "#e0dfe1" ] } ] } [/block] ## Step 4: Keep your new_transaction.php URL handy. Proceed to Android integration and paste the URL. If everything went well, you should see a success screen: [block:image] { "images": [ { "image": [ "https://files.readme.io/6ffd1cd-Screen_Shot_2017-10-05_at_11.12.44_AM.png", "Screen Shot 2017-10-05 at 11.12.44 AM.png", 2550, 1432, "#e1e0e2" ] } ] } [/block] Go to the activity you selected and just call InstamojoPay as shown below: ``` callInstamojoPay("tester@gmail.com", "7875432991", "20", "official", "buyername"); ``` You will receive a call back on the below function: ``` private void initListener() { listener = new InstapayListener() { @Override public void onSuccess(String response) { Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG) .show(); } @Override public void onFailure(int code, String reason) { Toast.makeText(getApplicationContext(), "Failed: " + reason, Toast.LENGTH_LONG) .show(); } }; } ``` ## Response Format: Success Response: **status=success:orderId=a089f02724ed4a8db6c069f6d30b3245:txnId=None:paymentId=MOJO7918005A76494611** Failure Response: **code - Failure Code Reason - Reason in String ** [block:api-header] { "title": "Other Back end Technologies" } [/block] If you are using Java, Go, Ruby, Python or NodeJS - here's what you need to do. 1. Get an Access Token using [Oauth 2.0 API](https://docs.instamojo.com/v2/docs/application-based-authentication) *Note that the API is called with x-www-form-urlencoded, as shown below* [block:image] { "images": [ { "image": [ "https://files.readme.io/9d510c1-Screen_Shot_2017-10-13_at_5.16.42_PM.png", "Screen Shot 2017-10-13 at 5.16.42 PM.png", 1952, 594, "#f6f6f6" ] } ] } [/block] 2. Pass the access token and create a Payment Request using [Payment Request API](https://docs.instamojo.com/v2/docs/create-a-payment-request) 3. Get Payment Request Id and create a Order using [Create Order API](https://docs.instamojo.com/v2/docs/create-an-order-using-payment-request-id) [block:callout] { "type": "success", "title": "Setting Redirect URL", "body": "While creating payment request, use the below Redirect URL\nhttps://www.instamojo.com/integrations/android/redirect/" } [/block] Write this code in your back end and host it on your back end server. Your API URL should look something like this: https://mywebsite.com/instamojo.py It should accept GET parameters like this: https://mywebsite.com/instamojo.py?action=new_transaction&amount=20&name=parth&purpose=testapi&email=test@gmail.com&phone=8888888888 Response should look like this ``` { "transaction_id":"36e47df0-f0c3-4930-9888-74d003553f0e", "payment_request":{ "id":"ec0bbe3d27df428fa3e86ff8b518ee18", "user":"https://api.instamojo.com/v2/users/92f7f8dfe5f248eaa332861d61d30e90/", "phone":"+918888888888", "email":"test@gmail.com", "buyer_name":"parth", "amount":"20.00", "purpose":"testapi", "status":"Pending", "expires_at":null, "payments":{ }, "send_sms":false, "send_email":false, "sms_status":null, "email_status":null, "shorturl":null, "longurl":"https://www.instamojo.com/@artpar/ec0bbe3d27df428fa3e86ff8b518ee18", "redirect_url":"https://www.instamojo.com/integrations/android/redirect/", "webhook":"YOUR_WEBHOOK_URL", "scheduled_at":null, "created_at":"2017-10-05T04:43:26.348492Z", "modified_at":"2017-10-05T04:43:26.348523Z", "resource_uri":"https://api.instamojo.com/v2/payment_requests/ec0bbe3d27df428fa3e86ff8b518ee18/", "allow_repeated_payments":false, "mark_fulfilled":true }, "order":{ "order_id":"72b8cfd4-3a52-4c4a-adaf-cec596fb380c", "name":"parth", "email":"test@gmail.com", "phone":"+918888888888", "amount":"20.00" }, "token":"P3XEAQ7ab3TlGD7iBENRhIOzUZTeBo" } ``` Test your API with [Postman](https://www.getpostman.com) and check if it's giving this output. If yes, congrats! Open devsupport AI tool and proceed for Instamojo Android integration and enter the URL (e.g. https://mywebsite.com/instamojo.py) to your API when asked. ## Want to test on Sandbox/Testing Environment? 1. Login and get your credentials from [Instamojo Sandbox Dashboard](https://test.instamojo.com/). 2. Update a. Client Id b. Client Secret c. URL in your back end code to get sandbox access token, order id and request id. 3. Change the redirect URL in your backend code to https://test.instamojo.com/integrations/android/redirect/ 3. In your Android code, update the env param inside callInstamojo function to Config.TEST Run your build and test it. ## Need help? Drop us an email at support@instamojo.com or support@devsupport.ai with the exact problem you are facing. We will help you out.