Fixes #343: Future Payment Caching Issue

This commit is contained in:
Jay Patel
2015-07-20 11:28:17 -05:00
parent 5aa215c235
commit 9caf75ee82
2 changed files with 9 additions and 5 deletions

View File

@@ -125,6 +125,10 @@ class OAuthTokenCredential extends PayPalResourceModel
*/
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
$token = AuthorizationCache::pull($config, $this->clientId);
if ($token) {

View File

@@ -58,7 +58,7 @@ $payment->setIntent("authorize")
// You need to get a permanent refresh token from the authorization code, retrieved from the 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
// 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 {
// Exchange authorization_code for long living refresh token. You should store
// 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
$payment->updateAccessToken($refreshToken, $apiContext);
$payment->updateAccessToken('NvtsgQLDxJXfFTOpYRS5Ad9S1kOd_QWCk4vkdPuBe9qDfKDBbKyioSMXeMwSaLKr4Lz_zoFEpZBiHrce4X4IcAfabH0', $apiContext);
// For Sample Purposes Only.
$request = clone $payment;
@@ -87,7 +87,7 @@ try {
} catch (Exception $ex) {
// 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);
}