Google Pay Card Payments - S2S Integration JSON API

Learn how to integrate Cards on Google Pay on your S2S Integration using JSON API.


Using this feature, you can allow your customers to make payments on your Android app using the cards they have saved on Google Pay.

To support Google Pay Cards on your S2S integration:

  1. Show Google Pay as a separate option when Google Pay is set up on your customer's device (Know how to on the customer's device).
  2. Trigger payment when the user clicks Pay with Google Pay Cards on your checkout.

Feature Request

  • This is an on-demand feature. Please raise a request with our to get this feature activated on your Razorpay account.
  • Watch this video to know how to raise a feature enablement request on the Razorpay Dashboard.
Feature Request GIF

Download the

and add the .aar file to the application library.

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

dependencies {
...
implementation(name:'tez-client-api-0.9.4', ext:'aar')
implementation 'com.android.support:customtabs:26.1.0'
implementation 'com.google.android.gms:play-services-tasks:15.0.1
implementation 'com.google.android.gms:play-services-wallet:18.0.0'
...
}

Show Google Pay as a payment option only when Google Pay is set up on your customer's device. Google Pay is set up when:

  1. The Google Pay app is installed, and
  2. Valid cards or bank accounts (UPI) are added to your customer's Google pay account.

This will enable you to show only relevant payment methods to your users.

Follow these steps to check if Google Pay Cards is supported:

Given below is the code sample:

Task<Boolean> task = null;
Context context = <ActivityClass>.this;
try {
task = mPaymentClient.isReadyToPay(context,jsonObjectRequest(payload));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
task.addOnCompleteListener(new OnCompleteListener<Boolean>() {
public void onComplete(Task<Boolean> task) {
boolean result = task.getResult();
if (result == true) {
//Google Pay card is available & ready for transaction
} else {
//Google Pay card either isn't available or set up for usage.
}
}
});

Invoke the isReadyToPay function when you want to check if Google Pay Cards is set up on your customer's device, using the following payload:

"apiVersion": 2,
"apiVersionMinor": 0,
"allowedPaymentMethods":[
{
"type":​ ​"CARD",
"parameters":{
"allowedCardNetworks"​ ​:​ ​["VISA", "MASTERCARD"],
}
},
{
"type":​ ​"UPI",
}
]

Show Pay with Google Pay cards method to your end customers only when isReadyToPay function returns true.

Order is an important step in the payment process.

  • An order should be created for every payment.
  • You can create an order using the . It is a server-side API call. Know how to 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.

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

curl -X POST https://api.razorpay.com/v1/orders
-u [YOUR_KEY_ID]:[YOUR_KEY_SECRET]
-H 'content-type:application/json'
-d '{
"amount": 50000,
"currency": "INR",
"receipt": "rcptid_11",
"partial_payment": true,
"first_payment_min_amount": 23000
}'

Here is the list of parameters and their description for creating an order:

amount

mandatory

integer The transaction amount, expressed in the currency subunit. For example, for an actual amount of ₹299.35, the value of this field should be 29935.

currency

mandatory

string The currency in which the transaction should be made. See the

. Length must be 3 characters.

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

.

The error response parameters are available in the

.

The razorpay_order_id returned on successful creation of the order should be sent to the Checkout form.

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:

POST
/payments/create/json
curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/payments/create/json \
-H "Content-Type: application/json" \
-d '{
"amount": "100",
"currency": "INR",
"email": "gaurav.kumar@example.com",
"contact": "9000090000",
"order_id": "order_EKwxwAgItmmXdp",
"provider": "google_pay",
"ip": "192.168.0.103",
"user_agent": "Mozilla/5.0",
"description": "Test payment"
}'

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

.

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.


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 create loadPaymentData payload 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 (authorized or failed).

As a next step, you need to initiate payment to Google SDK integrated in

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

{
"apiVersion": 2,
"apiVersionMinor": 0,
"allowedPaymentMethods": [
{
"type": "UPI",
"parameters": {
"payeeVpa": "<Razorpay provided VPA>",
"payeeName": "Some Name",
"referenceUrl": "Website URL",
"mcc": "<Razorpay provided 4 digit MCC>",
"transactionReferenceId": "<Razorpay provided ID>"
},
"tokenizationSpecification": {
"type": "DIRECT"
}
},
{
"type": "CARD",
"parameters": {
"allowedCardNetworks": [
"VISA",
"MASTERCARD"
]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "razorpayindia",
"gatewayMerchantId": "<YOUR_MERCHANT_ID>",
"gatewayTransactionId": "<PAYMENT_ID>"
}
}
}
],
"transactionInfo": {
"currencyCode": "INR",
"totalPrice": "5000.00",
"totalPriceStatus": "FINAL"
}
}

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:

ParameterData TypeDescriptionRequired?
apiVersionIntegerThe Google Pay API version used. The current version is 2.Y
apiVersionMinorIntegerThe Google Pay API minor version used. The current version is 0.Y
allowedPaymentMethodsArrayAn 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.currencyCodestringThe value is INR .Y
transactionInfo.totalPricestringThe payment amount passed in the API request in step 5. The amount here is in INR.Y
transactionInfo.totalPriceStatusstringThe value is FINAL .Y

The table below explains the fields for the UPI object:

Google Pay FieldRazorpay FieldValue
parameters.payeeVpa
required
provider_data.google_pay.upi.payee_vpaThis is your VPA created by Razorpay. This will be provided by Razorpay in payment response in step 5.
parameters.payeeName
required
NAYou need to pass the user-facing business name for your business.
parameters.referenceUrl
optional
NAYour website URL for this specific payment. You may pass your website URL here.
parameters.mcc
required
provider_data.google_pay.upi.mccThis 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_idThis is a unique ID generated for this UPI payment. This will be provided by Razorpay in payment response in step 5.
tokenizationSpecification.type
required
DIRECTAlways Direct

The table below explains the fields for the card object:

Google Pay FieldRazorpay FieldValue
parameters.allowedCardNetworks
required
provider_data.google_pay.card.supported_networksThis 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
DIRECTAlways Direct .
tokenizationSpecification.parameters.gateway
required
razorpayindiaAlways razorpayindia .
tokenizationSpecification.parameters.gatewayMerchantId
required
NAThis is the Razorpay merchant ID for your Razorpay account. You can find this by logging in to Razorpay dashboard and clicking the user icon on the top right corner.
tokenizationSpecification.parameters.gatewayTransactionId
required
provider_data.google_pay.card.gateway_reference_idThis is a unique ID generated for this Card payment. This will be provided by Razorpay in payment response in step 5.

The payload created by you in step 6 (using the data available in invoke_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:

mPaymentClient.loadPaymentData(MainActivity.this,transactionPayload,LOAD_PAYMENT_DATA_REQUEST_CODE);

This will open the Google Pay app on the customer's device for payment processing.

Google Pay app will return result to onActivityResult function as shown below:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == LOAD_PAYMENT_DATA_REQUEST_CODE) {
switch (resultCode) {
case Activity.RESULT_OK: //payment was successful
String paymentData = WalletUtils.getPaymentDataFromIntent(data);
break;
case Activity.RESULT_FIRST_USER: //internal error, something went wrong
int statusCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, WalletConstants.INTERNAL_ERROR);
handleResultStatusCode(click here)(statusCode);
break;
case Activity.RESULT_CANCELED: //the transaction was cancelled by USER
break;
}
}
}

Your app can further use the snippet code below to get more insight into the error code RESULT_FIRST_USER received in onActivityResult:

private void handleResultStatusCode(int statusCode) {
switch (statusCode) {
case WalletConstants.ERROR_CODE_BUYER_ACCOUNT_ERROR:
break;
case WalletConstants.ERROR_CODE_MERCHANT_ACCOUNT_ERROR:
break;
case WalletConstants.ERROR_CODE_UNSUPPORTED_API_VERSION:
case WalletConstants.INTERNAL_ERROR:
case WalletConstants.DEVELOPER_ERROR:
default:
Toast.makeText(this,"Internal error", Toast.LENGTH_SHORT).show();
//throw new IllegalStateException("Internal error.");
}
}

When your application gets Result_OK from the Google app, you can verify the same using any of the following methods:


Is this integration guide useful?