forked from w3c/payment-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2051 lines (2034 loc) · 83.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 Handler API
</title>
<meta charset='utf-8'>
<script src='https://www.w3.org/Tools/respec/respec-w3c-common' class=
'remove'></script>
<script src='utils.js' class='remove'></script>
<script class='remove'>
var respecConfig = {
github: "https://github.com/w3c/payment-handler/",
shortName: "payment-handler",
edDraftURI: "https://w3c.github.io/payment-handler/",
specStatus: "ED",
editors: [
{ name: "Adrian Hope-Bailie",
url: "https://github.com/adrianhopebailie",
company: "Ripple",
companyURL: "https://ripple.com",
w3cid: 42590
},
{ 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
},
{ name: "Andre Lyver",
url: "https://github.com/lyverovski",
company: "Shopify",
companyURL: "https://shopify.com",
w3cid: 87485
},
{ 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
},
],
license: "w3c-software-doc",
wg: "Web Payments Working Group",
wgURI: "https://www.w3.org/Payments/WG/",
wgPatentURI: "https://www.w3.org/2004/01/pp-impl/83744/status",
issueBase: "https://github.com/w3c/payment-handler/issues/",
githubAPI: "https://api.github.com/repos/w3c/payment-handler",
};
</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>
The <a data-cite="payment-request">Payment Request API</a> provides a
standard way to initiate payment requests from Web pages and
applications. User agents implementing that API prompt the user to
select a way to handle the payment request, after which the user agent
returns a payment response to the originating site. This specification
defines capabilities that enable Web applications to handle payment
requests.
</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>
The Web Payments Working Group seeks to streamline payments on the Web
to help reduce "shopping cart abandonment" and make it easier to deploy
new payment methods on the Web. It has published the Payment Request
API [[!payment-request]] as a standard way to initiate payment requests
from E-Commerce Web sites and applications.
</p>
<p>
A <dfn>payment app</dfn> is a Web application that can handle payment
requests on behalf of the user. This specification defines a number of
new Web platform features to handle payment requests:
</p>
<ul>
<li>An origin-based permission to handle payment request events.
</li>
<li>A payment request event type (<a>PaymentRequestEvent</a>). A <dfn>
payment handler</dfn> is an event handler for the
<a>PaymentRequestEvent</a>.
</li>
<li>An extension to the service worker registration interface
(<a>PaymentManager</a>) to manage the definition, display, and user
selection of <a>PaymentInstrument</a>s.
</li>
<li>A mechanism to respond to the PaymentRequestEvent.
</li>
</ul>
<p>
This specification does not address how software built with
operating-system specific mechanisms (e.g., "native mobile apps")
handle payment requests.
</p>
<p class="issue" title="Permission" data-number="151">
The term "payment app" may be useful as a shorthand for "Web app that
can handle payments with Payment Request API."
</p>
</section>
<section id='conformance'>
<p>
This specification defines one class of products:
</p>
<dl>
<dt>
<dfn>Conforming user agent</dfn>
</dt>
<dd>
<p>
A <a>user agent</a> MUST behave as described in this specification
to be considered conformant. In this specification, <dfn>user
agent</dfn> means a <em>Web browser or other interactive user
agent</em> as defined in [[!HTML5]].
</p>
<p>
User agents MAY implement algorithms given in this specification in
any way desired, so long as the end result is indistinguishable
from the result that would be obtained by the specification's
algorithms.
</p>
<p>
A conforming Payment Handler API user agent MUST also be a
<em>conforming implementation</em> of the IDL fragments of this
specification, as described in the “Web IDL” specification.
[[!WEBIDL-LS]]
</p>
<aside class="note">
This specification uses both the terms "conforming user agent(s)"
and "user agent(s)" to refer to this product class.
</aside>
</dd>
</dl>
</section>
<section id="dependencies">
<h2>
Dependencies
</h2>
<p>
This specification relies on several other underlying specifications.
</p>
<dl>
<dt>
Payment Request API
</dt>
<dd>
The terms <dfn data-lt="payment methods" data-cite=
"!payment-request#dfn-payment-method">payment method</dfn>,
<dfn data-cite=
"!payment-request#dom-paymentrequest">PaymentRequest</dfn>,
<dfn data-cite=
"!payment-request#dom-paymentresponse">PaymentResponse</dfn>,
<dfn data-cite=
"!payment-request#dom-paymentmethoddata-supportedmethods">supportedMethods</dfn>,
<dfn data-cite=
"!payment-request#paymentcurrencyamount-dictionary">PaymentCurrencyAmount</dfn>,
<dfn data-cite=
"!payment-request#paymentdetailsmodifier-dictionary">paymentDetailsModifier</dfn>,
<dfn data-cite=
"!payment-request#paymentdetailsinit-dictionary">paymentDetailsInit</dfn>,
<dfn data-cite=
"!payment-request#paymentmethoddata-dictionary">PaymentMethodData</dfn>,
<dfn data-cite="!payment-request#id-attribute">ID</dfn>,
<dfn data-cite="!payment-request#show-method">show()</dfn>, and
<dfn data-cite=
"!payment-request#user-accepts-the-payment-request-algorithm">user
accepts the payment request algorithm</dfn> are defined by the
Payment Request API specification [[!payment-request]].
</dd>
<dt>
ECMA-262 6th Edition, The ECMAScript 2015 Language Specification
</dt>
<dd>
The terms <dfn data-cite=
"!ECMA-262-2015#sec-promise-objects">Promise</dfn>, <dfn data-cite=
"!ECMA-262-2015#sec-object-internal-methods-and-internal-slots">internal
slot</dfn>, <code><dfn data-cite=
"!ECMA-262-2015#sec-native-error-types-used-in-this-standard-typeerror">
TypeError</dfn></code>, and <code><dfn data-cite=
"!ECMA-262-2015#sec-json.stringify">JSON.stringify</dfn></code> are
defined by [[!ECMA-262-2015]].
<p>
The term <dfn data-lt=
"JSON-serialized|JSON-serializable">JSON-serialize</dfn> applied to
a given object means to run the algorithm specified by the original
value of the <a>JSON.stringify</a> function on the supplied object,
passing the supplied object as the sole argument, and return the
resulting string. This can throw an exception.
</p>
</dd>
<dt>
Payment Method Identifiers
</dt>
<dd>
The terms <dfn data-lt="payment method identifiers">payment method
identifier</dfn> is defined by the Payment Method Identifier
specification [[!payment-method-id]].
</dd>
<dt>
Basic Card Payment
</dt>
<dd>
The terms <dfn data-cite=
"!payment-method-basic-card#method-id">basic-card</dfn>,
<dfn data-cite=
"!payment-method-basic-card#dfn-supportednetworks">supportedNetworks</dfn>,
and <dfn data-cite=
"!payment-method-basic-card#dfn-supportedtypes">supportedTypes</dfn>
are defined in [[!payment-method-basic-card]].
</dd>
<dt>
HTML5
</dt>
<dd>
The terms <dfn data-cite="!HTML5#global-object">global object</dfn>,
<dfn data-cite="!HTML5#top-level-browsing-context">top-level browsing
context</dfn>, <dfn data-cite="!HTML5#structured-clone">structured
clone</dfn>, <dfn data-cite="!HTML5#event-handlers">event
handler</dfn>, <dfn data-cite="!HTML5#event-handler-event-type">event
handler event type</dfn>, <dfn data-cite=
"!HTML5#concept-events-trusted">trusted event</dfn>, and
<dfn data-cite="!HTML5#user-interaction-task-source">user interaction
task source</dfn> are defined by [[!HTML5]].
</dd>
<dt>
RFC6454
</dt>
<dd>
The term <dfn>origin</dfn> is defined in [[!RFC6454]].
</dd>
<dt>
DOM
</dt>
<dd>
The term <dfn data-cite="!DOM4#firing-events">fires</dfn> (an event)
is defined in [[!DOM4]].
</dd>
<dt>
Web IDL
</dt>
<dd>
<p>
<dfn data-cite="!WEBIDL-LS#dfn-DOMException">DOMException</dfn> and
the following <a>DOMException</a> types from [[!WEBIDL-LS]] are
used:
</p>
<ul>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#invalidaccesserror">InvalidAccessError</dfn></code>"
</li>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#invalidstateerror">InvalidStateError</dfn></code>"
</li>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#notallowederror">NotAllowedError</dfn></code>"
</li>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#notfounderror">NotFoundError</dfn></code>"
</li>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#operationerror">OperationError</dfn></code>"
</li>
<li>"<code><dfn data-cite=
"!WEBIDL-LS#securityerror">SecurityError</dfn></code>"
</li>
</ul>
</dd>
<dt>
Secure Contexts
</dt>
<dd>
The term <dfn data-cite="!SECURE-CONTEXTS#secure-context">secure
context</dfn> is defined by the Secure Contexts specification
[[!SECURE-CONTEXTS]].
</dd>
<dt>
Service Workers
</dt>
<dd>
The terms <dfn data-cite=
"!SERVICE-WORKERS#service-worker-concept">service worker</dfn>,
<dfn data-cite="!SERVICE-WORKERS#dfn-service-worker-client">service
worker client</dfn>, <code><dfn data-cite=
"!SERVICE-WORKERS#service-worker-registration-concept">ServiceWorkerRegistration</dfn></code>,
<code><dfn data-cite=
"!SERVICE-WORKERS#service-worker-global-scope">ServiceWorkerGlobalScope</dfn></code>,
<dfn data-cite=
"!SERVICE-WORKERS#handle-functional-event-algorithm">handle
functional event</dfn>, <dfn data-cite=
"!SERVICE-WORKERS#dfn-extend-lifetime-promises">extend lifetime
promises</dfn>, and <dfn data-cite=
"!SERVICE-WORKERS#dfn-scope-url">scope URL</dfn> are defined in
[[!SERVICE-WORKERS]].
</dd>
</dl>
</section>
<section id="model">
<h2>
Overview of Handling Payment Requests
</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 handler</a>s are defined in <a>service worker</a> code.
</li>
<li>During service worker registration, the <a>PaymentManager</a> is
used to set:
<ul>
<li>A list of <a data-lt="PaymentInstrument.enabledMethods">enabled
payment methods</a>.
</li>
<li>[Optionally] the conditions under which the handler supports a
given payment method; these <a data-lt=
"PaymentInstrument.capabilities">capabilities</a> play a role in
matching computations.
</li>
<li>Information used in the display of <a data-lt=
"PaymentManager.instruments">instruments</a> supported by the
payment handler.
</li>
</ul>
</li>
<li>When the merchant (or other <dfn>payee</dfn>) calls the
[[payment-request]] method <a>show()</a> (e.g., when the user 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 supported by registered payment handlers. For
payment methods that support additional filtering, merchant and payment
handler capabilities are compared as part of determining whether there
is a match.
</li>
<li>The user agent displays a set of choices to the user: the
registered <a data-lt="PaymentManager.instruments">instruments</a> of
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 user (the <dfn>payer</dfn>) selects an <a data-lt=
"PaymentManager.instruments">instrument</a>, the user agent
<a>fires</a> a <a>PaymentRequestEvent</a> (cf. the <a>user interaction
task source</a>) in the service worker whose <a data-lt=
"ServiceWorkerRegistration.paymentManager">PaymentManager</a> the
instrument was registered with. The <a>PaymentRequestEvent</a> includes
some information from the PaymentRequest (defined in
[[!payment-request]]) as well as additional information (e.g., origin
and selected instrument).
</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
PaymentResponse (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 handler</a>s may be registered per
origin. The handler that is invoked is determined by the selection made
by the user of a <a data-lt="PaymentManager.instruments">payment
instrument</a>. The <a>service worker</a> which stored the <a data-lt=
"PaymentManager.instruments">payment instrument</a> with its
<a data-lt="ServiceWorkerRegistration.paymentManager">PaymentManager</a>
is the one that will be invoked.
</p>
<section class="informative" id="handling-a-payment-request">
<h2>
Handling a Payment Request
</h2>
<p>
The logic of a payment handler is driven by the payment methods that
it supports. Some payment methods, such as <a>basic-card</a> 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 <a>PaymentRequestEvent</a>
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>
Structure of a Web Payment App
</h2>
<figure>
<img alt=
"Architecture of a (Web) payment apps as defined in this specification."
src="app-arch.png">
<figcaption>
A Web payment app is associated with an origin. Payment handlers
respond to <a>PaymentRequestEvent</a>s. <a>PaymentManager</a>s
manage the definition, display, and user selection of
<a>PaymentInstrument</a>s. A <a>PaymentInstrument</a> supports one
or more payment methods.
</figcaption>
</figure>
</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 id="registration">
<h2>
Registration
</h2>
<section data-dfn-for="ServiceWorkerRegistration" data-link-for=
"ServiceWorkerRegistration">
<h2>
Extension to the <code>ServiceWorkerRegistration</code> interface
</h2>
<p>
This specification extends the <a>ServiceWorkerRegistration</a>
interface with the addition of a <dfn>paymentManager</dfn> attribute.
</p>
<pre class="idl">
partial interface ServiceWorkerRegistration {
readonly attribute PaymentManager paymentManager;
};
</pre>
</section>
<section data-dfn-for="PaymentManager" data-link-for="PaymentManager">
<h2>
<dfn>PaymentManager</dfn> interface
</h2>
<pre class="idl">
[SecureContext, Exposed=(Window,Worker)]
interface PaymentManager {
[SameObject] readonly attribute PaymentInstruments instruments;
[Exposed=Window] static Promise<PermissionState> requestPermission();
};
</pre>
<p>
The <a>PaymentManager</a> is used by <a>payment app</a>s to manage
their associated instruments and supported payment methods.
</p>
<section>
<h2>
<dfn>instruments</dfn> attribute
</h2>
<p>
This attribute allows manipulation of payment instruments
associated with a service worker (and therefore its payment
handler). To be a candidate payment handler, a handler must have at
least one registered payment instrument to present to the user.
That instrument needs to match the payment methods and required
capabilities specified by the payment request.
</p>
</section>
<section>
<h2>
<dfn>requestPermission()</dfn> method
</h2>
<p class="note">
The user agent is NOT REQUIRED to prompt the user to grant
permission to the origin for each new supported payment method or
new payment instrument.
</p>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>Let <var>permission</var> be the result of running
<a data-cite="!permissions#dfn-retrieve-the-permission-state">retrieve
the permission state algorithm</a> of the permission associated
with <a>payment handler</a>'s <a>origin</a>.
</li>
<li>If <var>permission</var> is "prompt", ask the user whether
allowing adding new payment instruments for the <a data-cite=
"!HTML#current-settings-object">current settings object</a>'s
origin is acceptable. If it is, set <var>permission</var> to
"granted", and "denied" otherwise.
</li>
<li>Resolve <var>p</var> with <var>permission</var>.
</li>
</ol>
</section>
</section>
<section data-dfn-for="PaymentInstruments" data-link-for=
"PaymentInstruments">
<h2>
<dfn>PaymentInstruments</dfn> interface
</h2>
<pre class="idl">
interface PaymentInstruments {
Promise<boolean> delete(DOMString instrumentKey);
Promise<PaymentInstrument> get(DOMString instrumentKey);
Promise<sequence<DOMString>> keys();
Promise<boolean> has(DOMString instrumentKey);
Promise<void> set(DOMString instrumentKey, PaymentInstrument details);
Promise<void> clear();
};
</pre>
<p>
The <a>PaymentInstruments</a> interface represents a collection of
payment instruments, each uniquely identified by an
<dfn>instrumentKey</dfn>. The <var>instrumentKey</var> identifier
will be passed to the payment handler to indicate the
<a>PaymentInstrument</a> selected by the user.
</p>
<section>
<h2>
<dfn>delete()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>If the collection contains a <a>PaymentInstrument</a> with a
matching <var>instrumentKey</var>, remove it from the collection
and resolve <var>p</var> with <b>true</b>.
</li>
<li>Otherwise, resolve <var>p</var> with <b>false</b>.
</li>
</ol>
</section>
<section>
<h2>
<dfn>get()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>If the collection contains a <a>PaymentInstrument</a> with a
matching <var>instrumentKey</var>, resolve <var>p</var> with that
<a>PaymentInstrument</a>.
</li>
<li>Otherwise, reject <var>p</var> with a <a>DOMException</a> whose
value is "<a>NotFoundError</a>".
</li>
</ol>
</section>
<section>
<h2>
<dfn>keys()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>Resolve <var>p</var> with a <dfn>Sequence</dfn> that contains
all the <var>instrumentKey</var>s for the <a>PaymentInstrument</a>s
contained in the collection, in original insertion order.
</li>
</ol>
</section>
<section>
<h2>
<dfn>has()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>If the collection contains a <a>PaymentInstrument</a> with a
matching <var>instrumentKey</var>, resolve <var>p</var> with
<b>true</b>.
</li>
<li>Otherwise, resolve <var>p</var> with <b>false</b>.
</li>
</ol>
</section>
<section>
<h2>
<dfn>set()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>permission</var> be the result of running
<a data-cite="!permissions#dfn-retrieve-the-permission-state">retrieving
the permission state</a> of the permission associated with
<a>payment handler</a>'s <a>origin</a>.
</li>
<li>If <var>permission</var> is not "granted", then return a
<a>Promise</a> rejected with a <a>NotAllowedError</a>.
</li>
<li>If the <a data-lt="PaymentInstrument.icons">icons</a> member of
<var>details</var> is present, then:
<ol>
<li>Let <var>convertedIcons</var> be the result of running the
<a>convert image objects</a> algorithm passing
<var>details</var>.<a data-lt=
"PaymentInstrument.icons">icons</a> as the argument.
</li>
<li>If the <var>convertedIcons</var> is an empty
<a>Sequence</a>, then return a <a>Promise</a> rejected with a
<a>TypeError</a>.
</li>
<li>Set <var>details</var>.<a data-lt=
"PaymentInstrument.icons">icons</a> to
<var>convertedIcons</var>.
</li>
</ol>
</li>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>If the <a data-lt="PaymentInstrument.icons">icons</a> member of
<var>details</var> is present, then for each <var>icon</var> in
<var>details</var>.<a data-lt="PaymentInstrument.icons">icons</a>:
<ol>
<li>If the user agent wants to display the <var>icon</var>,
then:
<ol>
<li>Let <var>fetchedImage</var> be the result of running
the <a data-cite=
"!appmanifest#fetching-image-objects">fetching image
object</a> passing <var>icon</var> as the argument.
</li>
<li>Set <var>icon</var>.<a>[[\fetchedImage]]</a> to
<var>fetchedImage</var>.
</li>
</ol>
</li>
</ol>
</li>
<li>If the collection contains a <a>PaymentInstrument</a> with a
matching <var>instrumentKey</var>, replace it with the
<a>PaymentInstrument</a> in <var>details</var>.
</li>
<li>Otherwise, insert the <a>PaymentInstrument</a> in
<var>details</var> as a new member of the collection and associate
it with the key <var>instrumentKey</var>.
</li>
<li>Resolve <var>p</var>.
</li>
</ol>
</section>
<section>
<h2>
<dfn>clear()</dfn> method
</h2>
<p>
When called, this method executes the following steps:
</p>
<ol>
<li>Let <var>p</var> be a new promise.
</li>
<li>Return <var>p</var> and perform the remaining steps in
parallel:
</li>
<li>Remove all <a>PaymentInstrument</a>s from the collection and
resolve <var>p</var>.
</li>
</ol>
</section>
<section data-dfn-for="PaymentInstrument" data-link-for=
"PaymentInstrument">
<h2>
<dfn>PaymentInstrument</dfn> dictionary
</h2>
<pre class="idl">
dictionary PaymentInstrument {
required DOMString name;
sequence<ImageObject> icons;
sequence<DOMString> enabledMethods;
object capabilities;
};
</pre>
<dl>
<dt>
<dfn>name</dfn> member
</dt>
<dd>
The <a>name</a> member is a string that represents the label for
this <a>PaymentInstrument</a> as it is usually displayed to the
user.
</dd>
<dt>
<dfn>icons</dfn> member
</dt>
<dd>
The <a>icons</a> member is an array of image objects that can
serve as iconic representations of the payment instrument when
presented to the user for selection.
</dd>
<dt>
<dfn>enabledMethods</dfn> member
</dt>
<dd>
The <a>enabledMethods</a> member is a list of one or more
<a>payment method identifiers</a> of the <a>payment methods</a>
supported by this instrument.
</dd>
<dt>
<dfn>capabilities</dfn> member
</dt>
<dd>
The <a>capabilities</a> member is a list of
payment-method-specific capabilities that this payment handler is
capable of supporting for this instrument. For example, for the
<a>basic-card</a> payment method, this object will consist of an
object with two fields: one for <a>supportedNetworks</a>, and
another for <a>supportedTypes</a>.
</dd>
</dl>
</section>
<section data-dfn-for="ImageObject" data-link-for="ImageObject">
<h2>
<dfn>ImageObject</dfn> dictionary
</h2>
<pre class="idl">
dictionary ImageObject {
required USVString src;
DOMString sizes;
DOMString type;
};
</pre>
<dl>
<dt>
<dfn>src</dfn> member
</dt>
<dd>
The <a>src</a> member is used to specify the <a>ImageObject</a>'s
source. It is a URL from which the user agent can fetch the
image’s data.
</dd>
<dt>
<dfn>sizes</dfn> member
</dt>
<dd>
The <a>sizes</a> member is used to specify the
<a>ImageObject</a>'s sizes. It follows the spec of sizes member
in <a data-cite="!HTML#the-link-element">HTML link element</a>,
which is a string consisting of an <a data-cite=
"!HTML#unordered-set-of-unique-space-separated-tokens">unordered
set of unique space-separated tokens</a> which are <a data-cite=
"!HTML#ascii-case-insensitive">ASCII case-insensitive</a> that
represents the dimensions of an image. Each keyword is either an
<a data-cite="!HTML#ascii-case-insensitive">ASCII
case-insensitive</a> match for the string "any", or a value that
consists of two valid non-negative integers that do not have a
leading U+0030 DIGIT ZERO (0) character and that are separated by
a single U+0078 LATIN SMALL LETTER X or U+0058 LATIN CAPITAL
LETTER X character. The keywords represent icon sizes in raw
pixels (as opposed to CSS pixels). When multiple image objects
are available, a user agent MAY use the value to decide which
icon is most suitable for a display context (and ignore any that
are inappropriate). The parsing steps for the <a>sizes</a> member
MUST follow <a data-cite="!HTML#attr-link-sizes">the parsing
steps for HTML link element sizes attribute</a>.
</dd>
<dt>
<dfn>type</dfn> member
</dt>
<dd>
The <a>type</a> member is used to specify the
<a>ImageObject</a>'s MIME type. It is a hint as to the media type
of the image. The purpose of this member is to allow a user agent
to ignore images of media types it does not support.
</dd>
</dl>
</section>
<section>
<h2>
<dfn>Convert image objects</dfn>
</h2>
<p>
When this algorithm with <var>inputImages</var> parameter is
invoked, the user agent must run the following steps:
</p>
<ol class="algorithm">
<li>Let <var>outputImages</var> be an empty <a>Sequence</a> of <a>
ImageObject</a>.
</li>
<li>For each <var>image</var> in <var>inputImages</var>:
<ol>
<li>If <var>image</var>.<a data-lt="ImageObject.type">type</a>
is not a <a data-cite="#valid-mime-type">valid MIME type</a> or
the value of type is not a supported media format, then return
an empty <a>Sequence</a> of <a>ImageObject</a>.
</li>
<li>If <var>image</var>.<a data-lt=
"ImageObject.sizes">sizes</a> is not a <a data-lt=
"ImageObject.sizes">valid value</a>, then return an empty
<a>Sequence</a> of <a>ImageObject</a>.
</li>
<li>Let <var>url</var> be the result of parsing
<var>image</var>.<a data-lt="ImageObject.src">src</a> with the
<a data-cite="!HTML#context-object">context object</a>'s
<a data-cite="!HTML#relevant-settings-object">relevant settings
object</a>'s <a data-cite="!HTML#api-base-url">API base
URL</a>.
</li>
<li>If <var>url</var> is failure, then return an empty
<a>Sequence</a> of <a>ImageObject</a>.
</li>
<li>If <var>url</var>'s <a data-cite=
"!HTML#concept-url-scheme">scheme</a> is not "https", then
return an empty <a>Sequence</a> of <a>ImageObject</a>.
</li>
<li>Set <var>image</var>.<a data-lt="ImageObject.src">src</a>
to <var>url</var>.
</li>
<li>Append <var>image</var> to <var>outputImages</var>
</li>
</ol>
</li>
<li>Return <var>outputImages</var>.
</li>
</ol>
<p>
According to the step 2.3, it is also possible to use the relative
url for <var>image</var>.<a data-lt="ImageObject.src">src</a>. The
following examples illustrate how relative URL resolution works in
different execution contexts.
</p>
<pre class="example html" title=
"Resolving the relative URL of image.src in window context.">
<-- In this example, code is located in https://www.example.com/bobpay/index.html -->
<script>
const instrumentKey = "c8126178-3bba-4d09-8f00-0771bcfd3b11";
const { registration } = await navigator.serviceWorker.register("/register/sw.js");
await registration.paymentManager.paymentInstruments.set({
instrumentKey,
{
name: "My Bob Pay Account: [email protected]",
enabledMethods: ["https://bobpay.com/"],
icons: [{
src: "icon/lowres.webp",
sizes: "48x48",
type: "image/webp"
}]
});
const { storedInstrument } =
await registration.paymentManager.paymentInstruments.get(instrumentKey);
// storedInstrument.icons[0].src == "https://www.example.com/bobpay/icon/lowres.webp";
</script>
</pre>
<pre class="example js" title=
"Resolving the relative URL of image.src in service worker context.">
// In this example, code is located in https://www.example.com/register/sw.js
const instrumentKey = "c8126178-3bba-4d09-8f00-0771bcfd3b11";
await self.registration.paymentManager.paymentInstruments.set({
instrumentKey,
{
name: "My Bob Pay Account: [email protected]",
enabledMethods: ["https://bobpay.com/"],
icons: [{
src: "../bobpay/icon/lowres.webp",
sizes: "48x48",
type: "image/webp"
}]
});
const { storedInstrument } =
await registration.paymentManager.paymentInstruments.get(instrumentKey);
// storedInstrument.icons[0].src == "https://www.example.com/bobpay/icon/lowres.webp";
</pre>
</section>
<section id="register-example" class="informative">
<h2>
Registration Example
</h2>
<p>
The following example shows how to register a payment handler:
</p>
<pre class="example js" title="Payment Handler Registration">
button.addEventListener("click", async() => {
const permission =
await navigator.permissions.query({ name: "paymenthandler" });
switch (permission) {