From e07946bcb5c861f004b6b92a1e632dd1622ad15d Mon Sep 17 00:00:00 2001
From: Domenic Denicola
Date: Tue, 13 Dec 2016 12:13:13 -0500
Subject: [PATCH] Various fixes to the PaymentRequest constructor
- Fixes #373: align ordering of steps with Blink's implementation, except check for allowed-to-use first since that makes more sense
- Fixes #334: properly get the total.amount.value instead of pretending total is a string
- Fixes #333 and fixes #335: do not assume various dictionaries are present
- Fixes part of #321: use proper dictionary terminology
- Ensures request.[[details]].shippingOptions/modifiers is always a sequence, instead of sometimes left as not present
- Fixes various algorithm structure and typographic issues
---
index.html | 301 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 199 insertions(+), 102 deletions(-)
diff --git a/index.html b/index.html
index 243571cd..4936663a 100644
--- a/index.html
+++ b/index.html
@@ -346,21 +346,6 @@
If a paymentRequestID
was not provided during construction, generate a paymentRequestID
.
- If the length of the methodData sequence is zero, then
- throw a TypeError; optionally informing the developer
- that at least one payment method is required.
-
- For each paymentMethod of methodData:
-
- - If the length of the supportedMethods
- sequence is zero, then throw a TypeError;
- optionally informing the developer that each payment
- method needs to include at least one payment method
- identifier.
-
-
-
If the current settings object has a responsible
browsing context that is not a top-level browsing context,
then
@@ -379,70 +364,200 @@
- If the details argument does not contain a value for
- total, then throw a
- TypeError; optionally informing the developer that including a
- total is required.
-
- If details.total.amount.value is not a
- valid decimal monetary value, then throw a TypeError;
- optionally informing the developer that the value is invalid.
-
- If the first character of details.total.amount.value is
- U+002D HYPHEN-MINUS, then throw a TypeError; optionally
- informing the developer that total can't be a negative amount
- value.
-
- If the sequence of details.displayItems contains any
- PaymentItem objects with an amount that is not a valid decimal
- monetary value, then throw a TypeError; optionally
- informing the developer that the value is invalid.
-
- If the sequence of details.shippingOptions contains
- any PaymentShippingOption objects with an amount that is not a valid
- decimal monetary value, then throw a TypeError; optionally
- informing the developer that the value is invalid.
-
- If details
contains a value for error
,
- then throw a TypeError.
-
- For each paymentMethod in the methodData
- argument, if the data field
- is supplied but is not a JSON-serializable object, then
- throw a TypeError.
-
- For each paymentDetailsModifier in details.modifiers:
+ Process payment methods:
+
+ - If the length of the methodData sequence is zero,
+ then throw a TypeError, optionally informing the
+ developer that at least one payment method is required.
+
+ - For each paymentMethod of methodData:
+
+ - If the length of the
+ paymentMethod.supportedMethods
+ sequence is zero, then throw a TypeError,
+ optionally informing the developer that each payment
+ method needs to include at least one payment method
+ identifier.
+
+ - If the data
+ member of paymentMethod is present, but
+ paymentMethod.data is not a
+ JSON-serializable object, then throw a
+ TypeError.
+
+
+
+
+
+ Process the total:
+
+ - If the total member of
+ details is not present, then throw a
+ TypeError, optionally informing the developer that
+ including total is
+ required.
+
+ - If details.total.amount.value is not a valid decimal
+ monetary value, then throw a TypeError;
+ optionally informing the developer that the value is invalid.
+
+ - If the first character of details.total.amount.value is U+002D HYPHEN-MINUS,
+ then throw a TypeError, optionally informing the
+ developer that the total can't be negative.
+
+
+
+ If the displayItems
+ member of details is present, then for each
+ item in details.displayItems:
+
+ - If item.amount.value is not a valid decimal
+ monetary value, then throw a TypeError,
+ optionally informing the developer that the value is invalid.
+
+
+
+ Let selectedShippingOption be null.
+
+ Process shipping options:
- - If the total field is
- supplied and is not a valid decimal monetary value, then
- throw a TypeError; optionally informing the developer that
- the value is invalid.
+
- Let options be an empty
+
sequence
<PaymentShippingOption>.
- - If the total field is
- supplied and the first character of
-
total.amount.value
is U+002D HYPHEN-MINUS, then
- throw a TypeError; optionally informing the developer that
- the value can't be non-negative amount.
+ - If the shippingOptions member of
+ details is present, then:
+
+ - Let seenIDs be an empty list.
+
+ - Set options to
+ details.shippingOptions.
+
+ - For each option in options:
+
+ - If option.amount.value is not a valid
+ decimal monetary value, then throw a
+ TypeError, optionally informing the developer that
+ the value is invalid.
+
+ - If seenIDs contains
+ option.id, then set
+ options to an empty sequence and break.
+
+ - Append option.id to seenIDs.
+
+
+
+ - For each option in options (which
+ may have been reset to the empty sequence in the previous
+ step):
+
+ - If option.selected is true,
+ then set selectedShippingOption to
+ option.id.
+
+
+
+
- - If the sequence of additionalDisplayItems
- contains any PaymentItem objects with an amount that is not a valid decimal
- monetary value, then throw a TypeError; optionally
- informing the developer that the value is invalid.
+
- Set details.shippingOptions to
+ options.
+ Process payment details modifiers:
+
+ - Let modifiers be an empty
+
sequence
<PaymentDetailsModifier>.
+
+ - If the modifiers
+ member of details is present, then:
+
+ - Set modifiers to
+ details.modifiers.
+
+ - For each modifier of modifiers:
+
+ - If the total member of
+ modifier is present, then:
+
+ - Let value be
+ modifier.total.amount.value.
+
+ - If value is not a valid decimal
+ monetary value, then throw a TypeError,
+ optionally informing the developer that the value is
+ invalid.
+
+ - If the first character of value is
+ U+002D HYPHEN-MINUS, then throw a TypeError,
+ optionally informing the developer that the value
+ can't be negative.
+
+
+
+ - If the additionalDisplayItems
+ member of modifier is present, then for each
+ item of modifier.additionalDisplayItems:
+
+ - Let value be
+ item.amount.value.
+
+ - If value is not a valid decimal
+ monetary value, then throw a TypeError,
+ optionally informing the developer that the value is
+ invalid.
+
+
+
+
+
+ - Set details.modifiers to
+ modifiers.
+
+
+
+
+
+ If the error member of
+ details is present, then throw a TypeError,
+ optionally informing the developer that an error message cannot be
+ specified in the constructor.
+
Let request be a new PaymentRequest.
+ Set request.[[\options]] to options.
+
+ Set request.[[\state]] to created.
+
+ Set request.[[\updating]] to false.
+
+ Set request.[[\details]] to details.
+
Set request.[[\methodData]] to
@@ -456,30 +571,28 @@
presenting payment methods.
- Set request.[[\details]] to details.
-
- Set request.[[\options]] to options.
-
- Set request.[[\state]] to created.
+ Set the value of request's shippingOption attribute to
+ selectedShippingOption.
Set the value of the
shippingAddress attribute on request to null.
- Set the value of the
- shippingOption attribute on request to null.
-
Set the value of the shippingType attribute on
request to null.
- If options.requestShipping
is set to true, then set
- the value of the If options.requestShipping is set to true,
+ then set the value of the shippingType attribute on
- request to options.shippingType
. If
- options.shippingType
is not a valid
- PaymentShippingType value then set the shippingType attribute on
- request to "shipping"
.
+ request to options.shippingType. If
+ options.shippingType is not a valid
+ PaymentShippingType value then set the value of the
+ shippingType attribute
+ on request to "shipping
".
This behavior allows a page to detect if it supplied an
unsupported shipping type. This will be important if new shipping
@@ -487,22 +600,6 @@
page is run in a user agent supporting an earlier version.
- If the details.shippingOptions
sequence contains
- multiple PaymentShippingOption objects that have the same
- id
, then set the shippingOptions field of
- request.[[\details]] to an empty sequence.
-
- If request.[[\details]] contains a
- shippingOptions
sequence and if any
- PaymentShippingOption in the sequence has the
- selected
field set to true, then set shippingOption to the
- id
of the last PaymentShippingOption in the
- sequence with selected
set to true.
-
- Set request.[[\updating]] to false.
-
Return request.