このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

PaymentRequest: id プロパティ

利用可能性は限定的

この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。

Want more support for this feature? Tell us why.

idPaymentRequest インターフェイスの読み取り専用プロパティで、特定の 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

The id is then also available in the PaymentResponse returned from the show() method, but under the requestId attribute.

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

ブラウザーの互換性