Integrate with Turbo UPI

Steps to integrate Razorpay Turbo UPI with your app.


Razorpay Turbo UPI enables businesses to offer faster and simpler payments by reducing the payment process from 5 steps to just 1, eliminating app redirections. This provides a seamless in-app payment experience, reduce dependencies on third-party UPI apps, and offers complete visibility into the payment journey.

You can easily integrate Turbo UPI with the Razorpay Flutter Standard SDK. Explore the full potential of

and learn how it works.

Turbo UPI Standard Checkout Flow

Prerequisites

  1. Contact our

    to get your mobile number, app, and GitHub account whitelisted for access to the https://github.com/upi-turbo/razorpay-turbo-flutter sample app repository.

  2. Review the

    documentation for integration guidelines.

  3. Add Location Dependency: The SDK requires location permission to complete device onboarding. Ensure you have added the necessary location dependencies as described below.

    • For iOS:
      Update your Info.plist file with the following keys to request location permissions:

      <key>NSLocationWhenInUseUsageDescription</key>
      <string>
      Your app needs access to your location while using the app.</string>

      Make sure these permissions are clearly communicated to your users to ensure a smooth onboarding experience.

  4. For Android-specific integrations, add the following dependencies to your build.gradle file:

Retrofit (for networking):

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

Glide (for image loading):

implementation 'com.github.bumptech.glide:glide:4.15.1'

Google Play Services (for authentication and location):

implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1'
implementation 'com.google.android.gms:play-services-location:21.0.0'

Kotlin Coroutines (for asynchronous operations):

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.3'

Enable viewBinding and dataBinding:

buildFeatures {
viewBinding = true
dataBinding = true
}

Ensure you sync your project after adding these dependencies.

Library Dependencies

To integrate Turbo UPI, you must add the required library dependencies to your Flutter project:

  1. Add the following entry to the dependencies section of your pubspec.yaml file:

    razorpay_turbo_standard: 1.0.0
  2. Run the following command in your terminal to fetch and install the new dependency:

    flutter pub get

Ensure your customers

to get started.

Follow these steps to integrate with Razorpay Turbo UPI:

To integrate Turbo UPI with your Flutter app, start by importing the required packages.

This sets up the SDK and enables your app to handle UPI payments. Use the code snippet below to import the package:

import 'package:razorpay_flutter/razorpay_flutter.dart';

Set up the Razorpay instance and register event listeners to handle payment success, failure, and session token refresh.

This ensures your app can respond appropriately to payment outcomes and keep session tokens up to date for a smooth user experience.

Add the following method during initialisation:

void initializeRazorpayWithEvents() {
// Create a Razorpay instance
razorpay = Razorpay("YOUR_KEY_ID");
//Session token event
razorpay.on(Razorpay.EVENT_FETCH_SESSION_TOKEN, _handleRefreshToken);
//Payment Events
razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, handlePaymentErrorResponse);
razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, handlePaymentSuccessResponse);
}

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.

  1. Trigger the S2S API from your Backend. Use the following API to generate a session token:

    Request Parameter

    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.

    Errors

    Given below is a list of errors you may face during session token.

  2. Create/Retry Session Token Mechanism

    To ensure a smooth experience during token expiry, the Turbo SDK provides the updateSessionToken method. This method dynamically fetches and updates the session token without reinitialising the session.

    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 using updateSessionToken.

    • Handle the event using the code given below:

      void _handleRefreshToken(dynamic response) async {
      // API Call to generate token
      razorpay.upiTurbo.updateSessionToken(token: ‘<session-token>’);
      };

You can link a customer's UPI account and initiate payments using the methods described below.

To link a customer's UPI account with your app, use the following code sample. This will prompt the customer to add and link their UPI account.

razorpay.upiTurbo.linkNewUpiAccount(
customerMobile: mobileNumber,
color: "#ffffff",
onSuccess: (List<UpiAccount> upiAccounts) {
// Handle successful linking. upiAccounts may be empty if no accounts are linked yet.
},
onFailure: (Error error) {
// Handle error during linking.
}
);

Request Parameters

customerMobile

mandatory

string Mobile number of the customer.

color

optional

string Colour in HEX format.

Response Parameters

To initiate a payment, call the Standard Checkout’s open method with the required payload:

Map<String, Object> payload = {
'amount': 100, // Amount in the smallest currency unit (e.g., paise)
'currency': 'INR',
'prefill': {
'contact': 'YOUR_MOBILE_NUMBER',
'email': 'YOUR_EMAIL'
},
'theme': {'color': '#0CA72F'},
'key': 'YOUR_KEY_ID',
'image': 'https://spaceplace.nasa.gov/templates/featured/sun/sunburn300.png'
};
razorpay.open(payload);

Request Parameters

payload

mandatory

Map<String, dynamic> Payload for initiating the transaction.

Handle payment success and failure responses:

  • Handle Payment Failure:

    Log and display error details such as error code, description, and metadata.

    void handlePaymentErrorResponse(PaymentFailureResponse response) {
    /**
    * PaymentFailureResponse contains:
    * 1. Error Code
    * 2. Error Description
    * 3. Metadata
    **/
    print('Payment Error Response: $response');
    }
  • Handle Payment Success:

    Log and display key information like order ID, payment ID, and signature.

    void handlePaymentSuccessResponse(PaymentSuccessResponse response) {
    /**
    * PaymentSuccessResponse contains:
    * 1. Order ID
    * 2. Payment ID
    * 3. Signature
    **/
    print('Payment Success Response: $response');
    }

By following these steps, you can seamlessly link customer UPI accounts and handle payments using Razorpay Turbo UPI in your Flutter app.

Razorpay provides a single exposed function that allows you to manage linked UPI accounts and access all non-transactional flows seamlessly.

View the non-transactional flow

Manage UPI Accounts

The SDK manages the linked UpiAccounts on the application by triggering manageUpiAccounts(). The sequence of steps is as given below:

  • Fetch balance: Check the customer's account balance.
  • Change UPI PIN: Provide the customer the ability to change their UPI PIN.
  • Reset UPI PIN: Let your customers reset the PIN for their account.
  • Delete the account from the application: Let your customers delink, that is, remove a selected UPI account from your application.
razorpay.upiTurbo.manageUpiAccounts(
customerMobile: "MOBILE_NUMBER",
color: "#ffffff",
onFailure:(Error error) {
}
);

Request Parameters

customerMobile

mandatory

string Mobile number of the customer.

color

optional

string Colour in HEX format.

Response Parameter

The SDKs given below provide access to exposed models for seamless integration.


Is this integration guide useful?


integrate flutter sdk
turbo upi
onboarding flow
non transactional flow