Checkout - iOS SDK

The iOS SDK library lets you seamlessly integrate the entire payment ecosystem in your iOS application and start accepting payments with Razorpay.

Note: We have moved our SDKs to Swift framework. This framework only supports iOS version 8.0 and later. Public contracts have not been changed. We have ensured that you would not have to change anything in your code when you will move from Objective-C library to our new Swift framework. If you wish to use the older version, you can find the documentation here.

Following are the two versions of our framework:

  • Razorpay | 1.0.17
  • Razorpay | 1.0.18

SDK

Framework Version

Framework Compiled With

Download Link

Razorpay(with bit code enabled)

1.0.18

Swift 4.1

Click here.

Razorpay(with bit code enabled)

1.0.17

Swift 3.1

Click here.

Step 1: Importing the Library#

For cocoapod users , our cocoapod page is CocoaPod (bitcode enabled).

Follow the instruction given below to import the SDK library to your Swift or Objective-C project:

For Swift:#

  1. Download the SDK from above and unzip it.
  2. Open your project in XCode and go to file under Menu. Select Add files to "yourproject".
  3. Select Razorpay.framework in the directory you just unzipped.
  4. Select the Copy items if needed check-box.
  5. Click Add.
  6. Navigate to Target settings > General and add the Razorpay.framework in both Embeded Binaries and Linked Frameworks and Libraries.

For Objective-C:#

  1. Download the SDK from above and unzip it.
  2. Open your project in XCode and go to file under Menu. Select Add files to "yourproject".
  3. Select Razorpay.framework in the directory you just unzipped.
  4. Select the Copy items if needed check-box.
  5. Click Add.
  6. Navigate to Target settings > General and add the Razorpay.framework in both Embeded Binaries and Linked Frameworks and Libraries.
  7. Go to Project Settings.
  8. Select Build Settings - All and Combined from the Menu of the project settings.
  9. Under Build Options set Always Embed Swift Standard Libraries option to TRUE.

For both iOS and Objective C projects - Make sure the framework is added in both the Embeded Binaries and Linked Frameworks and Libraries under Target settings - General.

Step 2: Initialize the Razorpay SDK#

To initialize the Razorpay SDK, you will need the following:

  • API key.
  • A delegate that implements RazorpayPaymentCompletionProtocol or RazorpayPaymentCompletionProtocolWithData.
import Razorpay class ViewController: UIViewController, RazorpayPaymentCompletionProtocol { var razorpay: Razorpay! . . override func viewDidLoad() { super.viewDidLoad() . . razorpay = Razorpay.initWithKey(razorpayTestKey, andDelegate: self) } . . }
#import <Razorpay/Razorpay.h> @interface ViewController () <RazorpayPaymentCompletionProtocol> { Razorpay *razorpay; . . - (void)viewDidLoad { [super viewDidLoad]; . . razorpay = [Razorpay initWithKey:@"YOUR_PUBLIC_KEY" andDelegate:self]; } }

Step 3: Pass Payment Options and Display Checkout Form#

Add the following code to your ViewController or where ever you want to initialize payments:

internal func showPaymentForm(){ let options: [String:Any] = [ "amount" : "100" //mandatory in paise "description": "purchase description" "image": "https://url-to-image.png", "name": "business or product name" "prefill": [ "contact": "9797979797", "email": "foo@bar.com" ], "theme": [ "color": "#F37254" ] ] razorpay.open(options) }
- (void)showPaymentForm { // called by your app NSDictionary *options = @{ @"amount": @"1000", // mandatory, in paise // all optional other than amount. @"image": @"https://url-to-image.png", @"name": @"business or product name", @"description": @"purchase description", @"prefill" : @{ @"email": @"foo@bar.com", @"contact": @"9797979797" }, @"theme": @{ @"color": @"#F37254" } }; [razorpay open:options]; }

You can find the list of all supported options here.

Progress Bar: To support theme color in progress bar, please pass HEX color values only.

Step 4: Handle Success and Errors#

You can handle success/errors when payment is completed by implementing onPaymentSuccess and onPaymentError methods of the RazorpayPaymentCompletionProtocol. Alternatively, you can also implement onPaymentSuccess and onPaymentError methods of RazorpayPaymentCompletionProtocolWithData.

public func onPaymentError(_ code: Int32, description str: String){ let alertController = UIAlertController(title: "FAILURE", message: str, preferredStyle: UIAlertControllerStyle.alert) let cancelAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil) alertController.addAction(cancelAction) self.view.window?.rootViewController?.present(alertController, animated: true, completion: nil) } public func onPaymentSuccess(_ payment_id: String){ let alertController = UIAlertController(title: "SUCCESS", message: "Payment Id \(payment_id)", preferredStyle: UIAlertControllerStyle.alert) let cancelAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil) alertController.addAction(cancelAction) self.view.window?.rootViewController?.present(alertController, animated: true, completion: nil) }
- (void)onPaymentSuccess:(nonnull NSString*)payment_id { [[[UIAlertView alloc] initWithTitle:@"Payment Successful" message:payment_id delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } - (void)onPaymentError:(int)code description:(nonnull NSString *)str { [[[UIAlertView alloc] initWithTitle:@"Error" message:str delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; }

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 / Unexpected behaviour
  • 2: Payment cancelled by user

Success handler will receive payment_id which you can use later for capturing purposes.

iOS 9 Update#

The iOS 9 has higher requirements for secure URLs. As many Indian banks do not comply with the requirements, you can implement the following as a workaround:

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

Add the above to your info.plist file. For more information click here.