blob: 0e5a4768e7626f666077e794e0731c9a1e3e9d35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
self.addEventListener('canmakepayment', (event) => {
event.respondWith(true);
});
async function responder(event) {
const methodName = event.methodData[0].supportedMethods;
if (!event.changePaymentMethod) {
return {
methodName,
details: {
changePaymentMethodReturned:
'The changePaymentMethod() method is not implemented.',
},
};
}
let changePaymentMethodReturned;
try {
const response = await event.changePaymentMethod(methodName, {
country: 'US',
});
changePaymentMethodReturned = response;
} catch (err) {
changePaymentMethodReturned = err.message;
}
return {methodName, details: {changePaymentMethodReturned}};
}
self.addEventListener('paymentrequest', (event) => {
event.respondWith(responder(event));
});
|