PaymentMethodChangeEvent.methodDetails - Web APIs 编辑
Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The read-only methodDetails
property of the PaymentMethodChangeEvent
interface is an object containing any data the payment handler may provide to describe the change the user has made to their payment method. The value is null
if no details are available.
Syntax
details = paymentMethodChangeEvent.methodName;
Value
An object containing any data needed to describe the changes made to the payment method. The contents vary depending on the actual payment method chosen, so you will need to refer to the methodName
property first, then inerpret the methodDetails
after that.
The default value is null
, indicating that no additional details are available.
Example
This example uses the paymentmethodchange
event to watch for changes to the payment method selected for Apple Pay, in order to compute a discount if the user chooses to use a Visa card as their payment method.
request.onpaymentmethodchange = function(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 result = calculateDiscount(ev.methodDetails);
Object.assign(newStuff, result);
break;
}
}
// finally...
ev.updateWith(newStuff);
};
const response = await request.show();
Note that the methodDetails
property is being used by the calculateDiscount()
function to compute any payment discount, then updateWith()
is called to update the event with the computed update.
Specifications
Specification | Status | Comment |
---|---|---|
Payment Request API The definition of 'PaymentMethodChangeEvent.methodDetails' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论