| Summary: | Payment Request API - PaymentDetailsUpdate requires "total" | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | nickgzzjr | ||||||
| Component: | New Bugs | Assignee: | 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: |
|
||||||||
Created attachment 417741 [details]
Patch
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. Created attachment 417745 [details]
Patch
Committed r271615: <https://trac.webkit.org/changeset/271615> All reviewed patches have been landed. Closing bug and clearing flags on attachment 417745 [details]. |
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." }