Calling event.updateWith inside the onshippingaddresschange or onshippingoptionchange event handlers with a PaymentDetailsUpdate object that has “shippingOptions” will ignore “error”. I expect “error” to take priority over “shippingOptions”. Example use case: A client might want to show an error informing the user the shipping address is incorrect, while updating or clearing the shipping options due to the address error. Code Example: request.onshippingaddresschange = event => { const paymentDetailsUpdate = { "total": { "label": "My Merchant", "amount": { "value": "27.50", "currency": "USD" } }, "error": "Can't ship to this address.", "shippingOptions": [ { "id": "ground", "label": "Ground Shipping", "amount": { "value": "5.00", "currency": "USD" } } ] }; event.updateWith(paymentDetailsUpdate); }; The following code will not show the “error”, instead will update the shipping options. If the “shippingOptions” is removed then the error shows as expected. Note: “total” needs to be included in order to prevent other error, separate bug has been filed https://bugs.webkit.org/show_bug.cgi?id=220561.
<rdar://problem/73204290>
Created attachment 417744 [details] Patch
According to https://www.w3.org/TR/payment-request/#dom-paymentdetailsupdate-error>, this behavior is actually correct/expected: > A human-readable string that explains why goods cannot be shipped to the chosen shipping address, or any other reason why no shipping options are available. When the payment request is updated using updateWith(), the PaymentDetailsUpdate can contain a message in the error member that will be displayed to the user if the PaymentDetailsUpdate indicates that there are no valid shippingOptions (and the PaymentRequest was constructed with the requestShipping option set to true). Based on this, in order for `error` to be used you cannot provide `shippingOptions` and must have previously `requestShipping`. IMO `error` really should've been named something like `shippingError` to better indicate this relationship/requirement, but that's my semi-ignorant perspective given that I was not part of the discussion. (note to self, look at the spec next time before jumping in 😅)