/**
  * Loads the configuration from the Database
  * @return ConfigurationModel
  */
 public function loadConfiguration()
 {
     $config_model = new ConfigurationModel();
     $config = Configuration::getMultiple(array('PIGMBH_PAYMILL_PUBLICKEY', 'PIGMBH_PAYMILL_PRIVATEKEY', 'PIGMBH_PAYMILL_DEBIT_DAYS', 'PIGMBH_PAYMILL_DEBUG', 'PIGMBH_PAYMILL_LOGGING', 'PIGMBH_PAYMILL_DEBIT', 'PIGMBH_PAYMILL_CREDITCARD', 'PIGMBH_PAYMILL_FASTCHECKOUT', 'PIGMBH_PAYMILL_ACCEPTED_BRANDS', 'PIGMBH_PAYMILL_CAPTURE'));
     $config_model->setPublicKey(isset($config['PIGMBH_PAYMILL_PUBLICKEY']) ? $config['PIGMBH_PAYMILL_PUBLICKEY'] : '');
     $config_model->setPrivateKey(isset($config['PIGMBH_PAYMILL_PRIVATEKEY']) ? $config['PIGMBH_PAYMILL_PRIVATEKEY'] : '');
     $config_model->setDebitDays(isset($config['PIGMBH_PAYMILL_DEBIT_DAYS']) ? $config['PIGMBH_PAYMILL_DEBIT_DAYS'] : '');
     $config_model->setDebug(isset($config['PIGMBH_PAYMILL_DEBUG']) ? $config['PIGMBH_PAYMILL_DEBUG'] : false);
     $config_model->setLogging(isset($config['PIGMBH_PAYMILL_LOGGING']) ? $config['PIGMBH_PAYMILL_LOGGING'] : false);
     $config_model->setDirectdebit(isset($config['PIGMBH_PAYMILL_DEBIT']) ? $config['PIGMBH_PAYMILL_DEBIT'] : false);
     $config_model->setCreditcard(isset($config['PIGMBH_PAYMILL_CREDITCARD']) ? $config['PIGMBH_PAYMILL_CREDITCARD'] : false);
     $config_model->setFastcheckout(isset($config['PIGMBH_PAYMILL_FASTCHECKOUT']) ? $config['PIGMBH_PAYMILL_FASTCHECKOUT'] : false);
     $config_model->setCapture(isset($config['PIGMBH_PAYMILL_CAPTURE']) ? $config['PIGMBH_PAYMILL_CAPTURE'] : false);
     $accepted_brands = false;
     if (isset($config['PIGMBH_PAYMILL_ACCEPTED_BRANDS'])) {
         $accepted_brands = Tools::jsonDecode($config['PIGMBH_PAYMILL_ACCEPTED_BRANDS'], true);
     }
     $config_model->setAccpetedCreditCards($accepted_brands);
     return $config_model;
 }
Exemplo n.º 2
0
 private function onConfigurationSave()
 {
     $old_config = $this->configuration_handler->loadConfiguration();
     $new_config = new ConfigurationModel();
     $accepted_brands = array();
     if (Tools::getValue('accepted_brands')) {
         foreach (Tools::getValue('accepted_brands') as $accepted_brand) {
             $accepted_brands[$accepted_brand] = true;
         }
     }
     $accepted_brands_result = array();
     foreach (array_keys($old_config->getAccpetedCreditCards()) as $key) {
         if (array_key_exists($key, $accepted_brands)) {
             $accepted_brands_result[$key] = true;
         } else {
             $accepted_brands_result[$key] = false;
         }
     }
     $new_config->setCreditcard(Tools::getValue('creditcard', 'OFF'));
     $new_config->setDirectdebit(Tools::getValue('debit', 'OFF'));
     $new_config->setDebug(Tools::getValue('debug', 'OFF'));
     $new_config->setFastcheckout(Tools::getValue('fastcheckout', 'OFF'));
     $new_config->setLogging(Tools::getValue('logging', 'OFF'));
     $new_config->setPrivateKey(trim(Tools::getValue('privatekey', $old_config->getPrivateKey())));
     $new_config->setPublicKey(trim(Tools::getValue('publickey', $old_config->getPublicKey())));
     $new_config->setAccpetedCreditCards($accepted_brands_result);
     $new_config->setDebitDays(Tools::getValue('debit_days', '7'));
     $new_config->setCapture(Tools::getValue('capture_option', 'OFF'));
     $this->configuration_handler->updateConfiguration($new_config);
     $this->registerPaymillWebhook($new_config->getPrivateKey());
 }