CanMakePaymentEvent: respondWith() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{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
- {{domxref("Web-based Payment Handler API", "", "", "nocode")}}
- Web-based payment apps overview
- Setting up a payment method
- Life of a payment transaction
- Using the Payment Request API
- Payment processing concepts