From 8b6561fde3cf5de3841ceae47ae08c19578af0af Mon Sep 17 00:00:00 2001
From: Rouslan Solomakhin
operating-system specific mechanisms (e.g., "native mobile apps")
handle payment requests.
+
The term "payment app" may be useful as a shorthand for "Web app that can handle payments with Payment Request API."
@@ -208,13 +208,14 @@+ The paymentManager attribute exposes payment handler + functionality in the service worker. +
@@ -913,6 +918,84 @@
+ Given a PaymentMethodData and a PaymentInstrument that
+ match on payment method identifier, this algorithm returns
+ true
if this instrument can be used for payment:
+
false
.
+ true
.
+ + Example of how a payment handler should provide the list of all its + active cards to the browser. +
++ 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'], + }, + }); ++
+ In this case, new PaymentRequest([{supportedMethods:
+ 'basic-card'}], shoppingCart).canMakePayment()
should return
+ true
because there's an active card in the payment
+ handler. Note that new PaymentRequest([{supportedMethods:
+ 'basic-card', data: {supportedTypes: ['debit']}}],
+ shoppingCart).canMakePayment()
would return
+ false
because of mismatch in
+ supportedTypes
in this example.
+
+ If the payment handler supports CanMakePaymentEvent, the + user agent may use it to help with filtering of the available + payment handlers. +
+
+ Implementations may impose a timeout for developers to respond to the
+ CanMakePaymentEvent. If the timeout expires, then the
+ implementation will behave as if respondWith() was called with
+ false
.
+
+ This specification extends the ServiceWorkerGlobalScope + interface. +
++ partial interface ServiceWorkerGlobalScope { + attribute EventHandler oncanmakepayment; + }; ++
+ The oncanmakepayment attribute is an event handler + whose corresponding event handler event type is + canmakepayment. +
++ The CanMakePaymentEvent is used to check whether the payment + handler is able to respond to a payment request. +
++ [Constructor(DOMString type, CanMakePaymentEventInit eventInitDict), Exposed=ServiceWorker] + interface CanMakePaymentEvent : ExtendableEvent { + readonly attribute USVString topLevelOrigin; + readonly attribute USVString paymentRequestOrigin; + readonly attribute FrozenArray<PaymentMethodData> methodData; + readonly attribute FrozenArray<PaymentDetailsModifier> modifiers; + void respondWith(Promise<boolean>canMakePaymentResponse); + }; ++
+ The topLevelOrigin, paymentRequestOrigin, + methodData, and modifiers members share their + definitions with those defined for PaymentRequestEvent. +
++ This method is used by the payment handler to indicate whether it + can respond to a payment request. +
++ dictionary CanMakePaymentEventInit : ExtendableEventInit { + USVString topLevelOrigin; + USVString paymentRequestOrigin; + sequence<PaymentMethodData> methodData; + sequence<PaymentDetailsModifier> modifiers; + }; ++
+ The topLevelOrigin, paymentRequestOrigin, + methodData, and modifiers members share their + definitions with those defined for PaymentRequestEvent. +
++ Upon receiving a PaymentRequest, the user agent MUST + run the following steps: +
++ This example shows how to write a service worker that listens to the + CanMakePaymentEvent. When a CanMakePaymentEvent is + received, the service worker always returns true. +
++ self.addEventListener('canmakepayment', function(e) { + e.respondWith(true); + }); ++
This method is used by the payment handler to show a window to the @@ -1886,6 +2126,9 @@
true
.
+ "supported_origins": "*"
in its payment method
+ manifest, filter based on capabilities:
- 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. -
-
- Given a PaymentMethodData and a PaymentInstrument that
- match on payment method identifier, this algorithm returns
- true
if this instrument can be used for payment:
-
"supported_origins": "*"
in its payment method
- manifest, filter based on capabilities:
- false
.
- true
.
- - Example of how a payment handler should provide the list of all its - active cards to the browser. -
-- 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'], - }, - }); --
- In this case, new PaymentRequest([{supportedMethods:
- 'basic-card'}], shoppingCart).canMakePayment()
should return
- true
because there's an active card in the payment
- handler. Note that new PaymentRequest([{supportedMethods:
- 'basic-card', data: {supportedTypes: ['debit']}}],
- shoppingCart).canMakePayment()
would return
- false
because of mismatch in
- supportedTypes
in this example.
-
- The second bullet above may be amended to remove explicit mention of - ordering defined by the payee. -
-- The following are examples of payment handler ordering: -
-- 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 - other mechanisms such as links from their web sites. -
-- The user agent MUST enable the user to - select any displayed instrument. -
-- The Working Group is discussing how default payment instrument - display could further streamline the user experience. -
-- Users agents may wish to enable the user to select individual - displayed Instruments. The payment handler would receive information - about the selected Instrument and could take action, potentially - eliminating an extra click (first open the payment app then select - the Instrument). -
-
+ Given a PaymentMethodData and a PaymentInstrument that
+ match on payment method identifier, this algorithm returns
+ true
if this instrument can be used for payment:
+
"supported_origins": "*"
in its payment method
+ manifest, filter based on capabilities:
+ false
.
+ true
.
+ + Example of how a payment handler should provide the list of all its + active cards to the browser. +
++ 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'], + }, + }); ++
+ In this case, new PaymentRequest([{supportedMethods:
+ 'basic-card'}], shoppingCart).canMakePayment()
should return
+ true
because there's an active card in the payment
+ handler. Note that new PaymentRequest([{supportedMethods:
+ 'basic-card', data: {supportedTypes: ['debit']}}],
+ shoppingCart).canMakePayment()
would return
+ false
because of mismatch in
+ supportedTypes
in this example.
+