diff --git a/index.html b/index.html index a8022918..5390bc4b 100644 --- a/index.html +++ b/index.html @@ -174,6 +174,7 @@

interface PaymentRequest : EventTarget { Promise<PaymentResponse> show(); Promise<void> abort(); + Promise<boolean> canMakePayment(); readonly attribute PaymentAddress? shippingAddress; readonly attribute DOMString? shippingOption; @@ -523,6 +524,84 @@

+
+

+ canMakePayment() method +

+

+ The canMakePayment method can be called by the page to know + if user has a payment method available for payment before calling + show. The canMakePayment method returns + a Promise that will be resolved when the user agent has determined + if at least one method is available from supportedMethods data. + + In order to prevent the page from probing different payment methods supported by user, canMakePayment + can only be called once per top-level domain. Multiple calls to canMakePayment will result in + rejection of the promise with QuotaExceededError. To reduce privacy risks, implementations MAY limit calls + to canMakePayment for a certain period of time before allowing top-level origin to call + canMakePayment again. However canMakePayment can be called multiple times with same + set of supportedMethods per top-level origin. +

+

+ The canMakePayment method MUST act as follows: +

+
    +
  1. + Let this be the PaymentRequest object on which the method is called. +
  2. +
  3. + If the value of request@[[\state]] is not "created", then + reject promise with InvalidStateError. +
  4. +
  5. + Set the value of request@[[\state]] to "interactive". +
  6. +
  7. + Let canMakePaymentPromise be a new Promise. +
  8. +
  9. + Store canMakePaymentPromise in request@[[\canMakePaymentPromise]]. +
  10. +
  11. + Return canMakePaymentPromise and asynchronously perform the remaining steps. +
  12. +
  13. + Let topLevelOrigin be the URL of the top level page. + Let cachedSupportedMethods be supportedMethods sequences from each PaymentMethodData from previous call to PaymentRequest. + Let cachedResponse be response from previous call to canMakePayment. + Let canMakePaymentQuotaReached be boolean value of previous call to canMakePayment for the topLevelOrigin. +
  14. +
  15. + Let supportedMethods be the union of all the supportedMethods sequences from each + PaymentMethodData in the request@[[\methodData]] sequence. +
  16. +
  17. + If cachedSupportedMethods is preset and matches supportMethods, + then resolve canMakePaymentPromise with cachedResponse. Else, + set cachedSupportedMethods to supportedMethods. +
  18. +
  19. + If canMakePaymentQuotaReached is set, then reject the canMakePaymentPromise + with QuotaExceededError. +
  20. +
  21. + Let acceptedMethods be supportedMethods with all identifiers removed that the + user agent does not support. +
  22. +
  23. + If the length of acceptedMethods is zero, then resolve canMakePaymentPromise with + false, otherwise resolve acceptPromise with true. +
  24. +
  25. + Cache the response in cachedResponse and set canMakePaymentQuotaReached to + to true. +
  26. +
  27. + In addition, implementations may choose to implement a timeout to reset + canMakePaymentQuotaReached for the topLevelOrigin. +
  28. +
+

State transitions