Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
The shippingOption read-only attribute of the PaymentRequest interface returns either the id of a selected shipping option, null (if no shipping option was set to be selected) or a shipping option selected by the user. It is initially null by when no "selected" shipping options are provided.
This attribute is only populated if the constructor is called with the requestShipping flag set to true. If requestShipping was false (or missing), shippingOption returns null, even the developer provides a selected a shipping option.
Syntax
// Returns the id of the selected PaymentShippingOption var shippingOption = request.shippingOption;
Example
In the example below, the PaymentRequest.onshippingoptionchange and the PaymentRequest.onshippingaoptionchange events are dispatched. In each calls to updateDetails() are made, one using a promise, and the other with a plain JS object. This demotrates synchrounous and asynchronous updates to a payment sheet.
const request = new PaymentRequest(methodData, details, options);
// Async update to details
request.onshippingaddresschange = ev => {
ev.updateWith(checkShipping(request));
};
// Sync update to the total
request.onshippingoptionchange = ev => {
const shippingOption = shippingOptions.find(
option => option.id === request.id
);
const newTotal = {
currency: "USD",
label: "Total due",
value: calculateNewTotal(shippingOption),
};
ev.updateWith({ ...details, total: newTotal });
};
async function checkShipping(request) {
try {
const json = request.shippingAddress.toJSON();
await ensureCanShipTo(json);
const { shippingOptions, total } = await calculateShipping(json);
return { ...details, shippingOptions, total };
} catch (err) {
return { ...details, error: `Sorry! we can't ship to your address.` };
}
}
Specifications
| Specification | Status | Comment |
| Payment Request APIThe definition of 'shippingOption' in that specification. | Candidate Recommendation | Initial definition. |
Browser Compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
shippingOption
|
Chrome
Full support 60 |
Edge
Full support 15 |
Firefox No support No No support No Notes' Available only in nightly builds. |
IE
No support No |
Opera
Full support 47 |
Safari
Full support 11.1 |
WebView Android
No support No |
Chrome Android
Full support 53 |
Firefox Android No support No No support No Notes' Available only in nightly builds. |
Opera Android
Full support 44 |
Safari iOS
Full support 11.3 |
Samsung Internet Android
Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
PaymentRequest.shippingOption by Mozilla Contributors is licensed under CC-BY-SA 2.5.