Back to Content

CanMakePaymentEvent: respondWith() method

files/en-us/web/api/canmakepaymentevent/respondwith/index.md

latest1.4 KB
Original Source

{{APIRef("Web-Based Payment Handler API")}}{{SeeCompatTable}}{{AvailableInWorkers("service")}}

The respondWith() method of the {{domxref("CanMakePaymentEvent")}} interface enables the service worker to respond appropriately to signal whether it is ready to handle payments.

Syntax

js-nolint
respondWith(response)

Parameters

  • response
    • : A {{jsxref("Promise")}} that resolves with a boolean value to signal that it is ready to handle a payment request: (true), or not (false).

Return value

None (undefined).

Examples

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also