Create payment requests

You can create a payment request using JavaScript. The following sections provide some basic examples:

Create a payment method

To create a payment request, add Google Pay and its details in your supporting methods. The Unified Payment Interface (UPI) payment mechanism is supported in Google Pay. This means you need to specify the URL and UPI fields while creating the payment request object.

For example:

supportedMethods: "https://tez.google.com/pay"
pa: the retailers vpa to receive the money.

Constructing a new PaymentRequest object can be done at any point in your site or app. Until you call its show() method, nothing will be displayed.

Mandatory fields

To make UPI transactions, the following fields are required:

Fields Description
pa Payee address or business virtual payment address (VPA).
pn Payee name or business name.
mc Business retailer category code.
tr Transaction reference ID. (Business specific ID. Must be unique for each request.)
url Transaction reference URL.
am Transaction amount. (Up to two decimal digits are allowed. This should be set in the details object instead of the supportedInstruments object.)
cu Currency code. (This should be set in the details object instead of supportedInstruments object. Only the Indian rupee (INR) is currently supported.)

Optional fields

Fields Description
tid Transaction ID generated by the payment service provider (PSP) of the business.
tn Transaction note. It is the description appearing in the Google Pay payflow. (Maximum length is 80 characters)

For a complete list of supported fields, refer to the NPCI UPI Linking Specs

Create a payment request

The following code snippet illustrates how to add Google Pay as the supported payment method and define the mandatory fields. The fields associated with the order amount, such as am and cu, must be defined in the detailed object. To define order value, see Create order amount.

  const supportedInstruments = [
    {
      supportedMethods: ['https://tez.google.com/pay'],
      data: {
        pa: 'merchant-vpa@xxx',
        pn: 'Merchant Name',
        tr: '1234ABCD',  // your custom transaction reference ID
        url: 'http://url/of/the/order/in/your/website',
        mc: '1234', // your merchant category code
        tn: 'Purchase in Merchant',
      },
    }
  ];

You must supply an array of objects that indicate your supported Payment method as Google Pay. Each Payment method must include a supportedMethods parameter that identifies the Payment method. You must also pass values for the mandatory fields in the array.

After you create the Payment method and values for its required parameters, you must define the order amount in the PaymentRequest object. To define amount, see Create order amount.