← Back to release summary

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

Ecosystem

Explainers: https://github.com/w3c/payment-request/issues/912

View on chromestatus.com