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

Make UAs throw for invalid monetary amounts #256

Merged
merged 5 commits into from
Sep 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 65 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,46 @@ <h2>PaymentRequest constructor</h2>
<a><code>TypeError</code></a>.
</li>
<li>
If <code>details</code> contains a value for <code>error</code>, then throw a
If <code>details.total.amount.value</code> is not a <a>valid decimal monetary value</a>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>
If the first character of <code>details.total.amount.value</code> is U+002D HYPHEN-MINUS, then throw a
<a><code>TypeError</code></a>. <code>total</code> MUST be a non-negative amount.
</li>
<li>
If the <code>details.displayItems</code> sequence contains any <a><code>PaymentItem</code></a>
objects with an <code>amount</code> that is not a <a>valid decimal monetary value</a>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>
If the <code>details.shippingOptions</code> sequence contains any <a><code>PaymentShippingOption</code></a>
objects with an <code>amount</code> that is not a <a>valid decimal monetary value</a>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>
If <code>details</code> contains a value for <code>error</code>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>
For each <a><code>PaymentMethodData</code></a> in <code>methodData</code>, if the <code>data</code> field
is supplied but is not a <a>JSON-serializable object</a>, then <a>throw</a> a <a><code>TypeError</code></a>.
</li>
<li>
For each <a><code>PaymentDetailsModifier</code></a> in <code>details.modifiers</code>, if the <code>total</code> field
is supplied and is not a <a>valid decimal monetary value</a>, then throw a <a><code>TypeError</code></a>.
</li>
<li>
For each <a><code>PaymentDetailsModifier</code></a> in <code>details.modifiers</code>, if the <code>total</code> field
is supplied and the first character of <code>total.amount.value</code> is U+002D HYPHEN-MINUS, then throw a
<a><code>TypeError</code></a>. <code>total</code> MUST be a non-negative amount.
</li>
<li>
For each <a><code>PaymentDetailsModifier</code></a> in <code>details.modifiers</code>, if the
<code>additionalDisplayItems</code> sequence contains any <a><code>PaymentItem</code></a>
objects with an <code>amount</code> that is not a <a>valid decimal monetary value</a>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>Let <em>request</em> be a new <a><code>PaymentRequest</code></a>.</li>
<li>
Store <code>methodData</code> into <em>request</em>@[[\methodData]].
Expand Down Expand Up @@ -648,12 +672,18 @@ <h2>PaymentCurrencyAmount</h2>
</dd>
<dt><code><dfn>value</dfn></code></dt>
<dd>
A string containing the decimal monetary value. If a decimal separator is needed, then the string
MUST use a single U+002E FULL STOP character as the decimal separator. The string MUST begin
with a single U+002D HYPHEN-MINUS character if the value is negative. All other characters must
be characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).
A <a>valid decimal monetary value</a> containing a monetary amount. A string is a <dfn>valid
decimal monetary value</dfn> if it consists of the following components in the given order:
<ol>
<li>Optionally, a single U+002D HYPHEN-MINUS character (-), to indicate that the amount is
negative</li>
<li>One or more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9)</li>
<li>Optionally, a single U+002E FULL STOP character (.) followed by one or more characters in
the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9)</li>
</ol>
<div class="note">
The string matches the regular expression <code>^-?[0-9]+(\.[0-9]+)?$</code>.
The following regular expression is an implementation of the above definition.
<pre class="hljs">^-?[0-9]+(\.[0-9]+)?$</pre>
</div>
</dd>
</dl>
Expand Down Expand Up @@ -1193,29 +1223,48 @@ <h2>updateWith()</h2>
<a><code>PaymentDetails</code></a> dictionary, then:
<ol>
<li>
If <code>details</code> contains a <code>total</code> value and the first character of
If <code>details</code> contains a <code>total</code> value and <code>total.amount.value</code>
is a <a>valid decimal monetary value</a> and the first character of
<code>total.amount.value</code> is NOT U+002D HYPHEN-MINUS, then copy
<code>total</code> value to the <code>total</code> field of <em>target</em>@[[\details]]
(<code>total</code> MUST be a non-negative amount).
</li>
<li>
If <code>details</code> contains a <code>displayItems</code> value, then copy
this value to the <code>displayItems</code> field of <em>target</em>@[[\details]].
If <code>details</code> contains a <code>displayItems</code> value and every
<a><code>PaymentItem</code></a> in the <code>displayItems</code> has an
<code>amount.value</code> containing a <a>valid decimal monetary value</a>,
then copy <code>details.displayItems</code> to the <code>displayItems</code>
field of <em>target</em>@[[\details]].
</li>
<li>
If <code>details</code> contains a <code>modifiers</code> value, then copy
this value to the <code>modifiers</code> field of <em>target</em>@[[\details]].
If <code>details</code> contains a <code>modifiers</code> value, then:
<ol>
<li>Let <em>modifiers</em> be the sequence <code>details.modifiers</code>.</li>
<li>For each <a><code>PaymentDetailsModifier</code></a> in <em>modifiers</em>, if the
<code>total</code> field is supplied and is not a <a>valid decimal monetary value</a>,
then set <em>modifiers</em> to an empty sequence.</li>
<li>For each <a><code>PaymentDetailsModifier</code></a> in <em>modifiers</em>, if the
<code>additionalDisplayItems</code> sequence contains any <a><code>PaymentItem</code></a>
objects with an <code>amount</code> that is not a <a>valid decimal monetary value</a>,
then set <em>modifiers</em> to an empty sequence.</li>
<li>Copy <em>modifiers</em> to the <code>modifiers</code> field of <em>target</em>@[[\details]].</li>
</ol>
</li>
<li>
If <code>details</code> contains a <code>shippingOptions</code> sequence, then:
<ol>
<li>Let <em>shippingOptions</em> be the sequence <code>details.shippingOptions</code>.</li>
<li>
If the <code>details.shippingOptions</code> sequence contains multiple
If the <em>shippingOptions</em> sequence contains multiple
<a><code>PaymentShippingOption</code></a> objects that have the same <code>id</code>,
then set the <code>shippingOptions</code> field of <em>request</em>@[[\details]]
to an empty sequence.
Otherwise copy the <code>shippingOptions</code> sequence from <code>details</code> to the
<code>shippingOptions</code> field of <em>target</em>@[[\details]].
then set <em>shippingOptions</em> to the empty sequence.</li>
<li>
If the <em>shippingOptions</em> sequence contains a <a><code>PaymentShippingOption</code></a>
that has an <code>amount.value</code> that is not a <a>valid decimal monetary value</a>,
then set <em>shippingOptions</em> to the empty sequence.</li>
<li>
Copy <em>shippingOptions</em> to the <code>shippingOptions</code> field of
<em>target</em>@[[\details]].
</li>
<li>Let <em>newOption</em> be <em>null</em>.</li>
<li>
Expand Down