/**
  * Update Transaction Statuses
  * 
  * Loops through all locally stored transactions with the 'authorized' or 'submittd_for_settlement' status, 
  * checks to see if the status in the API has changed, and updates the local status accordingly.
  *
  * @access public
  * @return void
  */
 public function update_transaction_statuses()
 {
     $this->info('BEGIN: Update Transaction Statuses');
     if (!empty($this->args[0])) {
         $this->environment = $this->args[0];
     }
     foreach (array('BraintreeTransaction', 'BraintreeRemoteTransaction') as $model_name) {
         if (!isset($this->{$model_name})) {
             $this->{$model_name} = ClassRegistry::init('Braintree.' . $model_name);
         }
     }
     $this->BraintreeTransaction->remote_sync = false;
     $transactions = $this->BraintreeTransaction->find('all', array('conditions' => array('BraintreeTransaction.status' => array('authorized', 'submitted_for_settlement')), 'order' => array('BraintreeTransaction.created' => 'asc'), 'contain' => array('BraintreeMerchant')));
     foreach ($transactions as $transaction) {
         if (empty($transaction['BraintreeMerchant']['id'])) {
             continue;
         }
         BraintreeConfig::set(array('environment' => $this->environment, 'merchantId' => $transaction['BraintreeMerchant']['id'], 'publicKey' => $transaction['BraintreeMerchant']['braintree_public_key'], 'privateKey' => $transaction['BraintreeMerchant']['braintree_private_key']));
         $remote_transaction = $this->BraintreeRemoteTransaction->find('first', array('conditions' => array('BraintreeRemoteTransaction.id' => $transaction['BraintreeTransaction']['id']), 'contain' => false));
         if (!empty($remote_transaction['BraintreeRemoteTransaction']['status']) && $transaction['BraintreeTransaction']['status'] != $remote_transaction['BraintreeRemoteTransaction']['status'] && $remote_transaction['BraintreeRemoteTransaction']['status'] != 'settling') {
             $this->BraintreeTransaction->id = $transaction['BraintreeTransaction']['id'];
             if ($this->BraintreeTransaction->saveField('status', $remote_transaction['BraintreeRemoteTransaction']['status'])) {
                 $this->success('Successfully updated status for BraintreeTransaction.id ' . $transaction['BraintreeTransaction']['id'] . ' to ' . $remote_transaction['BraintreeRemoteTransaction']['status']);
             } else {
                 $this->error('Could not save status for BraintreeTransaction.id ' . $transaction['BraintreeTransaction']['id'] . ' to ' . $remote_transaction['BraintreeRemoteTransaction']['status'], false);
             }
         }
     }
     $this->info('END: Update Transaction Statuses');
 }
        if (!empty($publicKey)) {
            Braintree_Configuration::publicKey($publicKey);
        }
        if (!empty($privateKey)) {
            Braintree_Configuration::privateKey($privateKey);
        }
        return true;
    }
    public function get($config)
    {
        switch ($config) {
            case 'environment':
                return Braintree_Configuration::environment();
                break;
            case 'merchantId':
                return Braintree_Configuration::merchantId();
                break;
            case 'publicKey':
                return Braintree_Configuration::publicKey();
                break;
            case 'privateKey':
                return Braintree_Configuration::privateKey();
                break;
            default:
                return false;
                break;
        }
    }
}
BraintreeConfig::set(array('environment' => Configure::read('Braintree.environment'), 'merchantId' => Configure::read('Braintree.merchantId'), 'publicKey' => Configure::read('Braintree.publicKey'), 'privateKey' => Configure::read('Braintree.privateKey')));
 /**
  * beforeSave
  * Accomplishes the following if remote sync is enabled:
  * - Sets the primary key to be saved + any fields passed that are in the actual API schema
  * - Saves the information to the API
  * - Sets the remote ID to the ID for this local model
  * - Sets the braintree_merchant_id key for this model to the current merchantId being used
  *
  * @return	bool
  */
 public function beforeSave()
 {
     if (empty($this->id) && $this->autoPK) {
         $uuid = String::uuid();
         $this->id = $this->data[$this->alias][$this->primaryKey] = $uuid;
     }
     if ($this->remote_sync) {
         $remote_model_name = $this->_getRemoteModelName();
         if (!isset($this->{$remote_model_name})) {
             $this->{$remote_model_name} = ClassRegistry::init('Braintree.' . $remote_model_name);
         }
         if (!empty($this->id)) {
             $this->{$remote_model_name}->id = $this->id;
         }
         $whitelisted_fields = $this->{$remote_model_name}->_schema;
         if ($this->primaryKey != 'id') {
             $whitelisted_fields = array_merge(array($this->primaryKey => array()), $whitelisted_fields);
         }
         foreach ($whitelisted_fields as $field => $schema) {
             if (!empty($this->data[$this->alias][$field])) {
                 $remote_data[$remote_model_name][$field] = $this->data[$this->alias][$field];
             }
         }
         $success = $this->{$remote_model_name}->save($remote_data);
         if (!empty($this->{$remote_model_name}->id)) {
             $this->id = $this->{$remote_model_name}->id;
             $this->data[$this->alias][$this->primaryKey] = $this->id;
             $this->{$remote_model_name}->create(false);
             $this->{$remote_model_name}->id = null;
         }
         if (!$success) {
             return false;
         }
     }
     if (!empty($this->_schema['braintree_merchant_id'])) {
         $merchantId = BraintreeConfig::get('merchantId');
         if (empty($merchantId)) {
             return false;
         }
         $this->data[$this->alias]['braintree_merchant_id'] = $merchantId;
     }
     return true;
 }