Skip to main content

Advantages

Using the Native OTP feature, you can:
  • Increase success rates by up to 4%.
  • 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 Android Custom SDK.

Integration Steps

1.1 Update Razorpay Android Custom SDK version. 1.2 Implement CardsFlowCallback interface in the getCardsFlow function. 1.3 Call razorpay.getCardOtpData(CardsFlowCallback) Function. 1.4 Handle Success and Error Events. 1.5 Store Field in Server. 1.6 Verify Payment Signature.

1.1 Update Razorpay Android Custom SDK version

Update the Android Custom SDK version. This feature is available from version 3.9.3 and above.

1.2 Implement CardsFlowCallback Interface in getCardsFlow Function

Implement the CardsFlowCallback interface in the getCardsFlow function in the payment activity. The SDK fires the isNativeOtpEnabled function and determines whether the native OTP flow is enabled for the BIN.

Sample Code

Java

1.3 Call razorpay.getCardOtpData(CardsFlowCallback) Function

If Native OTP is enabled for BIN, you should call the razorpay.getCardOtpData(CardsFlowCallback) function. The SDK then fires the otpGenerateResponse(boolean otpGenerated) function and confirms if the OTP was successfully sent to the customer. Based on this information, you can display the generated OTP UI to the customer. After entering the OTP, the customer can either:
  • Submit 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 Tips
Do not perform any validation on the length of the OTP since this can vary across banks. However, the OTP should not be blank.
  • Request for OTP to be resent There could be situations when customers have to re-enter the OTP sent to them. The bank determines the number of retries that the user is allowed.
  • Cancel OTP Cancel the payment by cancelling the OTP.

Sample Code

Java

1.4 Handle Success and Error Events

You must handle the payment success and error events as shown in the code sample below:
Java
Handy Tips
To reuse the Razorpay Checkout web integration inside a web view on Android or iOS, pass a callback_url along with other checkout options to process the desired payment.

Use PaymentResultWithDataListener

You have the option to implement PaymentResultListener or PaymentResultWithDataListener to receive callbacks for the payment result.
  • PaymentResultListener provides only payment_id as the payment result.
  • PaymentResultWithDataListener provides additional payment data such as email and contact of the customer, along with the order_id, payment_id, signature and more.
Java

Step 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.

Step 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.

Test the Integration

After the integration is complete, a Pay button appears on your webpage/app. Click the button and make a test transaction to ensure the integration is working as expected. You can start accepting actual payments from your customers once the test transaction is successful.
Watch Out!This is a mock payment page that uses your test API keys, test card and payment details.
  • Ensure you have entered only your Test Mode API keys in the Checkout code.
  • Test mode features a mock bank page with Success and Failure buttons to replicate the live payment experience.
  • No real money is deducted due to the usage of test API keys. This is a simulated transaction.
Following are all the payment modes that the customer can use to complete the payment on the Checkout. Some of them are available by default, while others may require approval from us. Raise a request from the Dashboard to enable such payment methods.

Payment Method | Code | Availability

Debit Card | debit | ✓

Credit Card | credit | ✓

Netbanking | netbanking| ✓

UPI | upi | ✓

EMI - Credit Card EMI, Debit Card EMI and No Cost EMI | emi | ✓

Wallet | wallet | ✓

Cardless EMI | cardless_emi | Requires Approval.

Bank Transfer | bank_transfer | Requires Approval and Integration.

Emandate | emandate | Requires Approval and Integration.

Pay Later| paylater | Requires Approval.You can make test payments using one of the payment methods configured at the Checkout.

Netbanking

You can select any of the listed banks. After choosing a bank, Razorpay will redirect to a mock page where you can make the payment success or a failure. Since this is Test Mode, we will not redirect you to the bank login portals. Check the list of supported banks.

UPI

You can enter one of the following UPI IDs:
  • success@razorpay: To make the payment successful.
  • failure@razorpay: To fail the payment.
Check the list of supported UPI flows.
Handy Tips
You can use Test Mode to test UPI payments, and Live Mode for UPI Intent and QR payments.

Cards

You can use the following test cards to test transactions for your integration in Test Mode.

Domestic Cards

Use the following test cards for Indian payments:

Network | Card Number | CVV & Expiry Date

Visa | 4100 2800 0000 1007 | Use a random CVV and any future date ^^^^^

Mastercard | 5500 6700 0000 1002 |

RuPay | 6527 6589 0000 1005 |

Diners | 3608 280009 1007 |

Amex | 3402 560004 01007 |

Error Scenarios

Use these test cards to simulate payment errors. See the complete list of error test cards with detailed scenarios. Check the following lists:

International Cards

Use the following test cards to test international payments. Use any valid expiration date in the future in the MM/YY format and any random CVV to create a successful payment.

Card Network | Card Number | CVV & Expiry Date

Mastercard | 5555 5555 5555 4444 5105 1051 0510 5100 5104 0600 0000 0008 | Use a random CVV and any future date ^^

Visa | 4012 8888 8888 1881 | Check the list of supported card networks.

Wallet

You can select any of the listed wallets. After choosing a wallet, Razorpay will redirect to a mock page where you can make the payment success or a failure. Since this is Test Mode, we will not redirect you to the wallet login portals. Check the list of supported wallets.