Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit 2ebea76

Browse files
committed
Release 1.0.2
1 parent 27f515f commit 2ebea76

File tree

2 files changed

+116
-58
lines changed

2 files changed

+116
-58
lines changed

upload/admin/controller/payment/wallee.php

Lines changed: 106 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function install(){
2727
* @param bool $purge Set to false to skip purgin database.
2828
* @return void
2929
*/
30-
public function uninstall(){
30+
public function uninstall($purge = true){
3131
$this->load->model("extension/wallee/setup");
32-
$this->model_extension_wallee_setup->uninstall(true);
32+
$this->model_extension_wallee_setup->uninstall($purge);
3333
}
3434

3535
/**
@@ -41,6 +41,7 @@ public function index(){
4141
$this->load->model("setting/setting");
4242
$this->load->model("setting/store");
4343
$this->load->model("localisation/order_status");
44+
$this->load->model("extension/wallee/setup");
4445

4546
\WalleeHelper::instance($this->registry);
4647

@@ -71,66 +72,113 @@ private function synchronize($space_id){
7172
}
7273
}
7374

75+
private function validateGlobalSettings(array $global){
76+
if (!isset($global['wallee_application_key']) || empty($global['wallee_application_key'])) {
77+
throw new Exception($this->language->get('error_application_key_unset'));
78+
}
79+
if (isset($global['wallee_user_id']) && !empty($global['wallee_user_id'])) {
80+
if (!ctype_digit($global['wallee_user_id'])) {
81+
throw new Exception($this->language->get('error_user_id_numeric'));
82+
}
83+
}
84+
else {
85+
throw new Exception($this->language->get('error_user_id_unset'));
86+
}
87+
}
88+
89+
private function validateStoreSettings(array $store){
90+
if (isset($store['wallee_space_id']) && !empty($store['wallee_space_id'])) {
91+
if (!ctype_digit($store['wallee_space_id'])) {
92+
throw new Exception($this->language->get('error_space_id_numeric'));
93+
}
94+
}
95+
else {
96+
throw new Exception($this->language->get('error_space_id_unset'));
97+
}
98+
if (isset($store['wallee_space_view_id']) && !empty($store['wallee_space_view_id'])) {
99+
if (!ctype_digit($store['wallee_space_view_id'])) {
100+
throw new Exception($this->language->get('error_space_view_id_numeric'));
101+
}
102+
}
103+
}
104+
105+
private function persistStoreSettings(array $global, array $store){
106+
$newSettings = array_merge($global, $store);
107+
108+
// preserve migration state
109+
$newSettings['wallee_migration_version'] = $this->config->get('wallee_migration_version');
110+
$newSettings['wallee_migration_name'] = $this->config->get('wallee_migration_name');
111+
// preserve manual tasks
112+
$newSettings[\Wallee\Service\ManualTask::CONFIG_KEY] = WalleeVersionHelper::getPersistableSetting(
113+
$this->model_setting_setting->getSetting(\Wallee\Service\ManualTask::CONFIG_KEY, $store['id']), 0);
114+
// preserve notification url
115+
$newSettings['wallee_notification_url'] = WalleeVersionHelper::getPersistableSetting(
116+
$this->model_setting_setting->getSetting('wallee_notification_url', $store['id']), null);
117+
118+
// set directly accessible settings required for synchronization, reload according to new settings
119+
if ($store['wallee_status']) {
120+
$this->config->set('wallee_application_key', $global['wallee_application_key']);
121+
$this->config->set('wallee_user_id', $global['wallee_user_id']);
122+
$this->synchronize($store['wallee_space_id']);
123+
}
124+
125+
$newSettings['wallee_download_invoice'] = isset($store['wallee_download_invoice']);
126+
$newSettings['wallee_download_packaging'] = isset($store['wallee_download_packaging']);
127+
128+
WalleeVersionHelper::persistPluginStatus($this->registry, $newSettings);
129+
130+
$this->model_setting_setting->editSetting('wallee', $newSettings, $store['id']);
131+
132+
return true;
133+
}
134+
74135
/**
75136
* Processes post data to settings.
76137
*
77138
* @param array $shops
78139
*/
79140
private function processPostData($shops){
80-
$changed = false;
81-
$reinstall = false;
82-
$this->load->model('setting/setting');
83-
$this->load->model("extension/wallee/setup");
141+
if ($this->request->server['REQUEST_METHOD'] !== "POST") {
142+
return;
143+
}
144+
145+
try {
146+
$this->validateGlobalSettings($this->request->post);
147+
}
148+
catch (Exception $e) {
149+
$this->error['warning'] = $e->getMessage();
150+
return;
151+
}
152+
153+
$this->model_extension_wallee_setup->uninstall(false);
154+
84155
foreach ($shops as $store) {
85-
// Call validate method on POST
86-
if (($this->request->server['REQUEST_METHOD'] == "POST") && ($this->validateStore($store['id']))) {
87-
if (!$changed) {
88-
$this->model_extension_wallee_setup->uninstall(false);
89-
}
90-
$post = $this->request->post['stores'][$store['id']];
91-
92-
// global settings
93-
$post['wallee_migration_version'] = $this->config->get('wallee_migration_version');
94-
$post['wallee_migration_name'] = $this->config->get('wallee_migration_name');
95-
$post['wallee_application_key'] = $this->request->post['wallee_application_key'];
96-
$post['wallee_user_id'] = $this->request->post['wallee_user_id'];
97-
98-
// preserve manual tasks
99-
$post[\Wallee\Service\ManualTask::CONFIG_KEY] = WalleeVersionHelper::getPersistableSetting($this->model_setting_setting->getSetting(\Wallee\Service\ManualTask::CONFIG_KEY, $store['id']), 0);
100-
101-
// preserve notification url
102-
$post['wallee_notification_url'] = WalleeVersionHelper::getPersistableSetting($this->model_setting_setting->getSetting('wallee_notification_url', $store['id']), null);
103-
104-
// reload according to new settings
105-
if (isset($post['wallee_space_id']) && isset($post['wallee_status']) && $post['wallee_status']) {
106-
$this->config->set('wallee_application_key', $this->request->post['wallee_application_key']);
107-
$this->config->set('wallee_user_id', $this->request->post['wallee_user_id']);
108-
$this->synchronize($post['wallee_space_id']);
109-
$reinstall = true;
156+
$storeSettings = $this->request->post['stores'][$store['id']];
157+
$storeSettings['id'] = $store['id'];
158+
if ($this->validateStore($store['id'])) {
159+
if (isset($storeSettings['wallee_status']) && $storeSettings['wallee_status']) {
160+
try {
161+
$this->validateStoreSettings($storeSettings);
162+
}
163+
catch (Exception $e) {
164+
$this->error['warning'] = $e->getMessage();
165+
continue;
166+
}
110167
}
111-
112-
$post['wallee_download_invoice'] = isset($post['wallee_download_invoice']);
113-
$post['wallee_download_packaging'] = isset($post['wallee_download_packaging']);
114-
115-
WalleeVersionHelper::persistPluginStatus($this->registry, $post);
116-
117-
$this->model_setting_setting->editSetting('wallee', $post, $store['id']);
118-
$changed = true;
168+
$this->persistStoreSettings($this->request->post, $storeSettings);
119169
}
120170
}
121-
if ($changed) {
122-
if($reinstall){
123-
$this->install();
124-
}
171+
172+
$this->install();
173+
174+
if (!isset($this->error['warning'])) {
125175
$this->session->data['success'] = $this->language->get("message_saved_settings");
126176

127-
if (!isset($this->error['warning'])) {
128-
$this->response->redirect(
129-
$this->createUrl("extension/payment",
130-
array(
131-
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
132-
)));
133-
}
177+
$this->response->redirect(
178+
$this->createUrl("extension/payment",
179+
array(
180+
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
181+
)));
134182
}
135183
}
136184

@@ -146,12 +194,14 @@ private function getSettingPageVariables($shops){
146194
$data['shops'] = $shops;
147195

148196
// Form action url
149-
$data['action'] = $this->createUrl("payment/wallee", array(
150-
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
151-
));
152-
$data['cancel'] = $this->createUrl("extension/payment", array(
153-
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
154-
));
197+
$data['action'] = $this->createUrl("payment/wallee",
198+
array(
199+
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
200+
));
201+
$data['cancel'] = $this->createUrl("extension/payment",
202+
array(
203+
\WalleeVersionHelper::TOKEN => $this->session->data[\WalleeVersionHelper::TOKEN]
204+
));
155205

156206
return array_merge($this->getSettingsPageTranslatedVariables(), $data, $this->getAlertTemplateVariables(), $this->getSettingsPageBreadcrumbs(),
157207
$this->getSettingPageStoreVariables($shops), $this->getAdminSurroundingTemplates());

upload/admin/language/english/payment/wallee.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77
// @formatter:off
88
$_['heading_title'] = 'wallee';
9-
$_['heading_wallee'] = 'wallee';
9+
$_['heading_wallee'] = 'wallee';
1010
$_['text_wallee'] = '<a target="_BLANK" href="https://www.wallee.com"><img src="view/image/payment/wallee.png" alt="wallee Website" title="wallee Website" style="border: 1px solid #EEEEEE;" /></a>';
11-
// Walle Configurations (user id, application key, spaces)
11+
// Wallee Configurations (user id, application key, spaces)
1212
$_['title_global_settings'] = "Global credentials";
1313
$_['title_store_settings'] = "Store settings";
1414
$_['entry_user_id'] = "User Id";
@@ -86,6 +86,14 @@
8686

8787
$_['message_saved_settings'] = "The settings have been saved successfully. Don't forget to refresh the modifications!";
8888

89+
// errors
90+
$_['error_application_key_unset'] = "Application key must not be empty.";
91+
$_['error_space_id_unset'] = "Space ID must not be empty.";
92+
$_['error_space_id_numeric'] = "Space ID must be numeric.";
93+
$_['error_space_view_id_numeric'] = "Space view ID must be numeric.";
94+
$_['error_user_id_unset'] = "User ID must not be empty.";
95+
$_['error_user_id_numeric'] = "User ID must be numeric.";
96+
8997
/**
9098
* ===========================================================================================
9199
* Alerts

0 commit comments

Comments
 (0)