- From: Dave Longley <notifications@github.com>
- Date: Wed, 09 Aug 2017 15:54:23 +0000 (UTC)
- To: w3c/payment-handler <payment-handler@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 9 August 2017 15:54:45 UTC
In the [registration example](https://www.w3.org/TR/payment-handler/#register-example) the service worker `registration` variable is accessed before it is defined. I recommend moving the registration retrieval and `paymentManager` feature check to the top of the method:
```js
button.addEventListener("click", async() => {
const { registration } =
await navigator.serviceWorker.register('/sw.js');
if (!registration.paymentManager) {
return; // not supported, so bail out.
}
const permission =
await navigator.permissions.query({ name: "paymenthandler" });
switch (permission) {
case "denied":
return;
case "prompt":
const result = await registration.paymentManager.requestPermission();
if (result !== "granted") {
return;
}
break;
}
// Excellent, we got it! Let's now set up the user's cards.
await addInstruments(registration);
}, { once: true });
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-handler/issues/200
Received on Wednesday, 9 August 2017 15:54:45 UTC