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

Allow incremental request of billing and shipping address #873

Closed
wants to merge 52 commits into from
Closed
Changes from 5 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
36e6d65
very rough sketch of requestShippingAddress() method
danyao Jun 28, 2019
86af323
Use sequence instead of FrozenArray for requestShippingAddress() para…
danyao Sep 12, 2019
167f610
Apply reviewer suggestion.
danyao Sep 12, 2019
7c6233c
Add asides to encourage usage of requestShippingAddress.
danyao Sep 13, 2019
28f206c
Reformat and added notes to PaymentOptions section
danyao Sep 13, 2019
3ca2bab
Added incremental handling of billing address
danyao Oct 16, 2019
b7b503f
Reworded request{Billing|Shipping}Address to better incorporate into …
Oct 28, 2019
f037a39
Update index.html
danyao Nov 5, 2019
8648042
Update index.html
danyao Nov 5, 2019
f7a2b96
Update index.html
danyao Nov 5, 2019
3b8c4bb
Update index.html
danyao Nov 5, 2019
6cdff80
Update index.html
danyao Nov 5, 2019
8567e29
Update index.html
danyao Nov 5, 2019
96d3ad8
Update index.html
danyao Nov 5, 2019
7005bd7
Update index.html
danyao Nov 5, 2019
bd7d71d
Update index.html
danyao Nov 5, 2019
b8d5a1a
Update index.html
danyao Nov 5, 2019
3477651
Update index.html
danyao Nov 5, 2019
bfb61f5
Update index.html
danyao Nov 5, 2019
1c704b3
Update index.html
danyao Nov 5, 2019
fffefde
Update index.html
danyao Nov 5, 2019
9204c1f
Update index.html
danyao Nov 5, 2019
3a0014b
Update index.html
danyao Nov 5, 2019
27e8ddc
Update index.html
danyao Nov 5, 2019
a03bdf2
Update index.html
danyao Nov 5, 2019
75eab00
Update index.html
danyao Nov 5, 2019
2a3a327
Update index.html
danyao Nov 5, 2019
dc29a17
Update index.html
danyao Nov 5, 2019
b2ecd08
Update index.html
danyao Nov 5, 2019
d906d80
Update index.html
danyao Nov 5, 2019
0409663
Update index.html
danyao Nov 5, 2019
95308b2
Update index.html
danyao Nov 5, 2019
f39882d
Update index.html
danyao Nov 5, 2019
663ad79
Update index.html
danyao Nov 5, 2019
62c3122
Add link for redact list
Nov 5, 2019
ff6e092
Scope request*Address() to inside updateWith()
Nov 5, 2019
a4b426f
Update index.html
danyao Nov 13, 2019
1cc8745
Update index.html
danyao Nov 13, 2019
9d4e378
Update index.html
danyao Nov 13, 2019
6a5e9a9
Update index.html
danyao Nov 13, 2019
a60cd74
Update index.html
danyao Nov 13, 2019
f94504c
Update index.html
danyao Nov 13, 2019
7dafa28
Update index.html
danyao Nov 13, 2019
4ee4abf
Refactored algorithm and improved examples
Nov 13, 2019
3576016
Add PaymentMethodChangeEvent.constructor
Nov 13, 2019
a0fcb36
Update index.html
danyao Nov 13, 2019
12d30c2
Update index.html
danyao Nov 13, 2019
32f50df
Update index.html
danyao Nov 13, 2019
fa7d1c6
Update index.html
danyao Nov 13, 2019
5e9016a
tidy
marcoscaceres Dec 16, 2019
359fda5
Merge branch 'gh-pages' into danyao-requestShippingAddress
Feb 12, 2020
5f5bbc1
Merge branch 'gh-pages' into danyao-requestShippingAddress
Feb 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,91 @@ <h2>
</dd>
</dl>
</section>
<section data-dfn-for="AddressParts">
<h2>
<dfn>AddressParts</dfn> enum
</h2>
<pre class="idl">
enum AddressParts {
"addressLine",
"city",
"country",
"dependentLocality",
"organization",
"phone",
"postalCode",
"recipient",
"region",
"sortingCode"
};
</pre>
<p>
The {{AddressParts}} enum is used to represent individual parts of a
<a>physical address</a>.
</p>
<dl data-dfn-for="AddressFields">
danyao marked this conversation as resolved.
Show resolved Hide resolved
<dt>
"<dfn>addressLine</dfn>"
</dt>
<dd>
The <a>address line</a>.
</dd>
<dt>
"<dfn>city</dfn>"
</dt>
<dd>
The <a>city</a>.
</dd>
<dt>
"<dfn>country</dfn>"
</dt>
<dd>
The <a>country</a>.
</dd>
<dt>
"<dfn>dependentLocality</dfn>"
</dt>
<dd>
The <a>dependent locality</a>.
</dd>
<dt>
"<dfn>organization</dfn>"
</dt>
<dd>
The <a>organization</a>.
</dd>
<dt>
"<dfn>phone</dfn>"
</dt>
<dd>
The <a>phone number</a>.
</dd>
<dt>
"<dfn>postalCode</dfn>"
</dt>
<dd>
<a>postal code</a>.
</dd>
<dt>
"<dfn>recipient</dfn>"
</dt>
<dd>
The <a>recipient</a>.
</dd>
<dt>
"<dfn>region</dfn>"
</dt>
<dd>
The <a>region</a>.
</dd>
<dt>
"<dfn>sortingCode</dfn>"
</dt>
<dd>
The <a>sorting Code</a>.
</dd>
</dl>
</section>
<section data-dfn-for="PaymentShippingType">
<h2>
<dfn>PaymentShippingType</dfn> enum
Expand Down Expand Up @@ -2137,6 +2222,19 @@ <h2>
example, this would be set to true when physical goods need to be
shipped by the merchant to the user. This would be set to false for
the purchase of digital goods.
<aside class="note">
<p>
A developer may not need the full shipping address of a user, for
example, just having "country" may be sufficient to calculate
shipping cost. To be sensitive to user's privacy, developers should
prefer to use <a>PaymentRequestUpdateEvent.requestShippingAddress()
</a> to incrementally request only the address parts they need.
</p>
<p>
A future version of this specification may remove the all-in-one
{{PaymentOptions.requestShipping}} boolean.
</p>
danyao marked this conversation as resolved.
Show resolved Hide resolved
</aside>
</dd>
<dt>
<dfn>shippingType</dfn> member
Expand Down Expand Up @@ -3952,6 +4050,7 @@ <h2>
[SecureContext, Exposed=Window]
interface PaymentRequestUpdateEvent : Event {
constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict = {});
Promise&lt;PaymentAddress&gt; requestShippingAddress(sequence&lt;AddressParts&gt; addressParts);
void updateWith(Promise&lt;PaymentDetailsUpdate&gt; detailsPromise);
};
</pre>
Expand Down Expand Up @@ -3981,6 +4080,111 @@ <h3>
</li>
</ol>
</section>
<section>
<h2>
<dfn data-lt="requestShippingAddress(addressParts)">requestShippingAddress()</dfn> method
</h2>
<aside class="note">
<p>
Detailed shipping address contains sensitive user information.
Developers are encouraged to use {{requestShippingAddress()}}
to incrementally request pieces they require instead of asking for
all up front using the {{PaymentOptions.requestShipping}}
boolean. For example, if flat-rate shipping is available in
country A but only variable per-region shipping is available in
country B, a developer should request only "country" first and
decide if "region" is needed.
</p>
<p>
A future version of this specification may remove the all-in-one
{{PaymentOptions.requestShipping}} boolean.
</p>
danyao marked this conversation as resolved.
Show resolved Hide resolved
<p>
A developer can call {{requestShippingAddress()}} repeatedly.
Each call returns a promise that resolves to a {{PaymentAddress}}
with all previously requested address fields populated.
</p>
<p>
If a requested address part is also in the redact list of shipping
address, then the returned {{PaymentAddress}} will not have the
corresponding field populated.
</p>
<pre class="example js" title=
"how to use `requestShippingAddress()` correctly.">
request.onshippingaddresschange = ev =&gt; {
const promiseForUpdatingShippingCost =
ev.requestShippingAddress(["country", "postal_code"])
.then(address =&gt; {
const promiseForUpdate = getNewDetails(address);
return promiseForUpdate;
});
ev.updateWith(promiseForUpdatingShippingCost);
};
</pre>
</aside>
<p>
The <a><code>requestShippingAddress(|addressParts|)</code></a> method MUST act as
follows:
</p>
<ol class="algorithm">
<li>Let |event:PaymentRequestUpdateEvent| be this
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
{{PaymentRequestUpdateEvent}} instance.
</li>
<li>If |event|'s {{ Event.isTrusted }} attribute is false, then
danyao marked this conversation as resolved.
Show resolved Hide resolved
return <a>a promise rejected with</a> an {{"InvalidStateError"}}
{{DOMException}}.
</li>
<li>If |event|'s [=Event/target=] is an instance of
<a>PaymentResponse</a>, let |request:PaymentRequest| be |event|'s
[=Event/target=].<a>[[\request]]</a>.
</li>
<li>Otherwise, let |request:PaymentRequest| be the value of
|event|'s [=Event/target=].
</li>
<li>Assert: |request| is an instance of {{PaymentRequest}}.
</li>
<li>If |request|.<a>[[\state]]</a> is not "<a>interactive</a>",
then return <a> a promise rejected with</a> an {{"InvalidStateError"}}
{{DOMException}}.
</li>
<li>Let |shippingAddressPromise:Promise| be <a>a new promise</a>.</li>
<li>Return |shippingAddressPromise|, and perform the remaining steps <a>in
parallel</a>.
</li>
<li>Let |shippingAddress:PaymentAddress| be |request|'s
[=PaymentRequest/shippingAddress=].
<aside class="note">
This address should have already been redacted according to the
<a>shipping address changed algorithm</a>.
</aside>
</li>
<li>Let |details:AddressInit| be an {{AddressInit}} dictionary with
no members present.
</li>
<li>For each attribute |attributeName| in |shippingAddress:PaymentAddress|:
<ol>
<li>Set |details|[|attributeName|] to the value of
|shippingAddress|.[[|attributeName|]] if it is not empty.
</li>
</ol>
</li>
<li>Let |redactList| be the empty list. Set |redactList| to
« "organization", "phone", "recipient", "addressLine" ».
</li>
<li>For each |addressPart| in |addressParts|:
<ol>
<li>If |details|[|addresPart|] is already present, continue.</li>
<li>If |addressPart| is in |redactList|, continue. </li>
<li>Set |details|[|addressPart|] to the user provided value.</li>
</ol>
</li>
<li><a data-lt="PaymentAddress.PaymentAddress()">Internally construct
a new <a>PaymentAddress</a> with |details| and resolve
|shippingAddressPromise| with the result.
</li>
</ol>
</p>
</section>
<section>
<h2>
<dfn data-lt="updateWith(detailsPromise)">updateWith()</dfn> method
Expand Down