Bug 220561

Summary: Payment Request API - PaymentDetailsUpdate requires "total"
Product: WebKit Reporter: nickgzzjr
Component: New BugsAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, hi, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: Mac (Intel)   
OS: macOS 10.15   
Attachments:
Description Flags
Patch
none
Patch none

Description nickgzzjr 2021-01-12 13:32:36 PST
Calling event.updateWith inside the onshippingaddresschange or onshippingoptionchange event handlers with a PaymentDetailsUpdate object requires “total” to be included. When “total” is not included an error “RangeError: "" is not a valid currency code." is thrown. 

I expect “total” to NOT be required in the PaymentDetailsUpdate. Note: “total” should be required for PaymentDetailsInit but not for PaymentDetailsUpdate. Note: “newTotal” is required in the ApplePayJS API when using ApplePayShippingContactUpdate.

Simple example:

request.onshippingaddresschange = event => {
    const paymentDetailsUpdate = {};
    event.updateWith(paymentDetailsUpdate);
};

The above example will throw an error.

Though the PaymentDetailsUpdate can be more complex. 
For example, I might want to include an error in the PaymentDetailsUpdate:

const paymentDetailsUpdate = {
    "error": "Can't ship to this address."
}

This won’t work unless I include the total as such:

const paymentDetailsUpdate = {
    "total": {
        "label": "My Merchant",
        "amount": {
            "value": "27.50",
            "currency": "USD"
        }
    },
    "error": "Can't ship to this address."
}
Comment 1 Radar WebKit Bug Importer 2021-01-14 10:11:10 PST
<rdar://problem/73204405>
Comment 2 Devin Rousso 2021-01-15 14:36:38 PST
Created attachment 417741 [details]
Patch
Comment 3 Andy Estes 2021-01-15 15:10:37 PST
Comment on attachment 417741 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417741&action=review

> LayoutTests/http/tests/paymentrequest/updateWith-error.https.html:33
> +const applePay = {
> +    supportedMethods: "https://apple.com/apple-pay",
> +    data: {
> +        version: 2,
> +        merchantIdentifier: '',
> +        merchantCapabilities: ['supports3DS'],
> +        supportedNetworks: ['visa', 'masterCard'],
> +        countryCode: 'US',
> +    },
> +};
> +const validMethods = [applePay];
> +const validAmount = {
> +    currency: "USD",
> +    value: "5.00",
> +};
> +const validTotal = {
> +    label: "label",
> +    amount: validAmount,
> +};
> +const validDetails = {
> +    total: validTotal,
> +};

You could use what's in `http/tests/paymentrequest/resources/helpers.js` for most/all of this.
Comment 4 Devin Rousso 2021-01-15 15:32:54 PST
Created attachment 417745 [details]
Patch
Comment 5 EWS 2021-01-19 13:43:37 PST
Committed r271615: <https://trac.webkit.org/changeset/271615>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417745 [details].