Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal redirects to the same popup window

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.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>

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 enter image description here

Redirecting to the configured redirect URL enter image description here

like image 539
Balakrishnan Avatar asked Apr 03 '14 18:04

Balakrishnan


1 Answers

I had the exact problem, but the solution is in the documentation here:

https://developer.paypal.com/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>
like image 109
derekadk Avatar answered Sep 28 '22 21:09

derekadk