Integration of Razorpay Payment Gateway using Swift
Posted By : Lucky Mehndiratta | 21-Jan-2021
Integration of Razorpay Payment Gateway using Swift
As technology evolves it changes the lifestyle of the people in the world & the way of doing business in the market. To communicate, we use a different way to connect and to buy we need to go to the market/shop and buy the product. But now a day's this way of communication & business complete change. For business, sellers use the e-commerce platform to sell their products and give the best way to a buyer for their purchasing and capture the money from a buyer in one click.
For this, we need some way to get the money from the buyer. Payment Gateways is the best option for this. There are lots of payment gateway available in the market and we can use them based on the requirement. RazorPay is also the best option to integrate and provides a different way to capture the money from a buyer like as cards, UPI e.t.c.
Also Read: Apple Sign In with Swift
Let's Get Started
To integrate Razorpay in iOS we need to follow the following steps
1. Create the Razorpay Account
for testing purpose, we need to just sign up and get the testing Razorpay testing key
for production, we need to first do all the requirements mentioned in the Razorpay and get confirm/activate Razorpay Account.
2. Add the Pod in the podfile
pod 'razorpay-pod'
3. Start Coding
import the Razorpay where you want to initiate the payment process
import Razorpay
define Razorpay key
let razorKey = "your razorpay key" // get from the razorpay account
define function & add a delegate to your viewController
func openCheckout() {
let razorObj = RazorpayCheckout.initWithKey(razorKey, andDelegate: self)
let options: [AnyHashable:Any] = [
"prefill": [
"contact": "XYZ", // add contact number get from the user
"email": "[email protected]" // add email id
// "method":"wallet",
// "wallet":"amazonpay"
],
"image": "Server Image URL",
"amount" : XXX, // add amount
"timeout":XX, // add time out of the payment
"theme": [
"color": "#000000" // color theme
]
]
if let rp = self.razorObj {
rp.open(options)
} else {
// handle error
}
}
extension YourviewController : RazorpayPaymentCompletionProtocol {
func onPaymentError(_ code: Int32, description str: String) {
print(code, str)
}
func onPaymentSuccess(_ payment_id: String) {
print( payment_id)
}
}
Now you need to just call the function where you want and see the magic.
Also Read: Implement Apple Pay in iOS
Official Links
1. https://razorpay.com
2. https://razorpay.com/docs/payment-gateway/ios-integration/standard/
3. https://github.com/razorpay/razorpay-ios-sample-app
Thank you!
Choose Oodles For iOS App Development Using Swift
We are a full-scale Mobile App development company that specializes in building scalable web and mobile applications for multiple platforms. Our development team uses advanced frameworks, tools, SDKs and agile methodologies to develop feature-rich business applications with custom features. Our end-to-end mobile application development services render support for both Android and iOS platforms. We have successfully completed several full-fledged Android and iOS application development projects for startups, SMEs, and large-scale enterprises. For project-related queries, drop us a line at [email protected].
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Lucky Mehndiratta
He worked on swift language, UI Design, Api. He is quick in his work and performs at his best.