{"_id":"56e25e75353e060e00b96812","__v":0,"project":"54c83b5aab706219009e067b","user":{"_id":"56d827d73eb4dd0b00201ad2","username":"","name":"Akshay Bhalotia"},"initVersion":{"_id":"54dec8b6c2b4b70d009c3f0f","version":"1"},"hidden":false,"createdAt":"2016-03-11T05:58:13.266Z","fullscreen":false,"htmlmode":false,"html":"","body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"A new version of iOS SDK is available. You can click [here](https://razorpay.com/docs/ios/) to refer the documentation.\",\n  \"title\": \"New Version Available\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Integration method changed\",\n  \"body\": \"We have changed the integration method with this release. We highly recommend you to use the latest SDK. Nevertheless if you wish to stick to the older version, you can find the documentation [here](https://docs.razorpay.com/v1/page/ios-sdk-0100).\"\n}\n[/block]\n# v 0.14.1\n### Usage Instructions:\n## Step 1: Import library to your project\n- Download from [here](http://downloads.razorpay.com/Razorpay.framework-0.14.1.zip) and unzip. (For `bitcode` enabled SDK, click [here](http://downloads.razorpay.com/Razorpay.framework-0.14.1-bitcode.zip)). We also have a [CocoaPod](https://cocoapods.org/pods/razorpay-pod) for our SDK (non `bitcode` enabled).\n- Open your project in XCode and select `Add files to \"yourproject\"` from `file` menu.\n- Select Razorpay.framework in the directory you just unzipped.\n- Make sure 'Copy items if needed' is checked.\n- Click 'Add'.\n- In the \"Build Settings\" tab of your project settings, `-ObjC` flag should be present under \"Other Linker Flags\".\n- Under \"Link Binary With Libraries\" in the \"Build Settings\" tab of your project settings, add `CoreTelephony.framework` and `SystemConfiguration.framework`.\n\n## Step 2: Initialize Razorpay SDK\n\nYou'll need your public key and delegate that implements *RazorpayPaymentCompletionProtocol* and view controller where you want to show the checkout form.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <Razorpay/Razorpay.h>\\n\\n@interface ViewController () <RazorpayPaymentCompletionProtocol> {\\n  Razorpay *razorpay;\\n..  \\n..\\n  \\n// Any place before opening the checkout form (eg. viewDidLoad)\\n- (void)viewDidLoad {\\n  [super viewDidLoad];\\n  ..\\n  ..\\n  razorpay = [Razorpay initWithKey:@\\\"YOUR_PUBLIC_KEY\\\" andDelegate:self];\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"ViewController.m\"\n    }\n  ]\n}\n[/block]\n## Step 3: Pass payment options and show checkout form\n\nAdd following code to in your ViewController or where ever you want to initialize payments:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)showPaymentForm { // called by your app\\n  NSDictionary *options = @{\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"amount\\\": @\\\"1000\\\", // mandatory, in paise\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t      // all optional other than amount.\\n            \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"image\\\": @\\\"https://url-to-image.png\\\",\\n      \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"name\\\": @\\\"business or product name\\\",\\n      \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"description\\\": @\\\"purchase description\\\",\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"prefill\\\" : @{ \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"email\\\": @\\\"pranav@razorpay.com\\\",\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"contact\\\": @\\\"8879524924\\\"\\n                            \\t\\t},\\n      \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t@\\\"theme\\\": @{\\n                                  \\t@\\\"color\\\": @\\\"#F37254\\\"\\n                                }\\n                        \\t\\t};\\n\\t\\t[razorpay open:options];\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"ViewController.m\"\n    }\n  ]\n}\n[/block]\nThat's pretty much it. You can find the list of all supported options [here](https://docs.razorpay.com/docs/checkout-form#checkout-fields).\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Progress Bar\",\n  \"body\": \"To support theme color in progress bar, please pass HEX color values only.\"\n}\n[/block]\n## Step 4: Handle success/error when payment is done\n\nThis is done by implementing `onPaymentSuccess` and `onPaymentError` methods of the *RazorpayPaymentCompletionProtocol*:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)onPaymentSuccess:(nonnull NSString*)payment_id {\\n    \\t[[[UIAlertView alloc] initWithTitle:@\\\"Payment Successful\\\" message:payment_id delegate:self cancelButtonTitle:@\\\"OK\\\" otherButtonTitles:nil] show];\\n}\\n\\n- (void)onPaymentError:(int)code description:(nonnull NSString *)str {\\n    \\t[[[UIAlertView alloc] initWithTitle:@\\\"Error\\\" message:str delegate:self cancelButtonTitle:@\\\"OK\\\" otherButtonTitles:nil] show];\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"ViewController.m\"\n    }\n  ]\n}\n[/block]\nHere you have to put necessary actions after payment is completed based on success/error.\nPossible values for failure code are:\n* 0: Network error\n* 1: Initialization failure due to invalid options passed\n* 2: Payment cancelled by user\n\nSuccess handler will receive `payment_id` which you can use later for capturing purposes.\n\nYou can call `open` method any number of times. (eg. in case of payment failure, customer might want to retry so you can call the open method with same / different options based on your use case)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"iOS9 Update\"\n}\n[/block]\niOS 9 has higher requirements for secure URLs. Unfortunately, many of Indian banks do not comply, which leaves you with following workaround for time being:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<key>NSAppTransportSecurity</key>\\n<dict>\\n    <key>NSAllowsArbitraryLoads</key>\\n    <true/>\\n</dict>\",\n      \"language\": \"xml\",\n      \"name\": \"info.plist\"\n    }\n  ]\n}\n[/block]\n Add it to your info.plist file. more info [here](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33)\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Working with Swift\"\n}\n[/block]\nYou can easily use the SDK with swift using Objective-C Bridging Header. [Apple](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) has some nice documentation on subject.\n\nTo begin, create a new file (File > New > File > iOS > Source > Header File) and name it `YourProjectName-Bridging-Header.h`. Open the file and insert following line to it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <Razorpay/Razorpay.h>\",\n      \"language\": \"objectivec\",\n      \"name\": \"YourProjectName-Bridging-Header.h\"\n    }\n  ]\n}\n[/block]\nNext, go to your project's build settings, and type \"bridging\" to filter options. Look for an option named `Objective-C Bridging Header` and set its value to path of your file. It may look something like this:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/p7EuDSQXTGGEMUotYpEG_swiftexample-settings.png\",\n        \"swiftexample-settings.png\",\n        \"1756\",\n        \"726\",\n        \"#233e65\",\n        \"\"\n      ],\n      \"caption\": \"(swiftexample is the name of your project)\"\n    }\n  ]\n}\n[/block]\nThen in your ViewController, setup the SDK as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class ViewController: UIViewController, RazorpayPaymentCompletionProtocol.. {\\n\\n    private var razorpay : Razorpay!\\n    ..\\n    ..\\n    \\n    override func viewDidLoad() {\\n        super.viewDidLoad()\\n        ..\\n        ..\\n        razorpay = Razorpay.initWithKey(\\\"YOUR_PUBLIC_KEY\\\", andDelegate: self)\\n    }\",\n      \"language\": \"swift\",\n      \"name\": \"ViewController.swift\"\n    }\n  ]\n}\n[/block]\nWhen you want to open the checkout form:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"func showPaymentForm() {\\n        let options = [\\n            \\\"amount\\\" : \\\"2000\\\" // and all other options\\n        ]\\n        razorpay.open(options)\\n    }\",\n      \"language\": \"swift\",\n      \"name\": \"ViewController.swift\"\n    }\n  ]\n}\n[/block]\nYou'll need to implement necessary success/failure actions too:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"func onPaymentSuccess(payment_id: String) {\\n        UIAlertView.init(title: \\\"Payment Successful\\\", message: payment_id, delegate: self, cancelButtonTitle: \\\"OK\\\").show()\\n    }\\n    \\n    func onPaymentError(code: Int32, description str: String) {\\n        UIAlertView.init(title: \\\"Error\\\", message: str, delegate: self, cancelButtonTitle: \\\"OK\\\").show()\\n    }\",\n      \"language\": \"swift\",\n      \"name\": \"ViewController.swift\"\n    }\n  ]\n}\n[/block]","slug":"ios-integration","title":"iOS Integration"}

iOS Integration


[block:callout] { "type": "warning", "body": "A new version of iOS SDK is available. You can click [here](https://razorpay.com/docs/ios/) to refer the documentation.", "title": "New Version Available" } [/block] [block:callout] { "type": "info", "title": "Integration method changed", "body": "We have changed the integration method with this release. We highly recommend you to use the latest SDK. Nevertheless if you wish to stick to the older version, you can find the documentation [here](https://docs.razorpay.com/v1/page/ios-sdk-0100)." } [/block] # v 0.14.1 ### Usage Instructions: ## Step 1: Import library to your project - Download from [here](http://downloads.razorpay.com/Razorpay.framework-0.14.1.zip) and unzip. (For `bitcode` enabled SDK, click [here](http://downloads.razorpay.com/Razorpay.framework-0.14.1-bitcode.zip)). We also have a [CocoaPod](https://cocoapods.org/pods/razorpay-pod) for our SDK (non `bitcode` enabled). - Open your project in XCode and select `Add files to "yourproject"` from `file` menu. - Select Razorpay.framework in the directory you just unzipped. - Make sure 'Copy items if needed' is checked. - Click 'Add'. - In the "Build Settings" tab of your project settings, `-ObjC` flag should be present under "Other Linker Flags". - Under "Link Binary With Libraries" in the "Build Settings" tab of your project settings, add `CoreTelephony.framework` and `SystemConfiguration.framework`. ## Step 2: Initialize Razorpay SDK You'll need your public key and delegate that implements *RazorpayPaymentCompletionProtocol* and view controller where you want to show the checkout form. [block:code] { "codes": [ { "code": "#import <Razorpay/Razorpay.h>\n\n@interface ViewController () <RazorpayPaymentCompletionProtocol> {\n Razorpay *razorpay;\n.. \n..\n \n// Any place before opening the checkout form (eg. viewDidLoad)\n- (void)viewDidLoad {\n [super viewDidLoad];\n ..\n ..\n razorpay = [Razorpay initWithKey:@\"YOUR_PUBLIC_KEY\" andDelegate:self];\n}", "language": "objectivec", "name": "ViewController.m" } ] } [/block] ## Step 3: Pass payment options and show checkout form Add following code to in your ViewController or where ever you want to initialize payments: [block:code] { "codes": [ { "code": "- (void)showPaymentForm { // called by your app\n NSDictionary *options = @{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@\"amount\": @\"1000\", // mandatory, in paise\n\t\t\t\t\t\t\t\t\t\t\t\t\t // all optional other than amount.\n \t\t\t\t\t\t\t\t\t\t@\"image\": @\"https://url-to-image.png\",\n \t\t\t\t\t\t\t\t\t\t\t\t\t@\"name\": @\"business or product name\",\n \t\t\t\t\t\t\t\t\t\t\t\t\t@\"description\": @\"purchase description\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@\"prefill\" : @{ \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@\"email\": @\"pranav@razorpay.com\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@\"contact\": @\"8879524924\"\n \t\t},\n \t\t\t\t\t\t\t\t\t\t\t\t\t@\"theme\": @{\n \t@\"color\": @\"#F37254\"\n }\n \t\t};\n\t\t[razorpay open:options];\n}", "language": "objectivec", "name": "ViewController.m" } ] } [/block] That's pretty much it. You can find the list of all supported options [here](https://docs.razorpay.com/docs/checkout-form#checkout-fields). [block:callout] { "type": "warning", "title": "Progress Bar", "body": "To support theme color in progress bar, please pass HEX color values only." } [/block] ## Step 4: Handle success/error when payment is done This is done by implementing `onPaymentSuccess` and `onPaymentError` methods of the *RazorpayPaymentCompletionProtocol*: [block:code] { "codes": [ { "code": "- (void)onPaymentSuccess:(nonnull NSString*)payment_id {\n \t[[[UIAlertView alloc] initWithTitle:@\"Payment Successful\" message:payment_id delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil] show];\n}\n\n- (void)onPaymentError:(int)code description:(nonnull NSString *)str {\n \t[[[UIAlertView alloc] initWithTitle:@\"Error\" message:str delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil] show];\n}", "language": "objectivec", "name": "ViewController.m" } ] } [/block] Here you have to put necessary actions after payment is completed based on success/error. Possible values for failure code are: * 0: Network error * 1: Initialization failure due to invalid options passed * 2: Payment cancelled by user Success handler will receive `payment_id` which you can use later for capturing purposes. You can call `open` method any number of times. (eg. in case of payment failure, customer might want to retry so you can call the open method with same / different options based on your use case) [block:api-header] { "type": "basic", "title": "iOS9 Update" } [/block] iOS 9 has higher requirements for secure URLs. Unfortunately, many of Indian banks do not comply, which leaves you with following workaround for time being: [block:code] { "codes": [ { "code": "<key>NSAppTransportSecurity</key>\n<dict>\n <key>NSAllowsArbitraryLoads</key>\n <true/>\n</dict>", "language": "xml", "name": "info.plist" } ] } [/block] Add it to your info.plist file. more info [here](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33) [block:api-header] { "type": "basic", "title": "Working with Swift" } [/block] You can easily use the SDK with swift using Objective-C Bridging Header. [Apple](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) has some nice documentation on subject. To begin, create a new file (File > New > File > iOS > Source > Header File) and name it `YourProjectName-Bridging-Header.h`. Open the file and insert following line to it: [block:code] { "codes": [ { "code": "#import <Razorpay/Razorpay.h>", "language": "objectivec", "name": "YourProjectName-Bridging-Header.h" } ] } [/block] Next, go to your project's build settings, and type "bridging" to filter options. Look for an option named `Objective-C Bridging Header` and set its value to path of your file. It may look something like this: [block:image] { "images": [ { "image": [ "https://files.readme.io/p7EuDSQXTGGEMUotYpEG_swiftexample-settings.png", "swiftexample-settings.png", "1756", "726", "#233e65", "" ], "caption": "(swiftexample is the name of your project)" } ] } [/block] Then in your ViewController, setup the SDK as follows: [block:code] { "codes": [ { "code": "class ViewController: UIViewController, RazorpayPaymentCompletionProtocol.. {\n\n private var razorpay : Razorpay!\n ..\n ..\n \n override func viewDidLoad() {\n super.viewDidLoad()\n ..\n ..\n razorpay = Razorpay.initWithKey(\"YOUR_PUBLIC_KEY\", andDelegate: self)\n }", "language": "swift", "name": "ViewController.swift" } ] } [/block] When you want to open the checkout form: [block:code] { "codes": [ { "code": "func showPaymentForm() {\n let options = [\n \"amount\" : \"2000\" // and all other options\n ]\n razorpay.open(options)\n }", "language": "swift", "name": "ViewController.swift" } ] } [/block] You'll need to implement necessary success/failure actions too: [block:code] { "codes": [ { "code": "func onPaymentSuccess(payment_id: String) {\n UIAlertView.init(title: \"Payment Successful\", message: payment_id, delegate: self, cancelButtonTitle: \"OK\").show()\n }\n \n func onPaymentError(code: Int32, description str: String) {\n UIAlertView.init(title: \"Error\", message: str, delegate: self, cancelButtonTitle: \"OK\").show()\n }", "language": "swift", "name": "ViewController.swift" } ] } [/block]