/** * @test */ public function testLogoutWithCustomConfig() { $redirectUri = 'http://mywebsite.com'; $idToken = 'abc'; $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession"; $this->assertEquals($expectedBaseUrl . "?id_token={$idToken}&redirect_uri=" . urlencode($redirectUri) . "&logout=true", OpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config"); }
<?php require __DIR__ . '/../bootstrap.php'; use PayPal\Api\OpenIdSession; $baseUrl = getBaseUrl() . '/UserConsentRedirect.php?success=true'; // ### Get User Consent URL // The clientId is stored in the bootstrap file //Get Authorization URL returns the redirect URL that could be used to get user's consent $redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('openid', 'profile', 'address', 'email', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout', 'https://uri.paypal.com/services/invoicing'), null, null, null, $apiContext); // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="' . $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl);
public function appendEventXML(array $context = null) { $result = new XMLElement('paypal'); $cookie = new Cookie('paypal', TWO_WEEKS, __SYM_COOKIE_PATH__, null, true); $accessToken = $cookie->get('token'); //$accessToken->getRefreshToken() // var_dump($accessToken);die; if (!empty($accessToken)) { $user = $cookie->get('user'); $result->appendChild(General::array_to_xml($result, $user)); } else { $baseUrl = SYMPHONY_URL . '/extension/paypal/consent'; // ### Get User Consent URL // The clientId is stored in the bootstrap file //Get Authorization URL returns the redirect URL that could be used to get user's consent $redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('openid', 'profile', 'address', 'email', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout'), null, null, null, $this->apiContext); $authend = $this->mode == 'sandbox' ? '"authend": "sandbox",' : ''; $scriptInclude = '<span id="lippButton"></span> <script src="https://www.paypalobjects.com/js/external/api.js"></script> <script> paypal.use( ["login"], function(login) { login.render ({ "appid": "' . $this->clientId . '",' . $authend . '"scopes": "openid profile email address phone https://uri.paypal.com/services/paypalattributes https://uri.paypal.com/services/expresscheckout", "containerid": "lippButton", "locale": "en-us", "returnurl": "' . $baseUrl . '" }); }); </script>'; $result->appendChild(new XMLElement('authorize', $this->repairEntities($scriptInclude), array('url' => $this->repairEntities($redirectUrl)))); // var_dump($redirectUrl);die; } $context['wrapper']->appendChild($result); }
<?php require __DIR__ . '/../bootstrap.php'; use PayPal\Api\OpenIdSession; $baseUrl = getBaseUrl() . '/UserConsentRedirect.php?success=true'; // ### Get User Consent URL // The clientId is stored in the bootstrap file //Get Authorization URL returns the redirect URL that could be used to get user's consent $redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('profile', 'email', 'phone'), null, null, null, $apiContext); ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="' . $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl);
$app_return_url = '!!! URL TO THIS SCRIPT !!!'; $scope = array('openid', 'email'); #More info: https://developer.paypal.com/docs/integration/direct/identity/attributes/ ####################################################### error_reporting(E_ALL); ini_set('display_errors', 1); require_once dirname(__FILE__) . '/paypal-sdk/autoload.php'; use PayPal\Api\OpenIdSession; use PayPal\Api\OpenIdTokeninfo; use PayPal\Api\OpenIdUserinfo; use PayPal\Rest\ApiContext; use PayPal\Auth\OAuthTokenCredential; ####################################################### #Step 1: display link to paypal if (!isset($_GET['code']) and !isset($_GET['error'])) { $openidurl = OpenIdSession::getAuthorizationUrl($app_return_url, $scope, $paypal_client_id); echo 'Click here to <a href="https://www.paypal.com/webapps/auth/protocol/openidconnect' . $openidurl . '">log in with paypal</a>!'; die; } ####################################################### #Check return data for errors if (isset($_GET['error'])) { die('<h1>Error:</h1><pre>' . print_r($_GET, TRUE)); } ####################################################### #Step 2: get user data $api_context = new ApiContext(new OAuthTokenCredential($paypal_client_id, $paypal_secret)); $api_context->setConfig(array('mode' => 'live')); $token = OpenIdTokeninfo::createFromAuthorizationCode(array('code' => $_GET['code']), $paypal_client_id, $paypal_secret, $api_context); $user = OpenIdUserinfo::getUserinfo(json_decode($token, true), $api_context); $user = json_decode($user, true);