安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
PaymentRequest
event handler
onpaymentmethodchange
is invoked when the
paymentmethodchange
is fired, indicating that the user has changed payment methods within a given payment handler. For example, when using Apple Pay, the user can swipe to select different credit cards, debit cards, and so forth. Each time the user does so, this event is fired.
This event may not be fired by all payment handlers.
PaymentRequest.addEventListener('paymentmethodchange', paymentMethodChangeEvent => { ... });
PaymentRequest.onpaymentmethodchange = function(paymentMethodChangeEvent) { ... };
An event handler function which is to be called whenever the
paymentmethodchange
event is fired at the
PaymentRequest
, indicating that the user has changed payment methods within the same payment handler.
paymentmethodchange
event is triggered by a user-agent controlled interaction (i.e., the end-user switches from a debit to a credit card in the payment UI). To make sure you receive the event, you should add event listeners to
PaymentRequest
object after instantiation, but before you call
show()
.
An example payment method change handler is shown below; this example handles changes made to the payment method when using Apple Pay, specifically:
request.onpaymentmethodchange = ev => {
const { type: cardType } = ev.methodDetails;
const newStuff = {};
if (ev.methodName === "https://apple.com/apple-pay") {
switch (cardType) {
case "store":
// do Apple Pay specific handling for store card...
// methodDetails contains the store card information
const result = calculateDiscount(ev.methodDetails);
Object.assign(newStuff, result);
break;
}
}
// finally...
ev.updateWith(newStuff);
};
const response = await request.show();
| 规范 | 状态 | 注释 |
|---|---|---|
|
支付请求 API
The definition of 'onpaymentmethodchange' in that specification. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onpaymentmethodchange
|
Chrome 不支持 No | Edge 不支持 No |
Firefox
63
注意事项
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari ? | WebView Android 不支持 No | Chrome Android 不支持 No |
Firefox Android
63
注意事项
Disabled
|
Opera Android 不支持 No | Safari iOS ? | Samsung Internet Android 不支持 No |
完整支持
不支持
兼容性未知
见实现注意事项。
用户必须明确启用此特征。
PaymentRequest
onmerchantvalidation
onpaymentmethodchange
onshippingaddresschange
shippingAddress
shippingOption