我已成功集成 PayPal 识别/登录,但问题是,该网站(我的返回 URL)在客户端登录的 PayPal 弹出对话框中打开。
我希望登录窗口关闭,然后让主调用窗口转到返回 URL,以便用户继续在主屏幕上。
我在 PayPal 开发人员文档中找不到有关如何执行此操作的任何详细信息。按钮渲染中是否有我缺少的选项?
当前代码:
paypal.use( ['login'], function (login) {
login.render ({
"appid":"My_API_ID",
"authend":"sandbox",
"scopes":"openid profile email address",
"containerid":"paypalLogin",
"responseType":"code",
"locale":"en-us",
"buttonType":"LWP",
"buttonShape":"pill",
"buttonSize":"lg",
"fullPage":"false",
"returnurl":"http://mysite/php/paypal/paypal_api_login.php"
});
});
最佳答案
重定向发生在窗口中。在那里添加 JS 代码以保存 URL 信息或重定向打开的窗口(设置 window.opener.location.href
)和 window.close()
(如果需要)。
未经测试,但应该简单如下:
<script type="text/javascript">
if(window.opener) {
window.opener.location.href = window.location.href;
window.close()
}
</script>
或者也许更好的是添加并检查附加参数
<script type="text/javascript">
const REDIRECT_PARAM = '&redirected_opener=true';
if(window.opener && !window.location.href.includes(REDIRECT_PARAM)) {
window.opener.location.href = window.location.href + REDIRECT_PARAM;
window.close()
}
</script>
关于paypal - 使用 PayPal 登录 : Closing the login window to return to main site,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73883124/