forked from w3c/payment-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
5517 lines (5507 loc) · 227 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 = {
github: "https://github.com/w3c/payment-request/",
specStatus: "ED",
editors: [{
name: "Adrian Bateman",
company: "Microsoft Corporation",
w3cid: 42763,
}, {
name: "Zach Koch",
company: "Google",
w3cid: 76588,
}, {
name: "Roy McElmurry",
company: "Facebook",
w3cid: 88345,
}, {
name: "Domenic Denicola",
company: "Google",
w3cid: 52873,
}, {
name: "Marcos Cáceres",
company: "Mozilla",
w3cid: 39125,
}],
crEnd: "2018-10-31",
license: "w3c-software-doc",
previousMaturity: "WD",
previousPublishDate: "2016-07-05",
wg: "Web Payments Working Group",
wgURI: "https://www.w3.org/Payments/WG/",
wgPatentURI: "https://www.w3.org/2004/01/pp-impl/83744/status",
testSuiteURI: "https://w3c-test.org/payment-request/",
implementationReportURI: "https://w3c.github.io/test-results/payment-request/all.html",
caniuse: "payment-request",
lint: {
"no-headingless-sections": true,
"privsec-section": true,
"no-http-props": true,
"check-punctuation": true,
},
doJsonLd: true,
highlightVars: true,
pluralize: true,
xrefs: true,
};
</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>
<h1 id="title">
Payment Request API
</h1>
<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/payment-request/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>
<div class="note" title="Sending comments on this document">
<p>
If you wish to make comments regarding this document, please raise
them as <a href=
"https://github.com/w3c/payment-request/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>
<p>
The working group will demonstrate implementation experience by
producing an <a href=
"https://w3c.github.io/payment-request/reports/implementation.html">implementation
report</a>. The report will show two or more independent
implementations passing each mandatory test in the <a href=
"https://w3c-test.org/payment-request/">test suite</a> (i.e., each test
corresponds to a MUST requirement of the specification).
</p>
<p>
There has been no change in dependencies on other workings groups
during the development of this specification.
</p>
<section id="at-risk">
<h2>
Features at risk
</h2>
<p>
As this specification enters the Candidate Recommendation phase of
the W3C standardization process, the working group has identified the
following feature(s) as being "<dfn>at risk</dfn>" of being removed
from the specification. The working group seeks input from
implementers, developers, and the general public on whether these
features should remain in the specification. If no compelling use
cases are received, or if there is limited interest from
implementers, these features will be removed from the specification
before proceeding along the W3C Recommendation track.
</p>
<ul>
<li data-link-for="PaymentItem">
<a>PaymentItem</a>'s <a>type</a> member and the
<a>PaymentItemType</a> enum (see <a href=
"https://github.com/w3c/payment-request/issues/163">issue 163</a>).
</li>
<li data-link-for="PaymentRequest">As the <code>optional
detailsPromise</code> argument of the <a>show()</a> method was added
late in the Candidate Recommendation phase, the working group is
treating it "at risk" and considering moving it to a future version
of the specification. This is to avoid this version of the
specification from being delayed from progressing along the
Recommendation Track, in case we can't get two interoperable
implementations in a timely manner. However, if it gets interoperably
implemented relatively quickly, the feature will remain in this
version of the specification.
</li>
<li data-link-for="PaymentAddress">Due to <a>PaymentAddress</a>'s <a>
languageCode</a> attribute only being implemented in one browser
(Chrome), the attribute, and all its associated spec text, is <a>at
risk</a>.
</li>
</ul>
</section>
</section>
<section class='informative'>
<h2>
Introduction
</h2>
<p>
This specification describes an API that allows <a>user agents</a>
(e.g., browsers) to act as an intermediary between three parties in a
transaction:
</p>
<ul>
<li>the payee: the merchant that runs an online store, or other party
that requests to be paid.
</li>
<li>the payer: the party that makes a purchase at that online store,
and who authenticates and authorizes payment as required.
</li>
<li>the <dfn>payment method</dfn> provider: the party that provides the
means (e.g., credit card) that the payer uses to pay, and that is
accepted by the payee.
</li>
</ul>
<p>
The details of how to fulfill a payment request for a given <a>payment
method</a> is an implementation detail of a <dfn>payment handler</dfn>.
Concretely, each payment handler defines:
</p>
<dl>
<dt>
<dfn>Steps to check if a payment can be made</dfn>:
</dt>
<dd>
How a payment handler determines whether it, or the user, can
potentially "make a payment" is also an implementation detail of a
payment handler. For an example, see the <a data-cite=
"payment-method-basic-card#steps-to-check-if-a-payment-can-be-made">can
make payment</a> algorithm of [[payment-method-basic-card]].
</dd>
<dt>
<dfn>Steps to respond to a payment request</dfn>:
</dt>
<dd>
Steps that return an object or <a data-cite=
"!WEBIDL#idl-dictionary">dictionary</a> that a merchant uses to
process or validate the transaction. The structure of this object is
specific to each <a>payment method</a>. For an example of such an
object, see the <code><a data-cite=
"payment-method-basic-card#dom-basiccardresponse">BasicCardResponse</a></code>
dictionary of [[payment-method-basic-card]].
</dd>
<dt>
<dfn>Steps for when a user changes payment method</dfn> (optional)
</dt>
<dd>
Steps that describe how to handle the user changing payment method or
monetary instrument (e.g., from a debit card to a credit card) that
results in a <a data-cite="!WEBIDL#idl-dictionary">dictionary</a> or
<a data-cite="!WEBIDL#idl-object">object</a> or null.
</dd>
</dl>
<p>
This API 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 method</a> providers.
</li>
<li>Enable user agents to streamline the user's payment experience by
taking into account user preferences, merchant information, security
considerations, and other factors.
</li>
<li>Standardize (to the extent that it makes sense) the communication
flow between a merchant, user agent, and <a>payment method</a>
provider.
</li>
<li>Enable <a>payment method</a> providers 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 class="informative">
<h2>
Examples of usage
</h2>
<p>
In order to use the API, the developer needs to provide and keep track
of a number of key pieces of information. These bits of information are
passed to the <a>PaymentRequest</a> constructor as arguments, and
subsequently used to update the payment request being displayed to the
user. Namely, these bits of information are:
</p>
<ul>
<li>The <var>methodData</var>: A sequence of <a>PaymentMethodData</a>s
that represents the <a>payment methods</a> that the site supports
(e.g., "we support card-based payments, but only Visa and MasterCard
credit cards.").
</li>
<li>The <var>details</var>: The details of the transaction, as a
<a>PaymentDetailsInit</a> dictionary. This includes total cost, and
optionally a list of goods or services being purchased, for physical
goods, and shipping options. Additionally, it can optionally include
"modifiers" to how payments are made. For example, "if you pay with a
credit card of type X, it incurs a US$3.00 processing fee".
</li>
<li>The <var>options</var>: Optionally, a list of things as
<a>PaymentOptions</a> that the site needs to deliver the good or
service (e.g., for physical goods, the merchant will typically need an
physical address to ship to. For digital goods, an email will usually
suffice).
</li>
</ul>
<p data-link-for="PaymentRequest">
Once a <a>PaymentRequest</a> is constructed, it's presented to the end
user via the <a>show()</a> method. The <a>show()</a> returns a promise
that, once the user confirms request for payment, results in a
<a>PaymentResponse</a>.
</p>
<section>
<h3>
The <code>methodData</code> argument
</h3>
<p>
The <var>methodData</var> 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 js" title="The `methodData` argument">
const methodData = [
{
supportedMethods: "basic-card",
data: {
supportedNetworks: ["visa", "mastercard"],
supportedTypes: ["debit", "credit"],
},
},
{
supportedMethods: "https://example.com/bobpay",
data: {
merchantIdentifier: "XXXX",
bobPaySpecificField: true,
},
},
];
</pre>
</section>
<section>
<h3>
The <code>details</code> argument
</h3>
<p>
The <var>details</var> 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 js" title="The `details` argument">
const details = {
id: "super-store-order-123-12312",
displayItems: [
{
label: "Sub-total",
amount: { currency: "USD", value: "55.00" },
},
{
label: "Sales Tax",
amount: { currency: "USD", value: "5.00" },
type: "tax"
},
],
total: {
label: "Total due",
// The total is USD$65.00 here because we need to
// add shipping (below). The selected shipping
// costs USD$5.00.
amount: { currency: "USD", value: "65.00" },
},
};
</pre>
<section>
<h4>
Shipping options
</h4>
<p>
Here we see an example of how to add two shipping options to the
<var>details</var>.
</p>
<pre class="example js" title="Adding shipping options">
const shippingOptions = [
{
id: "standard",
label: "🚛 Ground Shipping (2 days)",
amount: { currency: "USD", value: "5.00" },
selected: true,
},
{
id: "drone",
label: "🚀 Drone Express (2 hours)",
amount: { currency: "USD", value: "25.00" }
},
];
Object.assign(details, { shippingOptions });
</pre>
</section>
<section>
<h4>
Conditional modifications to payment request
</h4>
<p>
Here we see how to add a processing fee for using a credit card.
Notice that it requires recalculating the total.
</p>
<pre class="example js" title=
"Modifying payment request based on card type">
// Credit card incurs a $3.00 processing fee.
const creditCardFee = {
label: "Credit card processing fee",
amount: { currency: "USD", value: "3.00" },
};
// Modifiers apply when the user chooses to pay with
// a credit card.
const modifiers = [
{
additionalDisplayItems: [creditCardFee],
supportedMethods: "basic-card",
total: {
label: "Total due",
amount: { currency: "USD", value: "68.00" },
},
data: {
supportedTypes: "credit",
},
},
];
Object.assign(details, { modifiers });
</pre>
</section>
</section>
<section>
<h3>
The <code>options</code> argument
</h3>
<p>
The <var>options</var> dictionary contains information the developer
needs from the user to perform the payment (e.g., the payer's name
and shipping address).
</p>
<pre class="example" title="The `options` argument">
const options = {
requestPayerEmail: false,
requestPayerName: true,
requestPayerPhone: false,
requestShipping: true,
}
</pre>
</section>
<section>
<h3>
Constructing a <code>PaymentRequest</code>
</h3>
<p>
Having gathered all the prerequisite bits of information, we can now
construct a <a>PaymentRequest</a> and request that the browser
present it to the user:
</p>
<pre class="example" title="Constructing a `PaymentRequest`">
async function doPaymentRequest() {
try {
const request = new PaymentRequest(methodData, details, options);
// See below for a detailed example of handling these events
request.onshippingaddresschange = ev => ev.updateWith(details);
request.onshippingoptionchange = ev => ev.updateWith(details);
const response = await request.show();
await validateResponse(response);
} catch (err) {
// AbortError, SecurityError
console.error(err);
}
}
async function validateResponse(response) {
try {
if (await checkAllValuesAreGood(response)) {
await response.complete("success");
} else {
await response.complete("fail");
}
} catch (err) {
// Something went wrong...
await response.complete("fail");
}
}
doPaymentRequest();
</pre>
</section>
<section>
<h3>
Handling events and updating the payment request
</h3>
<p>
Prior to the user accepting to make payment, the site is given an
opportunity to update the payment request in response to user input.
This can include, for example, providing additional shipping options
(or modifying their cost), removing items that cannot ship to a
particular address, etc.
</p>
<pre class="example" title="Registering event handlers">
const request = new PaymentRequest(methodData, details, options);
// Async update to details
request.onshippingaddresschange = ev => {
ev.updateWith(checkShipping(request));
};
// Sync update to the total
request.onshippingoptionchange = ev => {
// selected shipping option
const { shippingOption } = request;
const newTotal = {
currency: "USD",
label: "Total due",
value: calculateNewTotal(shippingOption),
};
ev.updateWith({ total: newTotal });
};
async function checkShipping(request) {
try {
const json = request.shippingAddress.toJSON();
await ensureCanShipTo(json);
const { shippingOptions, total } = await calculateShipping(json);
return { shippingOptions, total };
} catch (err) {
return { error: `Sorry! we can't ship to your address.` };
}
}
</pre>
</section>
<section>
<h3>
Fine-grained error reporting
</h3>
<p>
A developer can use the <a data-link-for=
"PaymentDetailsUpdate">shippingAddressErrors</a> member of the
<a>PaymentDetailsUpdate</a> dictionary to indicate that there are
validation errors with specific attributes of a
<a>PaymentAddress</a>. The <a data-link-for=
"PaymentDetailsUpdate">shippingAddressErrors</a> member is a
<a>AddressErrors</a> dictionary, whose members specifically demarcate
the fields of a <a>physical address</a> that are erroneous while also
providing helpful error messages to be displayed to the end user.
</p>
<pre class="example">
request.onshippingaddresschange = ev => {
ev.updateWith(validateAddress(request.shippingAddress));
};
function validateAddress(shippingAddress) {
const error = "Can't ship to this address.";
const shippingAddressErrors = {
city: "FarmVille is not a real place.",
postalCode: "Unknown postal code for your country.",
};
// Empty shippingOptions implies that we can't ship
// to this address.
const shippingOptions = [];
return { error, shippingAddressErrors, shippingOptions };
}
</pre>
</section>
<section data-link-for="PaymentResponse">
<h3>
POSTing payment response back to a server
</h3>
<p>
It's expected that data in a <a>PaymentResponse</a> will be POSTed
back to a server for processing. To make this as easy as possible,
<a>PaymentResponse</a> provides a <a>toJSON()</a> method that
serializes the object directly into JSON. This makes it trivial to
POST the resulting JSON back to a server using the <a data-cite=
"fetch">Fetch API</a>:
</p>
<pre class="example" title="POSTing with `fetch()`">
async function doPaymentRequest() {
const payRequest = new PaymentRequest(methodData, details, options);
const payResponse = await payRequest.show();
let result = "";
try {
const httpResponse = await fetch("/process-payment", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: payResponse.toJSON(),
});
result = httpResponse.ok ? "success" : "fail";
} catch (err) {
console.error(err);
result = "fail";
}
await payResponse.complete(result);
}
doPaymentRequest();
</pre>
</section>
</section>
<section data-dfn-for="PaymentRequest" data-link-for="PaymentRequest">
<h2>
<dfn>PaymentRequest</dfn> interface
</h2>
<pre class="idl">
[Constructor(sequence<PaymentMethodData> methodData, PaymentDetailsInit details, optional PaymentOptions options),
SecureContext, Exposed=Window]
interface PaymentRequest : EventTarget {
[NewObject]
Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise);
[NewObject]
Promise<void> abort();
[NewObject]
Promise<boolean> canMakePayment();
readonly attribute DOMString id;
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
readonly attribute PaymentShippingType? shippingType;
attribute EventHandler onmerchantvalidation;
attribute EventHandler onshippingaddresschange;
attribute EventHandler onshippingoptionchange;
attribute EventHandler onpaymentmethodchange;
};
</pre>
<div class="note">
<p>
A developer creates a <a>PaymentRequest</a> to make a payment
request. This is typically associated with the user initiating a
payment process (e.g., by activating a "Buy," "Purchase," or
"Checkout" button on a web site, selecting a "Power Up" in an
interactive game, or paying at a kiosk in a parking structure). The
<a>PaymentRequest</a> allows developers to exchange information with
the <a>user agent</a> while the user is providing input (up to the
point of user approval or denial of the payment request).
</p>
<p data-link-for="PaymentRequest">
The <a>shippingAddress</a>, <a>shippingOption</a>, and
<a>shippingType</a> attributes are populated during processing if the
<a data-lt="PaymentOptions.requestShipping">requestShipping</a>
member is set.
</p>
</div>
<p data-link-for="PaymentRequest">
Because the simultaneous display of multiple <a>PaymentRequest</a> user
interfaces might confuse the user, this specification limits the
<a>user agent</a> to displaying one at a time via the <a>show()</a>
method. This is ensured by a <dfn>payment request is showing</dfn>
boolean.
</p>
<section>
<h2>
Constructor
</h2>
<p>
The <a>PaymentRequest</a> is constructed using the supplied sequence
of <a>PaymentMethodData</a> <var>methodData</var> including any
<a>payment method</a> specific <a data-lt=
"PaymentMethodData.data">data</a>, the <a>PaymentDetailsInit</a>
<var>details</var>, and the <a>PaymentOptions</a> <var>options</var>.
</p>
<p data-tests=
"payment-request-constructor.https.html payment-request-insecure.http.html">
The <code><dfn data-lt=
"PaymentRequest.PaymentRequest()">PaymentRequest(<var>methodData</var>,
<var>details</var>, <var>options</var>)</dfn></code> constructor MUST
act as follows:
</p>
<ol data-link-for="PaymentDetailsBase" class="algorithm">
<li data-tests=
"allowpaymentrequest/active-document-cross-origin.https.sub.html, allowpaymentrequest/active-document-same-origin.https.html, allowpaymentrequest/removing-allowpaymentrequest.https.sub.html, allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html, allowpaymentrequest/setting-allowpaymentrequest.https.sub.html">
If the <a>current settings object</a>'s <a data-cite=
"!HTML#responsible-document">responsible document</a> is not
<a>allowed to use</a> the feature indicated by attribute name
<a>allowpaymentrequest</a>, then <a>throw</a> a
"<a>SecurityError</a>" <a>DOMException</a>.
</li>
<li>Let <var>serializedMethodData</var> be an empty list.
</li>
<li>Establish the request's id:
<ol>
<li data-tests="payment-request-id-attribute.https.html">If <var>
details</var>.<a data-lt="PaymentDetailsInit.id">id</a> is
missing, add an <a data-lt="PaymentDetailsInit.id">id</a>
member to <var>details</var> and set its value to a
<abbr title="Universally Unique Identifier">UUID</abbr>
[[!RFC4122]].
</li>
</ol>
</li>
<li>Process payment methods:
<ol data-link-for="PaymentMethodData">
<li>If the length of the <var>methodData</var> sequence is zero,
then <a>throw</a> a <a>TypeError</a>, optionally informing the
developer that at least one <a>payment method</a> is required.
</li>
<li>For each <var>paymentMethod</var> of <var>methodData</var>:
<ol>
<li data-tests=
"payment-request-ctor-pmi-handling.https.html">Run the steps
to <a data-cite=
"payment-method-id#dfn-validate-a-payment-method-identifier">
validate a payment method identifier</a> with
<var>paymentMethod</var>.<a data-lt=
"PaymentMethodData.supportedMethods">supportedMethods</a>.
If it returns false, then throw a <a>RangeError</a>
exception. Optionally, inform the developer that the
payment method identifier is invalid.
</li>
<li>If the <a data-lt="PaymentMethodData.data">data</a>
member of <var>paymentMethod</var> is missing, let
<var>serializedData</var> be null. Otherwise, let
<var>serializedData</var> be the result of
<a>JSON-serializing</a>
<var>paymentMethod</var>.<a data-lt="PaymentMethodData.data">data</a>
into a string. Rethrow any exceptions.
</li>
<li>Add the tuple (<var>paymentMethod</var>.<a data-lt=
"PaymentMethodData.supportedMethods">supportedMethods</a>,
<var>serializedData</var>) to
<var>serializedMethodData</var>.
</li>
</ol>
</li>
</ol>
</li>
<li data-link-for="PaymentDetailsInit">Process the total:
<ol>
<li data-tests=
"payment-request-ctor-currency-code-checks.https.html">
<a>Check and canonicalize total amount</a>
<var>details</var>.<a>total</a>.<a data-lt=
"PaymentItem.amount">amount</a>. Rethrow any exceptions.
</li>
</ol>
</li>
<li>If the <a>displayItems</a> member of <var>details</var> is
present, then for each <var>item</var> in
<var>details</var>.<a>displayItems</a>:
<ol>
<li data-tests=
"payment-request-ctor-currency-code-checks.https.html">
<a>Check and canonicalize amount</a>
<var>item</var>.<a data-lt="PaymentItem.amount">amount</a>.
Rethrow any exceptions.
</li>
</ol>
</li>
<li>Let <var>selectedShippingOption</var> be null.
</li>
<li>If the <a data-lt=
"PaymentOptions.requestShipping">requestShipping</a> member of <var>
options</var> is present and set to true, process shipping options:
<ol>
<li>Let <var>options</var> be an empty <code><a data-cite=
"!WEBIDL#idl-sequence">sequence</a></code><<a>PaymentShippingOption</a>>.
</li>
<li>If the <a>shippingOptions</a> member of <var>details</var> is
present, then:
<ol data-link-for="PaymentShippingOption">
<li>Let <var>seenIDs</var> be an empty set.
</li>
<li>For each <var>option</var> in
<var>details</var>.<a data-link-for=
"PaymentDetailsBase">shippingOptions</a>:
<ol>
<li data-tests=
"payment-request-ctor-currency-code-checks.https.html">
<a>Check and canonicalize amount</a>
<var>item</var>.<a data-lt=
"PaymentItem.amount">amount</a>. Rethrow any
exceptions.
</li>
<li>If <var>seenIDs</var> contains
<var>option</var>.<a>id</a>, then throw a
<a>TypeError</a>. Optionally, inform the developer that
shipping option IDs must be unique.
</li>
<li>Otherwise, append <var>option</var>.<a>id</a> to
<var>seenIDs</var>.
</li>
<li>If <var>option</var>.<a>selected</a> is true, then
set <var>selectedShippingOption</var> to
<var>option</var>.<a>id</a>.
</li>
</ol>
</li>
</ol>
</li>
<li>Set <var>details</var>.<a data-lt=
"PaymentDetailsBase.shippingOptions">shippingOptions</a> to <var>
options</var>.
</li>
</ol>
</li>
<li>Let <var>serializedModifierData</var> be an empty list.
</li>
<li data-link-for="PaymentDetailsBase">Process payment details
modifiers:
<ol>
<li>Let <var>modifiers</var> be an empty <code><a data-cite=
"!WEBIDL#idl-sequence">sequence</a></code><<a>PaymentDetailsModifier</a>>.
</li>
<li>If the <a>modifiers</a> member of <var>details</var> is
present, then:
<ol>
<li>Set <var>modifiers</var> to
<var>details</var>.<a>modifiers</a>.
</li>
<li>For each <var>modifier</var> of <var>modifiers</var>:
<ol>
<li>If the <a data-lt=
"PaymentDetailsModifier.total">total</a> member of <var>
modifier</var> is present, then:
<ol>
<li data-tests=
"payment-request-ctor-currency-code-checks.https.html">
<a>Check and canonicalize total amount</a>
<var>modifier</var>.<a data-lt=
"PaymentDetailsModifier.total">total</a>.<a data-lt="PaymentItem.amount">amount</a>.
Rethrow any exceptions.
</li>
</ol>
</li>
<li>If the <a data-lt=
"PaymentDetailsModifier.additionalDisplayItems">additionalDisplayItems</a>
member of <var>modifier</var> is present, then for each
<var>item</var> of <var>modifier</var>.<a data-lt=
"PaymentDetailsModifier.additionalDisplayItems">additionalDisplayItems</a>:
<ol>
<li data-tests=
"payment-request-ctor-currency-code-checks.https.html">
<a>Check and canonicalize amount</a>
<var>item</var>.<a data-lt=
"PaymentItem.amount">amount</a>. Rethrow any
exceptions.
</li>
</ol>
</li>
<li>If the <a data-lt=
"PaymentDetailsModifier.data">data</a> member of
<var>modifier</var> is missing, let
<var>serializedData</var> be null. Otherwise, let
<var>serializedData</var> be the result of
<a>JSON-serializing</a> <var>modifier</var>.<a data-lt=
"PaymentDetailsModifier.data">data</a> into a string.
Rethrow any exceptions.
</li>
<li>Add <var>serializedData</var> to
<var>serializedModifierData</var>.
</li>
<li>Remove the <a data-lt="PaymentDetailsModifier.data">
data</a> member of <var>modifier</var>, if it is
present.
</li>
</ol>
</li>
</ol>
</li>
<li>Set <var>details</var>.<a data-lt=
"PaymentDetailsBase.modifiers">modifiers</a> to
<var>modifiers</var>.
</li>
</ol>
</li>
<li>Let <var>request</var> be a new <a>PaymentRequest</a>.
</li>
<li>Set <var>request</var>.<a>[[\options]]</a> to <var>options</var>.
</li>
<li>Set <var>request</var>.<a>[[\state]]</a> to "<a>created</a>".
</li>
<li>Set <var>request</var>.<a>[[\updating]]</a> to false.
</li>
<li>Set <var>request</var>.<a>[[\details]]</a> to <var>details</var>.
</li>
<li>Set <var>request</var>.<a>[[\serializedModifierData]]</a> to
<var>serializedModifierData</var>.
</li>
<li>Set <var>request</var>.<a>[[\serializedMethodData]]</a> to <var>
serializedMethodData</var>.
</li>
<li>Set <var>request</var>.<a>[[\response]]</a> to null.
</li>
<li>Set the value of <var>request</var>'s <a data-lt=
"PaymentRequest.shippingOption">shippingOption</a> attribute to <var>
selectedShippingOption</var>.
</li>
<li>Set the value of the <a data-lt="PaymentRequest.shippingAddress">
shippingAddress</a> attribute on <var>request</var> to null.
</li>
<li>If <var>options</var>.<a data-lt=
"PaymentOptions.requestShipping">requestShipping</a> is set to true,
then set the value of the <a data-lt=
"PaymentRequest.shippingType">shippingType</a> attribute on
<var>request</var> to <var>options</var>.<a data-lt=
"PaymentOptions.shippingType">shippingType</a>. Otherwise, set it to
null.
</li>
<li>Return <var>request</var>.
</li>
</ol>
</section>
<section data-dfn-for="PaymentRequest" data-link-for="PaymentRequest">
<h2>
<dfn>id</dfn> attribute
</h2>
<p data-tests="payment-request-id-attribute.https.html">
When getting, the <a>id</a> attribute returns this
<a>PaymentRequest</a>'s <a>[[\details]]</a>.<a data-lt=
"PaymentDetailsInit.id">id</a>.
</p>
</section>
<section data-dfn-for="PaymentRequest" data-link-for="PaymentRequest">
<h2>
<dfn>show()</dfn> method
</h2>
<div class="note">
<p>
The <a>show()</a> method is called when a developer wants to begin
user interaction for the payment request. The <a>show()</a> 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 <a>show()</a> method returns.
</p>
<p>
It is not possible to show multiple <a>PaymentRequest</a>s at the
same time within one <a>user agent</a>. If a <a>PaymentRequest</a>
is already showing, calling <a>show()</a> —from any Web site— will
return <a>a promise rejected with</a> an "<a>AbortError</a>"
<a>DOMException</a>.
</p>
</div>
<p data-tests=
"payment-request-show-method.https.html, payment-request-show-method.https.html">
The <code>show(optional <var>detailsPromise</var>)</code> method MUST
act as follows:
</p>
<ol class="algorithm">
<li data-tests=
"payment-request-show-method.https.html, show-method-postmessage-manual.https.html">
If the method was not <a>triggered by user activation</a>, return <a>
a promise rejected with</a> with a "<a>SecurityError</a>"
<a>DOMException</a>.
</li>
<li>Let <var>request</var> be the <a>context object</a>.
</li>
<li>Let <var>document</var> be <var>request</var>'s <a data-cite=
"!HTML#concept-relevant-global">relevant global object</a>'s
<a data-cite="!HTML#concept-document-window">associated Document</a>.
</li>
<li data-tests="rejects_if_not_active.https.html">If
<var>document</var> is not <a data-cite="!HTML#fully-active">fully
active</a>, then return <a>a promise rejected with</a> an
"<a>AbortError</a>" <a>DOMException</a>.
</li>
<li>
<p>
Optionally, if the <a>user agent</a> wishes to disallow the call
to <a>show()</a> to protect the user, then return a promise
rejected with a "<a>SecurityError</a>" <a>DOMException</a>. For
example, the <a>user agent</a> may limit the rate at which a page
can call <a>show()</a>, as described in the <a href=
"#privacy">privacy considerations</a> section.
</p>
</li>
<li>If <var>request</var>.<a>[[\state]]</a> is not "<a>created</a>"
then return <a>a promise rejected with</a> an
"<a>InvalidStateError</a>" <a>DOMException</a>.
</li>
<li>If the <a>user agent</a>'s <a>payment request is showing</a>
boolean is true, then return <a>a promise rejected with</a> an
"<a>AbortError</a>" <a>DOMException</a>.
</li>
<li>Set <var>request</var>.<a>[[\state]]</a> to "<a>interactive</a>".
</li>
<li>Let <var>acceptPromise</var> be <a>a new promise</a>.
</li>
<li>Set <var>request</var>.<a>[[\acceptPromise]]</a> to
<var>acceptPromise</var>.
</li>
<li>
<p>
Optionally:
</p>
<ol>
<li>Reject <var>acceptPromise</var> with an "<a>AbortError</a>"
<a>DOMException</a>.
</li>
<li>Set <var>request</var>.<a>[[\state]]</a> to "<a>closed</a>".
</li>
<li>Return <var>acceptPromise</var>.
</li>
</ol>
<p class="note">
This allows the <a>user agent</a> to act as if the user had
immediately <a data-lt="user aborts the payment request">aborted
the payment request</a>, at its discretion. For example, in
"private browsing" modes or similar, user agents might take
advantage of this step.
</p>
</li>
<li>Set the <a>user agent</a>'s <a>payment request is showing</a>
boolean to true.
</li>
<li>Return <var>acceptPromise</var> and perform the remaining steps
<a>in parallel</a>.
</li>
<li>Let <var>handlers</var> be an empty <a>list</a>.
</li>
<li>For each <var>paymentMethod</var> tuple in
<var>request</var>.<a>[[\serializedMethodData]]</a>:
<ol>
<li>Let <var>identifier</var> be the first element in the
<var>paymentMethod</var> tuple.
</li>
<li>Let <var>data</var> be the result of <a data-cite=
"!ECMASCRIPT#sec-json.parse">JSON-parsing</a> the second element
in the <var>paymentMethod</var> tuple.
</li>
<li>If required by the specification that defines the
<var>identifier</var>, then <a data-cite=
"!WEBIDL#dfn-convert-ecmascript-to-idl-value">convert</a>
<var>data</var> to an IDL value of the type specified there.
Otherwise, <a data-cite=
"!WEBIDL#dfn-convert-ecmascript-to-idl-value">convert</a> to
<a data-cite="!WEBIDL#idl-object">object</a>.
</li>
<li>If conversion results in a <a data-cite=
"!WEBIDL#dfn-exception">exception</a> <var>error</var>:
<ol>