Prerequisites
- Create a Razorpay account.
- Generate the API Keys from the Dashboard. To go live with the integration and start accepting real payments, generate Live Mode API Keys and replace them in the integration.
- Integrate with Android Custom SDK.
Dependencies
Add the following line in yourbuild.gradle(app-level) file in the dependencies block:
Dependencies
Integration Steps
1. OTP Auto-Submission. 2. Override onActivityResultReceived. 3 Reset All Objects.Step 1: OTP Auto-Submission
You can use one of the options below based on your requirement:- WebView-based Payments: For card payments.
- Business OTP Page-based Payments: For native OTP payments.
WebView-based Payments
ThestartSmsListener function starts SmsRetrieverClient and attaches BroadcastReceivers, which notifies about the incoming SMS messages. Once the message is received and parsed, the OTP is auto-filled and subsequently auto-submitted on the page loaded in WebView.
Java
WebView
: object The object created by you and passed to Razorpay Custom Checkout SDK within which the ACS page loads.
Sample Code
Use the sample code given below:Java
Business OTP Page-based Payments
Razorpay offers Native OTP solutions where you can submit the OTP by calling the API provided by the Razorpay Custom Checkout SDK. To enable OTP auto-read and auto-submit of payments with this feature, we use a separate function that uses an interface to send the callback to you once the OTP is received.Java
OtpListener
: object Acts as a callback, triggered when the OTP is received and parsed after the timer is displayed.
onOtpReceived
: Triggered when the message is received and the SDK extracts OTP. Values:
sender: Sender of the message (default: razorpay).body: The entire message.OTP: OTP pin extracted from the message.
onOtpConfirmed
: Triggered when the timer for OTP Auto-submit is allowed/confirmed by the user. Values:
sender: Sender of the message (default: razorpay).body: The entire message.OTP: OTP pin extracted from the message.
Sample Code
Use the sample code given below:Java
Step 2: Override onActivityResultReceived
When the application does not use theRECEIVE_SMS permission, we use the SmsRetreiverClient API provided by Google, which enables the user to give a one-time consent for the application to read the incoming message.
The user’s response for the one-time consent is passed to the activity’s onActivityResult function. Since the SDK cannot override this, we request you send this data to us.
Java
requestCode
: string Passed by RazorpayOtpAssist SDK when the startActivityForResult is triggered.
resultCode
: string Contains user-selected action.
data
: intent Contains data from the user-selected action.
Sample Code
Use the sample code given below:Java
Step 3: Reset All Objects
You can use this function to destroy all objects used by theRazorpayOtpAssist SDK to avoid leaks or when starting a new transaction with the same Razorpay object.
Java
Sample Code
Use the code given below:Reset
Handy TipsWe recommend using the existing Razorpay object for the following reasons:
- You need not manage creating and deleting the
RazorpayOtpAssistobject. The Custom Checkout SDK handles this for you. - The Custom Checkout SDK becomes a singular entry point to use all Razorpay-powered features. This simplifies your integration process and improves the checkout experience for your customers.