diff --git a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php index b871044..50acb8a 100644 --- a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php @@ -26,30 +26,26 @@ public function index() // If POST request => validate the data before saving if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { // Edit settings - $this->model_setting_setting->editSetting('lemonway', $this->request->post); + $this->model_setting_setting->editSetting($this->prefix() . 'lemonway', $this->request->post); } // Load default layout $this->variables['header'] = $this->load->controller('common/header'); $this->variables['column_left'] = $this->load->controller('common/column_left'); $this->variables['footer'] = $this->load->controller('common/footer'); - - if (isset($this->session->data['user_token'])) { // OpenCart 3 - $this->variables['cancel_link'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); - } else { // OpenCart 2 - $this->variables['cancel_link'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=payment', true); - } + + $this->variables['cancel_link'] = (version_compare(VERSION, '3.0', '>=')) ? $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) : $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=payment', true); // Load setting values - $this->variables['lemonway_api_login'] = $this->model_setting_setting->getSettingValue('lemonway_api_login'); - $this->variables['lemonway_api_password'] = $this->model_setting_setting->getSettingValue('lemonway_api_password'); - $this->variables['lemonway_is_test_mode'] = $this->model_setting_setting->getSettingValue('lemonway_is_test_mode'); - $this->variables['lemonway_css_url'] = $this->model_setting_setting->getSettingValue('lemonway_css_url'); - $this->variables['lemonway_debug'] = $this->model_setting_setting->getSettingValue('lemonway_debug'); - $this->variables['lemonway_environment_name'] = $this->model_setting_setting->getSettingValue('lemonway_environment_name'); - $this->variables['lemonway_custom_wallet'] = $this->model_setting_setting->getSettingValue('lemonway_custom_wallet'); - $this->variables['lemonway_status'] = $this->model_setting_setting->getSettingValue('lemonway_status'); - $this->variables['lemonway_oneclick_enabled'] = $this->model_setting_setting->getSettingValue('lemonway_oneclick_enabled'); + $this->variables['lemonway_api_login'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_api_login'); + $this->variables['lemonway_api_password'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_api_password'); + $this->variables['lemonway_is_test_mode'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_is_test_mode'); + $this->variables['lemonway_css_url'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_css_url'); + $this->variables['lemonway_debug'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_debug'); + $this->variables['lemonway_environment_name'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_environment_name'); + $this->variables['lemonway_custom_wallet'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_custom_wallet'); + $this->variables['lemonway_status'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_status'); + $this->variables['lemonway_oneclick_enabled'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_oneclick_enabled'); // Alerts $this->variables['no_permission'] = false; @@ -81,6 +77,10 @@ public function index() $this->response->setOutput($this->load->view('extension/payment/lemonway', $this->variables)); } + private function prefix() { + return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; + } + private function validate() { $error = false; @@ -130,6 +130,11 @@ private function validate() $this->request->post['lemonway_oneclick_enabled'] = 0; } + foreach ($this->request->post as $key => $value) { + unset($this->request->post[$key]); + $this->request->post[$this->prefix() . $key] = $value; //concatinate your existing array with new one + } + return !$error; // If no error => validated } @@ -142,11 +147,11 @@ private function testConfig() // TEST if ($this->variables['lemonway_is_test_mode']) { // DIRECTKIT TEST URL - $dkUrl = $this->model_setting_setting->getSettingValue('lemonway_directkit_url_test'); + $dkUrl = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_directkit_url_test'); } //PROD else { // DIRECTKIT URL - $dkUrl = $this->model_setting_setting->getSettingValue('lemonway_directkit_url'); + $dkUrl = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_directkit_url'); } require_once DIR_SYSTEM . '/library/lemonway/LemonWayService.php'; @@ -172,7 +177,7 @@ private function testConfig() if (empty($this->variables['lemonway_environment_name'])) { // If lwecommerce, get wallet if (isset($res->WALLET->ID)) { - $this->model_setting_setting->editSettingValue('lemonway', 'lemonway_wallet', $res->WALLET->ID); + $this->model_setting_setting->editSettingValue($this->prefix() . 'lemonway', $this->prefix() . 'lemonway_wallet', $res->WALLET->ID); } } @@ -192,13 +197,13 @@ public function install() // Default settings $this->load->model('setting/setting'); - $this->model_setting_setting->editSetting('lemonway', [ - 'lemonway_status' => 1, - 'lemonway_css_url' => self::CSS_URL_DEFAULT, - 'lemonway_directkit_url' => sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), - 'lemonway_webkit_url' => sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), - 'lemonway_directkit_url_test' => sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_TEST, self::LEMONWAY_ENVIRONMENT_DEFAULT), - 'lemonway_webkit_url_test' => sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_TEST, self::LEMONWAY_ENVIRONMENT_DEFAULT) + $this->model_setting_setting->editSetting($this->prefix() . 'lemonway', [ + $this->prefix() . 'lemonway_status' => 1, + $this->prefix() . 'lemonway_css_url' => self::CSS_URL_DEFAULT, + $this->prefix() . 'lemonway_directkit_url' => sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), + $this->prefix() . 'lemonway_webkit_url' => sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), + $this->prefix() . 'lemonway_directkit_url_test' => sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_TEST, self::LEMONWAY_ENVIRONMENT_DEFAULT), + $this->prefix() . 'lemonway_webkit_url_test' => sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_TEST, self::LEMONWAY_ENVIRONMENT_DEFAULT) ]); } diff --git a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php index 676573d..a54add1 100644 --- a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php @@ -21,6 +21,10 @@ class ControllerExtensionPaymentLemonWay extends Controller private $money_in_trans_details; + private function prefix() { + return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; + } + /* Check if there are GET params */ @@ -60,22 +64,22 @@ private function getLemonWayConfig() { $config = array(); - if ($this->config->get('lemonway_is_test_mode')) { + if ($this->config->get($this->prefix() . 'lemonway_is_test_mode')) { // TEST - $config['dkURL'] = $this->config->get('lemonway_directkit_url_test'); //DIRECT KIT URL TEST - $config['wkURL'] = $this->config->get('lemonway_webkit_url_test'); //WEB KIT URL TEST + $config['dkURL'] = $this->config->get($this->prefix() . 'lemonway_directkit_url_test'); //DIRECT KIT URL TEST + $config['wkURL'] = $this->config->get($this->prefix() . 'lemonway_webkit_url_test'); //WEB KIT URL TEST } else { // PROD - $config['dkURL'] = $this->config->get('lemonway_directkit_url'); // DIRECT KIT URL PROD - $config['wkURL'] = $this->config->get('lemonway_webkit_url'); // WEBKIT URL PROD + $config['dkURL'] = $this->config->get($this->prefix() . 'lemonway_directkit_url'); // DIRECT KIT URL PROD + $config['wkURL'] = $this->config->get($this->prefix() . 'lemonway_webkit_url'); // WEBKIT URL PROD } - $config['login'] = $this->config->get('lemonway_api_login'); - $config['pass'] = $this->config->get('lemonway_api_password'); - $config['wallet'] = empty($this->config->get('lemonway_environment_name')) ? - $this->config->get('lemonway_wallet') : $this->config->get('lemonway_custom_wallet'); - $config['cssURL'] = $this->config->get('lemonway_css_url'); - $config['autoCommission'] = (int)!empty($this->config->get('lemonway_environment_name')); + $config['login'] = $this->config->get($this->prefix() . 'lemonway_api_login'); + $config['pass'] = $this->config->get($this->prefix() . 'lemonway_api_password'); + $config['wallet'] = empty($this->config->get($this->prefix() . 'lemonway_environment_name')) ? + $this->config->get($this->prefix() . 'lemonway_wallet') : $this->config->get($this->prefix() . 'lemonway_custom_wallet'); + $config['cssURL'] = $this->config->get($this->prefix() . 'lemonway_css_url'); + $config['autoCommission'] = (int)!empty($this->config->get($this->prefix() . 'lemonway_environment_name')); // Autocom = 0 if lwecommerce, 1 if custom environment return $config; @@ -95,7 +99,7 @@ private function getMoneyInTransDetails($wkToken) $config['login'], $config['pass'], substr($this->language->get('code'), 0, 2), - $this->config->get('lemonway_debug') + $this->config->get($this->prefix() . 'lemonway_debug') ); $params = array( @@ -163,7 +167,7 @@ public function index() $data['text_card'] = $this->language->get('text_card'); $data['link_checkout'] = $this->url->link('extension/payment/lemonway/checkout', '', true); - $data['lemonway_oneclick_enabled'] = $this->config->get('lemonway_oneclick_enabled'); + $data['lemonway_oneclick_enabled'] = $this->config->get($this->prefix() . 'lemonway_oneclick_enabled'); $data['customerId'] = empty($this->customer->getId()) ? 0 : $this->customer->getId(); // A guest customer has no Id, we consider it 0 @@ -225,7 +229,7 @@ public function checkout() $config['login'], $config['pass'], substr($this->language->get('code'), 0, 2), - $this->config->get('lemonway_debug') + $this->config->get($this->prefix() . 'lemonway_debug') ); $params = array(); @@ -241,7 +245,7 @@ public function checkout() $customerId = empty($this->customer->getId()) ? 0 : $this->customer->getId(); // A guest customer has no Id, we consider it 0 $useCard = ( - $this->config->get('lemonway_oneclick_enabled') && + $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && $customerId && $this->postValue('lemonway_oneclick') === 'use_card' ); @@ -249,7 +253,7 @@ public function checkout() if (!$useCard) { // If the client use a new card => MoneyInWebInit // Whether the client save a card $registerCard = (int)( - $this->config->get('lemonway_oneclick_enabled') && + $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && $customerId && $this->postValue('lemonway_oneclick') === 'register_card' ); @@ -406,7 +410,7 @@ public function checkoutReturn() if ($this->isGet()) { // If redirection // GET params - if ($this->config->get('lemonway_debug')) { + if ($this->config->get($this->prefix() . 'lemonway_debug')) { $debug_log = new Log('lemonway_debug.log'); $debug_log->write('GET params: ' . print_r($this->request->get, true)); } @@ -461,7 +465,7 @@ public function checkoutReturn() } } elseif ($this->isPost()) { // If IPN // Get response by IPN - if ($this->config->get('lemonway_debug')) { + if ($this->config->get($this->prefix() . 'lemonway_debug')) { $debug_log = new Log('lemonway_debug.log'); $debug_log->write('IPN: ' . print_r($this->request->post, true)); } diff --git a/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php index 3611167..9545ede 100644 --- a/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php @@ -1,6 +1,10 @@ =')) ? 'payment_' : ''; + } + /* This function is required for OpenCart to show the method in the checkout page */ @@ -8,13 +12,13 @@ public function getMethod($address, $total) { $this->load->language('extension/payment/lemonway'); - $mode = $this->config->get('lemonway_is_test_mode') ? " (Test)" : ""; + $mode = $this->config->get($this->prefix() . 'lemonway_is_test_mode') ? " (Test)" : ""; $method_data = array( 'code' => 'lemonway', 'title' => $this->language->get('text_card') . $mode, 'terms' => '', - 'sort_order' => '' /*TODO: $this->config->get('lemonway_cc_sort_order')*/ + 'sort_order' => '' /*TODO: $this->config->get($this->prefix() . 'lemonway_cc_sort_order')*/ ); return $method_data; diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig new file mode 100644 index 0000000..826fec1 --- /dev/null +++ b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig @@ -0,0 +1,92 @@ +