public function getAllPlans()
 {
     $apiKey = $this->getApiKey();
     $cache = Mage::app()->getCache();
     if ($plans = $cache->load(self::CACHE_KEY_PLANS)) {
         $plans = unserialize($plans);
         return $plans;
     }
     Divido::setMerchant($apiKey);
     $parameters = array('merchant' => $apiKey);
     $response = Divido_Finances::all($parameters);
     if ($response->status !== 'ok') {
         Mage::log('Could not get financing plans.', null, 'divido.log');
         return array();
     }
     $plans = $response->finances;
     $cache->save(serialize($plans), self::CACHE_KEY_PLANS, array('divido_cache'), self::CACHE_LIFETIME_PLANS);
     return $plans;
 }
Example #2
0
 public function getAllPlans()
 {
     if ($plans = $this->cache->get(self::CACHE_KEY_PLANS)) {
         // OpenCart 2.1 decodes json objects to associative arrays so we
         // need to make sure we're getting a list of simple objects back.
         $plans = array_map(function ($plan) {
             return (object) $plan;
         }, $plans);
         return $plans;
     }
     $api_key = $this->config->get('divido_api_key');
     if (!$api_key) {
         throw new Exception("No Divido api-key defined");
     }
     Divido::setMerchant($api_key);
     $response = Divido_Finances::all();
     if ($response->status != 'ok') {
         throw new Exception("Can't get list of finance plans from Divido!");
     }
     $plans = $response->finances;
     // OpenCart 2.1 switched to json for their file storage cache, so
     // we need to convert to a simple object.
     $plans_plain = array();
     foreach ($plans as $plan) {
         $plan_copy = new stdClass();
         $plan_copy->id = $plan->id;
         $plan_copy->text = $plan->text;
         $plan_copy->country = $plan->country;
         $plan_copy->min_amount = $plan->min_amount;
         $plan_copy->min_deposit = $plan->min_deposit;
         $plan_copy->max_deposit = $plan->max_deposit;
         $plan_copy->interest_rate = $plan->interest_rate;
         $plan_copy->deferral_period = $plan->deferral_period;
         $plan_copy->agreement_duration = $plan->agreement_duration;
         $plans_plain[] = $plan_copy;
     }
     $this->cache->set(self::CACHE_KEY_PLANS, $plans_plain);
     return $plans_plain;
 }
 protected function getCampaign()
 {
     $this->_setMerchant();
     $response = Divido_Finances::all(array('merchant' => $this->getApiKey()));
     return $response;
 }