我正在尝试打开stripe js的支付网关(结账页面)。我这样做了:
async function LoadPaymentController(){
var stripe = Stripe('pk_test_51JBxkrB1SsiUQAfnzEWMqNgSCr9yV7tvULhePuQxwP3iCVr1kkNZskUA51TOtE5gw7f1X1ZSw41FKbHoIAHDolgI00DStmrT1m');
// Call your backend to create the Checkout Session
fetch('/create-checkout-session', {
method: 'POST',
})
.then(function(response) {
return response.json();
})
.then(function(session) {
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
});
}
单击我的页面中的按钮时会调用此函数。但它返回错误
Stripe.js requires 'allow-same-origin' if sandboxed
当我用谷歌搜索时,我只找到了在 iframe 中使用的示例,但我没有这样做。
有人可以帮我从这里出去吗?
这似乎是内容安全政策 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy(CSP)相关。
主要浏览器最近对 CSP 进行了一些更改/添加:
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox
- https://caniuse.com/mdn-html_elements_iframe_sandbox-allow-same-origin https://caniuse.com/mdn-html_elements_iframe_sandbox-allow-same-origin
从您的服务器,我尝试将以下 CSP 指令/标头添加到您的文档中(即页面或客户端捆绑包入口点的主 HTML 文档)
Content-Security-Policy: sandbox allow-same-origin;
如果您还没有使用所选框架执行此操作的机制,您可以考虑使用类似于 React 的 NPM 包:https://www.npmjs.com/package/react-csp https://www.npmjs.com/package/react-csp
您还可以尝试使用像这样的扩展(对于 Chrome)来在开发时禁用页面上的 CSP,以确认 CSP 是问题所在:
- https://chrome.google.com/webstore/detail/disable-content-security/ieelmcmcagommmplceebfedjlakkhpden?hl=en https://chrome.google.com/webstore/detail/disable-content-security/ieelmcmcagommplceebfedjlakkhpden?hl=en
- https://chrome.google.com/webstore/detail/always-disable-content-se/ffelghdomoehpceihalcnbmnodohkibj?hl=en https://chrome.google.com/webstore/detail/always-disable-content-se/ffelghdomoehpceihalcnbmnodohkibj?hl=en
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)