Bug 220563 - Payment Request API - PaymentDetailsUpdate ignores “error” when “shippingOptions” is present
Summary: Payment Request API - PaymentDetailsUpdate ignores “error” when “shippingOpti...
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari 14
Hardware: Mac (Intel) macOS 10.15
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-01-12 13:35 PST by nickgzzjr
Modified: 2021-01-15 15:55 PST (History)
3 users (show)

See Also:


Attachments
Patch (7.85 KB, patch)
2021-01-15 15:26 PST, Devin Rousso
hi: review-
hi: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description nickgzzjr 2021-01-12 13:35:34 PST
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.
Comment 1 Radar WebKit Bug Importer 2021-01-14 10:08:19 PST
<rdar://problem/73204290>
Comment 2 Devin Rousso 2021-01-15 15:26:19 PST
Created attachment 417744 [details]
Patch
Comment 3 Devin Rousso 2021-01-15 15:55:50 PST
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 😅)