有一个页面实现了支付请求 api,它有一个 Applepay 按钮,一切正常。但是一旦页面嵌入到 iframe 中,就会发生 SecurityError 错误:尝试从具有与其顶级框架不同的安全来源的文档启动 Apple Pay 会话。
属性 allowpaymentrequest = 'true'
HTMLIFrameElement 接口的 allowPaymentRequest 属性返回一个布尔值,指示是否可以在跨域 iframe 上调用支付请求 API。
两个页面都是https。
示例.com:
const applePayMethod = {
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 3,
merchantIdentifier: "somemerchantid",
merchantCapabilities: ["supports3DS",],
supportedNetworks: ["masterCard", "visa"],
countryCode: "US",
},
};
const paymentDetails = {
total: {
label: "My Merchant",
amount: { value: "27.50", currency: "USD" },
},
}
try {
const request = new PaymentRequest([applePayMethod], paymentDetails, {});
const response = await request.show();
const status = processResponse(response);
response.complete(status);
} catch (e) {
console.log(e)
}
代码与 iframe.com
<iframe allowpaymentrequest='true' src="https://example.com/" frameborder="0"></iframe>