{"_id":"5a2ac24e878ac8001ce475d4","project":"56a1c9c13845200d0066d6fe","initVersion":{"_id":"56a1c9c23845200d0066d701","version":"1.1"},"user":{"_id":"56a1c959842b650d0088899c","username":"","name":"Instamojo"},"__v":0,"hidden":false,"createdAt":"2017-12-08T16:48:14.152Z","fullscreen":false,"htmlmode":false,"html":"","body":"Devsupport AI is a bot programmer that injects 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 & Python and are adding more technologies as we write this.)\n2. Client Id, and Client Secret from dashboard. \n3. Android Studio Project\n\n**Before proceeding further, have the above requisites up and ready.\n**\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Important!\",\n  \"body\": \"You are responsible for your client id and client secret. They are to be embedded in your server script. DO NOT use them in your Android code.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Not Using PHP or Python?\",\n  \"body\": \"If you are using other languages, take a look at this section: [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/devsupport-ai-android-integration#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. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/1700b78-Screen_Shot_2017-12-08_at_10.24.51_PM.png\",\n        \"Screen Shot 2017-12-08 at 10.24.51 PM.png\",\n        2562,\n        1444,\n        \"#e3e2e3\"\n      ]\n    }\n  ]\n}\n[/block]\n## Step 2: \nLink your Android project and proceed with integration.\n\n## Step 3:\nProceed with back end integration first. Choose either PHP or Python, fill your client_id and client_secret, and download the file generated by the tool. Host this file on your server and keep it's URL handy.  \n\nIf you use other back end technologies, refer [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/devsupport-ai-android-integration#other-back-end-technologies)\n\n##Step 4:\nProceed to Android integration and paste the access_token URL when the tool asks. E.g. https://iamironman.com/access_token.php or https://iambatman.com/access_token.py\n\nThat's it! You just completed Android integration. If all's well, you should see the screen below\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/324aa31-success.png\",\n        \"success.png\",\n        2550,\n        1432,\n        \"#e0e0e2\"\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:token=qyFwLidQ0aBNNWlsmwHx1gHFhlt6A1**\n\nFailure Response:\n**code - Failure Code\nReason - Reason in String\n**\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Important!\",\n  \"body\": \"Once you receive success callback, process the order. For your records, store token, orderid and payment id on your server.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Other Back end Technologies\"\n}\n[/block]\nDevsupport AI tool expects an access token generated on your server. \n## How do I get access token?\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var qs = require(\\\"querystring\\\");\\nvar http = require(\\\"https\\\");\\n\\nvar options = {\\n  \\\"method\\\": \\\"POST\\\",\\n  \\\"hostname\\\": \\\"test.instamojo.com\\\",\\n  \\\"port\\\": null,\\n  \\\"path\\\": \\\"/oauth2/token/\\\",\\n  \\\"headers\\\": {\\n    \\\"content-type\\\": \\\"application/x-www-form-urlencoded\\\",\\n    \\\"cache-control\\\": \\\"no-cache\\\"\\n  }\\n};\\n\\nvar req = http.request(options, function (res) {\\n  var chunks = [];\\n\\n  res.on(\\\"data\\\", function (chunk) {\\n    chunks.push(chunk);\\n  });\\n\\n  res.on(\\\"end\\\", function () {\\n    var body = Buffer.concat(chunks);\\n    console.log(body.toString());\\n  });\\n});\\n\\nreq.write(qs.stringify({ grant_type: 'client_credentials',\\n  client_id: 'test',\\n  client_secret: 'test' }));\\nreq.end();\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"OkHttpClient client = new OkHttpClient();\\n\\nMediaType mediaType = MediaType.parse(\\\"application/x-www-form-urlencoded\\\");\\nRequestBody body = RequestBody.create(mediaType, \\\"grant_type=client_credentials&client_id=test&client_secret=test\\\");\\nRequest request = new Request.Builder()\\n  .url(\\\"https://test.instamojo.com/oauth2/token/\\\")\\n  .post(body)\\n  .addHeader(\\\"content-type\\\", \\\"application/x-www-form-urlencoded\\\")\\n  .addHeader(\\\"cache-control\\\", \\\"no-cache\\\")\\n  .build();\\n\\nResponse response = client.newCall(request).execute();\",\n      \"language\": \"java\"\n    },\n    {\n      \"code\": \"package main\\n\\nimport (\\n\\t\\\"fmt\\\"\\n\\t\\\"strings\\\"\\n\\t\\\"net/http\\\"\\n\\t\\\"io/ioutil\\\"\\n)\\n\\nfunc main() {\\n\\n  url := \\\"https://test.instamojo.com/oauth2/token/\\\"\\n\\n\\tpayload := strings.NewReader(\\\"grant_type=client_credentials&client_id=test&client_secret=test\\\")\\n\\n\\treq, _ := http.NewRequest(\\\"POST\\\", url, payload)\\n\\n\\treq.Header.Add(\\\"content-type\\\", \\\"application/x-www-form-urlencoded\\\")\\n\\treq.Header.Add(\\\"cache-control\\\", \\\"no-cache\\\")\\n\\n\\tres, _ := http.DefaultClient.Do(req)\\n\\n\\tdefer res.Body.Close()\\n\\tbody, _ := ioutil.ReadAll(res.Body)\\n\\n\\tfmt.Println(res)\\n\\tfmt.Println(string(body))\\n\\n}\",\n      \"language\": \"go\"\n    }\n  ]\n}\n[/block]\nAccess Token looks like this:\n\n```\n\n{\n  \"access_token\": \"tyDkRjkirDEmF4PP8AHNrS3NnGwrt6\",\n  \"expires_in\": 36000,\n  \"token_type\": \"Bearer\",\n  \"scope\": \"read write payouts:read payments:read payments:fulfil payments:refund\"\n}\n\n```\n\nRead access_token and prepend your environment to it. \n\nE.g if you are testing on Test environment, access token should look like this: testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6\n\nIf you are on Production environment, access token should look like this:\nproductiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6\n\nHost your script on server, keep it's URL ready and proceed to the bot for Android integration.\n\nWhen publicly accessed, this url should output the access token. E.g. testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6 or productiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6\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":"devsupport-ai-android-integration","title":"Devsupport AI - Android Integration"}

Devsupport AI - Android Integration


Devsupport AI is a bot programmer that injects 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 & Python and are adding more technologies as we write this.) 2. Client Id, and Client Secret from dashboard. 3. Android Studio Project **Before proceeding further, have the above requisites up and ready. ** [block:callout] { "type": "danger", "title": "Important!", "body": "You are responsible for your client id and client secret. They are to be embedded in your server script. DO NOT use them in your Android code." } [/block] [block:callout] { "type": "info", "title": "Not Using PHP or Python?", "body": "If you are using other languages, take a look at this section: [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/devsupport-ai-android-integration#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. [block:image] { "images": [ { "image": [ "https://files.readme.io/1700b78-Screen_Shot_2017-12-08_at_10.24.51_PM.png", "Screen Shot 2017-12-08 at 10.24.51 PM.png", 2562, 1444, "#e3e2e3" ] } ] } [/block] ## Step 2: Link your Android project and proceed with integration. ## Step 3: Proceed with back end integration first. Choose either PHP or Python, fill your client_id and client_secret, and download the file generated by the tool. Host this file on your server and keep it's URL handy. If you use other back end technologies, refer [Other Back end Technologies](https://docs.instamojo.com/v1.1/page/devsupport-ai-android-integration#other-back-end-technologies) ##Step 4: Proceed to Android integration and paste the access_token URL when the tool asks. E.g. https://iamironman.com/access_token.php or https://iambatman.com/access_token.py That's it! You just completed Android integration. If all's well, you should see the screen below [block:image] { "images": [ { "image": [ "https://files.readme.io/324aa31-success.png", "success.png", 2550, 1432, "#e0e0e2" ] } ] } [/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:token=qyFwLidQ0aBNNWlsmwHx1gHFhlt6A1** Failure Response: **code - Failure Code Reason - Reason in String ** [block:callout] { "type": "warning", "title": "Important!", "body": "Once you receive success callback, process the order. For your records, store token, orderid and payment id on your server." } [/block] [block:api-header] { "title": "Other Back end Technologies" } [/block] Devsupport AI tool expects an access token generated on your server. ## How do I get access token? [block:code] { "codes": [ { "code": "var qs = require(\"querystring\");\nvar http = require(\"https\");\n\nvar options = {\n \"method\": \"POST\",\n \"hostname\": \"test.instamojo.com\",\n \"port\": null,\n \"path\": \"/oauth2/token/\",\n \"headers\": {\n \"content-type\": \"application/x-www-form-urlencoded\",\n \"cache-control\": \"no-cache\"\n }\n};\n\nvar req = http.request(options, function (res) {\n var chunks = [];\n\n res.on(\"data\", function (chunk) {\n chunks.push(chunk);\n });\n\n res.on(\"end\", function () {\n var body = Buffer.concat(chunks);\n console.log(body.toString());\n });\n});\n\nreq.write(qs.stringify({ grant_type: 'client_credentials',\n client_id: 'test',\n client_secret: 'test' }));\nreq.end();", "language": "javascript" }, { "code": "OkHttpClient client = new OkHttpClient();\n\nMediaType mediaType = MediaType.parse(\"application/x-www-form-urlencoded\");\nRequestBody body = RequestBody.create(mediaType, \"grant_type=client_credentials&client_id=test&client_secret=test\");\nRequest request = new Request.Builder()\n .url(\"https://test.instamojo.com/oauth2/token/\")\n .post(body)\n .addHeader(\"content-type\", \"application/x-www-form-urlencoded\")\n .addHeader(\"cache-control\", \"no-cache\")\n .build();\n\nResponse response = client.newCall(request).execute();", "language": "java" }, { "code": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\n url := \"https://test.instamojo.com/oauth2/token/\"\n\n\tpayload := strings.NewReader(\"grant_type=client_credentials&client_id=test&client_secret=test\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\treq.Header.Add(\"content-type\", \"application/x-www-form-urlencoded\")\n\treq.Header.Add(\"cache-control\", \"no-cache\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}", "language": "go" } ] } [/block] Access Token looks like this: ``` { "access_token": "tyDkRjkirDEmF4PP8AHNrS3NnGwrt6", "expires_in": 36000, "token_type": "Bearer", "scope": "read write payouts:read payments:read payments:fulfil payments:refund" } ``` Read access_token and prepend your environment to it. E.g if you are testing on Test environment, access token should look like this: testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6 If you are on Production environment, access token should look like this: productiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6 Host your script on server, keep it's URL ready and proceed to the bot for Android integration. When publicly accessed, this url should output the access token. E.g. testtyDkRjkirDEmF4PP8AHNrS3NnGwrt6 or productiontyDkRjkirDEmF4PP8AHNrS3NnGwrt6 ## 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.