使用 PayPal 登录:关闭登录窗口返回主站点

问题描述 投票:0回答:2

我已成功集成 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"
    });
});
paypal
2个回答
2
投票

重定向返回发生在窗口中。在那里添加 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>

0
投票

@Preston:对我来说这个解决方案不起作用。在我的弹出窗口(重定向到我的自定义重定向页面)中,window.opener(也是top.window.opener和parent.window.opener)为空,所以我无法重定向父窗口。有什么想法吗?

© www.soinside.com 2019 - 2024. All rights reserved.