/**
  * @param Paysera_WalletApi_Event_ResponseExceptionEvent $event
  */
 public function onResponseException(Paysera_WalletApi_Event_ResponseExceptionEvent $event)
 {
     if ($event->getException()->getErrorCode() === 'invalid_grant') {
         $options = $event->getOptions();
         if (!isset($options['oauth_access_token_retry'])) {
             $options['oauth_access_token_retry'] = true;
             $event->setOptions($options);
             $refreshToken = $this->token->getRefreshToken();
             if ($refreshToken !== null) {
                 $newToken = $this->oauthClient->refreshAccessToken($refreshToken);
                 $this->token = $newToken;
                 $this->signer = new Paysera_WalletApi_Auth_Mac($newToken->getMacId(), $newToken->getMacKey());
                 $event->stopPropagation()->setRepeatRequest(true);
                 $event->getDispatcher()->dispatch(Paysera_WalletApi_Events::AFTER_OAUTH_TOKEN_REFRESH, new Paysera_WalletApi_Event_MacAccessTokenEvent($newToken));
             }
         }
     }
 }
 /**
  * Gets OAuth access token from query parameters. Redirect URI must be the same as passed when getting the
  * authorization URI, otherwise authorization will fail
  * If no authorization parameters are passed, returns null
  * If authorization error is passed or some data is invalid (like state parameter), exception is thrown
  *
  * @param array  $params      takes $_GET if not passed
  * @param string $redirectUri takes current URI without authorization parameters if not passed
  *
  * @return Paysera_WalletApi_Entity_MacAccessToken|null
  *
  * @throws Paysera_WalletApi_Exception_OAuthException
  * @throws Paysera_WalletApi_Exception_ApiException
  */
 public function getOAuthAccessToken($params = null, $redirectUri = null)
 {
     if ($params === null) {
         $params = $_GET;
     }
     $authorizationCode = $this->getOAuthCode($params);
     if ($authorizationCode === null) {
         return null;
     }
     if ($redirectUri === null) {
         $redirectUri = $this->getCurrentUri();
     }
     return $this->oauthClient->exchangeCodeForAccessToken($authorizationCode, $redirectUri);
 }