PaymentRequest: PaymentRequest() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The PaymentRequest() constructor creates a new PaymentRequest object which will be used to handle the process of generating, validating, and submitting a payment request.

Syntax

js
new PaymentRequest(methodData, details)
new PaymentRequest(methodData, details, options)

Parameters

methodData

Contains an array of identifiers for the payment methods the merchant website accepts and any associated payment method specific data. Each item in the array contains the following fields:

supportedMethods

A string containing a payment method identifier. This is either a URL or one of the standardized payment method identifiers. The value and structure of the data field will vary depending on the value of the supportedMethods field.

data

A JSON-serializable object that provides optional information that might be needed by the supported payment methods. This has to conform to the type expected by the payment handler indicated by supportedMethods. Developers need to consult whomever controls the payment methods for the expected shape of the data object. If supportedMethods is secure-payment-confirmation, then data needs to conform to the SecurePaymentConfirmationRequest dictionary.

details

Provides information about the requested transaction. This parameter contains the following fields:

total

The total amount of the payment request.

id Optional

A free-form identifier for this payment request. If a value is not supplied, the browser will construct one.

displayItems

An array of optional line items for the payment request that the user agent may display, such as product details, tax, and shipping.

shippingOptions

The shipping options the user may choose from. If this sequence is blank, it indicates the merchant cannot ship to the current shipping address. The default shipping option may be indicated in this sequence.

modifiers

Modifiers for specific payment methods; for example, adjusting the total amount based on the payment method. This parameter contains the following fields:

additionalDisplayItems

An array of items to be appended to the details.displayItems property. This property is commonly used to add a discount or surcharge line item indicating the different amount in details.modifiers.total.

data

A JSON-serializable object that provides optional information that might be needed by the supported payment methods.

total

A total amount for the payment request that overrides value in details.total. This is typically used when details.modifiers.additionalItems adds a discount or a purchase to the request.

options Optional

Lets you set options that control the behavior of the user agent. This parameter contains the following fields:

requestPayerName

A Boolean indicating whether the user agent should collect the payer's name and submit it with the payment request. The default is false.

requestPayerEmail

A Boolean indicating whether the user agent should collect the payer's email address and submit it with the payment request. The default is false.

requestPayerPhone

A Boolean indicating whether the user agent should collect the payer's phone number and submit it with the payment request. The default is false.

requestShipping

A Boolean indicating whether the user agent should collect the payer's shipping address and submit it with the payment request. If you set this type to true, you should select an appropriate shippingType. The default is false.

shippingType

Lets you specify how the user interface refers to shipping when the word 'shipping' isn't appropriate for your use case. For example, in English speaking countries you would say "pizza delivery" not "pizza shipping". Valid values are "shipping", "delivery", and "pickup". Quotation marks must be included. The default value is "shipping".

Return value

A new PaymentRequest object, configured for use as configured by the input parameters.

Exceptions

SecurityError DOMException

Use of this feature was blocked by a Permissions Policy.

Examples

The following example shows minimal functionality and focuses instead on showing the complete context of instantiating a PaymentRequest object.

js
const supportedInstruments = [
  {
    supportedMethods: "https://example.com/pay",
  },
];

const details = {
  total: { label: "Donation", amount: { currency: "USD", value: "65.00" } },
  displayItems: [
    {
      label: "Original donation amount",
      amount: { currency: "USD", value: "65.00" },
    },
  ],
  shippingOptions: [
    {
      id: "standard",
      label: "Standard shipping",
      amount: { currency: "USD", value: "0.00" },
      selected: true,
    },
  ],
};

const options = { requestShipping: true };

try {
  const request = new PaymentRequest(supportedInstruments, details, options);
  // Add event listeners here.
  // Call show() to trigger the browser's payment flow.
  request
    .show()
    .then((instrumentResponse) => {
      // Do something with the response from the UI.
    })
    .catch((err) => {
      // Do something with the error from request.show().
    });
} catch (e) {
  // Catch any other errors.
}

Specifications

Specification
Payment Request API
# constructor

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
PaymentRequest() constructor
Chrome – Full support
Chrome 60 (Release date: 2017-07-25)
footnote Full support
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – No support
Firefox 55 (Release date: 2017-08-08)
disabled
disabled From version 55 users must explicitly set the dom.payments.request.enabled preference to true. To change preferences in Firefox, visit about:config.
Opera – Full support
Opera 47 (Release date: 2017-08-09)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 53 (Release date: 2016-09-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 136 (Release date: 2025-04-29)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
secure-payment-confirmation method
Experimental
Chrome – Full support
Chrome 95 (Release date: 2021-10-19)
footnote Full support
Edge – Full support
Edge 95 (Release date: 2021-10-21)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 81 (Release date: 2021-11-04)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 95 (Release date: 2021-10-19)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 67 (Release date: 2022-01-31)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.