W3cubDocs

/DOM

PaymentMethodChangeEvent.methodName

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

The read-only methodName property of the PaymentMethodChangeEvent interface is a string which uniquely identifies the payment handler currently selected by the user. The payment handler may be a payment technology, such as Apple Pay or Android Pay, and each payment handler may support multiple payment methods; changes to the payment method within the payment handler are described by the PaymentMethodChangeEvent.

Syntax

var methodName = paymentMethodChangeEvent.methodName;

Value

A DOMString which uniquely identifies the currently-selected payment handler. This may be a string chosen from the list of standardized payment method identifiers, or a URL used by the payment processing service. See Payment method identifiers in Payment Request API for more information.

The default value is the empty string, "".

Example

This example uses the paymentmethodchange event to watch for changes to the payment method selected for Apple Pay, in order to compute a discount if the user chooses to use a Visa card as their payment method.

request.onpaymentmethodchange = function(ev) {
  const { type: cardType } = ev.methodDetails;
  const newStuff = {};
  if (ev.methodName === "https://apple.com/apple-pay") {
    switch (cardType) {
      case "visa":
        // do Apple Pay specific handling for Visa card...
        // methodDetails contains the card information
        const result = calculateDiscount(ev.methodDetails);
        Object.assign(newStuff, result);
        break;
    }
  }
  // finally...
  ev.updateWith(newStuff);
};
const response = await request.show();

Specifications

Specification Status Comment
Payment Request API
The definition of 'PaymentMethodChangeEvent.methodName' in that specification.
Candidate Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support No ? 63
Disabled
63
Disabled
Disabled From version 63: this feature is behind the dom.payments.request.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No No ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No No ? 63
Disabled
63
Disabled
Disabled From version 63: this feature is behind the dom.payments.request.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No ? ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PaymentMethodChangeEvent/methodName