forked from w3c/payment-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2409 lines (2391 loc) · 99.1 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,
note: 'Former Editor'
},
{ 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",
testSuiteURI: "https://w3c-test.org/payment-handler/",
issueBase: "https://github.com/w3c/payment-handler/issues/",
githubAPI: "https://api.github.com/repos/w3c/payment-handler",
};
</script>
</head>
<body>
<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 (<a>PaymentRequestEvent</a>). A
<a>payment handler</a> 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 <a>PaymentRequestEvent</a>.
</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 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>canMakePayment()</a> or <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, either merchant and payment handler capabilities
are compared or <a>CanMakePaymentEvent</a> is used 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>
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, 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>
<p>
The <a>paymentManager</a> attribute exposes payment handler
functionality in the service worker.
</p>
</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();
attribute DOMString userHint;
};
</pre>
<p>
The <a>PaymentManager</a> is used by <a>payment handler</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>
<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. When a agent displays all
payment instruments available through a payment handler, it may
cause confusion to display the additional hint.
</p>
</section>
</section>
<section data-dfn-for="PaymentInstruments" data-link-for=
"PaymentInstruments">
<h2>
<dfn>PaymentInstruments</dfn> interface
</h2>
<pre class="idl">
[SecureContext, Exposed=(Window,Worker)]
interface PaymentInstruments {
Promise<boolean> delete(DOMString instrumentKey);
Promise<any> 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, if any.
</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, resolve <var>p</var> with <code>undefined</code>.
</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: john@example.com",
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: john@example.com",
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() => {
if (!window.PaymentManager) {
return; // not supported, so bail out.
}
const result = await PaymentManager.requestPermission();
if (result !== "granted") {
return;
}
const { registration } =
await navigator.serviceWorker.register('/sw.js');
// Excellent, we got it! Let's now set up the user's cards.
await addInstruments(registration);
}, { once: true });
function addInstruments(registration) {
return Promise.all([
registration.paymentManager.instruments.set(
"dc2de27a-ca5e-4fbd-883e-b6ded6c69d4f",
{
name: "Visa ending ****4756",
enabledMethods: ["basic-card"],
capabilities: {
supportedNetworks: ['visa'],
supportedTypes: ['credit']
}
}),
registration.paymentManager.instruments.set(
"c8126178-3bba-4d09-8f00-0771bcfd3b11",
{
name: "My Bob Pay Account: john@example.com",
enabledMethods: ["https://bobpay.com/"]
}),
registration.paymentManager.instruments.set(
"new-card",
{
name: "Add new credit/debit card to ExampleApp",
enabledMethods: ["basic-card"],
capabilities: {
supportedNetworks:
['visa','mastercard','amex','discover'],
supportedTypes: ['credit','debit','prepaid']
}
}),
]);
};
</pre>
</section>
</section>
</section>
<section id="instrument-display-ordering">
<h2>
Origin and Instrument Display for Selection
</h2>
<p>
After applying the matching algorithm defined in Payment Request API,
the user agent displays a list of instruments from matching payment
apps for the user to make a selection. This specification includes a
limited number of display requirements; most user experience details
are left to implementers.
</p>
<section>
<h2>
Filtering of Payment Instruments
</h2>
<p>
Given a <a>PaymentMethodData</a> and a <a>PaymentInstrument</a> that
match on <a>payment method identifier</a>, this algorithm returns
<code>true</code> if this instrument can be used for payment:
</p>
<ol class="algorithm">
<li>Let <var>instrument</var> be the given <a>PaymentInstrument</a>.
</li>
<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>If <var>methodName</var> is a <a>standardized payment method
identifier</a> or is a <a>URL-based payment method identifier</a>
with <code>"supported_origins": "*"</code> in its payment method
manifest, filter based on <a data-lt=
"PaymentInstrument.capabilities">capabilities</a>:
<ol>
<li>For each <var>key</var> in <var>methodData</var>:
<ol>
<li>If the intersection of <var>methodData[key]</var> and
<var>instrument.capabilities[key]</var> is empty, return
<code>false</code>.
</li>
</ol>
</li>
<li>Otherwise, return <code>true</code>.
</li>
</ol>
</li>
<li>Otherwise, fire the <a>CanMakePaymentEvent</a> in the payment
handler and return the result.
</li>
</ol>
<div class="issue" data-number="157">
This is the current thinking about filtering of payment instruments.
As we continue to experiment with implementations, we are soliciting
feedback on this approach.
</div>
<section id="capabilities-example" class="informative">
<h2>
How to specify capabilities
</h2>
<p>
Example of how a payment handler should provide the list of all its
active cards to the browser.
</p>
<pre class="example js" title="Specifying capabilities">
await navigator.serviceWorker.register('/pw/app.js');
const registration = await navigator.serviceWorker.ready;
registration.paymentManager.userHint = '(Visa ****1111)';
await registration.paymentManager.instruments.set(
'12345',
{
name: "Visa ****1111",
icons: [{
src: '/pay/visa.png',
sizes: '32x32',
type: 'image/png',
}],
enabledMethods: ['basic-card'],
capabilities: {
supportedNetworks: ['visa'],
supportedTypes: ['credit'],
},
});
</pre>
<p>
In this case, <code>new PaymentRequest([{supportedMethods:
'basic-card'}], shoppingCart).canMakePayment()</code> should return
<code>true</code> because there's an active card in the payment
handler. Note that <code>new PaymentRequest([{supportedMethods:
'basic-card', data: {supportedTypes: ['debit']}}],
shoppingCart).canMakePayment()</code> would return
<code>false</code> because of mismatch in
<code>supportedTypes</code> in this example.
</p>
</section>
</section>
<section>
<h2>
Ordering of Payment Handlers
</h2>
<ul>
<li>The user agent <span class='rfc2119'>MUST</span> favor user-side
order preferences (based on user configuration or behavior) over
payee-side order preferences.
</li>
<li>The user agent <span class='rfc2119'>MUST</span> display matching
payment handlers in an order that corresponds to the order of
supported payment methods provided by the payee, except where
overridden by user-side order preferences.
</li>
<li>The user agent <span class='rfc2119'>SHOULD</span> allow the user
to configure the display of matching payment handlers to control the
ordering and define preselected defaults.
</li>
</ul>
<p class="issue" title=
"PR API payment method ordering and relation to this spec."
data-number="116">
The second bullet above may be amended to remove explicit mention of
ordering defined by the payee.
</p>
<p>
The following are examples of payment handler ordering:
</p>
<ul>
<li>For a given Web site, display payment handlers in an order that
reflects usage patterns for the site (e.g., a frequently used payment
handler at the top, or the most recently used payment handler at the
top).
</li>
<li>Enable the user to set a preferred order for a given site or for
all sites.
</li>
<li>If the origin of the site being visited by the user matches the
origin of a payment handler, show the payment handler at the top of
the list.
</li>
</ul>
<p class="issue" title="Merchant Preferences" data-number="74">
The Working Group has discussed two types of merchant preferences
related to payment apps: (1) highlighting merchant-preferred payment
apps already registered by the user and (2) recommending payment apps
not yet registered by the user. The current draft of the
specification does not address either point, and the Working Group is
seeking feedback on the importance of these use cases. Note that for
the second capability, merchants can recommend payment apps through