public function __construct(modX &$modx, array $config = array())
 {
     $this->modx =& $modx;
     $basePath = $this->modx->getOption('moneybird.core_path', $config, $this->modx->getOption('core_path') . 'components/moneybird/');
     $assetsUrl = $this->modx->getOption('moneybird.assets_url', $config, $this->modx->getOption('assets_url') . 'components/moneybird/');
     $this->config = array_merge(array('basePath' => $basePath, 'corePath' => $basePath, 'modelPath' => $basePath . 'model/', 'processorsPath' => $basePath . 'processors/', 'templatesPath' => $basePath . 'templates/', 'chunksPath' => $basePath . 'elements/chunks/', 'jsUrl' => $assetsUrl . 'js/', 'cssUrl' => $assetsUrl . 'css/', 'assetsUrl' => $assetsUrl, 'connectorUrl' => $assetsUrl . 'connector.php', 'cacheOptions' => array(xPDO::OPT_CACHE_KEY => 'moneybird')), $config);
     $this->modx->addPackage('moneybird', $this->config['modelPath']);
     // autoloader for MoneyBird API stuff
     require_once $this->config['modelPath'] . 'api/ApiConnector.php';
     spl_autoload_register('Moneybird\\ApiConnector::autoload');
     try {
         $accountname = $this->modx->getOption('moneybird.account_name', $config, '');
         $username = $this->modx->getOption('moneybird.auth_username', $config, '');
         $password = $this->modx->getOption('moneybird.auth_password', $config, '');
         if (empty($accountname) || empty($username) || empty($password)) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, '[MoneyBird] Account name, username and/or password to connect with MoneyBird are empty!');
         }
         // setup the transport and connector
         $transport = new Moneybird\HttpClient();
         $transport->setAuth($username, $password);
         $this->api = new Moneybird\ApiConnector($accountname, $transport, new Moneybird\XmlMapper());
         // some errors?
         $errors = $this->api->getErrors();
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $this->modx->log(modX::LOG_LEVEL_ERROR, '[MoneyBird] ' . $error->attribute . ': ' . $error->message);
             }
         }
     } catch (Exception $e) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[MoneyBird] ' . $e->getMessage());
     }
 }
Example #2
0
 function getTransport($config)
 {
     if ($config['authType'] == 'oauth') {
         $transport = new Moneybird\HttpClient_Oauth();
         $consumer = new Moneybird\Lib\OAuthConsumer($config['oauth']['consumerKey'], $config['oauth']['consumerSecret'], NULL);
         $token = new Moneybird\Lib\OAuthConsumer($config['oauth']['token'], $config['oauth']['tokenSecret']);
         $transport->setConsumerAndToken($consumer, $token);
     } else {
         $transport = new Moneybird\HttpClient();
         $transport->setAuth($config['username'], $config['password']);
     }
     return $transport;
 }