forked from LiveCarta/PayPal-PHP-SDK
Updates to LIPP & Future Payments
- Updated LIPP Sample code - Updated Future Payments to have helper functions for retrieving access token - Updated Logging Syntax to include timestamp and response json
This commit is contained in:
37
sample/lipp/GetUserInfo.php
Normal file
37
sample/lipp/GetUserInfo.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
// ### Obtain Access Token From Refresh Token
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Auth\OpenId\PPOpenIdTokenInfo;
|
||||
use PayPal\Auth\OpenId\PPOpenIdUserInfo;
|
||||
|
||||
// To obtain User Info, you have to follow three steps in general.
|
||||
// First, you need to obtain user's consent to retrieve the information you want.
|
||||
// This is explained in the example "ObtainUserConsent.php".
|
||||
|
||||
// Once you get the user's consent, the end result would be long lived refresh token.
|
||||
// This refresh token should be stored in a permanent storage for later use.
|
||||
|
||||
// Lastly, when you need to retrieve the user information, you need to generate the short lived access token
|
||||
// to retreive the information. The short lived access token can be retrieved using the example shown in
|
||||
// "GenerateAccessTokenFromRefreshToken.php", or as shown below
|
||||
|
||||
// You can retrieve the refresh token by executing ObtainUserConsent.php and store the refresh token
|
||||
$refreshToken = 'yzX4AkmMyBKR4on7vB5he-tDu38s24Zy-kTibhSuqA8kTdy0Yinxj7NpAyULx0bxqC5G8dbXOt0aVMlMmtpiVmSzhcjVZhYDM7WUQLC9KpaXGBHyltJPkLLQkXE';
|
||||
|
||||
try {
|
||||
|
||||
$tokenInfo = new PPOpenIdTokeninfo();
|
||||
$tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext);
|
||||
|
||||
$params = array('access_token' => $tokenInfo->getAccessToken());
|
||||
$userInfo = PPOpenIdUserinfo::getUserinfo($params, $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("User Information", "User Info", $userInfo->getUserId(), $userInfo->toJSON(JSON_PRETTY_PRINT));
|
||||
Reference in New Issue
Block a user