Skip to main content
To support Google Pay Cards on your custom checkout implementation:
  1. Show Google Pay as a separate option when Google Pay is set-up on your customer’s device.
  2. 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

Integration Steps

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’s build.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 your build.gradle file as shown below:
Update Razorpay Checkout version

Step 3: Add Dependencies in Build Gradle File

Add the following lines to your app’s build.gradle file.
Dependencies

Step 4: Add Metadata in Android Manifest File

Add the following lines inside the app’s AndroidManifest.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 to AndroidManifest.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 AndroidManifest.xml file with auto-OTP reading feature enabled is shown below:
AndroidManifest.xml file
To set your API key programmatically, that is, at the runtime instead of statically defining it in your 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.
Watch Out!Payments made without an order_id cannot be captured and will be automatically refunded. You must create an order before initiating payments to ensure proper payment processing.

API Sample Code

The following is a sample API request and response for creating an order:
Curl

Request Parameters

Here is the list of parameters and their description for creating an order:amount mandatory : integer Payment amount in the smallest currency sub-unit. For example, if the amount to be charged is 299, then pass 29900 in this field. In the case of three decimal currencies, such as KWD, BHD and OMR, to accept a payment of 295.991, pass the value as 295990. And in the case of zero decimal currencies such as JPY, to accept a payment of 295, pass the value as 295.
Watch Out!As per payment guidelines, you should pass the last decimal number as 0 for three decimal currency payments. For example, if you want to charge a customer 99.991 KD for a transaction, you should pass the value for the amount parameter as 99990 and not 99991.currency mandatory : string The currency in which the transaction should be made. See the list of supported currencies. Length must be 3 characters.
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.The razorpay_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, call getPaymentMethods. 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
Know how to integrate the different payment methods using Razorpay Android Custom SDK in detail.

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.
Java
You should show Google Pay cards method to your customers only when 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 using setWebView, 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 the creation 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 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:

  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.