private function generateAccessToken($config, $refreshToken = null)
{
$params = array('grant_type' => 'client_credentials');
if ($refreshToken != null) {
// If the refresh token is provided, it would get access token using refresh token
// Used for Future Payments
$params['grant_type'] = 'refresh_token';
$params['refresh_token'] = $refreshToken;
}
$payload = http_build_query($params);
$response = $this->getToken($config, $this->clientId, $this->clientSecret, $payload);
if ($response == null || !isset($response["access_token"]) || !isset($response["expires_in"])) {
$this->accessToken = null;
$this->tokenExpiresIn = null;
PayPalLoggingManager::getInstance(__CLASS__)->warning("Could not generate new Access token. Invalid response from server: ");
throw new PayPalConnectionException(null, "Could not generate new Access token. Invalid response from server: ");
} else {
$this->accessToken = $response["access_token"];
$this->tokenExpiresIn = $response["expires_in"];
}
$this->tokenCreateTime = time();
return $this->accessToken;
}