PaymentRequest: id 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

PaymentRequest 介面的只讀屬性 id 返回一個特定 PaymentRequest 例項的唯一識別符號。

在構造 PaymentRequest 例項時,您可以提供自定義 id。如果未提供,瀏覽器會自動將 id 值設定為 UUID。

示例

此示例顯示瞭如何為 PaymentRequest 例項提供自定義 id。

js
const details = {
  id: "super-store-order-123-12312",
  total: {
    label: "Total due",
    amount: { currency: "USD", value: "65.00" },
  },
};
const request = new PaymentRequest(methodData, details);
console.log(request.id); // super-store-order-123-12312

然後,該 id 也可以在 show() 方法返回的 PaymentResponse 中找到,但位於 requestId 屬性下。

js
const response = await request.show();
console.log(response.requestId === request.id);

// And in serialized form too
const json = response.toJSON();
console.log(json.requestId, response.requestId, request.id);

字串。

規範

規範
Payment Request API
# dom-paymentrequest-id

瀏覽器相容性