CanMakePaymentEvent: CanMakePaymentEvent() constructor

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

BCD tables only load in the browser

See also