-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.html
2078 lines (2071 loc) · 84.4 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 lang="en-US">
<head>
<meta charset="utf-8">
<title>
Payment Handler API
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class=
"remove"></script>
<script class="remove">
var respecConfig = {
github: "https://github.com/w3c/payment-handler/",
specStatus: "ED",
previousPublishDate: "2019-10-21",
prevVersion: "FPWD",
previousMaturity: "WD",
editors: [
{ name: "Adrian Hope-Bailie",
url: "https://github.com/adrianhopebailie",
company: "Coil",
companyURL: "https://coil.com",
w3cid: 42590
},
{ name: "Ian Jacobs",
url: "http://www.w3.org/People/Jacobs/",
company: "W3C",
companyURL: "https://www.w3.org/",
w3cid: 2175
},
{ name: "Rouslan Solomakhin",
url: "https://github.com/rsolomakhin",
company: "Google",
companyURL: "https://www.google.com/",
w3cid: 83784
},
{ name: "Jinho Bang",
company: "Samsung",
companyURL: "https://www.samsung.com/",
w3cid: 77147
},
],
formerEditors: [
{ name: "Andre Lyver",
url: "https://github.com/lyverovski",
company: "Shopify",
companyURL: "https://shopify.com",
w3cid: 87485
},
{ name: "Tommy Thorsen",
url: "https://github.com/tommythorsen",
company: "Opera",
companyURL: "https://opera.com",
w3cid: 90636,
},
{ name: "Adam Roach",
url: "https://github.com/adamroach",
company: "Mozilla",
companyURL: "https://mozilla.org",
w3cid: 67785
},
],
group: "payments",
testSuiteURI: "https://wpt.live/payment-handler/",
xref: "web-platform",
};
</script>
</head>
<body data-cite="service-workers payment-method-id">
<section id="abstract">
<p>
This specification defines capabilities that enable Web applications to
handle requests for payment.
</p>
</section>
<section id="sotd">
<p>
The Web Payments Working Group maintains <a href=
"https://github.com/w3c/payment-handler/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>
</section>
<section class="informative">
<h2>
Introduction
</h2>
<p>
This specification defines a number of new features to allow web
applications to handle requests for payments on behalf of users:
</p>
<ul>
<li>An origin-based permission to handle payment request events.
</li>
<li>A payment request event type ({{PaymentRequestEvent}}). A <a>payment
handler</a> is an event handler for the {{PaymentRequestEvent}}.
</li>
<li>An extension to the <a>service worker registration</a> interface
({{PaymentManager}}) to manage properties of payment handlers.
</li>
<li>A mechanism to respond to the {{PaymentRequestEvent}}.
</li>
</ul>
<p class="note">
This specification does not address how software built with
operating-system specific mechanisms (i.e., "native apps") handle
payment requests.
</p>
</section>
<section id="model">
<h2>
Overview
</h2>
<p>
In this document we envision the following flow:
</p>
<ol>
<li>An origin requests permission from the user to handle payment
requests for a set of supported payment methods. For example, a user
visiting a retail or bank site may be prompted to register a payment
handler from that origin. The origin establishes the scope of the
permission but the origin's capabilities may evolve without requiring
additional user consent.
</li>
<li>
<a>Payment handlers</a> are defined in <a>service worker</a> code.
</li>
<li>When the merchant (or other <dfn>payee</dfn>) calls the
[[payment-request]] method <a>canMakePayment()</a> or <a>show()</a>
(e.g., when the user -- the <dfn>payer</dfn> -- pushes a button on a
checkout page), the user agent computes a list of candidate payment
handlers, comparing the payment methods accepted by the merchant with
those known to the user agent through any number of mechanisms,
including, but not limited to:
<ul>
<li>Those previously registered through this API.</li>
<li>Those that may be registered through this API during the course of
the transaction, e.g., identified through a <a>payment method
manifest</a>.</li>
<li>Those registered through other mechanisms, e.g., the operating
system.</li>
</ul>
</li>
<li>The user agent displays a set of choices to the user: the candidate
payment handlers. The user agent displays these choices using
information (labels and icons) provided at registration or otherwise
available from the Web app.
</li>
<li>When the <a>payer</a> user selects a payment handler, the user agent
fires a {{PaymentRequestEvent}} (cf. the <a>user interaction task
source</a>) in the <a>service worker</a> for the selected payment
handler. The {{PaymentRequestEvent}} includes some information from the
PaymentRequest (defined in [[!payment-request]]) as well as additional
information (e.g., payee's origin).
</li>
<li>Once activated, the payment handler performs whatever steps are
necessary to <a href="#handling-a-payment-request">handle the payment
request</a>, and return an appropriate payment response to the
<a>payee</a>. If interaction with the user is necessary, the <a>payment
handler</a> can open a window for that purpose.
</li>
<li>The user agent receives a response asynchronously once the payment
handler has finished handling the request. The response becomes the
<a>PaymentResponse</a> (of [[!payment-request]]).
</li>
</ol>
<p class="note">
An origin may implement a payment app with more than one service worker
and therefore multiple <a>payment handlers</a> may be registered per
origin. The handler that is invoked is determined by the selection made
by the user.
</p>
<section class="informative" id="handling-a-payment-request">
<h2>
Handling a Payment Request
</h2>
<p>
A <dfn>payment handler</dfn> is a Web application that can handle a
request for payment on behalf of the user.
</p>
<p>
The logic of a payment handler is driven by the payment methods that
it supports. Some payment methods expect little to no processing by
the payment handler which simply returns payment card details in the
response. It is then the job of the payee website to process the
payment using the returned data as input.
</p>
<p>
In contrast, some payment methods, such as a crypto-currency payments
or bank originated credit transfers, require that the payment handler
initiate processing of the payment. In such cases the payment handler
will return a payment reference, endpoint URL or some other data that
the payee website can use to determine the outcome of the payment (as
opposed to processing the payment itself).
</p>
<p>
Handling a payment request may include numerous interactions: with
the user through a new window or other APIs (such as
[[[WebCryptoAPI]]]) or with other services and origins through web
requests or other means.
</p>
<p>
This specification does not address these activities that occur
between the payment handler accepting the {{PaymentRequestEvent}} and
the payment handler returning a response. All of these activities
which may be required to configure the payment handler and handle the
payment request, are left to the implementation of the payment
handler, including:
</p>
<ul>
<li>how the user establishes an account with an origin that provides
payment services.
</li>
<li>how an origin authenticates a user.
</li>
<li>how communication takes place between the payee server and the
payee Web application, or between a payment app origin and other
parties.
</li>
</ul>
<p>
Thus, an origin will rely on many other Web technologies defined
elsewhere for lifecycle management, security, user authentication,
user interaction, and so on.
</p>
</section>
<section class="informative">
<h2>
Relation to Other Types of Payment Apps
</h2>
<p>
This specification does not address how third-party mobile payment
apps interact (through proprietary mechanisms) with user agents, or
how user agents themselves provide simple payment app functionality.
</p>
<figure>
<img alt=
"Different types of payment apps. Payment Handler API is for Web apps."
src="app-types.png">
<figcaption>
Payment Handler API enables Web apps to handle payments. Other
types of payment apps may use other (proprietary) mechanisms.
</figcaption>
</figure>
</section>
</section>
</section>
<section id="registration">
<h2>
Registration
</h2>
<p>
One registers a payment handler with the user agent through a
just-in-time (JIT) registration mechanism.
</p>
<section>
<h2>
Just-in-time registration
</h2>
<p>
If a payment handler is not registered when a merchant invokes
{{PaymentRequest/show()}} method, a user agent may allow the user to
register this payment handler during the transaction ("just-in-time").
</p>
<p><em>The remaining content of this section is non-normative.</em></p>
<p>
A user agent may perform just-in-time installation by deriving payment
handler information from the <a>payment method manifest</a> that is
found through the <a>URL-based payment method identifier</a> that the
merchant requested.
</p>
</section>
</section>
<section id="management">
<h2>
Management
</h2>
<p>
This section describes the functionality available to a payment handler
to manage its own properties.
</p>
<section data-dfn-for="ServiceWorkerRegistration">
<h2>
Extension to the `ServiceWorkerRegistration` interface
</h2>
<pre class="idl">
partial interface ServiceWorkerRegistration {
[SameObject] readonly attribute PaymentManager paymentManager;
};
</pre>
<p>
The <dfn>paymentManager</dfn> attribute exposes payment handler
management functionality.
</p>
</section>
<section data-dfn-for="PaymentManager">
<h2>
<dfn>PaymentManager</dfn> interface
</h2>
<pre class="idl">
[SecureContext, Exposed=(Window)]
interface PaymentManager {
attribute DOMString userHint;
Promise<undefined> enableDelegations(sequence<PaymentDelegation> delegations);
};
</pre>
<p>
The {{PaymentManager}} is used by <a>payment handler</a>s to manage
their supported delegations.
</p>
<section>
<h2>
<dfn>userHint</dfn> attribute
</h2>
<p>
When displaying payment handler name and icon, the user agent may
use this string to improve the user experience. For example, a user
hint of "**** 1234" can remind the user that a particular card is
available through this payment handler.
</p>
</section>
<section>
<h2>
<dfn>enableDelegations()</dfn> method
</h2>
<p>
This method allows a <a>payment handler</a> to asynchronously
declare its supported <a>PaymentDelegation</a> list.
</p>
</section>
</section>
<section data-dfn-for="PaymentDelegation">
<h2>
<dfn>PaymentDelegation</dfn> enum
</h2>
<pre class="idl">
enum PaymentDelegation {
"shippingAddress",
"payerName",
"payerPhone",
"payerEmail"
};
</pre>
<dl>
<dt>
"<dfn>shippingAddress</dfn>"
</dt>
<dd>
The payment handler will provide shipping address whenever needed.
</dd>
<dt>
"<dfn>payerName</dfn>"
</dt>
<dd>
The payment handler will provide payer's name whenever needed.
</dd>
<dt>
"<dfn>payerPhone</dfn>"
</dt>
<dd>
The payment handler will provide payer's phone whenever needed.
</dd>
<dt>
"<dfn>payerEmail</dfn>"
</dt>
<dd>
The payment handler will provide payer's email whenever needed.
</dd>
</dl>
</section>
</section>
<section id="canmakepayment">
<h2>
Can make payment
</h2>
<p>
If the <a>payment handler</a> supports <a>CanMakePaymentEvent</a>, the
<a>user agent</a> may use it to help with filtering of the available
payment handlers.
</p>
<p>
Implementations may impose a timeout for developers to respond to the
<a>CanMakePaymentEvent</a>. If the timeout expires, then the
implementation will behave as if {{CanMakePaymentEvent/respondWith()}}
was called with `false`.
</p>
<section data-dfn-for="ServiceWorkerGlobalScope">
<h2>
Extension to `ServiceWorkerGlobalScope`
</h2>
<pre class="idl">
partial interface ServiceWorkerGlobalScope {
attribute EventHandler oncanmakepayment;
};
</pre>
<section>
<h2>
<dfn>oncanmakepayment</dfn> attribute
</h2>
<p>
The {{ServiceWorkerGlobalScope/oncanmakepayment}} attribute is an
<a>event handler</a> whose corresponding <a>event handler event
type</a> is "canmakepayment".
</p>
</section>
</section>
<section data-dfn-for="CanMakePaymentEvent">
<h2>
The <dfn>CanMakePaymentEvent</dfn>
</h2>
<p>
The <a>CanMakePaymentEvent</a> is used to as a signal for whether the
payment handler is able to respond to a payment request.
</p>
<pre class="idl">
[Exposed=ServiceWorker]
interface CanMakePaymentEvent : ExtendableEvent {
constructor(DOMString type);
undefined respondWith(Promise<boolean> canMakePaymentResponse);
};
</pre>
<section>
<h2>
<dfn>respondWith()</dfn> method
</h2>
<p>
This method is used by the payment handler as a signal for whether
it can respond to a payment request.
</p>
</section>
</section>
<section>
<h2>
<dfn>Handling a CanMakePaymentEvent</dfn>
</h2>
<p>
Upon receiving a <a>PaymentRequest</a>, the <a>user agent</a> MUST
run the following steps:
</p>
<ol>
<li>If <a>user agent</a> settings prohibit usage of
<a>CanMakePaymentEvent</a> (e.g., in private browsing mode),
terminate these steps.
</li>
<li>Let <var>registration</var> be a {{ServiceWorkerRegistration}}.
</li>
<li>If <var>registration</var> is not found, terminate these steps.
</li>
<li>
<p>
<a>Fire Functional Event</a> "<code>canmakepayment</code>" using
<a>CanMakePaymentEvent</a> on <var>registration</var>.
</p>
</li>
</ol>
</section>
<section id="canmakepayment-example" class="informative">
<h2>
Example of handling the <a>CanMakePaymentEvent</a>
</h2>
<p>
This example shows how to write a service worker that listens to the
<a>CanMakePaymentEvent</a>. When a <a>CanMakePaymentEvent</a> is
received, the service worker always returns true.
</p>
<pre class="example js" title="Handling the CanMakePaymentEvent">
self.addEventListener("canmakepayment", function(e) {
e.respondWith(new Promise(function(resolve, reject) {
resolve(true);
}));
});
</pre>
</section>
<section>
<h2>
Filtering of Payment Handlers
</h2>
<p>
Given a <a>PaymentMethodData</a> and a payment handler that matches on
<a>payment method identifier</a>, this algorithm returns
<code>true</code> if this payment handler can be used for payment:
</p>
<ol class="algorithm">
<li>Let <var>methodName</var> be the <a>payment method identifier</a>
string specified in the <a>PaymentMethodData</a>.
</li>
<li>Let <var>methodData</var> be the payment method specific data of
<a>PaymentMethodData</a>.
</li>
<li>Let <var>paymentHandlerOrigin</var> be the <a>origin</a> of the
{{ServiceWorkerRegistration}} scope URL of the payment handler.
</li>
<li>Let <var>paymentMethodManifest</var> be the <a>ingested</a> and
<a>parsed</a> <a>payment method manifest</a> for the
<var>methodName</var>.
</li>
<li>If <var>methodName</var> is a <a>URL-based payment method
identifier</a> with the <code>"*"</code> string <a>supported
origins</a> in <var>paymentMethodManifest</var>, return
<code>true</code>.
</li>
<li>Otherwise, if the <a>URL-based payment method identifier</a>
<var>methodName</var> has the same <a>origin</a> as
<var>paymentHandlerOrigin</var>, fire the <a>CanMakePaymentEvent</a>
in the payment handler and return the result.
</li>
<li>Otherwise, if <a>supported origins</a> in
<var>paymentMethodManifest</var> is an ordered set of [=url/origin=]
that contains the <var>paymentHandlerOrigin</var>, fire the
<a>CanMakePaymentEvent</a> in the payment handler and return the
result.
</li>
<li>Otherwise, return `false`.
</li>
</ol>
</section>
</section>
<section id="invocation">
<h2>
Invocation
</h2>
<p>
Once the user has selected a payment handler, the user agent fires a
{{PaymentRequestEvent}} and uses the subsequent
<a>PaymentHandlerResponse</a> to create a <a>PaymentResponse</a> for
[[!payment-request]].
</p>
<p class="issue" title=
"Support for Abort() being delegated to Payment Handler" data-number=
"117">
Payment Request API supports delegation of responsibility to manage an
abort to a payment app. There is a proposal to add a
paymentRequestAborted event to the Payment Handler interface. The event
will have a respondWith method that takes a boolean parameter
indicating if the paymentRequest has been successfully aborted.
</p>
<section data-dfn-for="ServiceWorkerGlobalScope" data-link-for=
"ServiceWorkerGlobalScope">
<h2>
Extension to <a>ServiceWorkerGlobalScope</a>
</h2>
<p>
This specification extends the <a>ServiceWorkerGlobalScope</a>
interface.
</p>
<pre class="idl">
partial interface ServiceWorkerGlobalScope {
attribute EventHandler onpaymentrequest;
};
</pre>
<section>
<h2>
<dfn>onpaymentrequest</dfn> attribute
</h2>
<p>
The <a>onpaymentrequest</a> attribute is an <a>event handler</a>
whose corresponding <a>event handler event type</a> is
{{PaymentRequestEvent}}.
</p>
</section>
</section>
<section data-dfn-for="PaymentRequestDetailsUpdate" data-link-for=
"PaymentRequestDetailsUpdate">
<h2>
The <dfn>PaymentRequestDetailsUpdate</dfn>
</h2>
<p>
The <code>PaymentRequestDetailsUpdate</code> contains the updated
total (optionally with modifiers and shipping options) and possible
errors resulting from user selection of a payment method, a shipping
address, or a shipping option within a payment handler.
</p>
<pre class="idl">
dictionary PaymentRequestDetailsUpdate {
DOMString error;
PaymentCurrencyAmount total;
sequence<PaymentDetailsModifier> modifiers;
sequence<PaymentShippingOption> shippingOptions;
object paymentMethodErrors;
AddressErrors shippingAddressErrors;
};
</pre>
<section>
<h2>
<dfn>error</dfn> member
</h2>
<p>
A human readable string that explains why the user selected payment
method, shipping address or shipping option cannot be used.
</p>
</section>
<section>
<h2>
<dfn>total</dfn> member
</h2>
<p>
Updated total based on the changed payment method, shipping
address, or shipping option. The total can change, for example,
because the billing address of the payment method selected by the
user changes the Value Added Tax (VAT); Or because the shipping
option/address selected/provided by the user changes the shipping
cost.
</p>
</section>
<section>
<h2>
<dfn>modifiers</dfn> member
</h2>
<p>
Updated modifiers based on the changed payment method, shipping
address, or shipping option. For example, if the overall total has
increased by €1.00 based on the billing or shipping address, then
the totals specified in each of the modifiers should also increase
by €1.00.
</p>
</section>
<section>
<h2>
<dfn>shippingOptions</dfn> member
</h2>
<p>
Updated shippingOptions based on the changed shipping address. For
example, it is possible that express shipping is more expensive or
unavailable for the user provided country.
</p>
</section>
<section>
<h2>
<dfn>paymentMethodErrors</dfn> member
</h2>
<p>
Validation errors for the payment method, if any.
</p>
</section>
<section>
<h2>
<dfn>shippingAddressErrors</dfn> member
</h2>
<p>
Validation errors for the shipping address, if any.
</p>
</section>
</section>
<section data-dfn-for="PaymentRequestEvent" data-link-for=
"PaymentRequestEvent">
<h2>
The <dfn>PaymentRequestEvent</dfn>
</h2>
<p>
The PaymentRequestEvent represents the data and methods available to
a Payment Handler after selection by the user. The user agent
communicates a subset of data available from the
<a>PaymentRequest</a> to the Payment Handler.
</p>
<pre class="idl">
[Exposed=ServiceWorker]
interface PaymentRequestEvent : ExtendableEvent {
constructor(DOMString type, optional PaymentRequestEventInit eventInitDict = {});
readonly attribute USVString topOrigin;
readonly attribute USVString paymentRequestOrigin;
readonly attribute DOMString paymentRequestId;
readonly attribute FrozenArray<PaymentMethodData> methodData;
readonly attribute object total;
readonly attribute FrozenArray<PaymentDetailsModifier> modifiers;
readonly attribute object? paymentOptions;
readonly attribute FrozenArray<PaymentShippingOption>? shippingOptions;
Promise<WindowClient?> openWindow(USVString url);
Promise<PaymentRequestDetailsUpdate?> changePaymentMethod(DOMString methodName, optional object? methodDetails = null);
Promise<PaymentRequestDetailsUpdate?> changeShippingAddress(optional AddressInit shippingAddress = {});
Promise<PaymentRequestDetailsUpdate?> changeShippingOption(DOMString shippingOption);
undefined respondWith(Promise<PaymentHandlerResponse> handlerResponsePromise);
};
</pre>
<section>
<h2>
<dfn>topOrigin</dfn> attribute
</h2>
<p>
Returns a string that indicates the <a>origin</a> of the top level
<a>payee</a> web page. This attribute is initialized by <a>Handling
a PaymentRequestEvent</a>.
</p>
</section>
<section>
<h2>
<dfn>paymentRequestOrigin</dfn> attribute
</h2>
<p>
Returns a string that indicates the <a>origin</a> where a
<a>PaymentRequest</a> was initialized. When a <a>PaymentRequest</a>
is initialized in the <a>topOrigin</a>, the attributes have the
same value, otherwise the attributes have different values. For
example, when a <a>PaymentRequest</a> is initialized within an
iframe from an origin other than <a>topOrigin</a>, the value of
this attribute is the origin of the iframe. This attribute is
initialized by <a>Handling a PaymentRequestEvent</a>.
</p>
</section>
<section data-cite="payment-request">
<h2>
<dfn>paymentRequestId</dfn> attribute
</h2>
<p>
When getting, the <a>paymentRequestId</a> attribute returns the
{{ PaymentRequest/[[details]] }}.<a>id</a> from the <a>PaymentRequest</a> that
corresponds to this {{PaymentRequestEvent}}.
</p>
</section>
<section>
<h2>
<dfn>methodData</dfn> attribute
</h2>
<p>
This attribute 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. It is populated from the
<a>PaymentRequest</a> using the <a>MethodData Population
Algorithm</a> defined below.
</p>
</section>
<section>
<h2>
<dfn>total</dfn> attribute
</h2>
<p>
This attribute indicates the total amount being requested for
payment. It is of type <a>PaymentCurrencyAmount</a> dictionary as
defined in [[payment-request]], and initialized with a copy of the
<a>total</a> field of the <a>PaymentDetailsInit</a> provided when
the corresponding <a>PaymentRequest</a> object was instantiated.
</p>
</section>
<section>
<h2>
<dfn>modifiers</dfn> attribute
</h2>
<p>
This sequence of <a>PaymentDetailsModifier</a> dictionaries
contains modifiers for particular payment method identifiers (e.g.,
if the payment amount or currency type varies based on a
per-payment-method basis). It is populated from the
<a>PaymentRequest</a> using the <a>Modifiers Population
Algorithm</a> defined below.
</p>
</section>
<section>
<h2>
<dfn>paymentOptions</dfn> attribute
</h2>
<p>
The value of <a data-cite=
"payment-request/#dom-paymentoptions">PaymentOptions</a> in the
<a>PaymentRequest</a>. Available only when shippingAddress and/or
any subset of payer's contact information are requested.
</p>
</section>
<section>
<h2>
<dfn>shippingOptions</dfn> attribute
</h2>
<p>
The value of <a data-cite=
"payment-request#dom-paymentdetailsbase-shippingoptions">ShippingOptions</a>
in the <a>PaymentDetailsInit</a> dictionary of the corresponding
<a>PaymentRequest</a>.(<a>PaymentDetailsInit</a> inherits
ShippingOptions from <a>PaymentDetailsBase</a>). Available only
when shipping address is requested.
</p>
</section>
<section>
<h2>
<dfn>openWindow()</dfn> method
</h2>
<p>
This method is used by the payment handler to show a window to the
user. When called, it runs the <a>open window algorithm</a>.
</p>
</section>
<section>
<h2>
<dfn data-lt=
"changePaymentMethod(methodName, methodDetails)">changePaymentMethod()</dfn>
method
</h2>
<p>
This method is used by the payment handler to get updated total
given such payment method details as the billing address. When
called, it runs the <a>change payment method algorithm</a>.
</p>
</section>
<section>
<h2>
<dfn data-lt=
"changeShippingAddress(shippingAddress)">changeShippingAddress()</dfn>
method
</h2>
<p>
This method is used by the payment handler to get updated payment
details given the shippingAddress. When called, it runs the
<a>change payment details algorithm</a>.
</p>
</section>
<section>
<h2>
<dfn data-lt=
"changeShippingOption(shippingOption)">changeShippingOption()</dfn>
method
</h2>
<p>
This method is used by the payment handler to get updated payment
details given the shippingOption identifier. When called, it runs
the <a>change payment details algorithm</a>.
</p>
</section>
<section>
<h2>
<dfn data-lt=
"respondWith(handlerResponsePromise)">respondWith()</dfn> method
</h2>
<p>
This method is used by the payment handler to provide a
<a>PaymentHandlerResponse</a> when the payment successfully
completes. When called, it runs the <a>Respond to PaymentRequest
Algorithm</a> with |event| and <var>handlerResponsePromise</var> as
arguments.
</p>
</section>
<p class="issue" title="Share user data with payment app?" data-number=
"123">
Should payment apps receive user data stored in the user agent upon
explicit consent from the user? The payment app could request
permission either at installation or when the payment app is first
invoked.
</p>
<section data-dfn-for="PaymentRequestEventInit">
<h2>
<dfn>PaymentRequestEventInit</dfn> dictionary
</h2>
<pre class="idl">
dictionary PaymentRequestEventInit : ExtendableEventInit {
USVString topOrigin;
USVString paymentRequestOrigin;
DOMString paymentRequestId;
sequence<PaymentMethodData> methodData;
PaymentCurrencyAmount total;
sequence<PaymentDetailsModifier> modifiers;
PaymentOptions paymentOptions;
sequence<PaymentShippingOption> shippingOptions;
};
</pre>
<p>
The <dfn>topOrigin</dfn>, <dfn>paymentRequestOrigin</dfn>,
<dfn>paymentRequestId</dfn>, <dfn>methodData</dfn>,
<dfn>total</dfn>, <dfn>modifiers</dfn>, <dfn>paymentOptions</dfn>,
and <dfn>shippingOptions</dfn> members share their definitions with
those defined for {{PaymentRequestEvent}}
</p>
</section>
<section>
<h2>
<dfn>MethodData Population Algorithm</dfn>
</h2>
<p>
To initialize the value of the <a>methodData</a>, the user agent
MUST perform the following steps or their equivalent:
</p>
<ol>
<li>Let <var>registeredMethods</var> be the set of registered
<a>payment method identifier</a>s of the invoked payment handler.
</li>
<li>Create a new empty <a>Sequence</a>.
</li>
<li>Set <var>dataList</var> to the newly created <a>Sequence</a>.
</li>
<li>For each item in
<a>PaymentRequest</a>@<var>[[\methodData]]</var> in the
corresponding payment request, perform the following steps:
<ol>
<li>Set <var>inData</var> to the item under consideration.
</li>
<li>Set <var>commonMethods</var> to the set intersection of
<var>inData</var>.<a>supportedMethods</a> and
<var>registeredMethods</var>.
</li>
<li>If <var>commonMethods</var> is empty, skip the remaining
substeps and move on to the next item (if any).
</li>
<li>Create a new <a>PaymentMethodData</a> object.
</li>
<li>Set <var>outData</var> to the newly created
<a>PaymentMethodData</a>.
</li>
<li>Set <var>outData</var>.<a>supportedMethods</a> to a list
containing the members of <var>commonMethods</var>.
</li>
<li>Set <var>outData</var>.data to a copy of
<var>inData</var>.data.
</li>
<li>Append <var>outData</var> to <var>dataList</var>.
</li>
</ol>
</li>
<li>Set <a>methodData</a> to <var>dataList</var>.
</li>
</ol>
</section>
<section>
<h2>
<dfn>Modifiers Population Algorithm</dfn>
</h2>
<p>
To initialize the value of the <a>modifiers</a>, the user agent
MUST perform the following steps or their equivalent:
</p>
<ol>
<li>Let <var>registeredMethods</var> be the set of registered
<a>payment method identifier</a>s of the invoked payment handler.
</li>
<li>Create a new empty <a>Sequence</a>.
</li>
<li>Set <var>modifierList</var> to the newly created
<a>Sequence</a>.
</li>
<li>For each item in
<a>PaymentRequest</a>@<var>[[\paymentDetails]]</var>.<a>modifiers</a>
in the corresponding payment request, perform the following steps:
<ol>
<li>Set <var>inModifier</var> to the item under consideration.
</li>
<li>Set <var>commonMethods</var> to the set intersection of
<var>inModifier</var>.<a>supportedMethods</a> and
<var>registeredMethods</var>.
</li>
<li>If <var>commonMethods</var> is empty, skip the remaining
substeps and move on to the next item (if any).
</li>
<li>Create a new <a>PaymentDetailsModifier</a> object.
</li>
<li>Set <var>outModifier</var> to the newly created
<a>PaymentDetailsModifier</a>.
</li>
<li>Set <var>outModifier</var>.<a>supportedMethods</a> to a
list containing the members of <var>commonMethods</var>.
</li>
<li>Set <var>outModifier</var>.<a>total</a> to a copy of <var>
inModifier</var>.<a>total</a>.
</li>
<li>Append <var>outModifier</var> to <var>modifierList</var>.
</li>
</ol>
</li>
<li>Set <a>modifiers</a> to <var>modifierList</var>.
</li>
</ol>
</section>
</section>
<section>
<h2>
Internal Slots
</h2>
<p>
Instances of {{PaymentRequestEvent}} are created with the internal
slots in the following table:
</p>
<table>
<tr>
<th>
Internal Slot
</th>
<th>
Default Value
</th>
<th>
Description (<em>non-normative</em>)
</th>
</tr>
<tr>
<td>
<dfn data-dfn-for="PaymentRequestEvent">[[\windowClient]]</dfn>
</td>
<td>
null
</td>
<td>
The currently active <dfn>WindowClient</dfn>. This is set if a
payment handler is currently showing a window to the user.
Otherwise, it is null.
</td>
</tr>
<tr>
<td>
<dfn data-dfn-for="PaymentRequestEvent">[[\respondWithCalled]]</dfn>
</td>
<td>
false
</td>
<td>