This repository has been archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
checkout-api.html
959 lines (869 loc) · 39.4 KB
/
checkout-api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
<!DOCTYPE html>
<html>
<head>
<title>Checkout API</title>
<meta charset='utf-8'>
<script src='https://www.w3.org/Tools/respec/respec-w3c-common'
async class='remove'></script>
<script class='remove'>
var respecConfig = {
specStatus: "CG-DRAFT",
shortName: "checkout-api",
editors: [
{ name: "TBD",
company: "TBD" },
],
authors: [
{ name: "Adrian Bateman",
company: "Microsoft Corporation" },
{ name: "Zach Koch",
company: "Google" },
{ name: "Dave Longley",
company: "Digital Bazaar" }
],
//previousMaturity: "FPWD",
//previousPublishDate: "1977-03-15",
wg: "Web Platform Incubator Community Group",
wgURI: "https://www.w3.org/community/wicg/",
issueBase: "https://github.com/WICG/web-payments-browser-api/issues/",
localBiblio: {
"PAYMENTARCH": {
title: "Payment Request Architecture"
, href: "architecture.html"
, authors: [
"Adrian Bateman"
]
, status: "CG-DRAFT"
},
"METHODIDENTIFIERS": {
title: "Payment Method Identifiers"
, href: "method-identifiers.html"
, authors: [
"Adrian Bateman"
]
, status: "CG-DRAFT"
},
"PAYMENTAPI": {
title: "Browser Payment API"
, href: "http://wicg.github.io/web-payments-browser-api/"
, authors: [
"Manu Sporny", "David Longley"
]
, status: "CG-DRAFT"
}
}
};
</script>
<style>
dt { margin-top: 0.75em; }
table { margin-top: 0.75em; border-collapse:collapse; border-style:hidden hidden none hidden }
table thead { border-bottom:solid }
table tbody th:first-child { border-left:solid }
table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
li { margin-top: 0.5em; margin-bottom: 0.5em;}
</style>
</head>
<body>
<section id='abstract'>
<p>
This specification describes a high-level electronic commerce checkout API to enable merchants (i.e. web sites selling
physical or digital goods) to provide a simple checkout flow for their customers.
Merchants that do not want the browser to handle the checkout flow
may use the more low-level <a href="wicg.github.io/web-payments-browser-api/">browser payment API</a>
to request payment. User agents (e.g. browsers) will facilitate the checkout flow between
merchant and user.
</p>
</section>
<section id='sotd'>
<p>
The Web Platform Incubator Community Group is incubating this specification to gather
feedback to refine the API. The specification is intended to align with the chartered scope
of the <a href="http://www.w3.org/Payments/WG/">Web Payments Working Group</a> and it is
possible that work on the API may be transferred to that group in future.
</p>
<p>
If you wish to make comments regarding this document, please contribute to the
<a href="https://github.com/WICG/Checkout/issues">issues list</a> in the
<a href="https://github.com/WICG/Checkout">GitHub repo</a>. Pull requests with
proposed text changes are welcome, but please note that you will be asked to join the Web
Platform Incubator Community Group and agree to the CLA for any substantive proposals.
</p>
</section>
<section class='informative'>
<h2>Introduction</h2>
<p>Buying things on the
web, particularly on mobile, is a frustrating experience for users. Every web site has its own flow
and its own validation rules, and most require users to manually type in the same set of information
over and over again. Likewise, it is difficult and time consuming for developers to create good
checkout flows that support various payment schemes.</p>
<p>This specification describes a high-level API that allows <a>user agents</a> (e.g. browsers) to
aid in the ecommerce checkout flow between the three key parties in every transaction: the merchant (e.g. an
online web store), the buyer (e.g. the user buying from the online web store), and the
<a>Payment Method</a> (e.g. credit card). Information necessary to process and confirm a
transaction is passed between the <a>Payment Method</a> and the merchant via the <a>user agent</a>
with the buyer confirming and authorizing as necessary across the
checkout flow.</p>
<p>In addition to better, more consistent checkout experience, this also enables web sites to take
advantage of more secure payment schemes (e.g. tokenization and system-level authentication)
that are not possible with standard JavaScript libraries. This has the potential to reduce
liability for the merchant and helps protect sensitive user information.</p>
<p>While many merchants are not interested in designing the entire checkout flow, some
may have special requirements that this API may not support. In those cases, merchants that do not want the browser to handle the checkout flow
may use the more low-level <a href="wicg.github.io/web-payments-browser-api/">browser payment API</a>
to request payment.</p>
<p>The API described in this document forms part of the Payment Request system described in
the Payment Request Architecture [[PAYMENTARCH]] document.</p>
<section id="goals">
<h2>Goals</h2>
<ul>
<li>Allow the user-agent to act as intermediary between merchants, users, and <a>payment
methods</a> in an electronic commerce checkout flow</li>
<li>Standardize (to the extent that it makes sense) the communication flow between a
merchant, user-agent, and <a>payment method</a> when checking out online</li>
<li>Allow <a>payment methods</a> to bring more secure payment transactions to the web</li>
</ul>
</section>
<section id="non-goals">
<h2>Non-goals</h2>
<ul>
<li>Not trying to create a new <a>payment method</a></li>
<li>Not trying to integrate directly with payment processors</li>
</ul>
</section>
</section>
<section id='conformance'>
<p>
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples,
and notes in this specification are non-normative. Everything else in this specification is
normative.
</p>
<p>
This specification defines one class of products:
</p>
<dl>
<dt><dfn>Conforming user agent</dfn></dt>
<dd>
<p>
A <dfn data-lt="user agents">user agent</dfn> MUST behave as described in this specification
in order to be considered conformant.
</p>
<p>
User agents MAY implement algorithms given in this
specification in any way desired, so long as the end result is
indistinguishable from the result that would be obtained by the
specification's algorithms.
</p>
<p>
A conforming Payment Request API user agent MUST also be a
<em>conforming implementation</em> of the IDL fragments
of this specification, as described in the
“Web IDL” specification. [[!WEBIDL]]
</p>
<aside class="note">
This specification uses both the terms "conforming user agent(s)"
and "user agent(s)" to refer to this product class.
</aside>
</dd>
</section>
<section id="dependencies">
<h3>Dependencies</h3>
<p>
This specification relies on several other underlying specifications.
</p>
<dl>
<dt>Payment Request Document Architecture</dt>
<dd>The terms <dfn data-lt="payment method|payment methods">Payment Method</dfn> and
<dfn data-lt="payment app|payment apps">Payment App</dfn> are defined by the Payment Request
Architecture document [[PAYMENTARCH]].</dd>
<dt>Payment Method Identifiers</dt>
<dd>The term <dfn data-lt="payment method identifier|payment method identifiers">Payment
Method Identifier</dfn> is defined by the Payment Method Identifiers specification
[[!METHODIDENTIFIERS]].</dd>
<dt>Browser Payment API</dt>
<dd>The low-level API that supports the initiation of payment can be found in [[!PAYMENTAPI]].
This specification depends on <dfn>PaymentRequest</dfn> and <dfn>NavigatorPayment</dfn> as defined in [[!PAYMENTAPI]].
</dd>
<dt>HTML5</dt>
<dd>The terms <dfn>global object</dfn>,
<dfn>queue a task</dfn>, <dfn>browsing context</dfn>, and
<dfn>top-level browsing context</dfn> are defined by [[!HTML5]].</dd>
<dt>ECMA-262 6th Edition, The ECMAScript 2015 Language Specification</dt>
<dd>
The terms <dfn>Promise</dfn>, <dfn>JSON.stringify</dfn>, and <dfn>JSON.parse</dfn> are
defined by [[!ECMA-262-2015]].
<p>The term <dfn>JSON object</dfn> used in this specification means an object that can
be serialized to a string using <a>JSON.stringify</a> and later deserialized back to an object
using <a>JSON.parse</a> with no loss of data.</p>
</dd>
<dt>DOM4</dt>
<dd>
The <code><dfn>Event</dfn></code> type and the term <dfn>fire an event</dfn> are defined by [[!DOM4]].
<p><dfn>DOMException</dfn> and the following DOMException types from [[!DOM4]] are used:</p>
<table>
<tr><th>Type</th><th>Message (optional)</th></tr>
<tr><td><code><dfn>InvalidAccessError</dfn></code></td><td>The object does not support the operation or argument</td></tr>
<tr><td><code><dfn>InvalidStateError</dfn></code></td><td>The object is in an invalid state</td></tr>
<tr><td><code><dfn>NotSupportedError</dfn></code></td><td>The payment method was not supported</td></tr>
<tr><td><code><dfn>SecurityError</dfn></code></td><td>The operation is only supported in a secure context</td></tr>
<tr><td><code><dfn>SyntaxError</dfn></code></td><td>A required parameter was missing or out-of-range</td></tr>
</table>
</dd>
<dt>WebIDL</dt>
<dd>When this specification says to <dfn>throw</dfn> an error, the <a>user agent</a> must throw an
error as described in [[!WEBIDL]]. When this occurs in a sub-algorithm, this results in
termination of execution of the sub-algorithm and all ancestor algorithms until one is
reached that explicitly describes procedures for catching exceptions.</dd>
<dt>Secure Contexts</dt>
<dd>The term <dfn>secure context</dfn> is defined by the Secure Contexts specification
[[!POWERFUL-FEATURES]].</dd>
</dl>
</section>
<section>
<h2>The <dfn>Checkout</dfn> Interface</h2>
<pre class="idl">
[Constructor]
interface Checkout : EventTarget {
Checkout send(DOMString itemType, optional Promise<sequence <CheckoutItem>> items);
Checkout request(DOMString optionType, optional Promise<sequence <CheckoutOption>> options);
attribute EventHandler onshippingAddressChange;
attribute EventHandler onshippingOptionChange;
Promise<CheckoutDetails> start();
Promise cancel(DOMString reason);
Promise finish(PaymentRequest request);
};
</pre>
<p>
This API allows merchants to collect the information they need to create a
payment request message but keeps the users in the same seamless, in-browser
checkout process. It will let a merchant site specify a line item estimate
(if necessary) and request a number of pieces of information, such as a shipping
address, that it needs before it can prepare the payment request message. Once
the merchant site has specified the information it needs, it tells the browser
to start the checkout process and waits for a promise to resolve.
</p>
<p>
The browser then opens a UI to take the user through the checkout process. The
button to finish the checkout button will be disabled until the user provides
all of the information that the merchant has requested. Sometimes some of the
information the merchant needs may depend on collecting other types of
information first. For example, the merchant may need to obtain the user's
shipping address before offering the appropriate shipping options for their
area. In this case, the merchant site may listen for an address change event
and, when it occurs, may request that the user additionally select a shipping
option from a list provided by the merchant site. The merchant may also
optionally call "cancel" if they can't ship to the user's address.
</p>
<p>
Only once all of the requested information has been provided, will the
user be able to click a button to proceed. Upon clicking it, the Promise
resolves with all the checkout details the merchant needs to generate a
payment request message. They do so and pass it to "finish" to complete the
checkout process and allow the user to pay with their choice of payment app.
</p>
<p>
Once finish is called, it internally calls navigator.payment.request(paymentRequest)
which returns a Promise that will eventually resolve to a payment
acknowledgement from the payment app selected by the user. This call causes the
in-browser UI to show the price and payment app selection screen, just like it
would have if called independently. If the user selects a payment app and
completes their payment, the merchant site will receive a payment
acknowledgement via the resolved promise, otherwise, it will receive an error.
</p>
<p>
The checkout flow and how the API is designed around it can be summed up by
considering the merchant's thought process:
</p>
<ol>
<li>
What do I need from the UA to generate a payment request? Ask for it.
If I anticipate needing more information, listen for events where
I can react to the information given so far and ask for more
information as needed.
</li>
<li>
Now I have everything I need, so generate a payment request and
finish the flow.
</li>
</ol>
<p class="issue">
This API can be used to give merchant sites a full, in-browser, checkout
experience, but builds on top of the navigator.payment.request API. It could
also be modified (internally) to build on top of other future APIs that expose
simple, low-level mechanisms for independently requesting things like shipping
address or other "identity credentials/verifiable claims" (this is aimed at
supporting The Extensible Web Manifesto approach). These APIs are not yet
exposed as low-level APIs, but this approach is an attempt to do some future
proofing should they be standardized at some point.
</p>
<p>The following examples show various <a><code>Checkout</code></a> flows
from simple to more complex:</p>
<pre id="simple-checkout-example" class="example highlight" title="A simple checkout flow">
var checkout = new Checkout();
checkout
.send('paymentItem', paymentItems) // send line item estimate to UA
.start() // start the checkout UI
.then(finishCheckout); // checkout UI has collected the info
function finishCheckout(checkoutDetails) {
// create a payment request from the checkout details
var paymentRequest = customCreatePaymentRequest(checkoutDetails);
// finish checkout will call `navigator.payment.request` internally
checkout.finish(paymentRequest).then(function(acknowledgement) {
// handle acknowledgement from payment app
}).catch(function(err) {
// handle error
});
}
</pre>
<pre id="checkout-request-address-example" class="example highlight" title="A checkout flow requesting shipping address">
var checkout = new Checkout();
checkout
.send('paymentItem', paymentItems) // send line item estimate to UA
.request('shippingAddress') // request shippingAddress from UA
.addEventListener('shippingAddressChange', shippingAddressChanged)
.start() // start the checkout UI
.then(finishCheckout); // checkout UI has collected the info
function shippingAddressChanged(event) {
var checkoutDetails = event.checkoutDetails;
if(!isAddressAcceptable(checkoutDetails.shippingAddress)) {
return checkout.cancel('We cannot ship to your address.');
}
// send updated payment items; note `send` can accept a Promise
checkout.send('paymentItem', getPaymentItems(checkoutDetails));
}
function getPaymentItems(checkoutDetails) {
// post checkout details to shipping calculation endpoint and return
// updated payment items in a Promise
return fetch('/calc-shipping', {
method: 'POST',
body: JSON.stringify(checkoutDetails)
}).then(function(res) {
return res.json();
});
}
function finishCheckout(checkoutDetails) {
// asynchronously create a payment request from the checkout details
customCreatePaymentRequest(checkoutDetails).then(function(paymentRequest) {
return checkout.finish(paymentRequest);
}).then(function(acknowledgement) {
// handle acknowledgement from payment app
}).catch(function(err) {
// handle error
});
}
</pre>
<pre id="checkout-request-address-and-option-example" class="example highlight" title="A checkout flow requesting shipping address and shipping option">
var checkout = new Checkout();
checkout
.send('paymentItem', paymentItems) // send line item estimate to UA
.request('shippingAddress') // request shippingAddress from UA
.request('shippingOption', shippingOptions) // request shippingOption from UA
.addEventListener('shippingAddressChange', shippingAddressChanged)
.addEventListener('shippingOptionChange', shippingOptionChanged)
.start() // start the checkout UI
.then(finishCheckout); // checkout UI has collected the info
function shippingAddressChanged(event) {
var checkoutDetails = event.checkoutDetails;
if(!isAddressAcceptable(checkoutDetails.shippingAddress)) {
return checkout.cancel('We cannot ship to your address.');
}
// send updated payment items; note `send` can accept a Promise
checkout.send('paymentItem', getPaymentItems(checkoutDetails));
}
function shippingOptionChanged(event) {
event.send('paymentItem', getPaymentItems(event.checkoutDetails));
}
function getPaymentItems(checkoutDetails) {
// post checkout details to shipping calculation endpoint and return
// updated payment items in a Promise
return fetch('/calc-shipping', {
method: 'POST',
body: JSON.stringify(checkoutDetails)
}).then(function(res) {
return res.json();
});
}
function finishCheckout(checkoutDetails) {
// asynchronously create a payment request from the checkout details
customCreatePaymentRequest(checkoutDetails).then(function(paymentRequest) {
return checkout.finish(paymentRequest);
}).then(function(acknowledgement) {
// handle acknowledgement from payment app
}).catch(function(err) {
// handle error
});
}
</pre>
<pre id="checkout-request-address-and-dependent-option-example" class="example highlight" title="A checkout flow requesting shipping address and address-dependent shipping option">
var checkout = new Checkout();
checkout
.send('paymentItem', paymentItems) // send line item estimate to UA
.request('shippingAddress') // request shippingAddress from UA
.addEventListener('shippingAddressChange', shippingAddressChanged)
.addEventListener('shippingOptionChange', shippingOptionChanged)
.start() // start the checkout UI
.then(finishCheckout); // checkout UI has collected the info
function shippingAddressChanged(event) {
var checkoutDetails = event.checkoutDetails;
if(!isAddressAcceptable(checkoutDetails.shippingAddress)) {
return checkout.cancel('We cannot ship to your address.');
}
// send updated payment items and additionally request shipping option
// selection; note `send` and `request` can each accept a Promise
checkout
.send('paymentItem', getPaymentItems(checkoutDetails))
.request('shippingOption', getShippingOptions(checkoutDetails.shippingAddress));
}
function shippingOptionChanged(event) {
event.send('paymentItem', getPaymentItems(event.checkoutDetails));
}
function getPaymentItems(checkoutDetails) {
// post checkout details to shipping calculation endpoint and return
// updated payment items in a Promise
return fetch('/calc-shipping', {
method: 'POST',
body: JSON.stringify(checkoutDetails)
}).then(function(res) {
return res.json();
});
}
function getShippingOptions(checkoutDetails) {
// determine shipping options from checkoutDetails.shippingAddress
// by, for example, restricting them based on country
// ...
return Promise.resolve(shippingOptions);
}
function finishCheckout(checkoutDetails) {
// asynchronously create a payment request from the checkout details
customCreatePaymentRequest(checkoutDetails).then(function(paymentRequest) {
return checkout.finish(paymentRequest);
}).then(function(acknowledgement) {
// handle acknowledgement from payment app
}).catch(function(err) {
// handle error
});
}
</pre>
<section>
<h2>send()</h2>
<p>
The <code><dfn>send</dfn></code> method queues checkout items to
send to the user agent, typically for display.
</p>
<p>
The <a><code>send</code></a> method MUST act as follows:
</p>
<ol>
<li>
...
</li>
</ol>
</section>
<section>
<h2>request()</h2>
<p>
The <code><dfn>request</dfn></code> method requests information
from the user agent that is required to create the payment request.
</p>
<p>
The <a><code>request</code></a> method MUST act as follows:
</p>
<ol>
<li>
...
</li>
</ol>
</section>
<section>
<h2>addEventListener()</h2>
<p>
The <code><dfn>addEventListener</dfn></code> method registers an
event listener for a particular type of event.
</p>
<p>
The <a><code>addEventListener</code></a> method MUST act as follows:
</p>
<ol>
<li>
...
</li>
</ol>
</section>
<section>
<h2>start()</h2>
<p>
The <code><dfn>start</dfn></code> method must ...
</p>
<p>The <a><code>start</code></a> call returns a Promise that
resolves to a <a><code>CheckoutDetails</code></a> dictionary once
the requested information has been provided by the user agent. A
website may add event listeners to capture events as the user provides
information in order to request more information as needed. Only once
all of the requested information has been provided will the Promise
resolve. At this point, the website can then create a payment request
payment request and call <a><code>finish</code></a> with it.
</p>
<p>The <a><code>start</code></a> method MUST act as follows:</p>
<ol>
<li>
...
</li>
</ol>
</section>
<section>
<h2>cancel()</h2>
<p>
The <code><dfn>cancel</dfn></code> method must ...
</p>
<p>The <a><code>cancel</code></a> method MUST act as follows:</p>
<ol>
<li>
...
</li>
</ol>
</section>
<section>
<h2>finish()</h2>
<p>
The <code><dfn>finish</dfn></code> method must ...
</p>
<p>The <a><code>finish</code></a> method MUST act as follows:</p>
<ol>
<li>
...
</li>
</ol>
</section>
<div class="issue" data-number="32" title="Should the web page be able to provide status information before calling complete()">
There is an open issue about whether there should be a way for a merchant to keep the user
informed about the progress of a transaction after the user approves the payment request.
</div>
</section>
<section>
<h2>CheckoutDetails dictionary</h2>
<pre class="idl">
dictionary CheckoutDetails {
sequence<PaymentItem> items;
ShippingAddress shippingAddress;
ShippingOption shippingOption;
};
</pre>
<p>
The Promise returned by <a><code>start</code></a> resolves to a
<code><dfn>CheckoutDetails</dfn></code> dictionary. It
provides the information requested from the user agent.
</p>
<p>
The following fields are part of the <code>CheckoutDetails</code> dictionary:
</p>
<dl>
<dt><code>items</code></dt>
<dd>
This sequence of <a><code>PaymentItem</code></a> dictionaries indicates details about
what the checkout is for. The sequence must contain at least one <code>PaymentItem</code>. The last
<code>PaymentItem</code> in the sequence represents the total payment requested. It is the
responsibility of the calling code to ensure that the total amount is the sum of the
preceding items. The <a>user agent</a> MAY not validate that this is true.
</dd>
<dt><code>shippingAddress</code></dt>
<dd>
The shipping address that the user selected. If the shipping address
is <code>null</code>, then this indicates that the user has not yet
selected a shipping address.
</dd>
<dt><code>shippingOption</code></dt>
<dd>
The shipping option that the user selected. If the option is
<code>null</code>, then this indicates that the user has not yet
selected a shipping option.
</dd>
</dl>
</section>
<section>
<h2>CheckoutItem interface</h2>
<pre class="idl">
dictionary CheckoutItem {
string id;
string label;
};
</pre>
<p>
The <a>CheckoutItem</a> dictionary is a base class for other types
of items. A web page may supply different types of information to a
user agent, typically for display to a user.
</p>
<p>
The following fields MUST be included in a <code>CheckoutItem</code> for it to be valid:
</p>
<dl>
<dt><code>id</code></dt>
<dd>This is a string identifier used to reference this <code>CheckoutItem</code>. It MUST be
unique for a given <a><code>Checkout</code></a>.</dd>
<dt><code>label</code></dt>
<dd>This is a human-readable description of the item. The <a>user agent</a> SHOULD use this
string to display the item to the user.</dd>
</dl>
</section>
<section>
<h2>PaymentItem dictionary</h2>
<pre class="idl">
dictionary PaymentItem : CheckoutItem {
FinancialAmount amount;
boolean shipping;
};
</pre>
<p>
A sequence of one or more <code>PaymentItem</code> dictionaries is included in the <a><code>CheckoutDetails</code></a>
dictionary to indicate the what the payment request is for and the value asked for.
</p>
<p>
In addition to the required fields for a <a><code>CheckoutItem</code></a>, the
following fields MUST be included in a <code>PaymentItem</code> for it to be valid:
</p>
<dl>
<dt><code>amount</code></dt>
<dd>
A <a><code>FinancialAmount</code></a> containing the monetary amount for the item.
<div class="issue" data-number="19" title="Clarity on Currency Conversion">
There is an open issue about whether there needs to be consideration of differences between
the currency specified by the merchant for the transaction amount and the currencies that
the <a>payment method</a> might support.
</div>
</dd>
</dl>
<p>
The following fields are optional and MAY be included in a <code>PaymentItem</code>:
</p>
<dl>
<dt><code>shipping</code></dt>
<dd>If the <code>shipping</code> field is included, then it indicates whether this
item represents the shipping cost when set to <code>true</code>. The <a>user agent</a>
MAY use this value to display the item differently in the user interface, perhaps
relating it to the available shipping options.</dd>
</dl>
</section>
<section>
<h2>ShippingAddress interface</h2>
<pre class="idl">
interface ShippingAddress {
/* [...] fields TBC */
};
</pre>
<p>
If the <a>requestShipping</a> flag was set to <code>true</code> in the <a>CheckoutDetails</a>
passed to the <a>Checkout</a> constructor, then the <a>user agent</a> will populate the
<code>shippingAddress</code> field of the <a><code>Checkout</code></a> object with
the user's selected shipping address.
</p>
<div class="issue" data-number="28" title="Write-up proposal for shipping address fields">
The fields of the <a><code>ShippingAddress</code></a> interface are
yet to be defined.
</div>
<div class="issue" data-number="16" title="Merchant requesting arbitrary data from the UA">
There is an open question about what data beyond shipping address the merchant might be able
to request from the <a>user agent</a>. For example, billing address, contact phone number, e-mail
address, or proof of age.
</div>
</section>
<section>
<h2>CheckoutOption interface</h2>
<pre class="idl">
dictionary CheckoutOption {
string id;
string label;
};
</pre>
<p>
The <a>CheckoutOption</a> dictionary is a base class for other types
of options. When a web page requests information from a user, it may
provide a list of options for the user to select from.
</p>
<p>
The following fields MUST be included in a <code>CheckoutOption</code> for it to be valid:
</p>
<dl>
<dt><code>id</code></dt>
<dd>This is a string identifier used to reference this <code>CheckoutOption</code>. It MUST be
unique for a given <a><code>Checkout</code></a>.</dd>
<dt><code>label</code></dt>
<dd>This is a human-readable description of the option. The <a>user agent</a> SHOULD use this
string to display the option to the user.</dd>
</dl>
</section>
<section>
<h2>ShippingOption interface</h2>
<pre class="idl">
dictionary ShippingOption : CheckoutOption {
FinancialAmount amount;
};
</pre>
<p>
The <a>ShippingOption</a> dictionary has fields describing a shipping option. A web page can
provide the user with one or more shipping options by calling <a><code>request</code></a>
method.
</p>
<p>
In addition to the required fields for a <a><code>CheckoutOption</code></a>, the
following fields MUST be included in a <code>ShippingOption</code> for it to be valid:
</p>
<dl>
<dd>This is a human-readable description of the item. The <a>user agent</a> SHOULD use this
string to display the shipping option to the user.</dd>
<dt><code>amount</code></dt>
<dd>
A <a><code>FinancialAmount</code></a> containing the monetary amount for the item.
</dd>
</dl>
</section>
<section>
<h2>Algorithms</h2>
<p class="issue">This entire section is out of date and needs to be updated if the approach above is deemed useful by the WG.</p>
<p>When the <a><code>Checkout</code></a> object is in the <code>interactive</code> state,
the <a>user agent</a> will trigger the following algorithms based on user interaction.</p>
<section>
<h2>Shipping address changed algorithm</h2>
<p>
The <dfn>shipping address changed algorithm</dfn> runs when the user provides a new shipping
address. It MUST run the following steps:
</p>
<ol>
<li>Let <em>request</em> be the <a><code>Checkout</code></a> object that the user is
interacting with.</li>
<li>Let <em>name</em> be <code><dfn>shippingaddresschange</dfn></code>.</li>
<li>
Set the <a><code>shippingAddress</code></a> attribute on <em>request</em> to the
shipping address provided by the user.
</li>
<li>
Run the <a>Checkout updated algorithm</a> with <em>request</em> and <em>name</em>.
</li>
</ol>
</section>
<section>
<h2>User agent delegates payment request algorithm</h2>
<p class="issue">This entire section is out of date and needs to be updated if the approach above is deemed useful by the WG.</p>
<p>
The <a><code>Checkout</code></a> interface allows a web page to call <code>abort</code>
to tell the <a>user agent</a> to abort the payment request and to tear down any user interface that
might be shown. For example, a web page may choose to do this the goods they are selling are
only available for a limited amount of time. If the user does not accept the payment request
within the allowed time period, then the request will be aborted.
</p>
<p>
A <a>user agent</a> may not always be able to abort a request. For example, if the <a>user agent</a>
has delegated responsibility for the request to another app. To support this situation,
the <a>user agent</a> must run the <dfn>User agent delegates payment request algorithm</dfn>.
The algorithm MUST run the following steps:
</p>
<ol>
<li>
Let <em>request</em> be the <a><code>Checkout</code></a> object that the user is
interacting with.
</li>
<li>
If the <em>updating</em> flag on <em>request</em> is <em>true</em>, then terminate this
algorithm and take no further action. The <a>user agent</a> user interface should ensure
that this never occurs.
</li>
<li>
If the <a><code>state</code></a> of <em>request</em> is not <code>interactive</code>,
then terminate this algorithm and take no further action. The <a>user agent</a> user
interface should ensure that this never occurs.
</li>
<li>
Set the <a><code>state</code></a> of <em>request</em> to <code>delegated</code>.
</li>
</ol>
<div class="issue" data-number="33" title="Should we support a delegated state for Checkout?">
<p>We believe there are <a>user agent</a> configurations that can cause the UI to get into a state
where cancellation by the web page during user interaction is difficult. Users should still
be able to cancel the payment but script will not be able to. We need to investigate in more
detail the consequences of this and whether it is really needed.</p>
<p>If we specify <code>delegated</code> then it isn't necessary for all <a>user agents</a> to be
able to move to this state but it would be necessary for all payment flows that wish to call
<a><code>abort</code></a> to account for the situation where this may fail in the <code>delegated</code>
state.</p>
</div>
</section>
<section>
<h2>User accepts the payment request algorithm</h2>
<p class="issue">This entire section is out of date and needs to be updated if the approach above is deemed useful by the WG.</p>
<p>
The <dfn data-lt="user accepts the payment request">user accepts the payment request
algorithm</dfn> runs when the user accepts the payment request and confirms that they want
to pay. It MUST run the following steps:
</p>
<ol>
<li>
Let <em>request</em> be the <a><code>Checkout</code></a> object that the user is
interacting with.
</li>
<li>
If the <em>updating</em> flag on <em>request</em> is <em>true</em>, then terminate this
algorithm and take no further action. The <a>user agent</a> user interface should ensure
that this never occurs.
</li>
<li>
If the <a><code>state</code></a> of <em>request</em> is not <code>interactive</code> and
the not <code>delegated</code>, then terminate this algorithm and take no further action.
The <a>user agent</a> user interface should ensure that this never occurs.
</li>
<li>
If the <code>requestShipping</code> value of <em>options</em> stored in <em>request</em>
is <code>true</code>, then if the <code>shippingAddress</code> attribute of <em>request</em>
is <code>null</code> or if the <code>shippingOption</code> attribute of <em>request</em>
is <code>null</code>, then terminate this algorithm and take no further action. This should
never occur.
</li>
<li>
Let <em>response</em> be a new <a><code>PaymentResponse</code></a>.
</li>
<li>
Set the <code>methodName</code> attribute value of <em>response</em> to the <a>payment method identifier</a>
for the <a>payment method</a> that the user selected to accept the payment.
</li>
<li>
Set the <code>details</code> attribute value of <em>response</em> to a <a>JSON object</a>
containing the <a>payment method</a> specific message used by the merchant to process
the transaction.
</li>
<li>
Set the <a><code>state</code></a> of <em>request</em> to <code>accepted</code>.
</li>
<li>
Resolve the pending <a><em>acceptPromise</em></a> for the <em>request</em> that was returned
by the <a><code>send</code></a> method call that started the payment request.
</li>
</ol>
</section>
</section>
<section>
<h2>Extensibility</h2>
<p>
In general, the WebIDL descriptions provided in this specification outline
the specific interfaces, properties, and values that an implementation MAY
depend on. It is expected that other properties and values will be stored in
objects that implement the various interfaces in this specification (e.g.
<a>CheckoutDetails</a>, <a>ShippingAddress</a>,
<a>CheckoutItem</a>, etc.). While this specification does not suggest a
single extension mechanism, it does anticipate extensibility.
To that end,
</p>
<ul>
<li>
Implementations MUST preserve unrecognized properties and their
associated values.
</li>
<li>
Another specification [LINK_TBD] explains how to extend the
parameters used with this API using JSON-LD.
</li>
</ul>
<p class="issue">
The Working Group seeks feedback from the Web community on that
specification and how well it furthers interoperability needs in the
payments ecosystem. To provide feedback, see the
<a href="#h-sotd">status section</a> above.
</p>
</section>
</body>
</html>