diff --git a/index.html b/index.html index 3f4da533..e63eed4d 100644 --- a/index.html +++ b/index.html @@ -400,7 +400,7 @@

} } catch (err) { // Something went wrong... - response.complete("unknown"); + await response.complete("fail"); } } doPaymentRequest(); @@ -419,18 +419,11 @@

           const request = new PaymentRequest(methodData, details, options);
-          request.onshippingaddresschange = async ev => {
-            // Can we ship here?
-            try {
-              const json = request.shippingAddress.toJSON();
-              const { shippingOptions, total } = await calculateShipping(json);
-              const newDetails = {...details, ...{ shippingOptions, total }};
-              ev.updateWith(newDetails);
-            } catch (err) {
-              ev.updateWith({ error: `Sorry! we can't ship to your address.` });
-            }
+          // Async update to details
+          request.onshippingaddresschange = ev => {
+            ev.updateWith(checkShipping(request));
           };
-          // update the total
+          // Sync update to the total
           request.onshippingoptionchange = ev => {
             const shippingOption = shippingOptions.find(
               option => option.id === request.id
@@ -442,6 +435,18 @@ 

}; ev.updateWith({ ...details, total: newTotal }); }; + async function checkShipping(request) { + try { + const json = request.shippingAddress.toJSON(); + + await ensureCanShipTo(json); + const { shippingOptions, total } = await calculateShipping(json); + + return { ...details, shippingOptions, total }; + } catch (err) { + return { ...details, error: `Sorry! we can't ship to your address.` }; + } + }

@@ -2387,12 +2392,6 @@

The PaymentRequestUpdateEvent enables developers to update the details of the payment request in response to a user interaction.

-

- If a developer wants to update the payment request, then they need to - call updateWith() and provide a PaymentDetailsUpdate - dictionary, or a promise for one, containing changed values that the - user agent SHOULD present to the user. -

The PaymentRequestUpdateEvent constructor MUST set the internal slot [[\waitForUpdate]] to false. @@ -2401,13 +2400,59 @@

updateWith() method

-

- If a developer wants to update the payment request, then they need - to call updateWith() and provide a - PaymentDetailsUpdate dictionary, or a promise for one, - containing changed values that the user agent presents to - the user. -

+

The updateWith(detailsPromise) method MUST act as follows:

@@ -2422,7 +2467,8 @@

throw an "InvalidStateError" DOMException.
  • Let request be the value of event's - target attribute. + target + attribute.
  • If request.[[\state]] is not "interactive", then throw an @@ -2444,11 +2490,6 @@

    required by the change. Developers MUST settle the detailsPromise to indicate that the payment request is valid again. -

    - The user agent SHOULD disable any part of the user - interface that could cause another update event to be fired. - Only one update may be processed at a time. -

  • @@ -2717,8 +2758,6 @@

  • In either case, run the following steps, after either the upon rejection or upon fulfillment steps have concluded:
      -
    1. Set event.[[\waitForUpdate]] to false. -
    2. Set request.[[\updating]] to false.
    3. The user agent SHOULD update the user interface @@ -2896,9 +2935,21 @@

      further action. The user agent user interface SHOULD ensure that this never occurs.

    4. +
    5. Let event be the result of creating an event using + PaymentRequestUpdateEvent. +
    6. +
    7. Initialize event's type attribute to name. +
    8. - Fire an event named name at request - using PaymentRequestUpdateEvent. + Dispatch + event at request. +
    9. +
    10. If + event.[[\waitForUpdate]] is true, disable any part + of the user interface that could cause another update event to be + fired.