PaymentMethodChangeEvent:methodDetails 屬性
PaymentMethodChangeEvent 介面中只讀的 methodDetails 屬性是一個物件,其中包含支付處理程式可能提供的任何資料,用於描述使用者對支付方式所做的更改。如果沒有可用詳細資訊,則值為 null。
值
一個包含描述支付方式所做更改所需任何資料的物件。其內容取決於所選的實際支付方式,因此您需要先參考 methodName 屬性,然後再解釋 methodDetails。
預設值為 null,表示沒有其他可用詳細資訊。
示例
此示例使用 paymentmethodchange 事件來監聽 Apple Pay 所選支付方式的更改,以便在使用者選擇使用 Visa 卡作為其支付方式時計算折扣。
js
request.onpaymentmethodchange = (ev) => {
const { type: cardType } = ev.methodDetails;
const newStuff = {};
if (ev.methodName === "https://apple.com/apple-pay") {
switch (cardType) {
case "visa": {
// do Apple Pay specific handling for Visa card…
// methodDetails contains the card information
const discount = calculateDiscount(ev.methodDetails);
Object.assign(newStuff, discount);
break;
}
}
}
// finally…
ev.updateWith(newStuff);
};
const response = await request.show();
請注意,methodDetails 屬性正在被 calculateDiscount() 函式使用以計算任何支付折扣,然後呼叫 updateWith() 以使用計算出的更新來更新事件。
規範
| 規範 |
|---|
| Payment Request API # dom-paymentmethodchangeevent-methoddetails |
瀏覽器相容性
載入中…