/**
  * Initializes service from gateway
  * @param Varien_Object $gateway Object with all connection params
  * @return
  */
 public function initFromVarienObject(Varien_Object $gateway)
 {
     $this->setType($gateway->getProtocol())->setHost($gateway->getHost())->setLogin($gateway->getLogin())->setPassword($gateway->getPassword())->setPort($gateway->getPort())->setSecure($this->_getGatewaySecure($gateway));
     $instanceConstructor = $this->_getConnectionConstructor();
     try {
         // Try to connect
         $this->setInstance(new $instanceConstructor($this->_getConnectionParams()));
     } catch (Zend_Mail_Protocol_Exception $e) {
         $this->log($e->getMessage());
         return $e->getMessage();
     }
     return true;
 }
Example #2
0
 /**
  *  Update our account information.
  *
  *    Path: account/update
  *
  *    Request body XML:
  *    <Update>
  *      <Authenticate>
  *         <Login>bob@foo.com</Login>
  *         <SessionID>10d0f31bbcc57750</SessionID>
  *      </Authenticate>
  *      <Request>
  *         <ControlID>control 12345</ControlID>
  *         <User>
  *             <SelectedLogin>bob@foo.com</SelectedLogin>
  *             <Login>joe@foo.com</Login>
  *             <ContactPhone1>954-312-1111</ContactPhone1>
  *             <ContactPhone2>954-312-2222</ContactPhone2>
  *         </User>
  *         <Company>My New Company Name</Company>
  *         <TimeZone>-5</TimeZone>
  *         <DST>US</DST>
  *      </Request>
  *    </Update>
  *
  *
  * @param Varien_Object $info
  * @return bool
  */
 public function updateAccount($info)
 {
     // set up request object
     $request = $this->getRequest('Update');
     $request->Request->ControlID = 1;
     if ($info->getLogin()) {
         $request->Request->User->SelectedLogin = $this->getUsername();
         $request->Request->User->Login = strtolower($info->getLogin());
     }
     if ($info->getContactPhone()) {
         $request->Request->User->SelectedLogin = strtolower($this->getUsername());
         $request->Request->User->ContactPhone1 = $info->getContactPhone();
         //            $request->Request->User->ContactPhone2   = '';
     }
     if ($info->getFirstName()) {
         $request->Request->User->SelectedLogin = strtolower($this->getUsername());
         $request->Request->User->FirstName = $info->getFirstName();
     }
     if ($info->getLastName()) {
         $request->Request->User->SelectedLogin = strtolower($this->getUsername());
         $request->Request->User->LastName = $info->getLastName();
     }
     //        $request->Request->Company = '';
     //        $request->Request->TimeZone = '';
     //        $request->Request->DST      = '';
     $url = $this->getUrl('account/update');
     // prepare response!
     /** @var $response SimpleXMLElement */
     $response = $this->getCurlResponse($url, $request);
     if ($response && property_exists($response, 'Request')) {
         // if we got a valid response back, we should check for errors
         /** @var $requestResponse SimpleXMLElement */
         $requestResponse = $response->Request;
         // if there aren't any errors...
         if ($requestResponse && property_exists($requestResponse, 'Status')) {
             if ($requestResponse->Status == '0') {
                 return true;
                 // success!
             } else {
                 $this->setLastApiStatus($requestResponse->Status);
                 if (property_exists($requestResponse, 'Message')) {
                     $this->setLastApiMessage($requestResponse->Message . ' (' . $this->getLastApiStatus() . ')');
                 }
             }
         }
     }
     // something terrible happened
     return false;
 }