Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: small cleanup of examples #263

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ an issuing bank during a checkout by the user on some merchant.
1. The verification completes; the bank iframe closes and the merchant finishes
the checkout process for the user.

Sample code for registering the user in this way follows:
Sample code for registering the user in this way follows. Note that the example code
presumes access to async/await, for easier to read promise handling.

<pre class="example" id="registration-example" highlight="js">
if (!window.PublicKeyCredential) { /* Client not capable. Handle error. */ }
Expand Down Expand Up @@ -330,12 +331,12 @@ const publicKey = {
};

// Note: The following call will cause the authenticator to display UI.
navigator.credentials.create({ publicKey })
.then(function (newCredentialInfo) {
// Send new credential info to server for verification and registration.
}).catch(function (err) {
// No acceptable authenticator or user refused consent. Handle appropriately.
});
try {
const newCredentialInfo = await navigator.credentials.create({ publicKey });
// Send new credential info to server for verification and registration.
} catch(err) {
// No acceptable authenticator or user refused consent. Handle appropriately.
}
</pre>

</div> <!-- non-normative -->
Expand Down Expand Up @@ -370,16 +371,14 @@ Payment Confirmation.
the transaction and the merchant finishes the checkout process for the user.

The sample code for authenticating the user follows. Note that the example code
presumes access to await/async, for easier to read promise handling.
presumes access to async/await, for easier to read promise handling.

<pre class="example" id="authentication-example" highlight="js">
/* isSecurePaymentConfirmationAvailable indicates whether the browser */
/* supports SPC. It does not indicate whether the user has a credential */
/* ready to go on this device. */
const spcAvailable =
PaymentRequest &&
PaymentRequest.isSecurePaymentConfirmationAvailable &&
await PaymentRequest.isSecurePaymentConfirmationAvailable();
await PaymentRequest?.isSecurePaymentConfirmationAvailable();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, I've never seen it before!

I think it's technically optional chaining (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) rather than nullish coalescing (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing), right?

Does this work as written if PaymentRequest itself is not defined? (As opposed to isSecurePaymentConfirmationAvailable not being defined). It seemed not when I tried it in Firefox, but I may have been holding it wrong. I had to do:

window.PaymentRequest?.isSecurePaymentConfirmationAvailable();

Without the window, I just got:

PaymentRequest?.isSecurePaymentConfirmationAvailable()
Uncaught ReferenceError: PaymentRequest is not defined
    <anonymous> debugger eval code:1
debugger eval code:1:1

if (!spcAvailable) {
/* Browser does not support SPC; merchant should fallback to traditional flows. */
}
Expand Down
Loading