PaymentMethodChangeEvent: methodName 屬性
PaymentMethodChangeEvent 介面的只讀 methodName 屬性是一個字串,用於唯一標識使用者當前選擇的支付處理程式。支付處理程式可以是 Apple Pay 或 Android Pay 等支付技術,每個支付處理程式可能支援多種支付方式;支付處理程式內的支付方式更改由 PaymentMethodChangeEvent 描述。
值
一個字串,用於唯一標識當前選擇的支付處理程式。這可以是從標準化支付方式識別符號列表中選擇的字串,也可以是支付服務使用的 URL。有關更多資訊,請參閱 支付方式識別符號。
預設值為空字串 ""。
示例
此示例使用 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();
請注意,calculateDiscount() 函式正在使用 methodDetails 屬性來計算任何支付折扣,然後呼叫 updateWith() 來更新帶有計算出的更新的事件。
規範
| 規範 |
|---|
| Payment Request API # dom-paymentmethodchangeevent-methodname |
瀏覽器相容性
載入中…