SlideShare a Scribd company logo
2
Most read
Razorpay Payment Gateway Integration In iOS Swift
Introduction
Razorpay is the fastest growing Payment Solution. Most of the developers prefer Razorpay as the
Payment solution in India. It is robust and provides developer friendly API & SDK for Android, iOS etc. It
provides different modes of payments like :- credit card, debit card, net banking, UPI and other popular
wallets. It provide the fast and reliable support.
In this blog we are going to focus on Razor Pay integration with iOS swift 4 using Xcode 10.1. in which
we will learn how can we integrate Razorpay with iOS app. We will create a demo app to integrate
Razorpay and pay some amount by using Razorpay payment gateway.
Prequisite
1.xcode 10.1
2.Swift 4
3.A Razorpay account (you can signup from here https://dashboard.Razorpay.com/#/access/signup)
4.your Razorpay key id (you can get from here https://dashboard.Razorpay.com/#/app/keys)
Let’s start the development :-
Step 1: Install pod for Razorpay
•Add pod ‘Razorpay-pod’ in the pod file.
•Run ‘pod install’ from terminal.
•Now open the xcworkspace
Step 2: Develop a basic UI as given below.
Step 3: Import Razorpay to your view Controller.
import Razorpay
step 4 :
1.Create action outlet of pay now button in your view controller.
1
2
@IBAction func payNowClicked(_ sender: Any) {
}
2. Create instance reference variable of type Razorpay.
1 private var razorpay:Razorpay?
3. Initialise that reference variable in viewDidLoad method of view controller by calling init method with
public key and delegate.
1
2
3
4
override func viewDidLoad() {
super.viewDidLoad()
razorpay =
Razorpay.initWithKey("rzp_test
_FYCQAsmKTFF8FR",
andDelegate: self)
}
4. Create extension of view controller and confirm RazorpayPaymentCompletionProtocol as given
below :-
a) onPaymentSuccess(_ payment_id: String)
b) onPaymentError(_ code: Int32, description str: String)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
extension ViewController: RazorpayPaymentCompletionProtocol {
func onPaymentSuccess(_ payment_id: String) {
let alert = UIAlertController(title: "Paid", message:
"Payment Success", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel,
handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
func onPaymentError(_ code: Int32, description str: String)
{
let alert = UIAlertController(title: "Error", message: "
(code)n(str)", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel,
handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
}
As you can see in above code we have two methods onPaymentSuccess and onPaymentError the
success method will be called if payment transaction is completed successfully where the
onPaymentError will be called if the transaction is not completed successfully. it provides some error
codes as given below :-
Possible values for a failure code are:
•0: Network error
•1: Initialization failure / Unexpected behavior
•2: Payment cancelled by user
Now inside action outlet of pay button create parameter for razor pay like.
1
2
3
4
5
6
7
8
9
10
11
12
13
let options: [String:Any] = [
"amount" : "100"
//mandatory in paise like:-
1000 paise == 10 rs
"description":
"purchase description"
"image": "https://url-
to-image.png",
"name": "business or
product name"
"prefill": [
"contact":
"9797979797",
"email":
"foo@bar.com"
],
"theme": [
"color": "#F37254"
]
]
Progress Bar:
To support theme color in the progress bar, pass HEX color values only.
after setting all parameters call the open method of Razorpay
1 razorpay?.open(options)
Complete Demo Project you can download here :- https://github.com/swiftserieschannel/RazorPayTest

More Related Content

PDF
Razorpay
PDF
Razorpay payment gateway integration in laravel and vue js 2
PPT
Razorpay
ODP
Joomla virtuemart razorpay payment gateway
DOCX
Paypal Integration For Android Application By LetsNurture
PDF
Payment api basics
PPTX
Accepting Online Payment for Your Library and ‘Stripe’ as an Example
PPTX
Build and graduate your app in ring central
Razorpay
Razorpay payment gateway integration in laravel and vue js 2
Razorpay
Joomla virtuemart razorpay payment gateway
Paypal Integration For Android Application By LetsNurture
Payment api basics
Accepting Online Payment for Your Library and ‘Stripe’ as an Example
Build and graduate your app in ring central

What's hot (20)

PDF
Abandoned carts
PPTX
Is authorization always needed for sms messages in ringcentral-api
PPTX
Payeezy Integration
PPTX
PPTX
SelfConnection
PPTX
Adaptive payments-talk
PDF
WAC Network APIs @ OverTheAir 2011
PPTX
Mule esb stripe
PDF
Droidcon Paris: The new Android SDK
PDF
Securing Single-Page Applications with OAuth 2.0
PPTX
Rest security in mule
PDF
Introducing safexpay smart NBFC solution
PPTX
Setting up organization with api access
PDF
Deep Dive into OAuth for Connected Apps
PDF
Droidcon DE 2013
PPTX
Password Replacement Technology : Removing Limitations of Current Passwords
PPTX
PPTX
Securing Insecure
PPTX
Applying OAuth on RingCentral API (part 3)
PDF
Recharge api by_saurabh_sharma
Abandoned carts
Is authorization always needed for sms messages in ringcentral-api
Payeezy Integration
SelfConnection
Adaptive payments-talk
WAC Network APIs @ OverTheAir 2011
Mule esb stripe
Droidcon Paris: The new Android SDK
Securing Single-Page Applications with OAuth 2.0
Rest security in mule
Introducing safexpay smart NBFC solution
Setting up organization with api access
Deep Dive into OAuth for Connected Apps
Droidcon DE 2013
Password Replacement Technology : Removing Limitations of Current Passwords
Securing Insecure
Applying OAuth on RingCentral API (part 3)
Recharge api by_saurabh_sharma
Ad

Similar to Razorpay Payment Gateway Integration In iOS Swift (20)

PDF
Learn how to use API with 2 API examples.pdf
PDF
java and javascript api dev guide
PDF
Advanced iOS Debbuging (Reloaded)
PDF
End to end todo list app with NestJs - Angular - Redux & Redux Saga
PDF
Let'Swift 2024 - Plugin 패턴을 이용하여 기능 확장하기
PPTX
Chaincode Use Cases
PDF
Integrating WordPress With Web APIs
PDF
Building Mobile Friendly APIs in Rails
PPTX
Telerik AppBuilder Presentation for TelerikNEXT Conference
PDF
android level 3
PDF
Paytm integration in swift
PDF
How to build twitter bot using golang from scratch
PPT
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
PPTX
Introduction to aop
PDF
Micro services from scratch - Part 1
PDF
How to integrate paytm payment gateway using react js in seven easy steps
PDF
Demystifying Apple 'Pie' & TouchID
PDF
Mobile Open Day: React Native: Crossplatform fast dive
PPTX
Reactive application using meteor
PPTX
Building a dashboard using AngularJS
Learn how to use API with 2 API examples.pdf
java and javascript api dev guide
Advanced iOS Debbuging (Reloaded)
End to end todo list app with NestJs - Angular - Redux & Redux Saga
Let'Swift 2024 - Plugin 패턴을 이용하여 기능 확장하기
Chaincode Use Cases
Integrating WordPress With Web APIs
Building Mobile Friendly APIs in Rails
Telerik AppBuilder Presentation for TelerikNEXT Conference
android level 3
Paytm integration in swift
How to build twitter bot using golang from scratch
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
Introduction to aop
Micro services from scratch - Part 1
How to integrate paytm payment gateway using react js in seven easy steps
Demystifying Apple 'Pie' & TouchID
Mobile Open Day: React Native: Crossplatform fast dive
Reactive application using meteor
Building a dashboard using AngularJS
Ad

More from InnovationM (20)

PDF
How to use data binding in android
PDF
Capture image on eye blink
PDF
Mob x in react
PDF
How to use geolocation in react native apps
PDF
Android 8 behavior changes
PDF
Understanding of react fiber architecture
PDF
Automatic reference counting (arc) and memory management in swift
PDF
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
PDF
How prototype works in java script?
PDF
React – Let’s “Hook” up
PDF
Line Messaging API Integration with Spring-Boot
PDF
Basic fundamental of ReactJS
PDF
Basic Fundamental of Redux
PDF
Integration of Highcharts with React ( JavaScript library )
PDF
Serialization & De-serialization in Java
PDF
Concept of Stream API Java 1.8
PDF
How to Make Each Round of Testing Count?
PDF
Model View Presenter For Android
PDF
Retrofit Library In Android
PDF
Eventbus Library and How Does it Work?
How to use data binding in android
Capture image on eye blink
Mob x in react
How to use geolocation in react native apps
Android 8 behavior changes
Understanding of react fiber architecture
Automatic reference counting (arc) and memory management in swift
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
How prototype works in java script?
React – Let’s “Hook” up
Line Messaging API Integration with Spring-Boot
Basic fundamental of ReactJS
Basic Fundamental of Redux
Integration of Highcharts with React ( JavaScript library )
Serialization & De-serialization in Java
Concept of Stream API Java 1.8
How to Make Each Round of Testing Count?
Model View Presenter For Android
Retrofit Library In Android
Eventbus Library and How Does it Work?

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25-Week II
sap open course for s4hana steps from ECC to s4
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A comparative analysis of optical character recognition models for extracting...
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence

Razorpay Payment Gateway Integration In iOS Swift

  • 1. Razorpay Payment Gateway Integration In iOS Swift Introduction Razorpay is the fastest growing Payment Solution. Most of the developers prefer Razorpay as the Payment solution in India. It is robust and provides developer friendly API & SDK for Android, iOS etc. It provides different modes of payments like :- credit card, debit card, net banking, UPI and other popular wallets. It provide the fast and reliable support. In this blog we are going to focus on Razor Pay integration with iOS swift 4 using Xcode 10.1. in which we will learn how can we integrate Razorpay with iOS app. We will create a demo app to integrate Razorpay and pay some amount by using Razorpay payment gateway. Prequisite 1.xcode 10.1 2.Swift 4 3.A Razorpay account (you can signup from here https://dashboard.Razorpay.com/#/access/signup) 4.your Razorpay key id (you can get from here https://dashboard.Razorpay.com/#/app/keys) Let’s start the development :- Step 1: Install pod for Razorpay •Add pod ‘Razorpay-pod’ in the pod file. •Run ‘pod install’ from terminal. •Now open the xcworkspace
  • 2. Step 2: Develop a basic UI as given below. Step 3: Import Razorpay to your view Controller. import Razorpay step 4 : 1.Create action outlet of pay now button in your view controller. 1 2 @IBAction func payNowClicked(_ sender: Any) { } 2. Create instance reference variable of type Razorpay. 1 private var razorpay:Razorpay? 3. Initialise that reference variable in viewDidLoad method of view controller by calling init method with public key and delegate. 1 2 3 4 override func viewDidLoad() { super.viewDidLoad() razorpay = Razorpay.initWithKey("rzp_test _FYCQAsmKTFF8FR", andDelegate: self) } 4. Create extension of view controller and confirm RazorpayPaymentCompletionProtocol as given below :- a) onPaymentSuccess(_ payment_id: String) b) onPaymentError(_ code: Int32, description str: String)
  • 3. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 extension ViewController: RazorpayPaymentCompletionProtocol { func onPaymentSuccess(_ payment_id: String) { let alert = UIAlertController(title: "Paid", message: "Payment Success", preferredStyle: .alert) let action = UIAlertAction(title: "OK", style: .cancel, handler: nil) alert.addAction(action) self.present(alert, animated: true, completion: nil) } func onPaymentError(_ code: Int32, description str: String) { let alert = UIAlertController(title: "Error", message: " (code)n(str)", preferredStyle: .alert) let action = UIAlertAction(title: "OK", style: .cancel, handler: nil) alert.addAction(action) self.present(alert, animated: true, completion: nil) } } As you can see in above code we have two methods onPaymentSuccess and onPaymentError the success method will be called if payment transaction is completed successfully where the onPaymentError will be called if the transaction is not completed successfully. it provides some error codes as given below :- Possible values for a failure code are: •0: Network error •1: Initialization failure / Unexpected behavior •2: Payment cancelled by user Now inside action outlet of pay button create parameter for razor pay like.
  • 4. 1 2 3 4 5 6 7 8 9 10 11 12 13 let options: [String:Any] = [ "amount" : "100" //mandatory in paise like:- 1000 paise == 10 rs "description": "purchase description" "image": "https://url- to-image.png", "name": "business or product name" "prefill": [ "contact": "9797979797", "email": "foo@bar.com" ], "theme": [ "color": "#F37254" ] ] Progress Bar: To support theme color in the progress bar, pass HEX color values only. after setting all parameters call the open method of Razorpay 1 razorpay?.open(options) Complete Demo Project you can download here :- https://github.com/swiftserieschannel/RazorPayTest