CanMakePaymentEvent: CanMakePaymentEvent() constructor

Limited availability

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

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is only available in Service Workers.

The CanMakePaymentEvent() constructor creates a new CanMakePaymentEvent object instance.

Syntax

js
new CanMakePaymentEvent(type)

Parameters

type

A string representing the type of event. In the case of CanMakePaymentEvent this is always canmakepayment.

Examples

A developer would not use this constructor manually. A new CanMakePaymentEvent object is constructed when a handler is invoked as a result of the canmakepayment event firing.

js
self.addEventListener("canmakepayment", (e) => {
  e.respondWith(
    new Promise((resolve, reject) => {
      someAppSpecificLogic()
        .then((result) => {
          resolve(result);
        })
        .catch((error) => {
          reject(error);
        });
    }),
  );
});

Specifications

Specification
Payment Handler API
# dom-canmakepaymentevent-constructor

Browser compatibility

desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CanMakePaymentEvent() constructor
Experimental

See also