MDN self-hosted library · e01.org

CanMakePaymentEvent

Web-Based Payment Handler APIservice

Web-Based Payment Handler APIservice

The CanMakePaymentEvent interface of the is the event object for the canmakepayment event, fired on a payment app's service worker to check whether it is ready to handle a payment. Specifically, it is fired when the merchant website calls the PaymentRequest() constructor.

Constructor

  • CanMakePaymentEvent()
  • : Creates a new CanMakePaymentEvent object instance.

Instance methods

  • respondWith()
  • : Enables the service worker to respond appropriately to signal whether it is ready to handle payments.

Examples

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

Specifications

Browser compatibility

See also