w3c / payment-request

Payment Request API
https://www.w3.org/TR/payment-request/
Other
489 stars 135 forks source link

Clarification question for `show()` algorithm #820

Closed rsolomakhin closed 5 years ago

rsolomakhin commented 5 years ago

TL;DR: Can show() be called on the same instance of PaymentRequest multiple times?

The show() algorithm includes the following steps:

  1. If request.[[state]] is not "created" then return a promise rejected with an "InvalidStateError" DOMException.
  2. If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.
  3. Set request.[[state]] to "interactive".

It looks like show() can be rejected without altering the request.[[state]], so the merchant can call show() on the same instance of PaymentRequest. Is this the only edge case where show() does not change state? Or am I reading the spec wrong?

marcoscaceres commented 5 years ago

TL;DR: Can show() be called on the same instance of PaymentRequest multiple times?

So, yes:

I don't think that's a bug... it's an oddity, for sure... but I don't think it's terrible.

I'll check what Firefox does...

marcoscaceres commented 5 years ago

Ok, made a fiddle: https://jsfiddle.net/cuz5mt6h/11/

Ok, so, in step 7, we should set the state to "closed".

@aestes, is that ok?

marcoscaceres commented 5 years ago

Ok, made a test page for Safari:

https://fiddle.jshell.net/cuz5mt6h/11/show/

Safari follows the spec (it show()s the second request, even after aborting the first .show()). I don't have a strong opinion - so if @aestes is ok with us changing step 7 above to "close" the state (and there is no valid use case for it), then that's fine.

I'll draft a PR in the meantime, as it's really simple to fix.