Collect Request Flow: This flow is available on desktop and mobile browsers. The customers enter their Google Pay VPA on the checkout form. Upon triggering a payment request via Razorpay’s upi method, the Collect request reaches the customer’s Google Pay application. The customer then completes the payment.
Intent-based Payment: This flow is applicable only to mobile and mobile-web payments. In these cases, the customer is redirected to Google Pay’s application to complete the payment. Intent-based payments are available on the Android SDK and on Google Chrome for Android (v56 and above, but not on Google Chrome WebViews).
Copyrazorpay.checkPaymentAdapter('gpay')
.then(() => {
// Google Pay is available, show the payment option
})
.catch(() => {
// Google Pay is unavailable
});
On Android, for intent-based payments, first you need to check if Google Pay is installed on the user’s device. You can use the razorpay.getAppsWhichSupportUpi method to retrieve the list of apps that support intent-based payments installed on a phone.
When a user selects Google Pay as the payment method, you need to submit the Google Pay's package name along with other checkout options to the Razorpay function razorpay.submit:
Copytry
{
JSONObjectdata=newJSONObject();
data.put("amount", 100000); //pass in paise (amount: 100000 equals ₹1000)
data.put("email", "gaurav.kumar@example.com"); //customer's email address
data.put("contact", "9876543210"); //customer's mobile number
data.put("order_id", "order_00000000000001"); //Razorpay Order idJSONObjectnotes=newJSONObject();
notes.put("custom_field", "Make it so."); //notes for the payment, if any
data.put("notes", notes);
data.put("method", "upi"); //Method specific fields
data.put("_[flow]", "intent");
data.put("upi_app_package_name", "com.google.android.apps.nbu.paisa.user");
razorpay.submit(data, newPaymentResultWithDataListener()
{
@OverridepublicvoidonPaymentSuccess(String razorpayPaymentId, PaymentData data)
{
// Razorpay payment ID, Razorpay order ID and Razorpay Signature is passed here after a successful payment// You will need the payment ID to capture the payment on your end
}
@OverridepublicvoidonPaymentError(int code, String description)
{
// Error code and description is passed here
}
});
}
catch (Exception e)
{
Log.e(TAG, "Error in submitting payment details", e);
}
Additionally, if you want to open Google Pay within your application for customers to make the payment without any redirection, you can do so by integrating with Google Pay SDK.
You also have the option to integrate Google Pay with the Custom Checkout on your Android app using Google's SDK.
This offers the advantage of letting you open Google Pay within your application for customers to make the payment without any redirection, improving the user experience.
To integrate Google Pay with the Checkout on your Android app using Google's SDK:
Download the following SDKs and add the .aar files to the application library.
Handy Tips
The Razorpay-Google Pay SDK acts as a wrapper over the native Google-SDK. This SDK connects Razorpay's SDK with the Google SDK. You need all the 3 SDKs (listed below) for the flow to work.
Razorpay Android SDK
Google Pay SDK
Razorpay-Google Pay SDK
Add the following lines of code to the build.gradle file of your application: