diff --git a/index.html b/index.html index 3f4da533..e63eed4d 100644 --- a/index.html +++ b/index.html @@ -400,7 +400,7 @@
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.` }; + } + }
- 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 @@
- 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 @@target
+ attribute.
- 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 @@
type
attribute to name.
+