- From: Dave Longley <notifications@github.com>
- Date: Wed, 09 Aug 2017 08:56:58 -0700
- To: w3c/payment-handler <payment-handler@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 9 August 2017 15:57:40 UTC
I suspect that this could be further simplified to just call `requestPermission` as well:
```js
button.addEventListener("click", async() => {
const { registration } =
await navigator.serviceWorker.register('/sw.js');
if (!registration.paymentManager) {
return; // not supported, so bail out.
}
const result = await registration.paymentManager.requestPermission();
if (result !== "granted") {
return;
}
// Excellent, we got it! Let's now set up the user's cards.
await addInstruments(registration);
}, { once: true });
```
This presumes that a call to `requestPermission` would, in effect, initially do the same thing as a `query` on the permission manager to see if permission was already granted (and return early). Off the top of my head, I believe this is how `Notification.requestPermission` works but I could be rusty on that.
--
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#issuecomment-321299449
Received on Wednesday, 9 August 2017 15:57:40 UTC