Simplify_AccessToken

AccessToken - used to manage OAuth access tokens.

Defined (1)

The class is defined in the following location(s).

/includes/gateways/simplify-commerce/includes/Simplify/AccessToken.php  
  1. class Simplify_AccessToken extends Simplify_Object { 
  2.  
  3. public function __construct($hash) { 
  4. $this->setAll($hash); 
  5.  
  6. /** 
  7. * Creates an OAuth access token 
  8. * @param $code - the authorisation code returned from the GET on /oauth/authorize 
  9. * @param $redirect_uri = this must be the redirect_uri set in the apps configuration 
  10. * @param $authentication - Authentication information to access the API. If not value is passed the global key Simplify::$publicKey and Simplify::$privateKey are used 
  11. * @return Simplify_AccessToken 
  12. */ 
  13. public static function create($code, $redirect_uri, $authentication = null) { 
  14.  
  15. $args = func_get_args(); 
  16. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 3); 
  17.  
  18. $props = 'code='.$code.'&redirect_uri='.$redirect_uri.'&grant_type=authorization_code'; 
  19. $resp = Simplify_AccessToken::sendRequest($props, "token", $authentication); 
  20.  
  21. return new Simplify_AccessToken($resp); 
  22.  
  23. /** 
  24. * Refreshes the current token. The access_token and refresh_token values will be updated. 
  25. * @param $authentication - Authentication information to access the API. If not value is passed the global key Simplify::$publicKey and Simplify::$privateKey are used 
  26. * @return Simplify_AccessToken 
  27. * @throws InvalidArgumentException 
  28. */ 
  29. public function refresh($authentication = null) { 
  30. $args = func_get_args(); 
  31.  
  32. $refresh_token = $this->refresh_token; 
  33. if (empty($refresh_token)) { 
  34. throw new InvalidArgumentException('Cannot refresh access token; refresh token is invalid'); 
  35.  
  36. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 1); 
  37.  
  38. $props = 'refresh_token='.$refresh_token.'&grant_type=refresh_token'; 
  39. $resp = Simplify_AccessToken::sendRequest($props, "token", $authentication); 
  40.  
  41. $this->setAll($resp); 
  42.  
  43. return $this; 
  44.  
  45. /** 
  46. * <p>Revokes a token from further use. 
  47. * @param $authentication - Authentication information to access the API. If not value is passed the global key Simplify::$publicKey and Simplify::$privateKey are used 
  48. * @return Simplify_AccessToken 
  49. * @throws InvalidArgumentException 
  50. */ 
  51. public function revoke($authentication = null) { 
  52. $args = func_get_args(); 
  53.  
  54. $access_token = $this->access_token; 
  55. if (empty($access_token)) { 
  56. throw new InvalidArgumentException('Cannot revoke access token; access token is invalid'); 
  57.  
  58. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 2); 
  59.  
  60. $props = 'token='.$access_token.''; 
  61.  
  62. Simplify_AccessToken::sendRequest($props, "revoke", $authentication); 
  63.  
  64. $this->access_token = null; 
  65. $this->refresh_token = null; 
  66. $this->redirect_uri = null; 
  67.  
  68. return $this; 
  69.  
  70. private static function sendRequest($props, $context, $authentication) { 
  71.  
  72. $url = Simplify_Constants::OAUTH_BASE_URL.'/'.$context; 
  73. $http = new Simplify_HTTP(); 
  74. $resp = $http->oauthRequest($url, $props, $authentication); 
  75.  
  76. return $resp; 
  77.  
  78. /** 
  79. * @ignore 
  80. */ 
  81. static public function getClazz() { 
  82. return "AccessToken"; 
  83.