安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

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 。若 requestShipping was false (or missing), shippingOption 返回 null , even the developer provides a  selected a shipping option.

句法

// Returns the id of the selected PaymentShippingOption
var shippingOption = request.shippingOption; 
					

范例

In the example below, the PaymentRequest.onshippingoptionchange 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.` };
  }
}
					

规范

规范 状态 注释
支付请求 API
The definition of 'shippingOption' in that specification.
候选推荐 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
shippingOption Chrome 61 Edge 15 Firefox 55 注意事项 Disabled
55 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 不支持 No Safari 11.1 WebView Android 不支持 No Chrome Android 53 Firefox Android 55 注意事项 Disabled
55 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 不支持 No Safari iOS 11.3 Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: