{"_id":"5a1b849dcfdb7900127167da","project":"56a1c9c13845200d0066d6fe","initVersion":{"_id":"56a1c9c23845200d0066d701","version":"1.1"},"user":{"_id":"56a1c959842b650d0088899c","username":"","name":"Instamojo"},"__v":0,"hidden":true,"createdAt":"2017-11-27T03:21:01.646Z","fullscreen":false,"htmlmode":false,"html":"","body":"[block:api-header]\n{\n  \"title\": \"Overview\"\n}\n[/block]\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\n2. Client Id, Client Secret and Salt from dashboard. Note that sandbox and production credentials are different. \n\n**Before proceeding further, have the above requisites up and ready.\n**\n[block:callout]\n{\n  \"type\": \"success\",\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  \"title\": \"Production Integration\"\n}\n[/block]\n##Using Cocapods (Highly recommended) \n1. Uncomment “use_frameworks!” in your podfile as Instamojo was built using Swift. Add the following Snippet to your Pod file\n\nIf you are using Xcode 9.0 (Swift 3.2 && Swift 4.0) \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pod 'Instamojo', :git => 'https://github.com/Instamojo/ios-sdk.git', :tag => '1.0.10'\\npod 'InstaMojoiOS', '0.0.2'  \",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nIf using Xcode 9.1 (Swift 3.2.2 && Swift 4.0.2) \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pod 'Instamojo', :git => 'https://github.com/Instamojo/ios-sdk.git', :tag => '1.0.12'\\npod 'InstaMojoiOS', '0.0.3'  \",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n2. Run Pod Install\n3. Make sure the InstaMojoiOS pod is always in the updated version: you can [check it here](https://github.com/CocoaPods/Specs/tree/master/Specs/8/b/e/InstaMojoiOS)\n4. If you are using older version, Run pod update \n\n**Always use the latest version\n**\n\n##Manually\n1. For InstaMojo manual integration, please refer https://docs.instamojo.com/page/ios-sdk#section-manually\n2. For InstaMojoiOS integartion, download the framework from https://github.com/shardullavekar/InstamojoiOS/raw/master/InstaMojo-0.0.2.tar.gz\nOpen it to unzip and add InstaMojoiOS.framework file to your project\n3. Select Target, Navigate to Build Phases and under Embedded Binaries click on “+” and select InstaMojoiOS.framework\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Embedding Binaries\",\n  \"body\": \"This process ensures that the added framework will be embedded within the App bundle. It also helps sharing the code between the app and extension bundles.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Using Objective C?\",\n  \"body\": \"If your project uses only Objective C, then the swift frameworks are not included. In that case, Instamojo framework can not be added to your project.\\n\\nAs a workaround to this issue, in Build Options set\\nAlways Embed Swift Standard Libraries = YES\"\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/4bd68fa-Screen_Shot_2017-11-19_at_9.12.15_PM.png\",\n        \"Screen Shot 2017-11-19 at 9.12.15 PM.png\",\n        1756,\n        1598,\n        \"#212d3e\"\n      ]\n    }\n  ]\n}\n[/block]\n##Backend Integration\nYou need to host a code snippet that gets an access token from Instamojo. Remember to insert your production credentials in the snippet below and host it on your server. \n\nKeep a URL to this code ready. E.g. https://yourwebsite.com/access_token.php\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Production Credentials\",\n  \"body\": \"Remember to insert your production credentials in Client Id and Client Secret\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$curl = curl_init();\\n\\ncurl_setopt_array($curl, array(\\n  CURLOPT_URL => \\\"https://api.instamojo.com/oauth2/token/\\\",\\n  CURLOPT_RETURNTRANSFER => true,\\n  CURLOPT_ENCODING => \\\"\\\",\\n  CURLOPT_MAXREDIRS => 10,\\n  CURLOPT_TIMEOUT => 30,\\n  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\\n  CURLOPT_CUSTOMREQUEST => \\\"POST\\\",\\n  CURLOPT_POSTFIELDS => \\\"grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET\\\",\\n  CURLOPT_HTTPHEADER => array(\\n    \\\"cache-control: no-cache\\\",\\n    \\\"content-type: application/x-www-form-urlencoded\\\"\\n  ),\\n));\\n\\n$response = curl_exec($curl);\\n$err = curl_error($curl);\\n\\ncurl_close($curl);\\n\\nif ($err) {\\n  echo \\\"cURL Error #:\\\" . $err;\\n} else {\\n  echo $response;\\n}\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"import requests\\n\\nurl = \\\"https://api.instamojo.com/oauth2/token/\\\"\\n\\npayload = \\\"grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET\\\"\\nheaders = {\\n    'content-type': \\\"application/x-www-form-urlencoded\\\",\\n    'cache-control': \\\"no-cache\\\"    \\n}\\n\\nresponse = requests.request(\\\"POST\\\", url, data=payload, headers=headers)\\n\\nprint(response.text)\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var request = require(\\\"request\\\");\\n\\nvar options = { method: 'POST',\\n  url: 'https://api.instamojo.com/oauth2/token/',\\n  headers: \\n   { 'cache-control': 'no-cache',\\n     'content-type': 'application/x-www-form-urlencoded' },\\n  form: \\n   { grant_type: 'client_credentials',\\n     client_id: 'YOUR_CLIENT_ID',\\n     client_secret: 'YOUR_CLIENT_SECRET' } };\\n\\nrequest(options, function (error, response, body) {\\n  if (error) throw new Error(error);\\n\\n  console.log(body);\\n});\\n\",\n      \"language\": \"javascript\",\n      \"name\": \"NodeJs\"\n    },\n    {\n      \"code\": \"curl -X POST -H \\\"Content-Type: application/x-www-form-urlencoded\\\" -H \\\"Cache-Control: no-cache\\\" -d 'grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET' \\\"https://api.instamojo.com/oauth2/token/\\\"\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nWhen you hit this URL, here is the expected outcome:\n\n```\n\n{\n  \"access_token\": \"9sFgDhiBqZO0NwQoga5b0TBvFcCFjR\",\n  \"expires_in\": 36000,\n  \"token_type\": \"Bearer\",\n  \"scope\": \"read write payouts:read payments:read payments:fulfil payments:refund\"\n}\n\n\n```\n\nAdd the Get Access Token URL in your info.plist under the key “InstaMojoConfigURL”\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/60f74af-Screen_Shot_2017-12-15_at_5.25.46_PM.png\",\n        \"Screen Shot 2017-12-15 at 5.25.46 PM.png\",\n        1082,\n        438,\n        \"#e5e4e4\"\n      ]\n    }\n  ]\n}\n[/block]\n#Swift Integration\n\n1. Import InstaMojoiOS\n2. Pass along the Order Details: Purpose, email, mobile and implement a completion block which returns success boolean and message string\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"IMConfiguration.sharedInstance.setupOrder(purpose: \\\"buying\\\", buyerName: \\\"Shardul\\\", emailId: \\\"tester@gmail.com\\\", mobile: \\\"7875432991\\\", amount: \\\"20\\\", environment: .Production, on: self) { (success, message) in\\n            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {\\n                if success {\\n                    let alert = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.alert)\\n                    alert.addAction(UIAlertAction(title: \\\"Ok\\\", style: UIAlertActionStyle.cancel, handler: nil))\\n                    self.present(alert, animated: true, completion: nil)\\n                } else {\\n                    let alert = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.alert)\\n                    alert.addAction(UIAlertAction(title: \\\"Ok\\\", style: UIAlertActionStyle.cancel, handler: nil))\\n                    self.present(alert, animated: true, completion: nil)\\n                }\\n            })\\n        }\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n#Objective-C Integration\n1. ``` #import <InstaMojoiOS/InstaMojoiOS-Swift.h> ```\n2. Pass along the Order Details like Purpose, email, mobile etc\nAnd implement a completion block which returns success boolean and message string\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[IMConfiguration sharedInstance] setupOrderWithPurpose:@\\\"buying\\\" buyerName:@\\\"Shardul\\\" emailId:@\\\"tester@gmail.com\\\" mobile:@\\\"7875432991\\\" amount:@\\\"20\\\" environment:EnvironmentProduction on:nil completion:^(BOOL success, NSString * _Nonnull message) {\\n        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\\n            UIAlertController *alert = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];\\n            [alert addAction:[UIAlertAction actionWithTitle:@\\\"Ok\\\" style:UIAlertActionStyleCancel handler:nil]];\\n            [self presentViewController:alert animated:true completion:nil];\\n        });\\n    }];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","slug":"ios-integration","title":"iOS Integration"}

iOS Integration


[block:api-header] { "title": "Overview" } [/block] ## 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 2. Client Id, Client Secret and Salt from dashboard. Note that sandbox and production credentials are different. **Before proceeding further, have the above requisites up and ready. ** [block:callout] { "type": "success", "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)", "title": "Production Integration" } [/block] ##Using Cocapods (Highly recommended) 1. Uncomment “use_frameworks!” in your podfile as Instamojo was built using Swift. Add the following Snippet to your Pod file If you are using Xcode 9.0 (Swift 3.2 && Swift 4.0) [block:code] { "codes": [ { "code": "pod 'Instamojo', :git => 'https://github.com/Instamojo/ios-sdk.git', :tag => '1.0.10'\npod 'InstaMojoiOS', '0.0.2' ", "language": "objectivec" } ] } [/block] If using Xcode 9.1 (Swift 3.2.2 && Swift 4.0.2) [block:code] { "codes": [ { "code": "pod 'Instamojo', :git => 'https://github.com/Instamojo/ios-sdk.git', :tag => '1.0.12'\npod 'InstaMojoiOS', '0.0.3' ", "language": "objectivec" } ] } [/block] 2. Run Pod Install 3. Make sure the InstaMojoiOS pod is always in the updated version: you can [check it here](https://github.com/CocoaPods/Specs/tree/master/Specs/8/b/e/InstaMojoiOS) 4. If you are using older version, Run pod update **Always use the latest version ** ##Manually 1. For InstaMojo manual integration, please refer https://docs.instamojo.com/page/ios-sdk#section-manually 2. For InstaMojoiOS integartion, download the framework from https://github.com/shardullavekar/InstamojoiOS/raw/master/InstaMojo-0.0.2.tar.gz Open it to unzip and add InstaMojoiOS.framework file to your project 3. Select Target, Navigate to Build Phases and under Embedded Binaries click on “+” and select InstaMojoiOS.framework [block:callout] { "type": "info", "title": "Embedding Binaries", "body": "This process ensures that the added framework will be embedded within the App bundle. It also helps sharing the code between the app and extension bundles." } [/block] [block:callout] { "type": "warning", "title": "Using Objective C?", "body": "If your project uses only Objective C, then the swift frameworks are not included. In that case, Instamojo framework can not be added to your project.\n\nAs a workaround to this issue, in Build Options set\nAlways Embed Swift Standard Libraries = YES" } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/4bd68fa-Screen_Shot_2017-11-19_at_9.12.15_PM.png", "Screen Shot 2017-11-19 at 9.12.15 PM.png", 1756, 1598, "#212d3e" ] } ] } [/block] ##Backend Integration You need to host a code snippet that gets an access token from Instamojo. Remember to insert your production credentials in the snippet below and host it on your server. Keep a URL to this code ready. E.g. https://yourwebsite.com/access_token.php [block:callout] { "type": "info", "title": "Production Credentials", "body": "Remember to insert your production credentials in Client Id and Client Secret" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, array(\n CURLOPT_URL => \"https://api.instamojo.com/oauth2/token/\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 30,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => \"grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET\",\n CURLOPT_HTTPHEADER => array(\n \"cache-control: no-cache\",\n \"content-type: application/x-www-form-urlencoded\"\n ),\n));\n\n$response = curl_exec($curl);\n$err = curl_error($curl);\n\ncurl_close($curl);\n\nif ($err) {\n echo \"cURL Error #:\" . $err;\n} else {\n echo $response;\n}", "language": "php" }, { "code": "import requests\n\nurl = \"https://api.instamojo.com/oauth2/token/\"\n\npayload = \"grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET\"\nheaders = {\n 'content-type': \"application/x-www-form-urlencoded\",\n 'cache-control': \"no-cache\" \n}\n\nresponse = requests.request(\"POST\", url, data=payload, headers=headers)\n\nprint(response.text)", "language": "python" }, { "code": "var request = require(\"request\");\n\nvar options = { method: 'POST',\n url: 'https://api.instamojo.com/oauth2/token/',\n headers: \n { 'cache-control': 'no-cache',\n 'content-type': 'application/x-www-form-urlencoded' },\n form: \n { grant_type: 'client_credentials',\n client_id: 'YOUR_CLIENT_ID',\n client_secret: 'YOUR_CLIENT_SECRET' } };\n\nrequest(options, function (error, response, body) {\n if (error) throw new Error(error);\n\n console.log(body);\n});\n", "language": "javascript", "name": "NodeJs" }, { "code": "curl -X POST -H \"Content-Type: application/x-www-form-urlencoded\" -H \"Cache-Control: no-cache\" -d 'grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET' \"https://api.instamojo.com/oauth2/token/\"", "language": "curl" } ] } [/block] When you hit this URL, here is the expected outcome: ``` { "access_token": "9sFgDhiBqZO0NwQoga5b0TBvFcCFjR", "expires_in": 36000, "token_type": "Bearer", "scope": "read write payouts:read payments:read payments:fulfil payments:refund" } ``` Add the Get Access Token URL in your info.plist under the key “InstaMojoConfigURL” [block:image] { "images": [ { "image": [ "https://files.readme.io/60f74af-Screen_Shot_2017-12-15_at_5.25.46_PM.png", "Screen Shot 2017-12-15 at 5.25.46 PM.png", 1082, 438, "#e5e4e4" ] } ] } [/block] #Swift Integration 1. Import InstaMojoiOS 2. Pass along the Order Details: Purpose, email, mobile and implement a completion block which returns success boolean and message string [block:code] { "codes": [ { "code": "IMConfiguration.sharedInstance.setupOrder(purpose: \"buying\", buyerName: \"Shardul\", emailId: \"tester@gmail.com\", mobile: \"7875432991\", amount: \"20\", environment: .Production, on: self) { (success, message) in\n DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {\n if success {\n let alert = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.alert)\n alert.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\n self.present(alert, animated: true, completion: nil)\n } else {\n let alert = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.alert)\n alert.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\n self.present(alert, animated: true, completion: nil)\n }\n })\n }", "language": "swift" } ] } [/block] #Objective-C Integration 1. ``` #import <InstaMojoiOS/InstaMojoiOS-Swift.h> ``` 2. Pass along the Order Details like Purpose, email, mobile etc And implement a completion block which returns success boolean and message string [block:code] { "codes": [ { "code": "[[IMConfiguration sharedInstance] setupOrderWithPurpose:@\"buying\" buyerName:@\"Shardul\" emailId:@\"tester@gmail.com\" mobile:@\"7875432991\" amount:@\"20\" environment:EnvironmentProduction on:nil completion:^(BOOL success, NSString * _Nonnull message) {\n dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\n UIAlertController *alert = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];\n [alert addAction:[UIAlertAction actionWithTitle:@\"Ok\" style:UIAlertActionStyleCancel handler:nil]];\n [self presentViewController:alert animated:true completion:nil];\n });\n }];", "language": "objectivec" } ] } [/block]