Support Google Pay for in-app payments

Google Pay supports generic Unified Payments Interface (UPI) API calls to make a payment request and receive the response. For more information regarding the request and response argument specifications, see NPCI UPI Linking Specification. This document also explains how merchant apps can use URL deep linking to invoke UPI apps on Android devices.

To integrate Google Pay with your app and receive payments, follow the steps below:

  1. Before you begin, make sure you have all required data as mentioned in the Prerequisites section.
  2. Generate an URI. Google Pay provides an example to generate URI. See the code sample to generate.
  3. Pass the generated URI to Google Pay using the above code.
  4. Google Pay is invoked and displays a Pay screen for user to enter amount and pay.
  5. If the Google Pay response status is Submitted or Succeeded, you must check with your PSP or payment aggregators to ensure that the correct order amount is paid.

The following code illustrates how to display Google Pay as mode of payment when user trigger the payment option in the merchant app.

String GOOGLE_PAY_PACKAGE_NAME = "com.google.android.apps.nbu.paisa.user";
int GOOGLE_PAY_REQUEST_CODE = 123;

Uri uri =
    new Uri.Builder()
        .scheme("upi")
        .authority("pay")
        .appendQueryParameter("pa", "your-merchant-vpa@xxx")
        .appendQueryParameter("pn", "your-merchant-name")
        .appendQueryParameter("mc", "your-merchant-code")
        .appendQueryParameter("tr", "your-transaction-ref-id")
        .appendQueryParameter("tn", "your-transaction-note")
        .appendQueryParameter("am", "your-order-amount")
        .appendQueryParameter("cu", "INR")
        .appendQueryParameter("url", "your-transaction-url")
        .build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_PAY_PACKAGE_NAME);
activity.startActivityForResult(intent, GOOGLE_PAY_REQUEST_CODE);