- Show Google Pay as a separate option when Google Pay is set-up on your customer’s device.
- Trigger payment when the user clicks Google Pay Cards on your checkout.
Feature RequestThis is an on-demand feature. Please raise a request with our Support team to get this feature activated on your Razorpay account.to get this feature activated on your account.
Prerequisites
- You should have already integrated Razorpay Custom Checkout on your Android app.
- Complete the onboarding process mentioned here.
Integration Steps
7
Step 7
9
Step 9
11
Step 11
12
Step 12
Step 1: Add or Update the Google SDKs
You will need to integrate the Google SDK in your Android app. Import the SDK from our Maven repository by adding the following lines to your app’sbuild.gradle file.
build.gradle
Step 2: Update Razorpay Custom Integration SDK
Google Pay Cards is supported on Razorpay Android - Custom Checkout version 3.8.8 and higher. If you are using an older version, you will need to update the same. You can update the Custom Checkout version in yourbuild.gradle file as shown below:
Update Razorpay Checkout version
Step 3: Add Dependencies in Build Gradle File
Add the following lines to your app’sbuild.gradle file.
Dependencies
Step 4: Add Metadata in Android Manifest File
Add the following lines inside the app’sAndroidManifest.xml file.
Adds Meta Data
Step 5: Instantiate and Initialize Razorpay Android Custom SDK
Instantiate
To instantiate Razorpay, pass a reference of your activity to the Razorpay constructor, as shown below:Instantiate Razorpau
Initialize
Add your Razorpay API keys toAndroidManifest.xml.
Handy TipsAPI keys should not be hardcoded in the app. It should be sent from your server-side as an app-related metadata fetch.The sample To set your API key programmatically, that is, at the runtime instead of statically defining it in your
AndroidManifest.xml file with auto-OTP reading feature enabled is shown below:AndroidManifest.xml file
AndroidManifest.xml, you can pass it as a parameter to the Razorpay constructor, as shown below:Set API Key Programmatically
Step 6: Implement Orders API in your Server-side
Order is an important step in the payment process.- An order should be created for every payment.
- You can create an order using the Orders API. It is a server-side API call. Know how to authenticate Orders API.
- The order_id received in the response should be passed to the checkout. This ties the Order with the payment and secures the request from being tampered.
Handy TipsRazorpay has added support for zero decimal currencies, such as JPY and three decimal currencies, such as KWD, BHD and OMR, allowing businesses to accept international payments in these currencies. Know more about Currency Conversion (May 2024).
receipt optional
: string Your receipt id for this order should be passed here. Maximum length is 40 characters.notes optional
: json object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.partial_payment optional
: boolean Indicates whether the customer can make a partial payment. Possible values:true: The customer can make partial payments.false(default): The customer cannot make partial payments.
id mandatory
: string Unique identifier of the customer. For example, cust_1Aa00000000004.Know more about Orders API.Response Parameters
Descriptions for the response parameters are present in the Orders Entity table.Error Response Parameters
The error response parameters are available in the API Reference Guide.Therazorpay_order_id, returned on successful creation of the order, should be sent to the Checkout form.Step 7: Fetch Payment Methods
To get a list of available payment methods, callgetPaymentMethods. This fetches the list of payment methods asynchronously and returns the result in JSON format in the onPaymentMethodsReceived callback. For the structure of the JSON result, you can refer: https://api.razorpay.com/v1/methods?key_id=`{Your_Key_ID}`
Java
Step 8: Check if Google Pay Cards is Setup on Customer’s Device
Handy TipsEnsure the Google Pay Cards feature is enabled for your account. If it is not enabled, get in touch with us to get it enabled on your account.Use the code given below to check if Google Pay cards are setup on your customer’s device.You should show Google Pay cards method to your customers only when
Java
isUserRegisteredOnGpay returns true.Step 9: Set Up the WebView
The bank ACS pages are displayed to the user in a WebView. You need to define a WebView in your layout and pass the reference to our SDK usingsetWebView, as shown below:
Java
Step 10: Submit Payment Data and Handle Success and Error Events
Once you have received the customer’s payment information, it needs to be sent to Razorpay to complete thecreation step of the payment flow. You can do this by invoking the submit method. Before invoking this method, you have to make your WebView visible to the customer. The data that needs to be submitted in the form of a JSONObject is shown below:
Java
Handy TipsTo 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.Using
You have the option to implement
Using 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 11: Store the Fields in the 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 12: 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:
-
Create a signature in your server using the following attributes:
order_id: Retrieve theorder_idfrom your server. Do not use therazorpay_order_idreturned by Checkout.razorpay_payment_id: Returned by Checkout.key_secret: Available in your server. Thekey_secretthat was generated from the Dashboard.
-
Use the SHA256 algorithm, the
razorpay_payment_idand theorder_idto construct a HMAC hex digest as shown below:HMAC Hex Digest -
If the signature you generate on your server matches the
razorpay_signaturereturned 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