forked from LiveCarta/PayPal-PHP-SDK
Fixes #343: Future Payment Caching Issue
This commit is contained in:
@@ -125,6 +125,10 @@ class OAuthTokenCredential extends PayPalResourceModel
|
|||||||
*/
|
*/
|
||||||
public function getAccessToken($config)
|
public function getAccessToken($config)
|
||||||
{
|
{
|
||||||
|
// Check if we already have accessToken in Cache
|
||||||
|
if ($this->accessToken && (time() - $this->tokenCreateTime) < ($this->tokenExpiresIn - self::$expiryBufferTime)) {
|
||||||
|
return $this->accessToken;
|
||||||
|
}
|
||||||
// Check for persisted data first
|
// Check for persisted data first
|
||||||
$token = AuthorizationCache::pull($config, $this->clientId);
|
$token = AuthorizationCache::pull($config, $this->clientId);
|
||||||
if ($token) {
|
if ($token) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ $payment->setIntent("authorize")
|
|||||||
// You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.
|
// You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.
|
||||||
|
|
||||||
// authorization code from mobile sdk
|
// authorization code from mobile sdk
|
||||||
$authorizationCode = 'EJfRuAqXEE95pdVMmOym_mftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY';
|
$authorizationCode = 'EK7_MAKlB4QxW1dWKnvnr_CEdLKnpH3vnGAf155Eg8yO8e_7VaQonsqIbTK9CR7tUsoIN2eCc5raOfaGbZDCT0j6k_BDE8GkyLgk8ulcQyR_3S-fgBzjMzBwNqpj3AALgCVR03zw1iT8HTsxZXp3s2U';
|
||||||
|
|
||||||
// Client Metadata id from mobile sdk
|
// Client Metadata id from mobile sdk
|
||||||
// For more information look for PayPal-Client-Metadata-Id in https://developer.paypal.com/docs/api/#authentication--headers
|
// For more information look for PayPal-Client-Metadata-Id in https://developer.paypal.com/docs/api/#authentication--headers
|
||||||
@@ -67,10 +67,10 @@ $clientMetadataId = '123123456';
|
|||||||
try {
|
try {
|
||||||
// Exchange authorization_code for long living refresh token. You should store
|
// Exchange authorization_code for long living refresh token. You should store
|
||||||
// it in a database for later use
|
// it in a database for later use
|
||||||
$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);
|
//$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);
|
||||||
|
echo $refreshToken;
|
||||||
// Update the access token in apiContext
|
// Update the access token in apiContext
|
||||||
$payment->updateAccessToken($refreshToken, $apiContext);
|
$payment->updateAccessToken('NvtsgQLDxJXfFTOpYRS5Ad9S1kOd_QWCk4vkdPuBe9qDfKDBbKyioSMXeMwSaLKr4Lz_zoFEpZBiHrce4X4IcAfabH0', $apiContext);
|
||||||
|
|
||||||
// For Sample Purposes Only.
|
// For Sample Purposes Only.
|
||||||
$request = clone $payment;
|
$request = clone $payment;
|
||||||
@@ -87,7 +87,7 @@ try {
|
|||||||
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||||
ResultPrinter::printError("Future Payment", "Payment", null, $request, $ex);
|
ResultPrinter::printError("Future Payment", "Payment", null, $payment, $ex);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user