diff --git a/index.html b/index.html index 444f1bb..2353cdc 100644 --- a/index.html +++ b/index.html @@ -275,6 +275,9 @@
NotAllowedError"
+ NotFoundError"
PaymentManager interface
+ [SecureContext]
interface PaymentManager {
[SameObject] readonly attribute PaymentInstruments instruments;
[SameObject] readonly attribute PaymentWallets wallets;
- Promise<boolean> requestPermission();
+ [Exposed=Window] static Promise<PermissionState> requestPermission();
};
@@ -561,14 +565,36 @@
requestPermission() method
-
- The means for code requesting permission to handle payments is not
- yet defined.
-
-
+
The user agent is NOT REQUIRED to prompt the user to grant
permission to the origin for each new supported payment method.
+
+ When called, this method executes the following steps:
+
+
+ - Let p be a new promise.
+
+ - Run the following steps in parallel:
+
+ - Let permission be the result of running
+
+ retrieve the permission state algorithm of the permission
+ associated with payment handler's origin.
+
+ - If permission is "prompt", ask the user whether
+ allowing adding new payment instruments for the current settings object's
+ origin is acceptable. If it is, set permission to
+ "granted", and "denied" otherwise.
+
+ - Resolve p with permission.
+
+
+
+ - Return p
+
+
When called, this method executes the following steps:
+ - Let permission be the result of running
+ retrieving
+ the permission state of the permission associated with
+ payment handler's origin.
+
+ - If permission is not "granted", then return a
+ Promise rejected with a NotAllowedError.
+
- If the icons member of
details is present, then:
@@ -953,6 +987,14 @@
When called, this method executes the following steps:
+ - Let permission be the result of running
+ retrieve
+ the permission state algorithm of the permission associated
+ with payment handler's origin.
+
+ - If permission is not "granted", then return a
+ Promise rejected with a NotAllowedError.
+
- If the icons member of
details is present, then:
@@ -1249,34 +1291,27 @@
The following example shows how to register a payment handler:
-
- requestPermission() is not
- yet defined. The code below is based on one potential model, but this
- is likely to change.
-
- window.addEventListerner("DOMContentLoaded", async() => {
- const { registration } =
- await navigator.serviceWorker.register('/sw.js');
- if (!paymentManager) {
- return; // not supported, so bail out.
- }
- const state =
+ button.addEventListener("click", async() => {
+ const permission =
await navigator.permissions.query({ name: "paymenthandler" });
-
- switch (state) {
+ switch (permission) {
case "denied":
return;
case "prompt":
- // Note -- it's not clear how this should work yet; see Issue 94.
const result = await registration.paymentManager.requestPermission();
- if (result === "denied") {
+ if (result !== "granted") {
return;
}
break;
}
+
+ const { registration } =
+ await navigator.serviceWorker.register('/sw.js');
+ if (!registration.paymentManager) {
+ return; // not supported, so bail out.
+ }
+
// Excellent, we got it! Let's now set up the user's cards.
await addInstruments(registration);
}, { once: true });