- Show Google Pay as a separate option when Google Pay is set up on your customer’s device (Know how to check if Google Pay Cards is available on the customer’s device).
- Trigger payment when the user clicks Pay with Google Pay Cards on your checkout.
Prerequisites
- Sign up for a Razorpay account.
- Generate API Keys on the Dashboard.
- Configure payment capture settings on the Dashboard.
- Follow the Razorpay S2S Integration documentation.
- You must have a PCI compliance certificate to get this feature enabled on your account.
Integration Steps
[Download the SDKs](#step-1-download-the-sdks)
[Add dependencies in Build Gradle file](#step-2-add-dependencies-in...
[Check if GPay Cards is supported](#step-3-check-if-gpay-cards-is-s...
[Create an order](#step-4-create-an-order)
[Create a payment](#step-5-create-a-payment)
[Prepare payload for Initiating Payment to Google](#step-6-prepare-...
[Invoke Google Pay App](#step-7-invoke-google-pay-app)
[Handle response from Google Pay App (optional)](#step-8-handle-res...
[Verify payment status](#step-9-verify-payment-status)
Step 1: Download the SDKs
Download the Google Pay SDK and add the .aar file to the application library.Step 2: Add Dependencies in Build Gradle File
Add the following lines to your app’sbuild.gradle file.
Step 3: Check if Gpay Cards is Supported
ShowGoogle Pay as a payment option only when Google Pay is set up on your customer’s device. Google Pay is set up when:
- The Google Pay app is installed, and
- Valid cards or bank accounts (UPI) are added to your customer’s Google pay account.
Step 3.1: Integrate the following code snippet in your app
Given below is the code sample:Step 3.2: Check if Google Pay Cards is set up
Invoke theisReadyToPay function when you want to check if Google Pay Cards is set up on your customer’s device, using the following payload:
Pay with Google Pay cards method to your end customers only when isReadyToPay function returns true.
Step 4: Create an Order
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.
Step 5: Create a Payment
Once an order is created, your next step is to create a payment. The following API will create a payment with Pay with Google Pay Cards as the payment method: /payments/create/jsonRequest Parameters
amount mandatory
: integer The amount to be paid by the customer in currency subunits. For example, if the amount is ₹100, enter 10000.
currency mandatory
: string The currency in which the payment should be made by the customer. See the list of supported currencies.
order_id mandatory
: string Order ID generated in the previous step.
email mandatory
: string Email address of the customer.
contact mandatory
: string Phone number of the customer.
provider mandatory
: string Name of the service provider partnered with Razorpay. Enter the value google_pay.
notes optional
: object Set of key-value pairs used to store additional information about the payment. It can hold a maximum of 15 key-value pairs, each 256 characters long (maximum).
callback_url optional
: string URL endpoint where Razorpay will submit the final payment status.
ip optional
: string Customer IP Address.
referrer optional
: string Customer referrer.
user_agent optional
: string Customer user-agent.
Response Parameters
Given below are the response parameters:razorpay_payment_id
: string Unique identifier of the payment. Present for all responses.
next
: array A list of action objects available to you to continue the payment process. Present when the payment requires further processing.
action
: string An indication of the next step available to you to continue the payment process. Possible value:
invoke_sdk: Contains the payload needed to createloadPaymentDatapayload as specified by the Google SDK specification. Use this to create the payload and pass it to the customer’s device. Use the same to invoke the Google Pay app on the user’s android app.poll: Contains the URL you must poll to fetch the payment status (authorizedorfailed).
Step 6: Prepare payload for Initiating Payment to Google
As a next step, you need to initiate payment to Google SDK integrated in Step 2. To initiate the payment, you need to create a payload in the format prescribed by Google. The payload structure is explained in this step: Google Pay payload: Google expects following payload in payment request:Request Parameters
As can be seen, the payload has a lot of fields. Razorpay will provide values to be passed in some of the fields. For the remaining fields, you would need to be pass the values from your end. The value to be passed in each field is displayed in the table below:Parameter | Data Type | Description | Required?
apiVersion | Integer | The Google Pay API version used. The current version is 2. | Y
apiVersionMinor | Integer | The Google Pay API minor version used. The current version is 0. | Y
allowedPaymentMethods | Array | An array of objects for each method to be allowed. In this case, it will have two objects one each for UPI and Cards respectively. Each of the objects are explained in subsequent tables. | Y
transactionInfo.currencyCode | string | The value is INR. | Y
transactionInfo.totalPrice | string | The payment amount passed in the API request in step 5. The amount here is in INR. | Y
transactionInfo.totalPriceStatus | string | The value isFINAL. | Y
UPI Object
The table below explains the fields for the UPI object:Google Pay Field | Razorpay Field | Value
parameters.payeeVpa
required | provider_data.google_pay.upi.payee_vpa | This is your VPA created by Razorpay. This will be provided by Razorpay in payment response in step 5.
parameters.payeeName
required | NA | You need to pass the user-facing business name for your business.
parameters.referenceUrl
optional | NA | Your website URL for this specific payment. You may pass your website URL here.
parameters.mcc
required | provider_data.google_pay.upi.mcc | This is a digit category code for your business. This will be provided by Razorpay in payment response in step 5.
parameters.transactionReferenceId
required | provider_data.google_pay.upi.gateway_reference_id | This is a unique ID generated for this UPI payment. This will be provided by Razorpay in payment response in step 5.
tokenizationSpecification.type
required | DIRECT | Always Direct
Card Object
The table below explains the fields for the card object:Google Pay Field | Razorpay Field | Value
parameters.allowedCardNetworks
required | provider_data.google_pay.card.supported_networks | This field indicates the card networks to be supported by Google. This will be provided by Razorpay in payment response in step 5. * You will need to transform network names in block letters.For example, convert Visa to VISA and MasterCard to MASTERCARD.
tokenizationSpecification.type
required | DIRECT | Always Direct.
tokenizationSpecification.parameters.gateway
required | razorpayindia | Always razorpayindia.
tokenizationSpecification.parameters.gatewayMerchantId
required | NA | This is the Razorpay merchant ID for your Razorpay account. You can find this by logging in to the Dashboard and clicking the user icon on the top right corner.
tokenizationSpecification.parameters.gatewayTransactionId
required | provider_data.google_pay.card.gateway_reference_id | This is a unique ID generated for this Card payment. This will be provided by Razorpay in payment response in step 5.
Step 7: Invoke Google Pay App
The payload created by you in step 6 (using the data available ininvoke_sdk action in next array) will be used here. You will need to pass the payload to your Android app and initiate the loadPaymentData function as shown below:
Step 8: Handle response from Google Pay App (Optional)
Google Pay app will return result toonActivityResult function as shown below:
RESULT_FIRST_USER received in onActivityResult:
Step 9: Verify Payment Status
When your application getsResult_OK from the Google app, you can verify the same using any of the following methods: