Exemple #1
0
 public static function refresh($force = false)
 {
     $settings = \Shop\Models\Settings::fetch();
     if (empty($settings->{'currency.openexchangerates_api_id'})) {
         static::log('Could not refresh list of valid currencies.  Please provide an open exchange rates API ID in the Shop Configuration page', 'ERROR');
         return false;
     }
     // once a day is enough
     if (!empty($settings->currencies_last_refreshed) && $settings->currencies_last_refreshed > time() - 24 * 60 && empty($force)) {
         return false;
     }
     $oer = new \Shop\Lib\OpenExchangeRates($settings->{'currency.openexchangerates_api_id'});
     if ($response = $oer->currencies()) {
         if ($currencies = \Dsc\ArrayHelper::fromObject($response)) {
             foreach ($currencies as $code => $title) {
                 $currency = (new static())->setParam('conditions', array('code' => $code))->getItem();
                 if (empty($currency->id)) {
                     $currency = new static();
                 }
                 $currency->code = $code;
                 $currency->title = $title;
                 $currency->store();
             }
             $settings->currencies_last_refreshed = time();
             $settings->save();
         }
     }
     return true;
 }
Exemple #2
0
 /**
  * Get an item from an object using dot notation
  *
  * @param  array   $array
  * @param  string  $key
  * @param  mixed   $default
  * @return mixed
  */
 public static function get($object, $key, $default = null)
 {
     $array = \Dsc\ArrayHelper::fromObject($object);
     return \Dsc\ArrayHelper::get($array, $key, $default);
 }
Exemple #3
0
 public function cvnMatch($data = array())
 {
     if (is_object($data)) {
         $data = \Dsc\ArrayHelper::fromObject($data);
     }
     if (!is_array($data)) {
         return null;
     }
     // check CVN response
     /*
     D The transaction was considered to be suspicious by the issuing bank.
     I The CVN failed the processor's data validation.
     M The CVN matched.
     N The CVN did not match.
     P The CVN was not processed by the processor for an unspecified reason.
     S The CVN is on the card but was not included in the request.
     U Card verification is not supported by the issuing bank.
     X Card verification is not supported by the card association.
     1 Card verification is not supported for this processor or card type.
     2 An unrecognized result code was returned by the processor for the card
     verification response.
     3 No result code was returned by the processor.
     */
     $cv_result = isset($data['auth_cv_result']) ? $data['auth_cv_result'] : null;
     switch ($cv_result) {
         // No Match
         case "D":
         case "I":
         case "N":
         case "S":
             return false;
             break;
             // Match
         // Match
         case "M":
             return true;
             break;
             // Unavailable
         // Unavailable
         case "P":
         case "U":
         case "X":
         case "1":
         case "2":
         case "3":
         default:
             return null;
             break;
     }
 }
Exemple #4
0
 protected function doUpdate(array $data, $key = null)
 {
     if (empty($this->list_route)) {
         throw new \Exception('Must define a route for listing the items');
     }
     if (empty($this->create_item_route)) {
         throw new \Exception('Must define a route for creating the item');
     }
     if (empty($this->edit_item_route)) {
         throw new \Exception('Must define a route for editing the item');
     }
     if (!isset($data['submitType'])) {
         $data['submitType'] = "save_edit";
     }
     $f3 = \Base::instance();
     $flash = \Dsc\Flash::instance();
     $model = $this->getModel();
     $this->item = $this->getItem();
     // save
     $save_as = false;
     try {
         $values = $data;
         unset($values['submitType']);
         //\Dsc\System::instance()->addMessage(\Dsc\Debug::dump($values), 'warning');
         if ($data['submitType'] == 'save_as') {
             $this->item = $model->saveAs($this->item, $values);
             \Dsc\System::instance()->addMessage('Item cloned. You are now editing the new item.', 'success');
         } else {
             $this->item = $model->update($this->item, $values);
             \Dsc\System::instance()->addMessage('Item updated', 'success');
         }
     } catch (\Exception $e) {
         \Dsc\System::instance()->addMessage('Save failed with the following errors:', 'error');
         \Dsc\System::instance()->addMessage($e->getMessage(), 'error');
         foreach ($model->getErrors() as $error) {
             \Dsc\System::instance()->addMessage($error, 'error');
         }
         if ($f3->get('AJAX')) {
             // output system messages in response object
             return $this->outputJson($this->getJsonResponse(array('error' => true, 'message' => \Dsc\System::instance()->renderMessages())));
         }
         // redirect back to the edit form with the fields pre-populated
         \Dsc\System::instance()->setUserState('use_flash.' . $this->edit_item_route, true);
         $flash->store($data);
         $id = $this->item->get($this->getItemKey());
         $route = str_replace('{id}', $id, $this->edit_item_route);
         $this->setRedirect($route);
         return false;
     }
     // redirect to the editing form for the new item
     if (method_exists($this->item, 'cast')) {
         $this->item_data = $this->item->cast();
     } else {
         $this->item_data = \Dsc\ArrayHelper::fromObject($this->item);
     }
     if ($f3->get('AJAX')) {
         return $this->outputJson($this->getJsonResponse(array('message' => \Dsc\System::instance()->renderMessages(), 'result' => $this->item_data)));
     }
     switch ($data['submitType']) {
         case "save_new":
             $route = $this->create_item_route;
             break;
         case "save_close":
             $route = $this->list_route;
             break;
         case "save_as":
         default:
             $flash->store($this->item_data);
             $id = $this->item->get($this->getItemKey());
             $route = str_replace('{id}', $id, $this->edit_item_route);
             break;
     }
     $this->setRedirect($route);
     return $this;
 }