Apple Pay Payment Request API iframe



有一个页面实现了支付请求api,它有一个Applepay按钮,一切正常。但是,一旦页面嵌入到 iframe 中,就会发生 SecurityError 错误:尝试从安全源与其顶级框架不同的文档启动 Apple Pay 会话。

属性允许付款请求 = 'true'

HTMLIFrameElement 接口的 allowPaymentRequest 属性返回一个布尔值,指示是否可以在跨源 iframe 上调用支付请求 API。

这两个页面都是https。

example.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)
}  

code-with-iframe.com

<iframe allowpaymentrequest='true' src="https://example.com/" frameborder="0"></iframe>

Allowpaymentrequest 属性已弃用,浏览器不再支持

在此处查看更多内容

最新更新