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:
- 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).
- 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 Curlec account.- Sign up for a Razorpay account.
- Generate on the Dashboard.
- Configure on the Dashboard.
- Follow the .
- You must have a PCI compliance certificate to get this feature enabled on your account.
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.1implementation '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:
- The Google Pay app is installed, and
- 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": "MYR","receipt": "rcptid_11"}'
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 MYR 299.00, 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. The length must be 3 characters.
Handy Tips
Razorpay 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
(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
.Descriptions for the response parameters are present in the
table.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:
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.
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 createloadPaymentData
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
orfailed
).
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:
The table below explains the fields for the UPI object:
The table below explains the fields for the card object:
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:
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == LOAD_PAYMENT_DATA_REQUEST_CODE) {switch (resultCode) {case Activity.RESULT_OK: //payment was successfulString paymentData = WalletUtils.getPaymentDataFromIntent(data);break;case Activity.RESULT_FIRST_USER: //internal error, something went wrongint statusCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, WalletConstants.INTERNAL_ERROR);handleResultStatusCode(click here)(statusCode);break;case Activity.RESULT_CANCELED: //the transaction was cancelled by USERbreak;}}}
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?
ON THIS PAGE