/** * Validates the licence entered by the customer in the * extensions system configuration tab. * * @param Faett_Manager_Package_Interfaces_Information * $information The package information to validate the licence for * @return void * @throws Faett_Manager_Exceptions_InvalidLicenceException * Is thrown if the licence is not valid */ public function validate(Faett_Manager_Package_Interfaces_Information $information) { // create a valid session key for the package $key = str_replace('/', '.', $information->getIdentifier()); // load the sesssion $sess = Mage::getSingleton('adminhtml/session'); // check if a valid licence is available if ($data = $sess->getData($key)) { // check if a valid licence was found if (array_key_exists(self::HAS_VALID_LICENCE, $data) && $data[self::HAS_VALID_LICENCE]) { // if yes, return without doing anything return; } } // initialize the SOAP client $client = new Zend_Soap_Client($channelUrl = $this->_getChannelUrl($information)); try { // login to webservice $session = $client->login($username = $this->_getUsername($information), $password = $this->_getPassword($information)); } catch (Exception $e) { // if the channel login failed throw an exception throw Faett_Manager_Exceptions_ChannelLoginException::create('Channel login failed for validating package ' . $information->getIdentifier()); } // split the identifier into alias and package name list($alias, $packageName) = explode('/', $information->getIdentifier()); // check if the licence is valid $isValid = $client->call($session, Faett_Manager_Model_Connector::CHANNEL_VALIDATE, array($serialz = $information->getSerialz(), $alias, array('packageName' => $packageName))); // if a valid licence was found set it in the session if ($isValid) { $sess->setData($key, array(self::HAS_VALID_LICENCE => true)); } else { // if the licence is not valid throw an exception throw Faett_Manager_Exceptions_InvalidLicenceException::create('Serialz ' . $serialz . ' is not valid for package ' . $information->getIdentifier()); } }
/** * Validates the licence entered by the customer in the * extensions system configuration tab. * * @param Faett_Manager_Package_Interfaces_Information * $information The package information to validate the licence for * @return void * @throws Faett_Manager_Exceptions_InvalidLicenceException * Is thrown if the licence is not valid * @throws Faett_Manager_Exceptions_ChannelLoginException * Is thrown if the connection to the channel can't be established */ public function validate(Faett_Manager_Package_Interfaces_Information $information) { // create a valid session key for the package $key = str_replace('/', '.', $information->getIdentifier()); // load the sesssion $sess = Mage::getSingleton('adminhtml/session'); // check if a valid licence is available if ($data = $sess->getData($key)) { // check if a valid licence was found if (array_key_exists(self::HAS_VALID_LICENCE, $data) && $data[self::HAS_VALID_LICENCE]) { // if yes, return without doing anything return; } } // try to login to the channel try { // initialize the SOAP client $client = new Zend_Soap_Client($channelUrl = $this->_getChannelUrl($information)); // login to webservice $session = $client->login($username = $this->_getUsername($information), $password = $this->_getPassword($information)); } catch (SoapFault $sfe) { // log the exception Mage::logException($sfe); // if the channel login failed throw an exception throw Faett_Manager_Exceptions_ChannelLoginException::create('Channel login failed for validating package ' . $information->getIdentifier()); } // check the licence itself try { // call the SOAP webservice to check if the licence is valid $client->call($session, Faett_Manager_Model_Connector::CHANNEL_VALIDATE_SIMPLE, array($information->getIdentifier(), $alias)); } catch (SoapFault $sfe) { // if the licence is not valid throw an exception throw Faett_Manager_Exceptions_InvalidLicenceException::create('Licence is not valid for package ' . $information->getIdentifier()); } // if a valid licence was found set it in the session $sess->setData($key, array(self::HAS_VALID_LICENCE => true)); }