Optional "total" field in PaymentRequest API
- Category
- Miscellaneous
- Type
- New or changed feature
- Status
- In development (Chrome In development)
- Intent stage
- Start prototyping
WPT details: https://wpt.fyi/results/payment-request?label=master&label=experimental&aligned&q=payment-request%2F
Summary
The "total" field (together with the "details" field) of PaymentRequest API is optional so that developers can use other information (e.g., product Id) to make the requests when the total amount is unknown or redundant. As an example, when Digital Product Management (DPM) API is used with PaymentRequest API, developers only need to provide product Id to buy digital goods from digital stores.
Motivation
When Digital Product Management (DPM) API is used with PaymentRequest API, developers are allowed to specify product Id instead of the total amount in sending a PaymentRequest to buy digital goods from digital stores. In this use case of PaymentRequest API, the total amount becomes redundant (total can be calculated from product Id) or even unknown (app stores may not inform the merchants of the unit price). By making “total” optional, we can improve the developer ergonomics in these cases. Below demonstrates how developer ergonomics are improved. Without the proposed feature, developers would be forced to put a redundant (if unit prices is unknown) or a fake (if unit price is known) “total” object: new PaymentRequest([{supportedMethods: methodName, data: {productId: ‘abc’}], {total: {amount: “1”, currency: “USD”}}); With the proposed feature, developers could simply write: new PaymentRequest([{supportedMethods: methodName, data: {productId: ‘abc’}]);
Standards & signals
- Firefox: No signal
- Safari: No signal
- Web developers: No signals
- Tracking bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1066531
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=payment-request%2F
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+Optional%20%22total%22%20field%20in%20PaymentRequest%20API
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=Optional%20%22total%22%20field%20in%20PaymentRequest%20API
- Baseline status: https://webstatus.dev/?q=Optional%20%22total%22%20field%20in%20PaymentRequest%20API
Explainers: https://github.com/w3c/payment-request/issues/912