admin管理员组文章数量:1353284
I integrated PayPal's Identity API in my webpage. As usual when user clicks login with paypal
(JavaScript button) it opens a new window for login purpose. But after a valid login it redirect me to the same popup window.
Note: I replaced my domain name as domain
App return URL (test): .php/users/paypalidentity
View
//url .php
<span id="paypalButton"></span>
<script src=".js"></script>
<script>
paypal.use( ["login"], function(login) {
login.render ({
"appid": MYAPPID,
"authend": "sandbox",
"scopes": "openid email profile address phone ",
"containerid": "paypalButton",
"locale": "en-us",
"returnurl": ".php/users/paypalidentity"
});
});
</script>
Controller
//url .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());
Successful Login
Redirecting to the configured redirect URL
I integrated PayPal's Identity API in my webpage. As usual when user clicks login with paypal
(JavaScript button) it opens a new window for login purpose. But after a valid login it redirect me to the same popup window.
Note: I replaced my domain name as domain
App return URL (test): http://domain.esy.es/index.php/users/paypalidentity
View
//url http://domain.esy.es/index.php
<span id="paypalButton"></span>
<script src="https://www.paypalobjects./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./services/paypalattributes",
"containerid": "paypalButton",
"locale": "en-us",
"returnurl": "http://domain.esy.es/index.php/users/paypalidentity"
});
});
</script>
Controller
//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());
Successful Login
Redirecting to the configured redirect URL
Share Improve this question asked Apr 3, 2014 at 18:40 BalakrishnanBalakrishnan 2,4512 gold badges28 silver badges48 bronze badges 3- Pretty sure you need to add a close() trigger from the PayPal javascript on your return URL. In fact, the procedure would be to create a separate return URL that has nothing but this close() action on it. PayPal would redirect to it, but then it would immediately close, leaving you with the screen behind like you want. It's detailed in the docs. Let me see if I can find it and post an official answer. – Drew Angell Commented Apr 4, 2014 at 0:45
- Last answer does what you asked for - mark it. – nikib3ro Commented Jan 28, 2015 at 7:57
- Great question. It is June 2016 now and PayPal still has not explained how to do it. – Green Commented Jun 15, 2016 at 3:17
4 Answers
Reset to default 3I had the exact problem, but the solution is in the documentation here:
https://developer.paypal./docs/classic/express-checkout/digital-goods/ClosingWindow/
Refer to "Reloading Parent Page to a Specific URL" and add this script to the return and cancel pages.
<script>
top.window.opener.location ='http://your-url-here.html';
// if you want to close the window
// window.close();
</script>
You need to add the close action in your return URL (and most likely use a separate URL as the return URL with nothing but the close action in it).
Take a look at the Adaptive Payments documentation. Do a find on that page for the word close and it'll take you straight to the section that covers how to handle this.
Note: You are responsible for closing the minibrowser after PayPal redirects to the page specified in either the return or cancel URL. PayPal provides a JavaScript function that you call to close a PayPal minibrowser or lightbox.
Setting top.window.opener.location
will update your original "opener" window. You will also need to close the dialog by calling top.close()
. This is just an attempt at bining the other two answers and sharing the solution I arrived at with their help. Note that this code is in a url other than the "opener" window.
<script src="https://www.paypalobjects./js/external/api.js"></script>
<script>
top.window.opener.location ='http://yourdomain.';
top.close();
</script>
Few more points to add.
fullPage
option currently has no effects, and:
- If user login inside the pop-up, then redirect happens in it, not the parent page
- If user already login before and press "Continue", then the redirect happens in the parent page, and the pop-up would be closed.
To distinguish them, check top.window.opener
is null
or not
if (top.window.opener) {
top.window.opener.location = window.location.href;
top.close();
}
本文标签: javascriptPayPal redirects to the same popup windowStack Overflow
版权声明:本文标题:javascript - PayPal redirects to the same popup window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743926471a2563053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论