PayPal 重定向到相同的弹出窗口

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

我在我的网页中集成了 PayPal 的 Identity API。像往常一样,当用户单击

login with paypal
JavaScript 按钮)时,它会打开一个新窗口用于登录。但在有效登录后,它会将我重定向到同一个弹出窗口。

注意:我将域名替换为

domain

应用程序返回URL(测试): http://domain.esy.es/index.php/users/paypalidentity

查看

//url http://domain.esy.es/index.php
<span id="paypalButton"></span>
<script src="https://www.paypalobjects.com/js/external/api.js"></script>
<script>
    paypal.use( ["login"], function(login) {
        login.render ({
            "appid": MYAPPID,
            "authend": "sandbox",
            "scopes": "openid email profile address phone https://uri.paypal.com/services/paypalattributes",
            "containerid": "paypalButton",
            "locale": "en-us",
            "returnurl": "http://domain.esy.es/index.php/users/paypalidentity"
        });
    });
</script>

控制器

//url http://domain.esy.es/index.php/users/paypalidentity
require_once __DIR__ . '/../../vendor/autoload.php';
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$code = $_REQUEST['code'];
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$params = array(
    'client_id' => MYCLIENTID,
    'client_secret' => MYSECRET,
    'code' => $code
);
$token = PPOpenIdTokeninfo::createFromAuthorizationCode($params,$apicontext);
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$params = array('access_token' => $token->getAccessToken());
$user = PPOpenIdUserinfo::getUserinfo($params,$apicontext);
$this->session->set_userdata(
    array(
        'name'=>$user->getName()
    )
);
redirect(base_url());

登录成功 enter image description here

重定向到配置的重定向URL enter image description here

javascript php redirect paypal
4个回答
3
投票

我遇到了确切的问题,但解决方案位于此处的文档中:

https://developer.paypal.com/docs/classic/express-checkout/digital-goods/ClosingWindow/

请参阅“将父页面重新加载到特定 URL”并将此脚本添加到返回和取消页面。

<script>
    top.window.opener.location ='http://your-url-here.html';
    // if you want to close the window
    // window.close();
</script>

1
投票

您需要在返回 URL 中添加关闭操作(并且很可能使用单独的 URL 作为返回 URL,其中只包含关闭操作)。

查看自适应支付文档。在该页面上查找“close”一词,它会直接带您进入介绍如何处理此问题的部分。

注意:您有责任在 PayPal 后关闭迷你浏览器 重定向到返回或取消 URL 中指定的页面。 PayPal 提供了一个 JavaScript 函数,您可以调用该函数来关闭 PayPal 迷你浏览器或灯箱。


1
投票

设置

top.window.opener.location
将更新您原来的“开启器”窗口。您还需要通过调用
top.close()
来关闭对话框。这只是尝试结合其他两个答案并分享我在他们的帮助下得出的解决方案。请注意,此代码位于“opener”窗口以外的 URL 中。

<script src="https://www.paypalobjects.com/js/external/api.js"></script>
<script>
top.window.opener.location ='http://yourdomain.com';
top.close();
</script>

0
投票

还有几点需要补充。

fullPage
选项目前没有效果,并且:

  1. 如果用户在弹出窗口内登录,则重定向发生在其中,而不是父页面
  2. 如果用户之前已经登录并按“继续”,则重定向发生在父页面,并且弹出窗口将被关闭。

要区分它们,请检查

top.window.opener
是否为
null

if (top.window.opener) {
    top.window.opener.location = window.location.href;
    top.close();
}
© www.soinside.com 2019 - 2024. All rights reserved.