Пример #1
0
 /**
  * Send the registration data to Styla and request module configuration
  *
  * @param array                     $loginData
  * @param Mage_Oauth_Model_Consumer $consumer
  * @param Mage_Oauth_Model_Token    $token
  * @param                           $scopeData
  * @return stdClass
  * @throws Exception
  * @throws Styla_Connect_Exception
  */
 public function sendRegistrationRequest($loginData, $consumer, $token, $scopeData)
 {
     //at this point we have all the login data we need for styla to access our api
     $stylaApi = Mage::getSingleton('styla_connect/styla_api');
     //make the api request to styla api
     $apiRequest = $stylaApi->getRequest(Styla_Connect_Model_Styla_Api::REQUEST_TYPE_REGISTER_MAGENTO_API);
     $apiRequest->setConnectionType(Zend_Http_Client::POST);
     $apiRequest->setParams(array('styla_email' => $loginData['email'], 'styla_password' => $loginData['password'], 'consumer_key' => $consumer->getKey(), 'consumer_secret' => $consumer->getSecret(), 'token_key' => $token->getToken(), 'token_secret' => $token->getSecret()));
     $apiResponse = $stylaApi->callService($apiRequest, false);
     if (!$apiResponse->isOk()) {
         throw new Exception("Couldn't connect to Styla API. Error result: " . $apiResponse->getHttpStatus() . ($apiResponse->getError() ? ' - ' . $apiResponse->getError() : ''));
     }
     //setup the api urls for this client
     /** @var array $connectionData */
     $connectionData = $apiResponse->getResult();
     return $connectionData;
 }
Пример #2
0
 /**
  * Return complete callback URL or boolean FALSE if no callback provided
  *
  * @param Mage_Oauth_Model_Token $token Token object
  * @param bool $rejected OPTIONAL Add user reject sign
  * @return bool|string
  */
 public function getFullCallbackUrl(Mage_Oauth_Model_Token $token, $rejected = false)
 {
     $callbackUrl = $token->getCallbackUrl();
     if (Mage_Oauth_Model_Server::CALLBACK_ESTABLISHED == $callbackUrl) {
         return false;
     }
     if ($rejected) {
         /** @var $consumer Mage_Oauth_Model_Consumer */
         $consumer = Mage::getModel('oauth/consumer')->load($token->getConsumerId());
         if ($consumer->getId() && $consumer->getRejectedCallbackUrl()) {
             $callbackUrl = $consumer->getRejectedCallbackUrl();
         }
     } elseif (!$token->getAuthorized()) {
         Mage::throwException('Token is not authorized');
     }
     $callbackUrl .= false === strpos($callbackUrl, '?') ? '?' : '&';
     $callbackUrl .= 'oauth_token=' . $token->getToken() . '&';
     $callbackUrl .= $rejected ? self::QUERY_PARAM_REJECTED . '=1' : 'oauth_verifier=' . $token->getVerifier();
     return $callbackUrl;
 }
Пример #3
0
 /**
  * Send the registration data to Styla and request module configuration
  *
  * @param array                     $loginData
  * @param Mage_Oauth_Model_Consumer $consumer
  * @param Mage_Oauth_Model_Token    $token
  * @return stdClass
  * @throws Exception
  */
 public function sendRegistrationRequest($loginData, $consumer, $token)
 {
     //at this point we have all the login data we need for styla to access our api
     $stylaApi = Mage::getSingleton('styla_connect/styla_api');
     //make the api request to styla api
     $apiRequest = $stylaApi->getRequest(Styla_Connect_Model_Styla_Api::REQUEST_TYPE_REGISTER_MAGENTO_API);
     $apiRequest->setConnectionType(Zend_Http_Client::POST);
     $apiRequest->setParams(array('styla_email' => $loginData['email'], 'styla_password' => $loginData['password'], 'consumer_key' => $consumer->getKey(), 'consumer_secret' => $consumer->getSecret(), 'token_key' => $token->getToken(), 'token_secret' => $token->getSecret()));
     $apiResponse = $stylaApi->callService($apiRequest, false);
     if (!$apiResponse->isOk()) {
         throw new Exception("Couldn't connect to Styla API. Error result: " . $apiResponse->getHttpStatus() . ($apiResponse->getError() ? " - " . $apiResponse->getError() : ""));
     }
     //setup the api urls for this client
     /** @var array $connectionData */
     $connectionData = $apiResponse->getResult();
     /**
      * store the result data, so we don't have to call the api anymore in the future (on every change of the module's operating mode
      * the configuration gets overwritten, so otherwise we'd have to call the api every time we change it)
      */
     $this->cacheConnectionData($connectionData, Mage::helper('styla_connect/config')->getMode());
     return $connectionData;
 }