Integrate Turbo UPI UI
Steps to integrate Razorpay Turbo UPI with your app.
Use Razorpay Turbo UPI to make UPI payments faster. Follow these steps to integrate with the Razorpay Turbo UPI UI SDK.
-
Contact our
to get your mobile number, app, and GitHub account whitelisted to get access to thehttps://github.com/upi-turbo/ios-sample-app- sample app repository. In this repository, you will find the framework files (libraries for Turbo) and the sample app source code to help you with the integration. Use branchcustom_ui/turbo_uito access sample app and frameworks for Turbo UPI with UI.
-
Integrate with the
. -
Add the following lines to your Podfile for Turbo pod installation:
pod 'razorpay-customui-pod'pod 'razorpay-turbo-custom/ui' -
Import the Turbo plugin as given below:
import Razorpayimport TurboUpiPluginUI
Watch Out!
- The minimum supported iOS version for using Turbo UPI is currently 12.0.
- Use the
rzp_test_0wFRWIZnH65unyAPI key id for testing on the UAT environment and the for prod testing.
Follow these steps:
Initialise the SDK and set up the Checkout instance (Razorpay) to handle payment outcomes like success and errors by listening to delegate methods.
var razorpay = RazorpayCheckout.initWithKey("YOUR_KEY_ID",andDelegate: self,withPaymentWebView: wkWebView,UIPlugin: RazorpayTurboUPI.UIPluginInstance)
To enhance security, you must create a session token via a server-to-server (S2S) call between your backend and Razorpay's backend. This session token ensures secure communication between the Turbo SDK and Razorpay's systems.
- Trigger the S2S API from your Backend. Use the following API to generate a session token:
Environment based URLs:
-
UAT:
https://api-web-turbo-upi.ext.dev.razorpay.in -
Production:
https://api.razorpay.com
Authorization Header Creation: Base64.encode(${public_key}:${secret})
customer_reference
mandatory
string A unique identifier for the customer provided by the business. The recommended value is mobile number. For example, 9000090000.
token
string A session token to be used in subsequent session-protected APIs.
expire_at
long Expiry time (in seconds) for the session token, used to optimise session handling and reduce unnecessary reinitialisations.
error
object The request failure due to business or technical failure.
- Pass the Generated Token to Turbo SDK. Use the session token in the , ensuring that it is refreshed upon expiry.
After generating the session token, initialise the Turbo SDK with the session delegate.
Use the initialize(...) method to configure the session.
razorpay?.upiTurboUI?.initialize(sessionDelegate: Any)
Using Delegate Pattern
To ensure a smooth experience during token expiry, the Turbo SDK provides the TurboSessionDelegate interface with a fetchToken method. This method dynamically fetches and updates the session token without reinitialising the session.
Initialise the TurboSessionDelegate object anonymously and pass it through the initialize method. The SDK will call fetchToken as needed and use the provided callback to handle the updated token. This allows you to seamlessly refresh the session by retrieving a new token via a server-to-server (S2S) call.
Below is an example of creating an instance of the TurboSessionDelegate interface using an anonymous object expression:
extension ViewController: TurboSessionDelegate {func fetchToken(completion: @escaping (Session) -> Void) {// fetch token here and once fetched,// it can be passed back to Turbo SDK using completion delegatecompletion(Session(token: <new-token>)}}
After initialising the Turbo SDK, proceed to securely link UPI accounts and complete the payment flow
-
You need to link the customer's UPI account with your app. Use the below code samples to fetch the UPI account.
Watch Out!
If the device binding is not completed and
getLinkedUpiAccountsis triggered, it will return anOnErrorwith aDEVICE_BINDING_INCOMPLETEerror message.- Get the customer's linked UpiAccount list using the below code. This function can be called from anywhere in the application, providing multiple entry points for customers to link their UPI account with your app.
razorpay?.upiTurboUI?.getLinkedUpiAccounts("9000090000", resultDelegate: self)-
If your customer has already linked the UPI account, use the following code to fetch it. If there are no linked UPI accounts, an empty list is returned.
extension ViewController: UPITurboResultDelegate {func onSuccessFetchingLinkedAcc(_ accList: [UpiAccount]) {if accList.count > 0 {print("Success Fetching Accounts")} else {// call linkNewUpiAccount()}}func onErrorFetchingLinkedAcc(_ error: TurboUpiPlugin.TurboError?) {print("Error: \(error?.errorDescription)")print("Error code: \(error?.errorCode)")}}
-
If the customer has not linked any UPI account, they can link UPI accounts using the following method:
- Link one UPI account at a time:
Use the following code to link the newly created UPI account with your app. This function can be called from anywhere in the application, providing multiple entry points for customers to link their UPI account with your app.
self.razorpay?.upiTurboUI?.linkNewUpiAccount(mobileNumber: "MOBILE_NUMBER",color: "<accent-color>",completionHandler: { upiAccounts, error inprint(upiAccounts)}) - Link one UPI account at a time:
-
The Reward feature allows you to allocate rewards to users without specific criteria. To avail rewards, you need to configure them from the Dashboard. You can seamlessly integrate this function into your application, providing multiple entry points for users to check their rewards eligibility before completing a payment.
razorpay.upiTurboUI?.getRewardForCustomer(mobileNumber: "9000090000",action: RewardAction.payment,amount: "10000",rewardsDelegate: self)extension ViewController: UpiTurboCustomerRewardsDelegate {func onSuccess(_ reward: CustomerReward) {// Handle success}func onFailure(_ error: TurboError?) {// Handle failure}}mobileNumber
mandatory
stringThe customer's mobile number.action
mandatory
RewardActionThis parameter specifies the action to check reward eligibility. Possible values:onboarding: To check reward eligibility for Onboarding.payment: To check reward eligibility for Payment.
amount
optional
stringThe transaction amount expressed in the currency subunits.rewardsDelegate
mandatory
delegateThis parameter allows you to receive callbacks regarding reward eligibility. -
To process the payments, call the
authorizemethod of custom checkout with the provided payload. Upon receiving thePaymentDataresponse, you will also receiverewardStatusalong with the payment response. Please note that therewardStatuskey will be present in the response only if your eligible for a reward.let turboPayload: [AnyHashable: Any] = ["currency": "INR","amount": "700","email": "EMAIL_ID","contact": "9000090000","method": "upi","upi": ["flow": "in_app"],"order_id": "YOUR_ORDER_ID",]turboPayload["upiAccount"] = upiAccountrazorpay?.authorize(turboPayload)extension ViewController: RazorpayPaymentCompletionProtocol {func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable: Any]) {let rewardStatus = response["rewardStatus"]// Show payment success screen with reward if rewarded}func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable: Any]){// Handle payment error}}customer_id
optional
stringUnique identifier of the customer to whom the Customer Identifier must be tagged. Create a customer using theamount
mandatory
integerThe transaction amount expressed in the currency subunit. For example, for an actual amount of ₹299.35, the value of this field should be29935.currency
mandatory
stringThe currency in which the transaction should be made.email
mandatory
stringEmail address of the customer.contact
mandatory
stringCustomer's phone number.order_id
mandatory
.stringOrder id generated via themethod
mandatory
stringThe payment method used by the customer on Checkout. In this case, it isupi(default).upi
mandatory
Details of the UPI payment.
flow
mandatory
stringType of the UPI method. In this case, it isin_app.
You can directly interact with the exposed methods of the Turbo Framework to perform the non-transactional flows listed below.
To determine the device binding status, use the RZPTurboUPI.isDeviceOnboarded() variable, which returns a boolean value. This indicates whether device binding—a prerequisite for adding UPI accounts—has been successfully completed for the user's mobile number.
if RZPTurboUPI.isDeviceOnboarded() {// User device onboarded} else {// Call Link New Account for Device Binding}
The SDKs given below provide access to exposed models for seamless integration.
We recommend the following:
- Complete the integration on UAT before using the prod builds.
- Perform the UAT using the Razorpay-provided API keys.
Complete these steps to take your integration live:
-
You should get your app id whitelisted by Razorpay to test on prod.
Handy Tips
Contact our
to get your mobile number and app whitelisted. -
Import the prod library from the GitHub repository →
https://github.com/upi-turbo/ios-sample-appcustom_ui/turbo_ui branch. -
Switch to Prod environment and podfile.
-
Replace the UAT credential with the
for prod testing.
For iOS users, outgoing device binding SMS is editable by default. To ensure these SMS messages are non-editable, you must complete the following steps:
- Log in to the .
- Fill out the necessary details to request permission for the
setUPIVerificationCodeSendCompletionAPI, which allows secure, non-editable content for device registration SMS. - Await approval from Apple.
Once Apple approves the entitlement, share the request details with NPCI for their approval. Use the format given below for submitting the details:
- Name of the App:
- Functionality (UPI or CBDC App): UPI
- App ID:
- Team ID:
- Request ID:
- Bundle ID:
Is this integration guide useful?
ON THIS PAGE