-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
411 lines (411 loc) · 14.7 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
<!DOCTYPE html>
<html>
<head>
<title>
Payment-Request Handler API
</title>
<meta charset="utf-8">
<script src="https://www.w3.org/Tools/respec/respec-w3c-common" class=
"remove">
</script>
<script class="remove">
var respecConfig = {
shortName: "payment-handler",
edDraftURI: "https://marcoscaceres.github.io/payment-request-handler/",
specStatus: "unofficial",
editors: [{
name: "Contributor list",
href: "https://github.com/marcoscaceres/payment-request-handler/graphs/contributors",
}],
license: "w3c-software-doc",
wg: "Web Payments Working Group",
wgURI: "https://www.w3.org/Payments/WG/",
wgPublicList: "public-payments-wg",
wgPatentURI: "https://www.w3.org/2004/01/pp-impl/83744/status",
issueBase: "https://marcoscaceres.github.io/payment-request-handler/issues/",
"otherLinks": [{
"key": "Repository",
"data": [
{
"value": "We are on Github.",
"href": "https://github.com/marcoscaceres/payment-request-handler"
},
{
"value": "File a bug.",
"href": "https://github.com/marcoscaceres/payment-request-handler/issues"
},
{
"value": "Commit history.",
"href": "https://github.com/marcoscaceres/payment-request-handler/commits/gh-pages"
}],
}]
};
</script>
</head>
<body>
<section id="abstract">
<p>
This specification allows a web application to handle requests for
payment on the end-user's behalf. The API also allows a web application
to manage multiple payment methods for the user (e.g., multiple credit
cards, proprietary payment methods, etc.). The API relies on a service
worker to handle the request for payment, and affords a web application
the ability to present a UI suitable for fulfilling a request for
payment.
</p>
</section>
<section id="sotd"></section>
<section class="informative">
<h2>
Use cases and requirements
</h2>
<p>
The use cases for this specification:
</p>
<ul>
<li>Register, with user consent, to handle <a>requests for payment</a>
of particular types (e.g., credit cards, a proprietary payment method).
</li>
<li>Allow the end-user to manage <a>payment methods</a> (adding,
deleting, modifying, etc.) - and for these methods to be available as
payment options upon request for payment.
</li>
</ul>
<p>
As such, the requirements are that this specification can:
</p>
<ul>
<li>handle invocation of methods from the <a data-cite=
"payment-request">Payment Request API</a> and facilitate communication
between a <a>PaymentRequest</a>, the end-user (through a UI), and a <a>
PaymentResponse</a> on a third party site.
</li>
<li>facilitate the display, and management, of the registered payment
methods in multiple contexts - including in web pages and in browser
generated UIs.
</li>
</ul>
</section>
<section class="informative">
<h2>
Usage examples
</h2>
<section class="informative">
<h3>
Registering to handle payments
</h3>
<p>
The following example shows how a web application requests permission
to handle payment requests from the end-user. It also shows how a web
application can then start to manage payment methods on behalf of the
end-user.
</p>
<pre class="example" title="Payment Handler Registration" data-include=
"examples/register_paymenthandler.js"></pre>
</section>
<section class="informative">
<h3>
Handling a request for payment
</h3>
<p>
The following shows how to process a request for payment via a
service worker. In this example, the credit card information is
dynamically generated.
</p>
<pre class="example" title=
"Handling 'onpaymentrequest' in ServiceWorker" data-include=
"examples/sw_onpaymentrequest.js">
</pre>
</section>
<section class="informative">
<h3>
Checking if the app can make a payment
</h3>
<p>
The following shows how a web application can respond to a merchant's
request to check if it can make an payment.
</p>
<pre class="example" title="Using `canMakePayment()`" data-include=
"examples/canmakepayment.js"></pre>
</section>
</section>
<section>
<h2>
Model
</h2>
<p>
To enable web applications to handle requests for payment, this
specification defines the following:
</p>
<ul>
<li>A <a>PaymentManager</a>, which allows web applications to request
permission to handle payment request.
</li>
<li>An <a>PaymentMethodMap</a> API
(<a>ServiceWorkerRegistration.paymentManager</a>) to manage, through
usual map-like asynchronous operations, <a>payment methods</a> that the
web application is capable of handling.
</li>
<li>A means to be notified of requests for payment, via a service
worker event ("paymentrequest" event type) - and a corresponding
<a>PaymentRequestEvent</a>, that contains the information about the
payment request.
</li>
<li>A means for third-party sites to check if a registered payment
handler can potentially handle a request for payment, again through a
service worker. This is done through a "canMakePayment" event and a
corresponding <a>CanMakePaymentEvent</a> interface.
</li>
<li>A means to open a payment-specific UI from the service worker, via
<a>PaymentRequestEvent.openClientWindow()</a>. If UI is needed to
complete a purchase, it's within this <a>WindowClient</a> that a
<a>payment flow</a> takes place.
</li>
</ul>
<p>
If granted the "<a>payment-request-handler</a>" permission, the web
application can manage <a>payment methods</a> (e.g., credit cards,
communication with a proprietary payment provider, etc.) on behalf of
the user. This is done by via the a <a>PaymentMethodMap</a>, which is a
persistent data-store for payment methods.
</p>
<p>
Handling payment requests is done through an "onpaymentrequest" event
associated with a service worker registration: when there is a payment
request that matches a payment method supported by the web application
(e.g., basic card), the service worker is notified via an event. More
specifically, it defines how to register web applications with user
agents, gives recommendations on how the user agents can present
registration information to user, and the interaction between a payment
handler and another that has made a request for payment using the
<a data-cite="!payment-request">Payment Request API.</a>
</p>
</section>
<section>
<h2>
Identity
</h2>
<p>
For the purpose of handling payment requests, a web application is
identified by its <a data-cite="!ORIGIN">origin</a>.
</p>
<p>
As <a>origin</a>'s are not the most user-friendly way for end-users to
recognize a web application, it is RECOMMENDED that web applications
support the <cite><a data-cite="appmanifest">Web App
Manifest</a></cite> specification ([[!appmanifest]]). The
[[!appmanifest]] specification provides end-user friendly meta-data and
icons that can help end-users identify a web application.
</p>
</section>
<section>
<h2>
Permission
</h2>
<p>
The <dfn>"payment-request-handler"</dfn> permission is the permission
associated with the usage of this specification. It is a <a data-cite=
"!permissions#boolean-feature">boolean feature</a>.
</p>
</section>
<section>
<h3>
Extensions to the <a>ServiceWorkerRegistration</a> interface
</h3>
<pre class="idl">
partial interface ServiceWorkerRegistration {
[SameObject] readonly attribute PaymentManager paymentManager;
};
</pre>
</section>
<section>
<h2>
<dfn>PaymentManager</dfn> interface
</h2>
<pre class="idl">
interface paymentManager {
readonly attribute PaymentMethodMap paymentMethods;
Promise<PermissionState> register();
Promise<void> unregister();
};
</pre>
</section>
<section>
<h2>
<dfn>PaymentMethodMap</dfn> interface
</h2>
<pre class="idl">
[Exposed=(Window,Worker)]
interface PaymentMethodMap {
[NewObject] Promise<boolean> delete(DOMString methodKey);
[NewObject] Promise<PaymentMethodDetails> get(DOMString methodKey);
[NewObject] Promise<sequence<DOMString>> keys();
[NewObject] Promise<boolean> has(DOMString methodKey);
[NewObject] Promise<void> set(DOMString methodKey, PaymentMethodDetails details);
// This doesn't exist yet in WebIDL I think - need to coordinate with
// Domenic.
// asyncIterator = { record<DOMString, PaymentMethodDetails>> }
};
</pre>
</section>
<section>
<h2>
Extensions to <dfn>PaymentRequest</dfn> interface
</h2>
<pre class="idl">
interface PaymentRequest : EventTarget {
readonly attribute FrozenArray<PaymentMethod> supportedMethods;
readonly attribute DOMString? paymentRequestID;
readonly attribute PaymentItem total;
readonly attribute DisplayItems displayItems;
readonly attribute sequence<RequestedData> requestedFields;
attribute EventHander onabort;
};
</pre>
</section>
<section>
<h2>
<dfn>PaymentMethodDetails</dfn> dictionary
</h2>
<pre class="idl">
dictionary PaymentMethodDetails {
required DOMString name;
required Sequence<DOMString> method;
sequence <PaymentMethodIcon> icons;
};
</pre>
</section>
<section>
<h2>
<dfn>PaymentMethodIcon</dfn> dictionary
</h2>
<pre class="idl">
dictionary PaymentMethodIcon {
USVString src;
DOMString sizes;
DOMString type;
};
</pre>
</section>
<section>
<pre class="idl">
partial interface ServiceWorkerGlobalScope {
attribute EventHandler onpaymentrequest;
attribute EventHandler oncanMakePayment;
};
</pre>
</section>
<section data-dfn-for="PaymentRequestDetails" data-link-for=
"PaymentRequestDetails">
<h2>
<dfn>PaymentRequestDetails</dfn> interface
</h2>
<pre class="idl">
interface PaymentRequestDetails : EventTarget {
readonly attribute DOMString? id;
readonly attribute PaymentItem total;
readonly attribute DisplayItems displayItems;
readonly attribute FrozenArray<requestedFields> requestedFields;
readonly attribute any data;
attribute EventHander onabort;
};
</pre>
</section>
<section data-dfn-for="PaymentRequestEvent" data-link-for=
"PaymentRequestEvent">
<h2>
<dfn>PaymentRequestEvent</dfn> interface
</h2>
<pre class="idl">
[Exposed=ServiceWorker,
Constructor(DOMString type, optional PaymentRequestEventInit eventInitDict)]
interface PaymentRequestEvent : ExtendableEvent {
readonly attribute PaymentRequest requestData;
readonly attribute USVString origin;
Promise<WindowClient> openClientWindow(USVString url);
void respondWith(Promise<PaymentResponse> paymentResponse);
};
</pre>
</section>
<section data-dfn-for="PaymentRequestEventInit" data-link-for=
"PaymentRequestEventInit">
<h2>
<dfn>PaymentRequestEventInit</dfn> interface
</h2>
<pre class="idl">
dictionary PaymentRequestEventInit : EventInit {
USVString origin = "";
};
</pre>
</section>
<section data-dfn-for="RequestedFields" data-link-for="RequestedFields">
<h2>
<dfn>RequestedFields</dfn> enum
</h2>
<pre class="idl">
enum RequestedFields {
"payerEmail",
"payerName",
"payerPhone",
"shipping",
};
</pre>
</section>
<section data-dfn-for="PaymentResponse" data-link-for="PaymentResponse">
<h2>
Extensions to the <dfn data-cite=
"payment-request#paymentresponse-interface">PaymentResponse</dfn>
interface
</h2>
<pre class="idl">
[Constructor(DOMString id, DOMString methodName, PaymentResponseInit details)]
partial interface PaymentResponse {
Promise<PaymentDetails> updateShippingAddress(ShippingAddress? newAddress);
Promise<PaymentDetails> updateShippingOption(DOMString id);
readonly attribute Promise<PaymentComplete> isComplete;
};
</pre>
</section>
<section data-dfn-for="CanMakePaymentEvent" data-link-for=
"CanMakePaymentEvent">
<h2>
<dfn>CanMakePaymentEvent</dfn> interface
</h2>
<pre class="idl">
[Exposed=ServiceWorker,
Constructor(DOMString type, optional CanMakePaymentEventInit eventInitDict)]
interface CanMakePaymentEvent : ExtendableEvent {
readonly attribute FrozenArray<PaymentMethod> methods;
void canMakePayment(Promise<Boolean> result);
};
</pre>
</section>
<section data-dfn-for="CanMakePaymentEventInit" data-link-for=
"CanMakePaymentEventInit">
<h2>
<dfn>CanMakePaymentEventInit</dfn> dictionary
</h2>
<pre class="idl">
dictionary CanMakePaymentEventInit : EventInit {
required sequence<DOMString> paymentMethods;
};
</pre>
</section>
<section>
<h2>
Dependencies
</h2>
<p>
The following are defined in [[!SERVICE-WORKERS]]:
</p>
<ul>
<li>
<code><dfn data-cite=
"!SERVICE-WORKERS#ServiceWorkerRegistration">ServiceWorkerRegistration</dfn></code>
</li>
</ul>
</section>
<section id="conformance"></section>
<section class="appendix" id="idl-index"></section>
</body>
</html>