From c3a3ff7d2491b921efa4e22820255650e180cc8b Mon Sep 17 00:00:00 2001 From: Ade Bateman Date: Wed, 27 Apr 2016 14:34:55 -0700 Subject: [PATCH] Refactor the supportedMethods and payment specific data This change updates the first argument to the PaymentRequest constructor to combine the supportedMethods and payment method specific data. By making this change it is possible to share an instance of data amongst multiple payment methods that wasn't possible before. --- specs/paymentrequest.html | 110 +++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/specs/paymentrequest.html b/specs/paymentrequest.html index a1601a59..b631e315 100644 --- a/specs/paymentrequest.html +++ b/specs/paymentrequest.html @@ -226,7 +226,7 @@

Dependencies

PaymentRequest interface

-        [Constructor(sequence<DOMString> supportedMethods, PaymentDetails details, optional PaymentOptions options, optional object data)]
+        [Constructor(sequence<PaymentMethodData> methodData, PaymentDetails details, optional PaymentOptions options)]
         interface PaymentRequest : EventTarget {
           Promise<PaymentResponse> show();
           void abort();
@@ -255,7 +255,7 @@ 

PaymentRequest interface

user interaction:

-        var payment = new PaymentRequest(supportedMethods, details, options, data);
+        var payment = new PaymentRequest(methodData, details, options);
         payment.addEventListener("shippingaddresschange", function (changeEvent) {
             // Process shipping address change
         });
@@ -273,9 +273,9 @@ 

PaymentRequest interface

PaymentRequest constructor

- The PaymentRequest is constructed using the supplied supportedMethods - list, the payment details, the payment options, and any payment - method specific data. + The PaymentRequest is constructed using the supplied methodData + list including any payment method specific data, the payment details, + and the payment options.

It is proposed that a conformance criteria for implementations of this API be @@ -286,10 +286,21 @@

PaymentRequest constructor

payment app.
-

The supportedMethods sequence contains the payment method identifiers - for the payment methods that the merchant web site accepts.

+

The methodData sequence contains PaymentMethodData dictionaries + containing the payment method identifiers for the payment methods that the web site accepts + and any associated payment method specific data.

-            ["visa", "bitcoin", "bobpay.com"]
+            [
+              {
+                supportedMethods: ["visa","bitcoin"]
+              },
+              {
+                supportedMethods: ["bobpay.com"],
+                data: {
+                  "merchantIdentifier": "XXXX",
+                  "bobPaySpecificField": true
+              }
+            ]
           

The details object contains information about the transaction that the @@ -324,24 +335,10 @@

PaymentRequest constructor

"requestShipping": true }
- -

data is a JSON-serializable object that provides optional information that might - be needed by the supported payment methods.

-
-            {
-              "bobpay.com": {
-                  "merchantIdentifier": "XXXX",
-                  "bobPaySpecificField": true
-              },
-              "bitcoin": {
-                  "address": "XXXX"
-              }
-            }
-          
- There is an open issue about whether supportedMethods, details, and data + There is an open issue about whether methodData, details, and data should be combined into a single object.
@@ -375,9 +372,13 @@

PaymentRequest constructor

  1. - If the length of the supportedMethods sequence is zero, then throw + If the length of the methodData sequence is zero, then throw a TypeError.
  2. +
  3. + For each PaymentMethodData dictionary, if the length of the + supportedMethods sequence is zero, then throw a TypeError. +
  4. If the global object of the script calling the constructor is not considered a secure context, then throw a SecurityError. @@ -402,21 +403,14 @@

    PaymentRequest constructor

    than zero, then throw a TypeError.
  5. - If data is not a JSON-serializable object, then throw a TypeError. -
  6. -
  7. - If the name of any top level field of data does not match one of the payment method identifiers - in supportedMethods, then throw a TypeError. -
  8. -
  9. - If the value of any top level field is not a JSON-serializable object, then - throw a TypeError. + For each PaymentMethodData in methodData, if the data field + is supplied but is not a JSON-serializable object, then throw a TypeError.
  10. Let request be a new PaymentRequest.
  11. - Store supportedMethods into request@[[\supportedMethods]]. + Store methodData into request@[[\methodData]].

    - The supportedMethods supplied to the PaymentRequest constructor + The methodData supplied to the PaymentRequest constructor SHOULD be in the order of preference of the caller. Implementations MAY show payment methods in this order if possible but SHOULD prioritize the preference of the user when presenting payment methods. @@ -424,7 +418,6 @@

    PaymentRequest constructor

  12. Store details into request@[[\details]].
  13. Store options into request@[[\options]].
  14. -
  15. Store data into request@[[\data]].
  16. Set the value request@[[\state]] to created.
  17. Set the value of the shippingAddress attribute on request to null. @@ -472,11 +465,16 @@

    show()

    Return acceptPromise and asynchronously perform the remaining steps.
  18. - Let acceptedMethods be the sequence of payment method identifiers request@[[\supportedMethods]] - with all identifiers removed that the user agent does not accept. + Let supportedMethods be the union of all the supportedMethods sequences from each + PaymentMethodData in the request@[[\methodData]] sequence. +
  19. +
  20. + Let acceptedMethods be supportedMethods with all identifiers removed that the + user agent does not accept.
  21. - If the length of acceptedMethods is zero, then reject acceptPromise with a NotSupportedError. + If the length of acceptedMethods is zero, then reject acceptPromise with a + NotSupportedError.
  22. Show a user interface to allow the user to interact with the payment request process. The acceptPromise will @@ -544,8 +542,8 @@

    Internal Slots

    - - + + @@ -558,13 +556,6 @@

    Internal Slots

    - - - - @@ -588,6 +579,29 @@

    Internal Slots

    +
    +

    PaymentMethodData dictionary

    +
    +        dictionary PaymentMethodData {
    +          required sequence<DOMString> supportedMethods;
    +          object data;
    +        };
    +      
    +

    + A PaymentMethodData dictionary is used to indicate a set of supported payment + methods and any associated payment method specific data for those methods. +

    +

    The following fields are part of the PaymentMethodData dictionary:

    +
    +
    supportedMethods
    +
    supportedMethods is a required sequence of strings containing payment method identifiers for + payment methods that the merchant web site accepts.
    +
    data
    +
    data is a JSON-serializable object that provides optional information that + might be needed by the supported payment methods.
    +
    +
    +

    CurrencyAmount

    Internal SlotDescription (non-normative)
    [[\supportedMethods]]The supportMethods supplied to the constructor.[[\methodData]]The methodData supplied to the constructor.
    [[\details]] [[\options]] The PaymentOptions supplied to the constructor.
    [[\data]] - The payment method specific data supplied to the constructor used - by a Payment App to influence the app's behavior. -
    [[\state]] The current state of the payment request.