Prerequisites
-
Contact our integrations team to get your mobile number, app, and GitHub account whitelisted to get access to the
https://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 Razorpay iOS Custom SDK.
-
Add the following lines to your Podfile for Turbo pod installation:
-
Import the Turbo plugin as given below:
1. Integration Steps
Follow these steps:1.1 Initialise the Razorpay Checkout
Initialise the SDK and set up the Checkout instance (Razorpay) to handle payment outcomes like success and errors by listening to delegate methods.Swift
1.2 Create a Session Token
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.How to Create a Session Token
- Trigger the S2S API from your Backend. Use the following API to generate a session token:
-
UAT:
https://api-web-turbo-upi.ext.dev.razorpay.in -
Production:
https://api.razorpay.com
Base64.encode(${public_key}:${secret})
Curl
Request Parameters
customer_reference mandatory
: string A unique identifier for the customer provided by the business. The recommended value is mobile number. For example, 9000090000.
Response Parameters
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 initialisation step, ensuring that it is refreshed upon expiry.
1.3 Initialise Turbo SDK
After generating the session token, initialise the Turbo SDK with the session delegate. Use the initialize(…) method to configure the session.Swift
Create/Retry Session Token Mechanism
Using Delegate Pattern To ensure a smooth experience during token expiry, the Turbo SDK provides theTurboSessionDelegate 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:
Kotlin
1.4 Handle UPI Account Linking and Payment Flow
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.
Request Parameters
mobile_num
: string The customer’s mobile number.
Delegate
: object The Delegate to be sent is of type UpiTurboResultDelegate.
-
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.
Swift
-
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:
Swift
Request Parameters
mobile_num mandatory
: string Customer’s mobile number needed to initialise the SDKs.
color
: string Colour in HEX format.
-
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.
Swift
Request Parameters
mobileNumber mandatory
: string The customer’s mobile number.
action mandatory
: RewardAction This 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
: string The transaction amount expressed in the currency subunits.
rewardsDelegate mandatory
: delegate This 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.Swift
Request Parameters
customer_id optional
: string Unique identifier of the customer to whom the Customer Identifier must be tagged. Create a customer using the Customer API
amount mandatory
: integer The transaction amount expressed in the currency subunit. For example, for an actual amount of ₹299.35, the value of this field should be 29935.
currency mandatory
: string The currency in which the transaction should be made.
email mandatory
: string Email address of the customer.
contact mandatory
: string Customer’s phone number.
order_id mandatory
: string Order id generated via the Orders API.
method mandatory
: string The payment method used by the customer on Checkout. In this case, it is upi (default).
upi mandatory
: Details of the UPI payment.
flow mandatory
: string Type of the UPI method. In this case, it is in_app.
Non-Transactional Flow
You can directly interact with the exposed methods of the Turbo Framework to perform the non-transactional flows listed below.Manage UPI Accounts
Let Razorpay SDK manage the linked UpiAccounts on the applications by triggeringmanageUpiAccounts().
Swift
Additional Features
Device Binding Status
To determine the device binding status, use theRZPTurboUPI.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.
Swift
Clear SDK
To clear all SDK data, useRZPTurboUPI.clearSDKState(). This will remove all stored SDK values and allow you to start fresh.
Swift
Models Exposed from the SDKs
The SDKs given below provide access to exposed models for seamless integration.UpiAccount
Method | Return Type | Description
accountNumber | String | Returns masked bank account number.
type | String | The account type. Possible values are bank_account or credit_card.
ifsc | String | Returns IFSC for Bank.
bankName | String | Returns the name of the bank.
bankLogoUrl | String | Returns the URL to the logo of the PNG image.
bankPlaceholderUrl | String | Image URL for bank logo placeholder.
pinLength | Integer | Length on UPI PIN.
UpiBankAccount
Method | Return Type | Description
accountNumber | String | Account number.
beneficiaryName | String | Name of account holder.
bank | UpiBank | The bank Object.
type | String | The account type. Possible values are savings, current and credit.
UpiBank
Properties | Type | Description
ifsc | String | IFSC of the bank.
logo | String | Bank logo URL.
name | String | Name of the bank.
bankPlaceholderUrl | String | Image URL for bank logo placeholder.
TurboError
Error | Description
errorCode | Types of error codes - BAD_REQUEST_ERROR: Failure from the client’s end (SDK).
-
GATEWAY_ERROR: Failure either from the Secure Component or the Bank. -
SERVER_ERROR: Failure at PSP.
errorDescription| Brief description of the error.errorReason| Specifies the specific reason for the error.errorSource| Indicates the origin of the error. Possible values: -gateway -
issuer_bank -
beneficiary_bank -
customer_psp -
customer -
internal
errorStep| Highlights the stage where the error occurred. Refer to the list of possible error reasons.
CustomerReward
Method | Return Type | Description
eligible | Boolean | Eligible status of the reward.
rewards | Array | List of rewards from multiple rewards partners.
Reward
Method | Return Type | Description
rewardPartnerName | String | Partner name from whom the reward is assigned.
rewardPartnerLogoUrl | String | Partner logo URL.
preAllotText | String | Customer action before allotting the reward.
postAllotText | String | Customer action after allotting the reward.
couponCode | String | Coupon code for allotting the reward.
termsAndConditions | Array | Terms and conditions for allotting the reward.
PaymentData
Method | Return Type | Description
rewardStatus | Boolean | Reward allotment status.
RewardAction
Method | Return Type | Description
Onboarding | RewardAction | Action associated with the onboarding process.
Payment | RewardAction | Action associated with the payment process.
2. Test Integration
We recommend the following:- Complete the integration on UAT before using the prod builds.
- Perform the UAT using the Razorpay-provided API keys.
3. Go-live Checklist
Complete these steps to take your integration live:- You should get your app id whitelisted by Razorpay to test on prod.
Handy Tips
-
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 Razorpay live keys for prod testing.
Requesting UPI Device Validation Entitlement
1. Submit a Request on the Apple Developer Portal
- Log in to the Apple Developer Portal.
- 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.
2. Submit Details to NPCI
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:
3. Follow the Guidelines for Implementation
- Ensure your app supports iOS 17 and above.
- Use the
setUPIVerificationCodeSendCompletionAPI to comply with NPCI requirements.