forked from w3c/payment-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2185 lines (2170 loc) · 85.6 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' 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: "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: {
"METHOD-IDENTIFIERS": {
title: "Payment Method Identifiers",
href: "https://www.w3.org/TR/payment-method-id/",
authors: [
"Adrian Bateman", "Zach Koch", "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?utf8=%E2%9C%93&q=is%3Aopen%20is%3Aissue%20-label%3A%22Priority%3A%20Postponed%22%20"
}]
}]
};
</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 standardizes an API to allow merchants (i.e. web
sites selling physical or digital goods) to utilize one or more payment
methods with minimal integration. User agents (e.g., browsers)
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?utf8=%E2%9C%93&q=is%3Aopen%20is%3Aissue%20-label%3A%22Priority%3A%20Postponed%22%20">
a list of all bug reports that the group has not yet addressed</a>.
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 three systems in
every transaction: the merchant (e.g., an online web store), the buyer
represented by the <a>user agent</a> (e.g., the user buying from the
online web store), and the <dfn data-lt=
"payment method|payment methods">Payment Method</dfn> (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>
<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 id="out-of-scope">
<h2>
Out of scope
</h2>
<ul>
<li>Create a new <a>payment method</a>
</li>
<li>Integrate directly with payment processors
</li>
</ul>
</section>
</section>
</section>
<section data-dfn-for="PaymentRequest">
<h2>
<code>PaymentRequest</code> interface
</h2>
<pre class="idl">
[Constructor(sequence<PaymentMethodData> methodData, PaymentDetails details, optional PaymentOptions options),
SecureContext]
interface PaymentRequest : EventTarget {
Promise<PaymentResponse> show();
Promise<void> abort();
Promise<Boolean> canMakeActivePayment();
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
readonly attribute PaymentShippingType? shippingType;
/* Supports "shippingaddresschange" event */
attribute EventHandler onshippingaddresschange;
/* Supports "shippingoptionchange" event */
attribute EventHandler onshippingoptionchange;
};
</pre>
<p>
A web page creates a <dfn>PaymentRequest</dfn> 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>PaymentRequest</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 <a data-lt="PaymentRequest.shippingAddress">shippingAddress</a>,
<a data-lt="PaymentRequest.shippingOption">shippingOption</a>, and
<a data-lt="PaymentRequest.shippingType">shippingType</a> attributes
are populated during processing if the <a data-lt=
"PaymentOptions.requestShipping">requestShipping</a> flag is set.
</p>
<p class="note">
The <code>[SecureContext]</code> <a>extended attribute</a> means that
the <a>PaymentRequest</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>PaymentRequest</a>
and begin the user interaction:
</p>
<pre class="example">
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>
Constructor
</h2>
<p>
The <a>PaymentRequest</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>PaymentMethodData</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">
[
{
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">
{
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">
{
requestShipping: true
}
</pre>
</div>
<p>
The <a>PaymentRequest</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>TypeError</a>.
</li>
<li>For each <a>PaymentMethodData</a> dictionary, if the length of
the <code>supportedMethods</code> sequence is zero, then <a>throw</a>
a <a>TypeError</a>.
</li>
<li>If the <a>browsing context</a> of the script calling the
constructor is a <a>nested browsing context</a> whose origin is
different from the <a>top-level browsing context</a>'s origin and the
nested browsing context is not <a>allowed to make payment
requests</a>, then <a>throw</a> a <a>SecurityError</a>.
</li>
<li>If <code>details</code> does not contain a value for
<code>total</code>, then throw a <a>TypeError</a>.
</li>
<li>If <code>details.total.amount.value</code> is not a <a>valid
decimal monetary value</a>, then throw a <a>TypeError</a>.
</li>
<li>If the first character of <code>details.total.amount.value</code>
is U+002D HYPHEN-MINUS, then throw a <a>TypeError</a>.
<code>total</code> MUST be a non-negative amount.
</li>
<li>If the <code>details.displayItems</code> sequence contains any
<a>PaymentItem</a> objects with an <code>amount</code> that is not a
<a>valid decimal monetary value</a>, then throw a <a>TypeError</a>.
</li>
<li>If the <code>details.shippingOptions</code> sequence contains any
<a>PaymentShippingOption</a> objects with an <code>amount</code> that
is not a <a>valid decimal monetary value</a>, then throw a
<a>TypeError</a>.
</li>
<li>If <code>details</code> contains a value for <code>error</code>,
then throw a <a>TypeError</a>.
</li>
<li>For each <a>PaymentMethodData</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>TypeError</a>.
</li>
<li>For each <a>PaymentDetailsModifier</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>TypeError</a>.
</li>
<li>For each <a>PaymentDetailsModifier</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>TypeError</a>.
<code>total</code> MUST be a non-negative amount.
</li>
<li>For each <a>PaymentDetailsModifier</a> in
<code>details.modifiers</code>, if the
<code>additionalDisplayItems</code> sequence contains any
<a>PaymentItem</a> objects with an <code>amount</code> that is not a
<a>valid decimal monetary value</a>, then throw a <a>TypeError</a>.
</li>
<li>Let <em>request</em> be a new <a>PaymentRequest</a>.
</li>
<li>Store <code>methodData</code> into
<em>request</em>@[[\methodData]].
<p>
The <code>methodData</code> supplied to the <a>PaymentRequest</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 data-lt="PaymentRequest.shippingAddress">
shippingAddress</a> attribute on <em>request</em> to <em>null</em>.
</li>
<li>Set the value of the <a data-lt="PaymentRequest.shippingOption">
shippingOption</a> attribute on <em>request</em> to <em>null</em>.
</li>
<li>Set the value of the <a data-lt=
"PaymentRequest.shippingType">shippingType</a> attribute on
<em>request</em> to <em>null</em>.
</li>
<li>If <code>options.requestShipping</code> is set to
<code>true</code>, then set the value of the <a data-lt=
"PaymentRequest.shippingType">shippingType</a> attribute on
<em>request</em> to <code>options.shippingType</code>. If
<code>options.shippingType</code> is not a valid
<a>PaymentShippingType</a> value then set the <a data-lt=
"PaymentRequest.shippingType">shippingType</a> attribute on
<em>request</em> to <code>"shipping"</code>.
<div class="note">
This behavior allows a page to detect if it supplied an
unsupported shipping type. This will be important if new shipping
types are added to a future version of this specification but a
page is run in a <a>user agent</a> supporting an earlier version.
</div>
</li>
<li>If the <code>details.shippingOptions</code> sequence contains
multiple <a>PaymentShippingOption</a> objects that have the same
<code>id</code>, then set the <a data-lt=
"PaymentDetails.shippingOptions">shippingOptions</a> 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>PaymentShippingOption</a> in the sequence has the
<code>selected</code> field set to <code>true</code>, then set
<a data-lt="PaymentRequest.shippingOption">shippingOption</a> to the
<code>id</code> of the last <a>PaymentShippingOption</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 data-dfn-for="PaymentRequest">
<h2>
<code>show()</code> method
</h2>
<p>
The <dfn>show</dfn> method is called when the page wants to begin
user interaction for the payment request. The <code>show</code>
method returns 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 data-lt="PaymentRequest.show">show</a> method MUST act as
follows:
</p>
<ol>
<li>Let <em>request</em> be the <a>PaymentRequest</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>InvalidStateError</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>PaymentMethodData</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>NotSupportedError</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 data-dfn-for="PaymentRequest">
<h2>
<code>abort()</code> method
</h2>
<p>
The <dfn>abort</dfn> 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 data-lt=
"PaymentRequest.show">show</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 data-lt="PaymentRequest.abort">abort</a> method MUST act as
follows:
</p>
<ol>
<li>Let <em>request</em> be the <a>PaymentRequest</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>InvalidStateError</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>InvalidStateError</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>AbortError</a>.
</li>
<li>Resolve <em>promise</em> with <code>undefined</code>.
</li>
</ol>
</section>
<section>
<h2>
<code>canMakeActivePayment()</code> method
</h2>
<p>
The <dfn>canMakeActivePayment</dfn> method is called when the page wants to know if the user has a payment method available to use for payment before calling <a data-lt="PaymentRequest.show">show</a>. The <a>canMakeActivePayment</a> method returns a <a>Promise</a> that will be resolved when the <a>user agent</a> has determined if at least one method is available from <a>supportedMethods</a> data. In order to prevent the page from probing different payment methods supported by user, <a>canMakeActivePayment</a> can only be called once per top-level domain. Multiple calls to <a>canMakeActivePayment</a> will result in cached response from previous call. To reduce privacy risks, user agents MAY limit calls to <a>canMakeActivePayment</a> for a certain time before invalidating the cached response per top-level domain. Developers can call <a>canMakeActivePayment</a> multiple times with same set of <a>supportedMethods</a> per top-level domain.
</p>
<p>
The <a>canMakeActivePayment</a> method MUST act as follows:
</p>
<ol>
<li>
Let <var>request</var> be the <a>PaymentRequest</a> object on which the method is called.
</li>
<li>If the value of <var>request</var>@[[\state]] is not "created", then
<a>throw</a> an <a>InvalidStateError</a>.</li>
<li>
Set the value of <em>request</em>@[[\state]] to "interactive".
</li>
<li>
Let <var>acceptPromise</var> be a new <a>Promise</a>.
</li>
<li>
Store <var>acceptPromise</var> in <em>request</em>@[[\acceptPromise]].
</li>
<li>
Return <var>acceptPromise</var> and asynchronously perform the remaining steps.
</li>
<li>
Let <var>topLevelDomain</var> be the URL of the top level page. Let <var>cachedResponse</var> be cached result of previous call to <a>canMakeActivePayment</a>. If is <var>cachedResponse</var> present, resolve <var>acceptPromise</var> promise with <var>cachedResponse</var>.
</li>
<li>
Let <var>cacheInvalidateTimer</var> be the time <a>user agent</a> recorded for previous call to <a>canMakeActivePayment</a> for <var>topLevelDomain</var>. Set <a>DateTime</a> to <var>cacheInvalidateTimer</var> if it's not set.
</li>
<li>
If <var>cacheInvalidateTimer</var> is set and is still active, resolve <var>acceptPromise</var> promise with <var>cached</var> response.
</li>
<li>
Let <var>supportedMethods</var> be the union of all the <a>supportedMethods</a> sequences from each
<a>PaymentMethodData</a> in the <var>request</var>@[[\methodData]] sequence.
</li>
<li>
Let <var>acceptedMethods</var> be <var>supportedMethods</var> with all identifiers removed that the
<a>user agent</a> does not accept and method supports active payment instrument for payment.
</li>
<li>
If the length of <var>acceptedMethods</var> is zero, then resolve <var>acceptPromise</var> with
<code>false</code>, otherwise resolve <var>acceptPromise</var> with <code>true</code>.
</li>
<li>
Cache the response in <var>cachedResponse</var> and set <var>cacheInvalidateTimer</var> to certain <a>DateTime</a> for the <var>topLevelDomain</var>.
</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 data-dfn-for="PaymentRequest">
<h2>
<code>shippingAddress</code> attribute
</h2>
<p>
<dfn>shippingAddress</dfn> 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>
<dfn>onshippingaddresschange</dfn> is an <code>EventHandler</code>
for an <code>Event</code> named <code>shippingaddresschange</code>.
</p>
</section>
<section data-dfn-for="PaymentRequest">
<h2>
<code>shippingOption</code> attribute
</h2>
<p>
<dfn>shippingOption</dfn> 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>
<dfn>onshippingoptionchange</dfn> 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>PaymentRequest</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>PaymentDetails</a> for the payment request
initially supplied to the constructor and then updated with calls
to <a data-lt=
"PaymentRequestUpdateEvent.updateWith">updateWith</a>.
</td>
</tr>
<tr>
<td>
[[\options]]
</td>
<td>
The <a>PaymentOptions</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 data-lt=
"PaymentRequestUpdateEvent.updateWith">updateWith</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 data-lt=
"PaymentRequest.show">show</a> that will be resolved if the user
accepts the payment request.
</td>
</tr>
</table>
</section>
</section>
<section data-dfn-for="PaymentMethodData">
<h2>
<code>PaymentMethodData</code> dictionary
</h2>
<pre class="idl">
dictionary PaymentMethodData {
required sequence<DOMString> supportedMethods;
object data;
};
</pre>
<p>
A <dfn>PaymentMethodData</dfn> 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>PaymentMethodData</a>
dictionary:
</p>
<dl>
<dt>
<dfn>supportedMethods</dfn>
</dt>
<dd>
<a data-lt="PaymentMethodData.supportedMethods">supportedMethods</a>
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>
<dfn>data</dfn>
</dt>
<dd>
<a data-lt="PaymentMethodData.data">data</a> is a
<a>JSON-serializable object</a> that provides optional information
that might be needed by the supported payment methods.
</dd>
</dl>
</section>
<section data-dfn-for="PaymentCurrencyAmount">
<h2>
<code>PaymentCurrencyAmount</code> dictionary
</h2>
<pre class="idl">
dictionary PaymentCurrencyAmount {
required DOMString currency;
required DOMString value;
DOMString currencySystem = "urn:iso:std:iso:4217";
};
</pre>
<p>
A <dfn>PaymentCurrencyAmount</dfn> dictionary is used to supply
monetary amounts.
</p>
<p>
The following fields are required:
</p>
<dl>
<dt>
<dfn>currencySystem</dfn>
</dt>
<dd>
A URL that indicates the currency system that the <a data-lt=
"PaymentCurrencyAmount.currency">currency</a> identifier belongs to.
By default, the value is <code>urn:iso:std:iso:4217</code> indicating
that <code>currency</code> is defined by [[ISO4217]] (for example,
<code>USD</code> for US Dollars).
</dd>
<dt>
<dfn>currency</dfn>
</dt>
<dd>
A string containing a currency identifier. The value of
<code>currency</code> can be any string that is valid within the
currency system indicated by <code>currencySystem</code>.
</dd>
<dt>
<dfn>value</dfn>
</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">
{
"currency": "USD",
"value" : "55.00"
}
</pre>
</section>
<section data-dfn-for="PaymentDetails">
<h2>
<code>PaymentDetails</code> dictionary
</h2>
<pre class="idl">
dictionary PaymentDetails {
PaymentItem total;
sequence<PaymentItem> displayItems;
sequence<PaymentShippingOption> shippingOptions;
sequence<PaymentDetailsModifier> modifiers;
DOMString error;
};
</pre>
<p>
The <dfn>PaymentDetails</dfn> dictionary is passed to the
<a>PaymentRequest</a> constructor and provides information about the
requested transaction. The <code>PaymentDetails</code> dictionary is
also used to update the payment request using <a data-lt=
"PaymentRequestUpdateEvent.updateWith">updateWith</a>.
</p>
<p>
The following fields are part of the <code>PaymentDetails</code>
dictionary:
</p>
<dl>
<dt>
<dfn>total</dfn>
</dt>
<dd>
This <a>PaymentItem</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>
<dfn>displayItems</dfn>
</dt>
<dd>
This sequence of <a>PaymentItem</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>
<dfn>shippingOptions</dfn>
</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 data-lt=
"PaymentRequest.shippingAddress">shippingAddress</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 data-lt=
"PaymentRequest.shippingOption">shippingOption</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>PaymentRequest</a> was constructed with <a>PaymentOptions</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>shippingoptionchange</a> event will
be fired for this option unless the user selects an alternative
option first.
</p>
</dd>
<dt>
<dfn>modifiers</dfn>
</dt>
<dd>
This sequence of <a>PaymentDetailsModifier</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 data-lt=
"PaymentRequestUpdateEvent.updateWith">updateWith</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 goods cannot be
shipped to the chosen shipping address.
<p>
The <code>error</code> field cannot be passed to the
<a>PaymentRequest</a> constructor. Doing so will cause a
<a>TypeError</a> to be thrown.
</p>
</dd>
</dl>
</section>
<section data-dfn-for="PaymentDetailsModifier">
<h2>
<code>PaymentDetailsModifier</code> dictionary
</h2>
<pre class="idl">
dictionary PaymentDetailsModifier {
required sequence<DOMString> supportedMethods;
PaymentItem total;
sequence<PaymentItem> additionalDisplayItems;
object data;
};
</pre>
<p>
The <dfn>PaymentDetailsModifier</dfn> dictionary provides details that
modify the <a>PaymentDetails</a> based on <a>payment method
identifier</a>. It contains the following fields:
</p>
<dl>
<dt>
<dfn>supportedMethods</dfn>
</dt>
<dd>
The <a data-lt=
"PaymentDetailsModifier.supportedMethods">supportedMethods</a> field
contains a sequence of <a>payment method identifiers</a>. The
remaining fields in the <a>PaymentDetailsModifier</a> apply only if
the user selects a <a>payment method</a> included in this sequence.
</dd>
<dt>
<dfn>total</dfn>
</dt>
<dd>
This <a>PaymentItem</a> value overrides the <code>total</code> field
in the <a>PaymentDetails</a> dictionary for the <a>payment method
identifiers</a> in the <code>supportedMethods</code> field.
</dd>
<dt>
<dfn>additionalDisplayItems</dfn>
</dt>
<dd>
This sequence of <a>PaymentItem</a> dictionaries provides additional
display items that are appended to the <code>displayItems</code>
field in the <a>PaymentDetails</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 data-dfn-for="PaymentOptions">
<h2>
<code>PaymentOptions</code> dictionary
</h2>
<pre class="idl">
enum PaymentShippingType {
"shipping",
"delivery",
"pickup"
};
dictionary PaymentOptions {
boolean requestPayerName = false;
boolean requestPayerEmail = false;
boolean requestPayerPhone = false;