Skip to main content

Advantages

Using the Native OTP feature, you can:
  • Increase success rates.
  • Reduce payment failures due to low internet speeds.
  • Avoid failures due to redirects to bank pages.
  • Offer a consistent experience on mobile and web checkout.

Prerequisites

Before implementing the Native OTP feature, check the following prerequisites:
  1. Log in to the Dashboard and generate the API Keys.
  2. Integrate with the Razorpay iOS Custom SDK.

Integration Steps

1.1 Initialise the Razorpay iOS Custom SDK 1.2 Check Native OTP enablement using getCardsFlow function 1.3 Generate OTP using the razorpay.getCardOtpData function 1.4 Handle Success and Error Events 1.5 Store Details in Server 1.6 Verify Payment Signature

1.1 Initialise the Razorpay iOS Custom SDK

Use the code given below to initialise the SDK.
SDK
Handy TipsWebView is used to fall back to the current Custom UI flow or redirect to bank flow.

1.2 Check Native OTP Enablement Using the getCardsFlow Function

Use the getCardsFlow function to determine whether the native OTP flow is enabled for the card BIN. Given below is the sample code.
getCardsFlow
The card details are passed in the options dictionary, as shown below:
Payment details

1.3 Generate OTP Using the razorpay.getCardOtpData Function

If Native OTP is enabled for the BIN, you should call the razorpay.getCardOtpData function. The function callback returns a boolean and informs whether the OTP was successfully sent to the customer or not. Based on this information, you can display the generated OTP UI to the customer. Given below is the sample code:
getCardOtpData
After the OTP is generated, the customer can choose to:
  • Submit the OTP.
  • Request for the OTP to be resent.
  • Cancel the OTP.
  • Navigate to the bank page.

Submit the OTP

The customer needs to submit the OTP for authenticating the payment. The customer receives the OTP through your application frontend. For card payments, the customer receives the OTP via their preferred notification medium, SMS or email.
Handy TipsDo not perform any validation on the length of the OTP since this can vary across banks. However, the OTP should not be blank.Given below is the function to be invoked when customer clicks the submit button:
Submit OTP

Resend OTP

There could be situations when customers have to re-generate the OTP. Given below is the function to be invoked when the customer clicks the resend button:
Resend OTP

Cancel the OTP

Cancel the payment by cancelling the OTP. Given below is the function to be invoked when customer clicks the cancel button:
Cancel OTP

Redirect to Bank Page

Customers can navigate to the bank page by clicking the redirect button. You need to:
  1. Display the payment WebView passed earlier while initialising the SDK.
  2. Invoke the redirectToBankPage() function.
Invoke redirect function

1.4 Handle Success and Error Events

You must handle the payment success and error events using the RazorpayPaymentCompletionProtocol delegate methods:
Payment Success
Handy TipsTo reuse the Razorpay Checkout web integration inside a WebView on Android or iOS, pass a callback_url along with other checkout options to process the desired payment.

1.5 Store the Fields in Server

A successful payment returns the following fields to the Checkout form.

Success Callback

  • You need to store these fields in your server.
  • You can confirm the authenticity of these details by verifying the signature in the next step.
Success Callback
razorpay_payment_id : string Unique identifier for the payment returned by Checkout only for successful payments. razorpay_order_id : string Unique identifier for the order returned by Checkout. razorpay_signature : string Signature returned by the Checkout. This is used to verify the payment.

1.6 Verify Payment Signature

This is a mandatory step to confirm the authenticity of the details returned to the Checkout form for successful payments.

To verify the razorpay_signature returned to you by the Checkout form:

  1. Create a signature in your server using the following attributes:
    • order_id: Retrieve the order_id from your server. Do not use the razorpay_order_id returned by Checkout.
    • razorpay_payment_id: Returned by Checkout.
    • key_secret: Available in your server. The key_secret that was generated from the Dashboard.
  2. Use the SHA256 algorithm, the razorpay_payment_id and the order_id to construct a HMAC hex digest as shown below:
    HMAC Hex Digest
  3. If the signature you generate on your server matches the razorpay_signature returned to you by the Checkout form, the payment received is from an authentic source.

Generate Signature on Your Server

Given below is the sample code for payment signature verification:
Java

Post Signature Verification

After you have completed the integration, you can set up webhooks, make test payments, replace the test key with the live key and integrate with other APIs.