-
Notifications
You must be signed in to change notification settings - Fork 183
/
index.html
1483 lines (1400 loc) · 66.3 KB
/
index.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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Payment Request 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 = {
shortName: "payment-request",
edDraftURI: "https://w3c.github.io/browser-payment-api/",
specStatus: "ED",
editors: [
{ name: "Adrian Bateman",
company: "Microsoft Corporation" },
{ name: "Zach Koch",
company: "Google" },
{ name: "Richard Barnes",
company: "Mozilla Foundation" },
{ name: "Roy McElmurry",
company: "Facebook" },
],
license: "w3c-software-doc",
lint: true,
previousMaturity: "WD",
previousPublishDate: "2016-07-05",
wg: "Web Payments Working Group",
wgURI: "https://www.w3.org/Payments/WG/",
wgPublicList: "public-payments-wg",
wgPatentURI: "https://www.w3.org/2004/01/pp-impl/83744/status",
issueBase: "https://github.com/w3c/browser-payment-api/issues/",
localBiblio: {
"PAYMENT-ARCH": {
title: "Payment Request Architecture"
, href: "https://w3c.github.io/browser-payment-api/specs/architecture.html"
, authors: [
"Adrian Bateman"
, "Zach Koch"
, "Richard Barnes"
, "Roy McElmurry"
]
, status: "ED"
},
"METHOD-IDENTIFIERS": {
title: "Payment Method Identifiers"
, href: "https://www.w3.org/TR/payment-method-id/"
, authors: [
"Adrian Bateman"
, "Zach Koch"
, "Richard Barnes"
, "Roy McElmurry"
]
, status: "WD"
}
},
otherLinks: [{
key: "Version control",
data: [{
value: "Github Repository",
href: "https://github.com/w3c/browser-payment-api"
}, {
value: "Issues",
href: "https://github.com/w3c/browser-payment-api/issues"
}]
}]
};
</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 web API to allow merchants (i.e. web sites selling
physical or digital goods) to easily accept payments from different payment methods with
minimal integration. User agents (e.g., browsers) will facilitate the payment flow between
merchant and user.
</p>
</section>
<section id='sotd'>
<p>
The working group maintains <a href="https://github.com/w3c/browser-payment-api/issues">a
list of all bug reports that the group has not yet addressed</a>.
This draft highlights some of the pending issues that are still to be discussed in the working
group. No decision has been taken on the outcome of these issues including whether they are valid.
Pull requests with proposed specification text for outstanding issues are strongly encouraged.
</p>
<p>
This specification was derived from a report published previously by the
<a href="https://www.w3.org/community/wicg/">Web Platform Incubator Community Group</a>.
</p>
<div class="note">
<p><strong>Sending comments on this document</strong></p>
<p>If you wish to make comments regarding this document, please raise them as
<a href="https://github.com/w3c/browser-payment-api/issues">GitHub issues</a>.
Only send comments by email if you are unable to raise issues on GitHub (see
links below). All comments are welcome.</p>
</div>
</section>
<section class='informative'>
<h2>Introduction</h2>
<p>Buying things on the
web, particularly on mobile, can be 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 an API that allows <a>user agents</a> (e.g., browsers) to act
as an intermediary 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 flow.</p>
<p>In addition to better, more consistent user experiences, 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>The API described in this document forms part of the Payment Request system described in
the Payment Request Architecture [[PAYMENT-ARCH]] 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></li>
<li>Standardize (to the extent that it makes sense) the communication flow between a
merchant, user agent, and <a>payment method</a></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>
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. In this specification, <a>user agent</a> means a <em>Web
browser or other interactive user agent</em> as defined in [[!HTML5]].
</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-2]]
</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>
</dl>
</section>
<section id="dependencies">
<h2>Dependencies</h2>
<p>
This specification relies on several other underlying specifications.
</p>
<dl>
<dt>Payment Request Architecture</dt>
<dd>The terms <dfn data-lt="payment method|payment methods">Payment Method</dfn>,
<dfn data-lt="payment app|payment apps">Payment App</dfn>, and <dfn>Payment Transaction
Message Specification</dfn> are defined by the Payment Request Architecture document
[[PAYMENT-ARCH]].</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
[[!METHOD-IDENTIFIERS]].</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>internal slot</dfn>, <dfn><code>TypeError</code></dfn>, <dfn>JSON.stringify</dfn>, and <dfn>JSON.parse</dfn> are
defined by [[!ECMA-262-2015]].
<p>This document uses the format <em>object</em>@[[\slotname]] to mean the internal slot [[\slotname]]
of the object <em>object</em>.</p>
<p>The term <dfn>JSON-serializable 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 terms <dfn>fire an event</dfn>, <dfn>dispatch flag</dfn>,
<dfn>stop propagation flag</dfn>, and <dfn>stop immediate propagation flag</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>AbortError</dfn></code></td><td>The payment request was aborted</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>
</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-2]]. 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.
<p>The term <dfn>extended attribute</dfn> is defined by [[!WEBIDL-2]].</p></dd>
<dt>Secure Contexts</dt>
<dd>The term <dfn>secure context</dfn> is defined by the Secure Contexts specification
[[SECURE-CONTEXTS]].</dd>
</dl>
</section>
<section>
<h2>PaymentRequest interface</h2>
<pre class="idl">
[Constructor(sequence<PaymentMethodData> methodData, PaymentDetails details, optional PaymentOptions options),
SecureContext]
interface PaymentRequest : EventTarget {
Promise<PaymentResponse> show();
Promise<void> abort();
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
/* Supports "shippingaddresschange" event */
attribute EventHandler onshippingaddresschange;
/* Supports "shippingoptionchange" event */
attribute EventHandler onshippingoptionchange;
};
</pre>
<p>
A web page creates a <a><code>PaymentRequest</code></a> to make a payment request. This is
typically associated with the user initiating a payment process
(e.g., selecting a "Power Up" in an interactive game, pulling up to an automated kiosk in a parking structure,
or activating a "Buy", "Purchase", or "Checkout" button).
The <a><code>PaymentRequest</code></a> allows the web page to exchange information with the
<a>user agent</a> while the user is providing input before approving or denying a payment request.
</p>
<p>
The <code>shippingAddress</code> and <dfn><code>shippingOption</code></dfn> attributes
are populated during processing if the <a><code>requestShipping</code></a> flag is set.
</p>
<p class="note">
The <code>[SecureContext]</code> <a>extended attribute</a> means that the <a><code>PaymentRequest</code></a>
is only exposed within a <a>secure context</a> and won't be accessible elsewhere.
</p>
<p>The following example shows how to construct a <a><code>PaymentRequest</code></a> and begin the
user interaction:</p>
<pre class="example highlight">
var payment = new PaymentRequest(methodData, details, options);
payment.addEventListener("shippingaddresschange", function (changeEvent) {
// Process shipping address change
});
payment.show().then(function(paymentResponse) {
// Process paymentResponse
// paymentResponse.methodName contains the selected payment method
// paymentResponse.details contains a payment method specific response
paymentResponse.complete("success");
}).catch(function(err) {
console.error("Uh oh, something bad happened", err.message);
});
</pre>
<section>
<h2>PaymentRequest constructor</h2>
<p>
The <a><code>PaymentRequest</code></a> is constructed using the supplied <code>methodData</code>
list including any <a>payment method</a> specific <code>data</code>, the payment <code>details</code>,
and the payment <code>options</code>.
</p>
<div class="note">
<p>The <code>methodData</code> sequence contains <a><code>PaymentMethodData</code></a> dictionaries
containing the <a>payment method identifiers</a> for the <a>payment methods</a> that the web site accepts
and any associated <a>payment method</a> specific data.</p>
<pre class="example highlight">
[
{
supportedMethods: ["visa","bitcoin"]
},
{
supportedMethods: ["bobpay.com"],
data: {
merchantIdentifier: "XXXX",
bobPaySpecificField: true
}
}
]
</pre>
<p>The <code>details</code> object contains information about the transaction that the
user is being asked to complete such as the line items in an order.</p>
<pre class="example highlight">
{
displayItems: [
{
label: "Sub-total",
amount: { currency: "USD", value : "55.00" }, // US$55.00
},
{
label: "Sales Tax",
amount: { currency: "USD", value : "5.00" }, // US$5.00
}
],
total: {
label: "Total due",
amount: { currency: "USD", value : "60.00" }, // US$60.00
}
}
</pre>
<p>The <code>options</code> object contains information about what options the web page
wishes to use from the payment request system.</p>
<pre class="example highlight">
{
requestShipping: true
}
</pre>
</div>
<p>
The <a><code>PaymentRequest</code></a> constructor MUST act as follows:
</p>
<ol>
<li>
If the length of the <code>methodData</code> sequence is zero, then <a>throw</a>
a <a><code>TypeError</code></a>.
</li>
<li>
For each <a><code>PaymentMethodData</code></a> dictionary, if the length of the
<code>supportedMethods</code> sequence is zero, then <a>throw</a> a <a><code>TypeError</code></a>.
</li>
<li>
If the <a>browsing context</a> of the script calling the constructor is
not a <a>top-level browsing context</a>, then <a>throw</a> a <a><code>SecurityError</code></a>.
<div class="issue" data-number="2"
title="Should the Payment Request API only be available in a top-level browsing context? ">
<p>There is an open issue about requiring
a top-level browsing context for using <code>PaymentRequest</code>. Requiring one
is a mitigation for a user being tricked into thinking a trusted site is asking for
payment when in fact an untrusted iframe is asking for payment. The problem is some iframes may
have a legitimate reason to request payment.</p>
</div>
</li>
<li>
If <code>details</code> does not contain a value for <code>total</code>, then throw a
<a><code>TypeError</code></a>.
</li>
<li>
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]].
<p>
The <code>methodData</code> supplied to the <a><code>PaymentRequest</code></a> 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.
</p>
</li>
<li>Store <code>details</code> into <em>request</em>@[[\details]].</li>
<li>Store <code>options</code> into <em>request</em>@[[\options]].</li>
<li>Set the value <em>request</em>@[[\state]] to <em>created</em>.</li>
<li>
Set the value of the <a><code>shippingAddress</code></a> attribute on <em>request</em> to <em>null</em>.
</li>
<li>
Set the value of the <a><code>shippingOption</code></a> attribute on <em>request</em> to <em>null</em>.
</li>
<li>
If the <code>details.shippingOptions</code> 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.
</li>
<li>
If <em>request</em>@[[\details]] contains a <code>shippingOptions</code> sequence and
if any <a><code>PaymentShippingOption</code></a> in the sequence
has the <code>selected</code> field set to <code>true</code>, then set
<a><code>shippingOption</code></a> to the <code>id</code> of the last <a><code>ShippingOption</code></a>
in the sequence with <code>selected</code> set to <code>true</code>.
</li>
<li>Set the value <em>request</em>@[[\updating]] to <em>false</em>.</li>
<li>Return <em>request</em>.</li>
</ol>
</section>
<section>
<h2>show()</h2>
<p>
The <code><dfn>show</dfn></code> method is called when the page wants to begin user interaction for the
payment request. The <code>show</code> method will return a <a>Promise</a> that will be resolved when the
<a>user accepts the payment request</a>. Some kind of user interface will be presented to the user to facilitate the
payment request after the <code>show</code> method returns.
</p>
<p>
The <a><code>show</code></a> method MUST act as follows:
</p>
<ol>
<li>
Let <em>request</em> be the <a><code>PaymentRequest</code></a> object on which the method is called.
</li>
<li>If the value of <em>request</em>@[[\state]] is not <em>created</em> then
<a>throw</a> an <a><code>InvalidStateError</code></a>.</li>
<li>
Set the value of <em>request</em>@[[\state]] to <em>interactive</em>.
</li>
<li>
Let <em>acceptPromise</em> be a new <a>Promise</a>.
</li>
<li>
Store <em>acceptPromise</em> in <em>request</em>@[[\acceptPromise]].
</li>
<li>
Return <em>acceptPromise</em> and asynchronously perform the remaining steps.
</li>
<li>
Let <em>supportedMethods</em> be the union of all the <code>supportedMethods</code> sequences from each
<a><code>PaymentMethodData</code></a> in the <em>request</em>@[[\methodData]] sequence.
</li>
<li>
Let <em>acceptedMethods</em> be <em>supportedMethods</em> with all identifiers removed that the
<a>user agent</a> does not accept.
</li>
<li>
If the length of <em>acceptedMethods</em> is zero, then reject <em>acceptPromise</em> with a
<a><code>NotSupportedError</code></a>.
</li>
<li>
Show a user interface to allow the user to interact with the payment request process. The <em>acceptPromise</em> will
later be resolved by the <a>user accepts the payment request algorithm</a> through interaction with the user interface.
</li>
</ol>
</section>
<section>
<h2>abort()</h2>
<p>
The <code><dfn>abort</dfn></code> method may be called if the web page wishes to tell the
<a>user agent</a> to abort the payment <em>request</em> and to tear down any user interface that
might be shown. <code>abort</code> can only be called after the <a><code>show</code></a> method
has been called and before the <em>request</em>@[[\acceptPromise]] has been resolved.
For example, a web page might choose to do this if 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> might 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. In this situation, <code>abort</code> will
reject the returned <a>Promise</a>.
</p>
<p>The <a><code>abort</code></a> method MUST act as follows:</p>
<ol>
<li>
Let <em>request</em> be the <a><code>PaymentRequest</code></a> object on which the method is called.
</li>
<li>If the value of <em>request</em>@[[\state]] is not <em>interactive</em> then
<a>throw</a> an <a><code>InvalidStateError</code></a>.</li>
<li>Let <em>promise</em> be a new <a>Promise</a>.</li>
<li>Return <em>promise</em> and asynchronously perform the remaining steps.</li>
<li>Try to abort the current user interaction and close down any remaining user interface.</li>
<li>If it is not possible to abort the current user interaction, then reject <em>promise</em>
with <a><code>InvalidStateError</code></a> and abort this algorithm.</li>
<li>Set the value of the internal slot <em>request</em>@[[\state]] to <em>closed</em>.</li>
<li>Reject the promise <em>request</em>@[[\acceptPromise]] with an <a><code>AbortError</code></a>.</li>
<li>Resolve <em>promise</em> with <code>undefined</code>.</li>
</ol>
</section>
<section>
<h2 id="state-transitions" class="informative">State transitions</h2>
<p>The internal slot [[\state]] follows the following state transitions:</p>
<img alt="Transition diagram for internal slot state of a PaymentRequest object"
src="images/state-transitions.svg" width="518" height="125">
</section>
<section>
<h2>shippingAddress</h2>
<p>
<code>shippingAddress</code> is populated when the user provides a shipping
address. It is <em>null</em> by default.
When a user provides a shipping address, the <a>shipping address changed algorithm</a> runs.
</p>
<p>
<code><dfn>onshippingaddresschange</dfn></code> is an <code>EventHandler</code> for an
<code>Event</code> named <code>shippingaddresschange</code>.
</p>
</section>
<section>
<h2>shippingOption</h2>
<p>
<code>shippingOption</code> is populated when the user chooses a shipping
option. It is <em>null</em> by default.
When a user chooses a shipping option, the <a>shipping option changed algorithm</a> runs.
</p>
<p>
<code><dfn>onshippingoptionchange</dfn></code> is an <code>EventHandler</code> for an
<code>Event</code> named <code>shippingoptionchange</code>.
</p>
</section>
<section>
<h2>Internal Slots</h2>
<p>Instances of <a><code>PaymentRequest</code></a> are created with the internal slots in
the following table:</p>
<table>
<tr><th>Internal Slot</th><th>Description (<em>non-normative</em>)</th></tr>
<tr>
<td>[[\methodData]]</td>
<td>The <code>methodData</code> supplied to the constructor.</td>
</tr>
<tr>
<td>[[\details]]</td>
<td>
The current <a><code>PaymentDetails</code></a> for the payment request initially
supplied to the constructor and then updated with calls to <a><code>updateWith</code></a>.
</td>
</tr>
<tr>
<td>[[\options]]</td>
<td>The <a><code>PaymentOptions</code></a> supplied to the constructor.</td>
</tr>
<tr>
<td>[[\state]]</td>
<td>The current <a class="internalDFN" href="#state-transitions">state</a> of the payment request.</td>
</tr>
<tr>
<td>[[\updating]]</td>
<td>
<em>true</em> is there is a pending <a><code>updateWith</code></a> call to update
the payment request and <em>false</em> otherwise.
</td>
</tr>
<tr>
<td>[[\acceptPromise]]</td>
<td>
The pending <a>Promise</a> created during <a><code>show</code></a> that will be
resolved if the user accepts the payment request.
</td>
</tr>
</table>
</section>
</section>
<section>
<h2>PaymentMethodData dictionary</h2>
<pre class="idl">
dictionary PaymentMethodData {
required sequence<DOMString> supportedMethods;
object data;
};
</pre>
<p>
A <a><code>PaymentMethodData</code></a> dictionary is used to indicate a set of supported <a>payment
methods</a> and any associated <a>payment method</a> specific data for those methods.
</p>
<p>The following fields are part of the <a><code>PaymentMethodData</code></a> dictionary:</p>
<dl>
<dt><code>supportedMethods</code></dt>
<dd><code>supportedMethods</code> is a required sequence of strings containing <a>payment method identifiers</a> for
<a>payment methods</a> that the merchant web site accepts.</dd>
<dt><code>data</code></dt>
<dd><code>data</code> is a <a>JSON-serializable object</a> that provides optional information that
might be needed by the supported payment methods.</dd>
</dl>
</section>
<section>
<h2>PaymentCurrencyAmount</h2>
<pre class="idl">
dictionary PaymentCurrencyAmount {
required DOMString currency;
required DOMString value;
};
</pre>
<p>
A <a><code>PaymentCurrencyAmount</code></a> dictionary is used to supply monetary amounts.
</p>
<p>
The following fields are required:
</p>
<dl>
<dt><code><dfn>currency</dfn></code></dt>
<dd>
<code>currency</code> is a string containing a currency identifier. The most common
identifiers are three-letter alphabetic codes as defined by [[ISO4217]] (for example,
<code>"USD"</code> for US Dollars) however any string is considered valid.
</dd>
<dt><code><dfn>value</dfn></code></dt>
<dd>
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 following regular expression is an implementation of the above definition.
<pre class="hljs">^-?[0-9]+(\.[0-9]+)?$</pre>
</div>
</dd>
</dl>
<p>The following example shows how to represent US$55.00.</p>
<pre class="example highlight">
{
"currency": "USD",
"value" : "55.00"
}
</pre>
</section>
<section>
<h2>PaymentDetails dictionary</h2>
<pre class="idl">
dictionary PaymentDetails {
PaymentItem total;
sequence<PaymentItem> displayItems;
sequence<PaymentShippingOption> shippingOptions;
sequence<PaymentDetailsModifier> modifiers;
DOMString error;
};
</pre>
<p>
The <code><dfn>PaymentDetails</dfn></code> dictionary is passed to the <a><code>PaymentRequest</code></a>
constructor and provides information about the requested transaction. The <code>PaymentDetails</code>
dictionary is also used to update the payment request using <a><code>updateWith</code></a>.
</p>
<p>
The following fields are part of the <code>PaymentDetails</code> dictionary:
</p>
<dl>
<dt><code>total</code></dt>
<dd>
This <a><code>PaymentItem</code></a> contains the total amount of the payment request.
<p>
<code>total</code> MUST be a non-negative value. This means that the <code>total.amount.value</code>
field MUST NOT begin with a U+002D HYPHEN-MINUS character.
</p>
</dd>
<dt><code>displayItems</code></dt>
<dd>
This sequence of <a><code>PaymentItem</code></a> dictionaries contains line items
for the payment request that the <a>user agent</a> MAY display. For example, it might include
details of products or breakdown of tax and shipping. It is optional to provide this
information.
<p>The <a>user agent</a> MAY validate that the <code>total</code> amount is the
sum of these items, but it is the responsibility of the calling code to ensure that.</p>
</dd>
<dt><code>shippingOptions</code></dt>
<dd>
A sequence containing the different shipping options for the user to choose from.
<p>If the sequence is empty, then this indicates that the merchant
cannot ship to the current <a><code>shippingAddress</code></a>.</p>
<p>If an item in the sequence has the <code>selected</code> field set to <code>true</code>,
then this is the shipping option that will be used by default and <a><code>shippingOption</code></a>
will be set to the <code>id</code> of this option without running the <a>shipping option changed
algorithm</a>. Authors SHOULD NOT set <code>selected</code> to <code>true</code> on more than
one item. If more than one item in the sequence has <code>selected</code> set to <code>true</code>,
then <a>user agents</a> MUST select the last one in the sequence.</p>
<p>The <code>shippingOptions</code> field is only used if the <a><code>PaymentRequest</code></a> was
constructed with <a><code>PaymentOptions</code></a> <code>requestShipping</code>
set to <code>true</code>.</p>
<p class="note">
If the sequence has an item with the <code>selected</code>
field set to <code>true</code>, then authors are responsible for ensuring that the <code>total</code> field includes
the cost of the shipping option. This is because no <a><code>shippingoptionchange</code></a> event
will be fired for this option unless the user selects an alternative option first.
</p>
</dd>
<dt><code>modifiers</code></dt>
<dd>
This sequence of <a><code>PaymentDetailsModifier</code></a> dictionaries contains modifiers
for particular payment method identifiers. For example, it allows you to adjust the total
amount based on payment method.
</dd>
<dt><code>error</code></dt>
<dd>
When the payment request is updated using <a><code>updateWith</code></a>, the <code>PaymentDetails</code>
can contain a message in the <code>error</code> field that will be displayed to the user. For example,
this might commonly be used to explain why good cannot be shipped to the chosen shipping address.
<p>
The <code>error</code> field cannot be passed to the <a><code>PaymentRequest</code></a> constructor.
Doing so will cause a <a><code>TypeError</code></a> to be thrown.
</dd>
</dl>
</section>
<section>
<h2>PaymentDetailsModifier dictionary</h2>
<pre class="idl">
dictionary PaymentDetailsModifier {
required sequence<DOMString> supportedMethods;
PaymentItem total;
sequence<PaymentItem> additionalDisplayItems;
object data;
};
</pre>
<p>
The <code><dfn>PaymentDetailsModifier</dfn></code> dictionary provides details that modify the
<a><code>PaymentDetails</code></a> based on <a>payment method identifier</a>. It contains the
following fields:
</p>
<dl>
<dt><code>supportedMethods</code></dt>
<dd>
The <code>supportedMethods</code> field contains a sequence of <a>payment method identifiers</a>.
The remaining fields in the <a><code>PaymentDetailsModifier</code></a> apply only if the user selects
a <a>payment method</a> included in this sequence.
</dd>
<dt><code>total</code></dt>
<dd>
This <a><code>PaymentItem</code></a> value overrides the <code>total</code> field in the
<a><code>PaymentDetails</code></a> dictionary for the <a>payment method identifiers</a>
in the <code>supportedMethods</code> field.
</dd>
<dt><code>additionalDisplayItems</code></dt>
<dd>
This sequence of <a><code>PaymentItem</code></a> dictionaries provides additional display
items that are appended to the <code>displayItems</code> field in the <a><code>PaymentDetails</code></a>
dictionary for the <a>payment method identifiers</a> in the <code>supportedMethods</code>
field. This field is commonly used to add a discount or surcharge line item indicating the
reason for the different <code>total</code> amount for the selected <a>payment method</a>
that the user agent MAY display.
<p>
The user agent MAY validate that the <code>total</code> amount is the sum of the <code>displayItems</code>
and the <code>additionalDisplayItems</code>, but it is the responsibility of the calling code to ensure that.
</p>
</dd>
<dt><code>data</code></dt>
<dd><code>data</code> is a <a>JSON-serializable object</a> that provides optional information that
might be needed by the supported payment methods.</dd>
</dl>
</section>
<section>
<h2>PaymentOptions dictionary</h2>
<pre class="idl">
dictionary PaymentOptions {
boolean requestPayerEmail = false;
boolean requestPayerPhone = false;
boolean requestShipping = false;
};
</pre>
<p>
The <code><dfn>PaymentOptions</dfn></code> dictionary is passed to the <a><code>PaymentRequest</code></a>
constructor and provides information about the options desired for the payment request.
</p>
<p>
The following fields MAY be passed to the <a><code>PaymentRequest</code></a> constructor:
</p>
<dl>
<dt><code><dfn>requestPayerEmail</dfn></code></dt>
<dd>
This <em>boolean</em> value indicates whether the <a>user agent</a> should collect and return
the payer's email address as part of the payment request. For example, this would be set to
<code>true</code> to allow a merchant to email a receipt.
</dd>
<dt><code><dfn>requestPayerPhone</dfn></code></dt>
<dd>
This <em>boolean</em> value indicates whether the <a>user agent</a> should collect and return
the payer's phone number as part of the payment request. For example, this would be set to
<code>true</code> to allow a merchant to phone a customer with a billing enquiry.
</dd>
<dt><code><dfn>requestShipping</dfn></code></dt>
<dd>
This <em>boolean</em> value indicates whether the <a>user agent</a> should collect and return
a shipping address as part of the payment request. For example, this would be set to
<code>true</code> when physical goods need to be shipped by the merchant to the user.
This would be set to <code>false</code> for an online-only electronic purchase transaction.
</dd>
</dl>
</section>
<section>
<h2>PaymentItem dictionary</h2>
<pre class="idl">
dictionary PaymentItem {
required DOMString label;
required PaymentCurrencyAmount amount;
};
</pre>
<p>
A sequence of one or more <code>PaymentItem</code> dictionaries is included in the <a><code>PaymentDetails</code></a>
dictionary to indicate what the payment request is for and the value asked for.
</p>
<p>
The following fields are required:
</p>
<dl>
<dt><code>label</code></dt>
<dd>This is a human-readable description of the item. The <a>user agent</a> may display
this to the user.</dd>
<dt><code>amount</code></dt>
<dd>
A <a><code>PaymentCurrencyAmount</code></a> containing the monetary amount for the item.
<div class="issue" data-number="3" title="Should it be possible to provide amounts in more than one currency">
There is an open issue about whether it should be possible to provide a <code>PaymentItem</code>
with amounts in more than once currency.
</div>
</dd>
</dl>
</section>
<section>
<h2>PaymentAddress interface</h2>
<pre class="idl">
[SecureContext]
interface PaymentAddress {
serializer = { attribute };
readonly attribute DOMString country;
readonly attribute FrozenArray<DOMString> addressLine;
readonly attribute DOMString region;
readonly attribute DOMString city;
readonly attribute DOMString dependentLocality;
readonly attribute DOMString postalCode;
readonly attribute DOMString sortingCode;
readonly attribute DOMString languageCode;
readonly attribute DOMString organization;
readonly attribute DOMString recipient;
readonly attribute DOMString phone;
};
</pre>
<dl>
<dt><code>country</code></dt>
<dd>This is the CLDR (Common Locale Data Repository) region code. For example, US, GB, CN, or JP.</dd>
<dt><code>addressLine</code></dt>
<dd>This is the most specific part of the address. It can include, for example, a street
name, a house number, apartment number, a rural delivery route, descriptive
instructions, or a post office box number.</dd>
<dt><code>region</code></dt>
<dd>This is the top level administrative subdivision of the country. For example, this can
be a state, a province, an oblast, or a prefecture.</dd>
<dt><code>city</code></dt>
<dd>This is the city/town portion of the address.</dd>
<dt><code>dependentLocality</code></dt>
<dd>This is the dependent locality or sublocality within a city. For example, used for neighborhoods,
boroughs, districts, or UK dependent localities.</dd>
<dt><code>postalCode</code></dt>
<dd>This is the postal code or ZIP code, also known as PIN code in India.</dd>
<dt><code>sortingCode</code></dt>
<dd>This is the sorting code as used in, for example, France.</dd>
<dt><code>languageCode</code></dt>
<dd>This is the BCP-47 language code for the address. It's used to determine the field
separators and the order of fields when formatting the address for display.</dd>
<dt><code>organization</code></dt>
<dd>This is the organization, firm, company, or institution at this address.</dd>
<dt><code>recipient</code></dt>
<dd>This is the name of the recipient or contact person. This field may, under certain
circumstances, contain multiline information. For example, it might contain "care of"
information.</dd>
<dt><code>phone</code></dt>
<dd>This is the phone number of the recipient or contact person.</dd>
</dl>
<p>
If the <a>requestShipping</a> flag was set to <code>true</code> in the <a>PaymentOptions</a>
passed to the <a>PaymentRequest</a> constructor, then the <a>user agent</a> will populate the
<code>shippingAddress</code> field of the <a><code>PaymentRequest</code></a> and ultimately the
<a><code>PaymentResponse</code></a> object with the user's selected shipping address after
the user has accepted the payment.
</p>
</section>
<section>
<h2>PaymentShippingOption dictionary</h2>
<pre class="idl">
dictionary PaymentShippingOption {
required DOMString id;
required DOMString label;
required PaymentCurrencyAmount amount;
boolean selected = false;
};
</pre>
<p>
The <a>PaymentShippingOption</a> dictionary has fields describing a shipping option. A web page can
provide the user with one or more shipping options by calling the <a>updateWith</a>
method in response to a change event.
</p>
<p>
The following fields are required:
</p>
<dl>
<dt><code>id</code></dt>
<dd>This is a string identifier used to reference this <code>PaymentShippingOption</code>. It MUST be
unique for a given <a><code>PaymentRequest</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 shipping option to the user.</dd>
<dt><code>amount</code></dt>
<dd>
A <a><code>PaymentCurrencyAmount</code></a> containing the monetary amount for the item.
</dd>
<dt><code>selected</code></dt>
<dd>This is set to <code>true</code> to indicate that this is the default selected <a>PaymentShippingOption</a>
in a sequence. <a>User agents</a> SHOULD display this option by default in the user interface.</dd>
</dl>
</section>
<section>
<h2>PaymentResponse interface</h2>
<pre class="idl">
enum PaymentComplete { "success", "fail", "" };
[SecureContext]
interface PaymentResponse {
serializer = { attribute };
readonly attribute DOMString methodName;
readonly attribute object details;