From d24b5cfdac2596596023b7cd69931bf9bc976c3d Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Wed, 12 Sep 2018 13:54:14 -0400 Subject: [PATCH 1/6] PaymentRequestEvent.changePaymentMethod(methodName, methodDetails). This patch adds a method for the payment handler to notify the payee that the payment method has changed. This enables the payee to update the total based on the billing address or validate the billing address, for example. --- index.html | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 9646b95..9c988ef 100644 --- a/index.html +++ b/index.html @@ -1151,6 +1151,63 @@

+
+

+ The PaymentMethodChangeResponse +

+

+ The PaymentMethodChangeResponse contains the udpated total + (optionally with modifiers) and possible errors resulting from user + selecting an payment method within a payment handler. +

+
+        dictionary PaymentMethodChangeResponse {
+          DOMString error;
+          PaymentItem total;
+          FrozenArray<PaymentDetailsModifier> modifiers;
+          AddressErrors billingAddressErrors;
+        };
+        
+
+

+ error member +

+

+ A human readable string that explains why the payment method cannot + be used. +

+
+
+

+ total member +

+

+ Updated total based on the changed payment method. This can change, + for example, in VAT calculations based on the billing address + associated with the payment method. +

+
+
+

+ modifiers member +

+

+ Updated modifiers based on the changed payment method. These change + change, for example, in VAT calculations based on the billing + address associated with the payment method. +

+
+
+

+ billingAddressErrors member +

+

+ Validation errors for the billing address of the payment method, if + any. +

+
+

@@ -1172,7 +1229,9 @@

readonly attribute object total; readonly attribute FrozenArray<PaymentDetailsModifier> modifiers; readonly attribute DOMString instrumentKey; + readonly attribute bool requestBillingAddress; Promise<WindowClient?> openWindow(USVString url); + Promise<PaymentMethodChangeResponse?> changePaymentMethod(DOMString methodName, object? methodDetails); void respondWith(Promise<PaymentHandlerResponse>handlerResponsePromise); }; @@ -1263,6 +1322,15 @@

PaymentInstrument.

+
+

+ requestBillingAddress attribute +

+

+ The value of PaymentOptions.requestBillingAddress + in the PaymentRequest. +

+

openWindow() method @@ -1272,6 +1340,18 @@

user. When called, it runs the open window algorithm.

+
+

+ changePaymentMethod() + method +

+

+ This method is used by the payment handler to get updated total + given such payment method details as the billing address. When + called, it runs the change payment method algorithm. +

+

+
+

+ Change Payment Method Algorithm +

+

+ When this algorithm is invoked with methodName and + methodDetails parameters, the user agent MUST run the + following steps: +

+
    +
  1. Run the payment method changed algorithm with + PaymentMethodChangeEvent event constructed using + the given methodName and methodDetails + parameters. +
  2. +
  3. If event.updateWith(detailsPromise) is not run, + return null. +
  4. +
  5. If event.updateWith(detailsPromise) throws, + rethrow the error. +
  6. +
  7. If event.updateWith(detailsPromise) times out + (optional), throw "InvalidStateError" DOMException. +
  8. +
  9. Construct and return a PaymentMethodChangeResponse from + the detailsPromise in + event.updateWith(detailsPromise). +
  10. +
+

Respond to PaymentRequest Algorithm @@ -2134,13 +2244,21 @@

"!payment-request#paymentdetailsinit-dictionary">paymentDetailsInit, PaymentMethodData, + PaymentOptions, + PaymentMethodChangeEvent, ID, canMakePayment(), - show(), and + show(), + updateWith(detailsPromise), user - accepts the payment request algorithm , payment method + changed algorithm, and JSON-serializable are defined by the Payment Request API specification [[!payment-request]]. From 457035484412f5b6a8dcc00683f88a1e9140c18e Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Wed, 12 Sep 2018 13:59:35 -0400 Subject: [PATCH 2/6] Generic payment method errors instead of billing address specific. --- index.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 9c988ef..403a905 100644 --- a/index.html +++ b/index.html @@ -1166,7 +1166,7 @@

DOMString error; PaymentItem total; FrozenArray<PaymentDetailsModifier> modifiers; - AddressErrors billingAddressErrors; + object paymentMethodErrors; };
@@ -1193,18 +1193,17 @@

modifiers member

- Updated modifiers based on the changed payment method. These change + Updated modifiers based on the changed payment method. These can change, for example, in VAT calculations based on the billing address associated with the payment method.

- billingAddressErrors member + paymentMethodErrors member

- Validation errors for the billing address of the payment method, if - any. + Validation errors for the payment method, if any.

From 5116da1b2e86479ff82faf67f7a4e6b8132a5391 Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Wed, 12 Sep 2018 15:35:52 -0400 Subject: [PATCH 3/6] Address comments. --- index.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 403a905..5793106 100644 --- a/index.html +++ b/index.html @@ -1157,9 +1157,9 @@

The PaymentMethodChangeResponse

- The PaymentMethodChangeResponse contains the udpated total - (optionally with modifiers) and possible errors resulting from user - selecting an payment method within a payment handler. + The PaymentMethodChangeResponse contains the updated + total (optionally with modifiers) and possible errors resulting from + user selection of a payment method within a payment handler.

         dictionary PaymentMethodChangeResponse {
@@ -1183,9 +1183,9 @@ 

total member

- Updated total based on the changed payment method. This can change, - for example, in VAT calculations based on the billing address - associated with the payment method. + Updated total based on the changed payment method. The total can + change, for example, because the billing address of the payment + method selected by the user changes the Value Added Tax (VAT).

@@ -1193,9 +1193,10 @@

modifiers member

- Updated modifiers based on the changed payment method. These can - change, for example, in VAT calculations based on the billing - address associated with the payment method. + Updated modifiers based on the changed payment method. For example, + if the overall total has increased by €1.00 based on the billing + address, then the totals specified in each of the modifiers should + also increase by €1.00.

From 2c698623961c1186cdbcbd1ae8493d486e32469c Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Wed, 12 Sep 2018 15:40:52 -0400 Subject: [PATCH 4/6] Use PaymentCurrencyAmount type total --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 5793106..16148af 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@

         dictionary PaymentMethodChangeResponse {
           DOMString error;
-          PaymentItem total;
+          PaymentCurrencyAmount total;
           FrozenArray<PaymentDetailsModifier> modifiers;
           object paymentMethodErrors;
         };
@@ -1226,7 +1226,7 @@ 

readonly attribute USVString paymentRequestOrigin; readonly attribute DOMString paymentRequestId; readonly attribute FrozenArray<PaymentMethodData> methodData; - readonly attribute object total; + readonly attribute PaymentCurrencyAmount total; readonly attribute FrozenArray<PaymentDetailsModifier> modifiers; readonly attribute DOMString instrumentKey; readonly attribute bool requestBillingAddress; From f25d42f0efe9b6df757b8e7db7ecf94daa1416df Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Thu, 13 Sep 2018 10:31:15 -0400 Subject: [PATCH 5/6] Do not use a dictionary as an attribute. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 16148af..e569668 100644 --- a/index.html +++ b/index.html @@ -1226,7 +1226,7 @@

readonly attribute USVString paymentRequestOrigin; readonly attribute DOMString paymentRequestId; readonly attribute FrozenArray<PaymentMethodData> methodData; - readonly attribute PaymentCurrencyAmount total; + readonly attribute object total; readonly attribute FrozenArray<PaymentDetailsModifier> modifiers; readonly attribute DOMString instrumentKey; readonly attribute bool requestBillingAddress; From 3525c7a9aba9f5ddf1358448e9fb12acb9086cac Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Thu, 13 Sep 2018 10:31:58 -0400 Subject: [PATCH 6/6] Make methodDetails optional. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index e569668..780dd57 100644 --- a/index.html +++ b/index.html @@ -1231,7 +1231,7 @@

readonly attribute DOMString instrumentKey; readonly attribute bool requestBillingAddress; Promise<WindowClient?> openWindow(USVString url); - Promise<PaymentMethodChangeResponse?> changePaymentMethod(DOMString methodName, object? methodDetails); + Promise<PaymentMethodChangeResponse?> changePaymentMethod(DOMString methodName, optional object? methodDetails = null); void respondWith(Promise<PaymentHandlerResponse>handlerResponsePromise); };