This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * 2007-2017 PrestaShop |
||
4 | * |
||
5 | * NOTICE OF LICENSE |
||
6 | * |
||
7 | * This source file is subject to the Academic Free License (AFL 3.0) |
||
8 | * that is bundled with this package in the file LICENSE.txt. |
||
9 | * It is also available through the world-wide-web at this URL: |
||
10 | * http://opensource.org/licenses/afl-3.0.php |
||
11 | * If you did not receive a copy of the license and are unable to |
||
12 | * obtain it through the world-wide-web, please send an email |
||
13 | * to [email protected] so we can send you a copy immediately. |
||
14 | * |
||
15 | * DISCLAIMER |
||
16 | * |
||
17 | * Do not edit or add to this file if you wish to upgrade PrestaShop to newer |
||
18 | * versions in the future. If you wish to customize PrestaShop for your |
||
19 | * needs please refer to http://www.prestashop.com for more information. |
||
20 | * |
||
21 | * @author PrestaShop SA <[email protected]> |
||
22 | * @copyright 2007-2017 PrestaShop SA |
||
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) |
||
24 | * International Registered Trademark & Property of PrestaShop SA |
||
25 | */ |
||
26 | |||
27 | if (!defined('_PS_VERSION_')) { |
||
28 | exit; |
||
29 | } |
||
30 | |||
31 | class Paylater extends PaymentModule |
||
32 | { |
||
33 | protected $output = ''; |
||
34 | public static $modulePath; |
||
35 | |||
36 | public function __construct() |
||
37 | { |
||
38 | $this->name = 'paylater'; |
||
39 | $this->tab = 'payments_gateways'; |
||
40 | $this->version = '5.2.8'; |
||
41 | $this->author = 'pagamastarde'; |
||
42 | $this->need_instance = 0; |
||
43 | $this->bootstrap = true; |
||
44 | $this->currencies = true; |
||
45 | $this->currencies_mode = 'checkbox'; |
||
46 | $this->module_key = '2b9bc901b4d834bb7069e7ea6510438f'; |
||
47 | $this->ps_versions_compliancy['min'] = '1.5.0'; |
||
48 | $this->ps_versions_compliancy['max'] = '1.6.9'; |
||
49 | $this->url='https://pmt.pagantis.com/v1/installments'; |
||
50 | $this->product_tab = 0; |
||
51 | $this->limited_currencies = array('EUR'); |
||
52 | self::initModuleAccess(); |
||
53 | |||
54 | parent::__construct(); |
||
55 | |||
56 | $this->displayName = $this->l('Paga+Tarde'); |
||
57 | $this->description = $this->l('Customers can pay later.'); |
||
58 | |||
59 | /* Backward compatibility */ |
||
60 | if (version_compare(_PS_VERSION_, "1.5", "<")) { |
||
61 | require(_PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php'); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | public function install() |
||
66 | { |
||
67 | Configuration::updateValue('PAYLATER_URL', 'https://pmt.pagantis.com/v1/installments'); |
||
68 | Configuration::updateValue('PAYLATER_ENVIRONMENT', 0); |
||
69 | Configuration::updateValue('PAYLATER_ACCOUNT_ID_TEST', ''); |
||
70 | Configuration::updateValue('PAYLATER_ACCOUNT_KEY_TEST', ''); |
||
71 | Configuration::updateValue('PAYLATER_ACCOUNT_ID_LIVE', ''); |
||
72 | Configuration::updateValue('PAYLATER_ACCOUNT_KEY_LIVE', ''); |
||
73 | Configuration::updateValue('PAYLATER_DISCOUNT', 'false'); |
||
74 | Configuration::updateValue('PAYLATER_WIDGET', 'true'); |
||
75 | Configuration::updateValue('PAYLATER_IFRAME', 'false'); |
||
76 | Configuration::updateValue('PAYLATER_MIN_AMOUNT', 10); |
||
77 | Configuration::updateValue('PAYLATER_PRODUCT_WIDGET', null); |
||
78 | Configuration::updateValue('PAYLATER_CART_WIDGET', null); |
||
79 | Configuration::updateValue('PAYLATER_STYLE_WIDGET', null); |
||
80 | Configuration::updateValue('PAYLATER_COLOR_WIDGET', null); |
||
81 | |||
82 | if (version_compare(_PS_VERSION_, "1.5", ">=")) { |
||
83 | $this->registerHook('displayPaymentEU'); |
||
84 | } |
||
85 | |||
86 | return parent::install() && |
||
87 | $this->registerHook('header') && |
||
88 | $this->registerHook('payment') && |
||
89 | $this->registerHook('paymentReturn') && |
||
90 | $this->registerHook('footer') && |
||
91 | $this->registerHook('displayProductButtons') && |
||
92 | $this->registerHook('displayRightColumnProduct') && |
||
93 | $this->registerHook('displayRightColumn') && |
||
94 | $this->registerHook('displayShoppingCart'); |
||
95 | } |
||
96 | |||
97 | public function uninstall() |
||
98 | { |
||
99 | Configuration::deleteByName('PAYLATER_URL'); |
||
100 | Configuration::deleteByName('PAYLATER_ENVIRONMENT'); |
||
101 | Configuration::deleteByName('PAYLATER_ACCOUNT_ID_TEST'); |
||
102 | Configuration::deleteByName('PAYLATER_ACCOUNT_KEY_TEST'); |
||
103 | Configuration::deleteByName('PAYLATER_ACCOUNT_ID_LIVE'); |
||
104 | Configuration::deleteByName('PAYLATER_ACCOUNT_KEY_LIVE'); |
||
105 | Configuration::deleteByName('PAYLATER_DISCOUNT'); |
||
106 | Configuration::deleteByName('PAYLATER_IFRAME'); |
||
107 | Configuration::deleteByName('PAYLATER_WIDGET'); |
||
108 | Configuration::deleteByName('PAYLATER_MIN_AMOUNT'); |
||
109 | Configuration::deleteByName('PAYLATER_PRODUCT_WIDGET'); |
||
110 | Configuration::deleteByName('PAYLATER_CART_WIDGET'); |
||
111 | Configuration::deleteByName('PAYLATER_STYLE_WIDGET'); |
||
112 | Configuration::deleteByName('PAYLATER_COLOR_WIDGET'); |
||
113 | |||
114 | if (!parent::uninstall()) { |
||
115 | return false; |
||
116 | } |
||
117 | |||
118 | return true; |
||
119 | } |
||
120 | |||
121 | public function postProcess() |
||
122 | { |
||
123 | if (Tools::isSubmit('submitPaylaterSettings')) { |
||
124 | $error = ''; |
||
125 | Configuration::updateValue('PAYLATER_ENVIRONMENT', Tools::getValue('PAYLATER_ENVIRONMENT')); |
||
126 | Configuration::updateValue('PAYLATER_ACCOUNT_ID_TEST', Tools::getValue('PAYLATER_ACCOUNT_ID_TEST')); |
||
127 | Configuration::updateValue('PAYLATER_ACCOUNT_KEY_TEST', Tools::getValue('PAYLATER_ACCOUNT_KEY_TEST')); |
||
128 | Configuration::updateValue('PAYLATER_ACCOUNT_ID_LIVE', Tools::getValue('PAYLATER_ACCOUNT_ID_LIVE')); |
||
129 | Configuration::updateValue('PAYLATER_ACCOUNT_KEY_LIVE', Tools::getValue('PAYLATER_ACCOUNT_KEY_LIVE')); |
||
130 | Configuration::updateValue('PAYLATER_DISCOUNT', Tools::getValue('PAYLATER_DISCOUNT')); |
||
131 | Configuration::updateValue('PAYLATER_WIDGET', Tools::getValue('PAYLATER_WIDGET')); |
||
132 | Configuration::updateValue('PAYLATER_PRODUCT_WIDGET', Tools::getValue('PAYLATER_PRODUCT_WIDGET')); |
||
133 | Configuration::updateValue('PAYLATER_CART_WIDGET', Tools::getValue('PAYLATER_CART_WIDGET')); |
||
134 | Configuration::updateValue('PAYLATER_STYLE_WIDGET', Tools::getValue('PAYLATER_STYLE_WIDGET')); |
||
135 | Configuration::updateValue('PAYLATER_COLOR_WIDGET', Tools::getValue('PAYLATER_COLOR_WIDGET')); |
||
136 | Configuration::updateValue('PAYLATER_IFRAME', Tools::getValue('PAYLATER_IFRAME')); |
||
137 | |||
138 | if (!Validate::isInt(Tools::getValue('PAYLATER_MIN_AMOUNT'))) { |
||
139 | $error .= $this->l('The minimun amount must be integer.'); |
||
140 | } else { |
||
141 | Configuration::updateValue('PAYLATER_MIN_AMOUNT', Tools::getValue('PAYLATER_MIN_AMOUNT')); |
||
142 | } |
||
143 | |||
144 | if ($error != '') { |
||
145 | $this->output .= $this->displayError($error); |
||
146 | } else { |
||
147 | $this->output .= $this->displayConfirmation($this->l('The settings updated ok.')); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | public function getContent() |
||
153 | { |
||
154 | $this->postProcess(); |
||
155 | |||
156 | $this->context->smarty->assign('module_dir', $this->_path); |
||
157 | $this->output .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/information.tpl'); |
||
158 | $this->output .= $this->displayFormSettings(); |
||
159 | return $this->output; |
||
160 | } |
||
161 | |||
162 | public function displayFormSettings() |
||
163 | { |
||
164 | |||
165 | $languages = Language::getLanguages(false); |
||
166 | foreach ($languages as $k => $language) { |
||
167 | $languages[$k]['is_default'] = (int)$language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'); |
||
168 | } |
||
169 | |||
170 | $helper = new HelperForm(); |
||
171 | $helper->module = $this; |
||
172 | $helper->name_controller = 'paylater'; |
||
173 | $helper->identifier = $this->identifier; |
||
174 | $helper->token = Tools::getAdminTokenLite('AdminModules'); |
||
175 | $helper->languages = $languages; |
||
176 | $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; |
||
177 | $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); |
||
178 | $helper->allow_employee_form_lang = true; |
||
179 | $helper->toolbar_scroll = true; |
||
180 | $helper->title = $this->displayName; |
||
181 | $helper->submit_action = 'submitPaylaterSettings'; |
||
182 | |||
183 | $this->fields_form[0]['form'] = array( |
||
184 | 'tinymce' => false, |
||
185 | 'legend' => array( |
||
186 | 'title' => $this->l('Pay later settings') |
||
187 | ), |
||
188 | 'input' => array( |
||
189 | array( |
||
190 | 'type' => 'select', |
||
191 | 'name' => 'PAYLATER_ENVIRONMENT', |
||
192 | 'is_bool' => true, |
||
193 | 'label' => $this->l('Choose environment'), |
||
194 | 'options' => array( |
||
195 | 'query' => array( |
||
196 | array( |
||
197 | 'id_env' => 0, |
||
198 | 'name' => $this->l('Test') |
||
199 | ), |
||
200 | array( |
||
201 | 'id_env' => 1, |
||
202 | 'name' => $this->l('Real') |
||
203 | ) |
||
204 | ), |
||
205 | 'id' => 'id_env', |
||
206 | 'name' => 'name' |
||
207 | ) |
||
208 | ), |
||
209 | array( |
||
210 | 'type' => 'text', |
||
211 | 'label' => $this->l('Account ID for test environment'), |
||
212 | 'name' => 'PAYLATER_ACCOUNT_ID_TEST', |
||
213 | 'required' => false, |
||
214 | 'col' => 4, |
||
215 | ), |
||
216 | array( |
||
217 | 'type' => 'text', |
||
218 | 'label' => $this->l('Account key for test environment'), |
||
219 | 'name' => 'PAYLATER_ACCOUNT_KEY_TEST', |
||
220 | 'required' => false, |
||
221 | 'col' => 4, |
||
222 | ), |
||
223 | array( |
||
224 | 'type' => 'text', |
||
225 | 'label' => $this->l('Account ID for live environment'), |
||
226 | 'name' => 'PAYLATER_ACCOUNT_ID_LIVE', |
||
227 | 'required' => false, |
||
228 | 'col' => 4, |
||
229 | ), |
||
230 | array( |
||
231 | 'type' => 'text', |
||
232 | 'label' => $this->l('Account key for live environment'), |
||
233 | 'name' => 'PAYLATER_ACCOUNT_KEY_LIVE', |
||
234 | 'required' => false, |
||
235 | 'col' => 4, |
||
236 | ), |
||
237 | array( |
||
238 | 'type' => 'select', |
||
239 | 'name' => 'PAYLATER_DISCOUNT', |
||
240 | 'desc' => $this->l('Pay the interest of the loan if set to true'), |
||
241 | 'is_bool' => true, |
||
242 | 'label' => $this->l('Discount'), |
||
243 | 'options' => array( |
||
244 | 'query' => array( |
||
245 | array( |
||
246 | 'id_discount' => 'false', |
||
247 | 'name' => $this->l('False') |
||
248 | ), |
||
249 | array( |
||
250 | 'id_discount' => 'true', |
||
251 | 'name' => $this->l('True') |
||
252 | ) |
||
253 | ), |
||
254 | 'id' => 'id_discount', |
||
255 | 'name' => 'name' |
||
256 | ) |
||
257 | ), |
||
258 | array( |
||
259 | 'type' => 'select', |
||
260 | 'name' => 'PAYLATER_IFRAME', |
||
261 | 'is_bool' => true, |
||
262 | 'label' => $this->l('Open in pop-up'), |
||
263 | 'options' => array( |
||
264 | 'query' => array( |
||
265 | array( |
||
266 | 'id_iframe' => 'false', |
||
267 | 'name' => $this->l('False') |
||
268 | ), |
||
269 | array( |
||
270 | 'id_iframe' => 'true', |
||
271 | 'name' => $this->l('True') |
||
272 | ) |
||
273 | ), |
||
274 | 'id' => 'id_iframe', |
||
275 | 'name' => 'name' |
||
276 | ) |
||
277 | ), |
||
278 | array( |
||
279 | 'type' => 'select', |
||
280 | 'name' => 'PAYLATER_WIDGET', |
||
281 | 'desc' => $this->l('Include widget in the payment method description'), |
||
282 | 'is_bool' => true, |
||
283 | 'label' => $this->l('Include widget in checkout page'), |
||
284 | 'options' => array( |
||
285 | 'query' => array( |
||
286 | array( |
||
287 | 'id_type' => 'true', |
||
288 | 'name' => $this->l('True') |
||
289 | ), |
||
290 | array( |
||
291 | 'id_type' => 'false', |
||
292 | 'name' => $this->l('False') |
||
293 | ) |
||
294 | ), |
||
295 | 'id' => 'id_type', |
||
296 | 'name' => 'name' |
||
297 | ) |
||
298 | ), |
||
299 | array( |
||
300 | 'type' => 'text', |
||
301 | 'label' => $this->l('Minimum amount'), |
||
302 | 'name' => 'PAYLATER_MIN_AMOUNT', |
||
303 | 'desc' => $this->l('Cart minimum amount to pay later'), |
||
304 | 'required' => false, |
||
305 | 'col' => 2, |
||
306 | ), |
||
307 | array( |
||
308 | 'type' => 'select', |
||
309 | 'label' => $this->l('Hook Product Widget'), |
||
310 | 'desc' => $this->l('Select the hook where you want to display the product widget'), |
||
311 | 'name' => 'PAYLATER_PRODUCT_WIDGET', |
||
312 | 'options' => array( |
||
313 | 'query' => array( |
||
314 | array( |
||
315 | 'id_option' => -1, |
||
316 | 'name' => $this->l('Do not include widtet in product page') |
||
317 | ), |
||
318 | array( |
||
319 | 'id_option' => 0, |
||
320 | 'name' => $this->l('displayProductButtons') |
||
321 | ), |
||
322 | array( |
||
323 | 'id_option' => 1, |
||
324 | 'name' => $this->l('displayRightColumnProduct') |
||
325 | ), |
||
326 | array( |
||
327 | 'id_option' => 2, |
||
328 | 'name' => $this->l('displayRightColumn') |
||
329 | ), |
||
330 | ), |
||
331 | 'id' => 'id_option', |
||
332 | 'name' => 'name' |
||
333 | ) |
||
334 | ), |
||
335 | array( |
||
336 | 'type' => 'select', |
||
337 | 'label' => $this->l('Widget style'), |
||
338 | 'desc' => $this->l('Select style of the widget'), |
||
339 | 'name' => 'PAYLATER_STYLE_WIDGET', |
||
340 | 'options' => array( |
||
341 | 'query' => array( |
||
342 | array( |
||
343 | 'id_option' => 0, |
||
344 | 'name' => $this->l('Mini Paga+Tarde') |
||
345 | ), |
||
346 | array( |
||
347 | 'id_option' => 1, |
||
348 | 'name' => $this->l('Completo Paga+Tarde') |
||
349 | ), |
||
350 | array( |
||
351 | 'id_option' => 2, |
||
352 | 'name' => $this->l('Seleccionable Paga+Tarde') |
||
353 | ), |
||
354 | array( |
||
355 | 'id_option' => 3, |
||
356 | 'name' => $this->l('Seleccionable Neutro') |
||
357 | ), |
||
358 | array( |
||
359 | 'id_option' => 4, |
||
360 | 'name' => $this->l('Seleccionable Simple') |
||
361 | ), |
||
362 | array( |
||
363 | 'id_option' => 5, |
||
364 | 'name' => $this->l('Texto descriptivo') |
||
365 | ), |
||
366 | ), |
||
367 | 'id' => 'id_option', |
||
368 | 'name' => 'name' |
||
369 | ) |
||
370 | ), |
||
371 | array( |
||
372 | 'type' => 'select', |
||
373 | 'name' => 'PAYLATER_COLOR_WIDGET', |
||
374 | 'desc' => $this->l('Widget Color'), |
||
375 | 'is_bool' => true, |
||
376 | 'label' => $this->l('Select the color of the widget'), |
||
377 | 'options' => array( |
||
378 | 'query' => array( |
||
379 | array( |
||
380 | 'id_type' => 'blue', |
||
381 | 'name' => $this->l('blue') |
||
382 | ), |
||
383 | array( |
||
384 | 'id_type' => 'grey', |
||
385 | 'name' => $this->l('grey') |
||
386 | ), |
||
387 | array( |
||
388 | 'id_type' => 'neutral', |
||
389 | 'name' => $this->l('neutral') |
||
390 | ) |
||
391 | ), |
||
392 | 'id' => 'id_type', |
||
393 | 'name' => 'name' |
||
394 | ) |
||
395 | ), |
||
396 | array( |
||
397 | 'type' => 'select', |
||
398 | 'name' => 'PAYLATER_CART_WIDGET', |
||
399 | 'desc' => $this->l('Include widget in shopping cart'), |
||
400 | 'is_bool' => true, |
||
401 | 'label' => $this->l('Include widget in shopping cart'), |
||
402 | 'options' => array( |
||
403 | 'query' => array( |
||
404 | array( |
||
405 | 'id_type' => 'true', |
||
406 | 'name' => $this->l('True') |
||
407 | ), |
||
408 | array( |
||
409 | 'id_type' => 'false', |
||
410 | 'name' => $this->l('False') |
||
411 | ) |
||
412 | ), |
||
413 | 'id' => 'id_type', |
||
414 | 'name' => 'name' |
||
415 | ) |
||
416 | ), |
||
417 | ), |
||
418 | 'submit' => array( |
||
419 | 'name' => 'submitPaylaterSettings', |
||
420 | 'title' => $this->l('Save') |
||
421 | ), |
||
422 | ); |
||
423 | |||
424 | $helper->fields_value['PAYLATER_ENVIRONMENT'] = Configuration::get('PAYLATER_ENVIRONMENT'); |
||
425 | $helper->fields_value['PAYLATER_ACCOUNT_ID_TEST'] = Configuration::get('PAYLATER_ACCOUNT_ID_TEST'); |
||
426 | $helper->fields_value['PAYLATER_ACCOUNT_KEY_TEST'] = Configuration::get('PAYLATER_ACCOUNT_KEY_TEST'); |
||
427 | $helper->fields_value['PAYLATER_ACCOUNT_ID_LIVE'] = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'); |
||
428 | $helper->fields_value['PAYLATER_ACCOUNT_KEY_LIVE'] = Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE'); |
||
429 | $helper->fields_value['PAYLATER_DISCOUNT'] = Configuration::get('PAYLATER_DISCOUNT'); |
||
430 | $helper->fields_value['PAYLATER_IFRAME'] = Configuration::get('PAYLATER_IFRAME'); |
||
431 | $helper->fields_value['PAYLATER_WIDGET'] = Configuration::get('PAYLATER_WIDGET'); |
||
432 | $helper->fields_value['PAYLATER_MIN_AMOUNT'] = Configuration::get('PAYLATER_MIN_AMOUNT'); |
||
433 | $helper->fields_value['PAYLATER_PRODUCT_WIDGET'] = Configuration::get('PAYLATER_PRODUCT_WIDGET'); |
||
434 | $helper->fields_value['PAYLATER_CART_WIDGET'] = Configuration::get('PAYLATER_CART_WIDGET'); |
||
435 | $helper->fields_value['PAYLATER_STYLE_WIDGET'] = Configuration::get('PAYLATER_STYLE_WIDGET'); |
||
436 | $helper->fields_value['PAYLATER_COLOR_WIDGET'] = Configuration::get('PAYLATER_COLOR_WIDGET'); |
||
437 | |||
438 | return $helper->generateForm($this->fields_form); |
||
439 | } |
||
440 | |||
441 | |||
442 | /** |
||
443 | * Retrocompatibility PS 1.4 get config values |
||
444 | * @return array |
||
445 | */ |
||
446 | protected function getConfigFormValues() |
||
447 | { |
||
448 | return array( |
||
449 | 'PAYLATER_ENVIRONMENT' => Configuration::get('PAYLATER_ENVIRONMENT'), |
||
450 | 'PAYLATER_ACCOUNT_ID_TEST' => Configuration::get('PAYLATER_ACCOUNT_ID_TEST'), |
||
451 | 'PAYLATER_ACCOUNT_KEY_TEST' => Configuration::get('PAYLATER_ACCOUNT_KEY_TEST'), |
||
452 | 'PAYLATER_ACCOUNT_ID_LIVE' => Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'), |
||
453 | 'PAYLATER_ACCOUNT_KEY_LIVE' => Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE'), |
||
454 | 'PAYLATER_DISCOUNT' => Configuration::get('PAYLATER_DISCOUNT'), |
||
455 | 'PAYLATER_MIN_AMOUNT' => Configuration::get('PAYLATER_MIN_AMOUNT'), |
||
456 | 'PAYLATER_WIDGET' => Configuration::get('PAYLATER_WIDGET'), |
||
457 | 'PAYLATER_IFRAME' => Configuration::get('PAYLATER_IFRAME'), |
||
458 | 'PAYLATER_PRODUCT_WIDGET' => Configuration::get('PAYLATER_PRODUCT_WIDGET'), |
||
459 | 'PAYLATER_CART_WIDGET' => Configuration::get('PAYLATER_CART_WIDGET'), |
||
460 | 'PAYLATER_STYLE_WIDGET' => Configuration::get('PAYLATER_STYLE_WIDGET'), |
||
461 | 'PAYLATER_COLOR_WIDGET' => Configuration::get('PAYLATER_COLOR_WIDGET') |
||
462 | ); |
||
463 | } |
||
464 | |||
465 | public function hookHeader() |
||
466 | { |
||
467 | // add logo for prestashop 1.6 |
||
468 | if (version_compare(_PS_VERSION_, "1.6", ">=")) { |
||
469 | $this->context->controller->addCSS($this->_path.'/views/css/front.css'); |
||
470 | } |
||
471 | // add iframe style |
||
472 | if (Configuration::get('PAYLATER_WIDGET') == 'false') { |
||
473 | return ""; |
||
474 | } |
||
475 | $this->context->controller->addCSS($this->_path.'/views/css/iframe.css'); |
||
476 | } |
||
477 | |||
478 | public function hookFooter($params) |
||
479 | { |
||
480 | $this->context->controller->addJS( |
||
481 | 'https://cdn.pagamastarde.com/pmt-simulator/3/js/pmt-simulator.min.js' |
||
482 | ); |
||
483 | $this->context->controller->addJS( |
||
484 | $this->_path.'/views/js/widget.js' |
||
485 | ); |
||
486 | } |
||
487 | |||
488 | public function hookPayment($params) |
||
489 | { |
||
490 | if ($this->context->cart->getOrderTotal() < Configuration::get('PAYLATER_MIN_AMOUNT')) { |
||
491 | return; |
||
492 | } |
||
493 | $currency_id = $params['cart']->id_currency; |
||
494 | $currency = new Currency((int) $currency_id); |
||
495 | if (in_array($currency->iso_code, $this->limited_currencies) == false) { |
||
0 ignored issues
–
show
|
|||
496 | return false; |
||
497 | } |
||
498 | |||
499 | $customer = new Customer((int)$params['cart']->id_customer); |
||
500 | //prevent opening payment method if no credentials introduced |
||
501 | if (Configuration::get('PAYLATER_ENVIRONMENT') == 0) { |
||
502 | if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_TEST')) == false || |
||
0 ignored issues
–
show
|
|||
503 | trim(Configuration::get('PAYLATER_ACCOUNT_KEY_TEST')) == false ) { |
||
0 ignored issues
–
show
|
|||
504 | return false; |
||
505 | } |
||
506 | } else { |
||
507 | if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_LIVE')) == false || |
||
0 ignored issues
–
show
|
|||
508 | trim(Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE')) == false) { |
||
0 ignored issues
–
show
|
|||
509 | return false; |
||
510 | } |
||
511 | } |
||
512 | |||
513 | $cart_products = $this->context->cart->getProducts(); |
||
514 | |||
515 | $items = array(); |
||
516 | $desciption=array(); |
||
517 | |||
518 | $discount = Configuration::get('PAYLATER_DISCOUNT'); |
||
519 | $discount_boolean = $discount == 'true' ? 1:0; |
||
0 ignored issues
–
show
$discount_boolean is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
520 | foreach ($cart_products as $p) { |
||
521 | $items[] = array( |
||
522 | 'description' => $p['name'], |
||
523 | 'quantity' => $p['cart_quantity'], |
||
524 | 'amount' => number_format($p['total_wt'], 2, '.', '') |
||
525 | ); |
||
526 | $desciption[]= $p['name']. " (".$p['cart_quantity'].")"; |
||
527 | } |
||
528 | |||
529 | //Shipping address |
||
530 | $saddress = new Address($this->context->cart->id_address_delivery); |
||
531 | $sstreet=$saddress->address1.' '.$saddress->address2; |
||
532 | $scity=$saddress->city; |
||
533 | $suser_state = new State($saddress->id_state); |
||
534 | $sprovince=$suser_state->name; |
||
535 | $szipcode=$saddress->postcode; |
||
536 | $sphone = $saddress->phone; |
||
537 | $smobile_phone = $saddress->phone_mobile; |
||
538 | $shipping_last_updated = Tools::substr($saddress->date_upd, 0, 10); |
||
539 | $shipping_date_add = Tools::substr($saddress->date_add, 0, 10); |
||
540 | |||
541 | |||
542 | //billing address |
||
543 | $billing_address = new Address($this->context->cart->id_address_invoice); |
||
544 | $street=$billing_address->address1.' '.$billing_address->address2; |
||
545 | $city=$billing_address->city; |
||
546 | $user_state2 = new State($billing_address->id_state); |
||
547 | $province=$user_state2->name; |
||
548 | $zipcode=$billing_address->postcode; |
||
549 | $phone = $billing_address->phone; |
||
550 | $mobile_phone = $billing_address->phone_mobile; |
||
551 | $billing_last_updated = Tools::substr($billing_address->date_upd, 0, 10); |
||
552 | $billing_date_add = Tools::substr($billing_address->date_add, 0, 10); |
||
553 | $shipping_dni = ''; |
||
554 | $billing_dni = ''; |
||
555 | //dni |
||
556 | $customer_dob = ($this->context->customer->birthday ? $this->context->customer->birthday : $customer->birthday); |
||
557 | $dob = ''; |
||
558 | $dni = ''; |
||
559 | if (property_exists($billing_address, 'dni')) { |
||
560 | $dni=$billing_address->dni; |
||
561 | $billing_dni = $billing_address->dni; |
||
562 | } |
||
563 | |||
564 | if (property_exists($saddress, 'dni')) { |
||
565 | if (trim($dni) == '' && $saddress->firstname == $this->context->cookie->customer_firstname |
||
566 | && $saddress->lastname == $this->context->cookie->customer_lastname) { |
||
567 | $dni=$saddress->dni; |
||
568 | } |
||
569 | $shipping_dni = $saddress->dni; |
||
570 | } |
||
571 | if ($billing_address->firstname == $this->context->cookie->customer_firstname && |
||
572 | $billing_address->lastname == $this->context->cookie->customer_lastname) { |
||
573 | $dob = ($this->context->customer->birthday ? $this->context->customer->birthday : $customer->birthday); |
||
574 | } |
||
575 | |||
576 | $customer_last_updated = Tools::substr($this->context->customer->date_upd, 0, 10); |
||
577 | |||
578 | if (version_compare(_PS_VERSION_, "1.5", "<")) { |
||
579 | $shippingCost = $this->context->cart->getOrderShippingCost(); |
||
580 | } else { |
||
581 | $shippingCost = $this->context->cart->getTotalShippingCost(null, true, null); |
||
582 | } |
||
583 | |||
584 | $link = Context::getContext()->link; |
||
585 | $callback_url = $link->getModuleLink('paylater', 'validation', array()); |
||
586 | $confirmationQuery = array( |
||
587 | 'id_cart' => $this->context->cart->id, |
||
588 | 'key' => $this->context->cart->secure_key, |
||
589 | ); |
||
590 | |||
591 | $url_OK = $link->getModuleLink('paylater', 'confirmation', $confirmationQuery); |
||
592 | |||
593 | if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { |
||
594 | $url_NOK = $link->getPageLink('order-opc'); |
||
595 | } else { |
||
596 | $url_NOK = $link->getPageLink('order'); |
||
597 | } |
||
598 | |||
599 | $cancelled_url = $link->getPageLink('order'); |
||
600 | |||
601 | if ($shippingCost > 0) { |
||
602 | $items[] = array( |
||
603 | 'description' => $this->l('Shipping cost'), |
||
604 | 'quantity' => 1, |
||
605 | 'amount' => number_format($shippingCost, 2, '.', '') |
||
606 | ); |
||
607 | $desciption[]= $this->l('Shipping cost'); |
||
608 | } |
||
609 | View Code Duplication | if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
610 | //mode live |
||
611 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'); |
||
612 | } else { |
||
613 | //mode test |
||
614 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_TEST'); |
||
615 | } |
||
616 | //discount |
||
617 | $discount = Configuration::get('PAYLATER_DISCOUNT'); |
||
618 | //1.4 fix |
||
619 | if ($discount == '0') { |
||
620 | $discount = 'false'; |
||
621 | } |
||
622 | if ($discount == '1') { |
||
623 | $discount = 'true'; |
||
624 | } |
||
625 | |||
626 | switch ($this->context->customer->id_gender) { |
||
627 | case 2: |
||
628 | $gender = 'female'; |
||
629 | break; |
||
630 | case 1: |
||
631 | $gender = 'male'; |
||
632 | break; |
||
633 | default: |
||
634 | $gender = ''; |
||
635 | break; |
||
636 | } |
||
637 | $discount_boolean = $discount == 'true' ? 1:0; |
||
638 | |||
639 | $iframe = Configuration::get('PAYLATER_IFRAME'); |
||
640 | |||
641 | if ($iframe == 1) { |
||
642 | $iframe = 'true'; |
||
643 | } |
||
644 | |||
645 | $endpoint = $this->url; |
||
646 | |||
647 | $order_id = $this->context->cart->id; |
||
648 | |||
649 | //description |
||
650 | $description = implode(',', $desciption); |
||
651 | |||
652 | $convert_price = Tools::convertPrice( |
||
653 | $this->context->cart->getOrderTotal(true, 3), |
||
654 | $this->context->currency |
||
655 | ); |
||
656 | |||
657 | $amount = number_format( |
||
658 | $convert_price, |
||
659 | 2, |
||
660 | '.', |
||
661 | '' |
||
662 | ); |
||
663 | $amount = str_replace('.', '', $amount); |
||
664 | |||
665 | View Code Duplication | if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
666 | $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE'); |
||
667 | } else { |
||
668 | $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_TEST'); |
||
669 | } |
||
670 | |||
671 | $widget_type = Configuration::get('PAYLATER_WIDGET') == 'false' ? '0' : '1'; |
||
672 | |||
673 | $total_paid = 0; |
||
674 | $num_prev_orders = 0; |
||
675 | $sign_up_date = ''; |
||
676 | $num_partial_refunds = 0; |
||
677 | $amount_refunded = 0; |
||
678 | $num_full_refunds = 0; |
||
679 | $super_checkout_enabled = false; |
||
680 | $onepagecheckoutps_enabled = false; |
||
681 | $onepagecheckout_enabled = false; |
||
682 | |||
683 | if (version_compare(_PS_VERSION_, "1.5", "<")) { |
||
684 | if ($this->context->cookie->logged) { |
||
685 | $orders = Order::getCustomerOrders($this->context->customer->id); |
||
686 | foreach ($orders as $o) { |
||
687 | $total_paid += $o['total_paid']; |
||
688 | $num_prev_orders++; |
||
689 | } |
||
690 | $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10); |
||
691 | $order_slips = OrderSlip::getOrdersSlip((int)$this->context->cookie->id_customer); |
||
692 | |||
693 | foreach ($order_slips as $o) { |
||
694 | $num_full_refunds++; |
||
695 | $amount_refunded += $o['amount']; |
||
696 | } |
||
697 | } |
||
698 | } else { |
||
699 | //query for paid statuses |
||
700 | $sql = new DbQuery(); |
||
701 | $sql->select('id_order_state'); |
||
702 | $sql->from('order_state', 'c'); |
||
703 | $sql->where('c.paid = 1'); |
||
704 | $db_paid_statuses = Db::getInstance()->executeS($sql); |
||
705 | $paid_statuses = array(); |
||
706 | foreach ($db_paid_statuses as $p) { |
||
707 | $paid_statuses[]=$p['id_order_state']; |
||
708 | } |
||
709 | if ($this->context->cookie->logged) { |
||
710 | $orders = Order::getCustomerOrders($this->context->customer->id); |
||
711 | foreach ($orders as $o) { |
||
712 | if (array_key_exists('id_order_state', $o) && in_array($o['id_order_state'], $paid_statuses)) { |
||
713 | $total_paid += $o['total_paid']; |
||
714 | $num_prev_orders++; |
||
715 | } |
||
716 | } |
||
717 | $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10); |
||
718 | $order_slips = OrderSlip::getOrdersSlip((int)$this->context->cookie->id_customer); |
||
719 | foreach ($order_slips as $o) { |
||
720 | $sql = new DbQuery(); |
||
721 | $sql->select('total_paid'); |
||
722 | $sql->from('orders', 'c'); |
||
723 | $sql->where('c.id_order = '.$o['id_order']); |
||
724 | $db_total_paid = Db::getInstance()->executeS($sql); |
||
725 | if ($db_total_paid[0]['total_paid'] <= $o['amount']) { |
||
726 | $num_full_refunds++; |
||
727 | } else { |
||
728 | $num_partial_refunds++; |
||
729 | } |
||
730 | $amount_refunded += $o['amount']; |
||
731 | } |
||
732 | } |
||
733 | $super_checkout_enabled = Module::isEnabled('supercheckout'); |
||
734 | $onepagecheckoutps_enabled = Module::isEnabled('onepagecheckoutps'); |
||
735 | $onepagecheckout_enabled = Module::isEnabled('onepagecheckout'); |
||
736 | } |
||
737 | |||
738 | $opc_enabled = Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 ? 1 : 0; |
||
739 | |||
740 | //d($key_to_use.$account_id.$order_id.$amount.$this->context->currency->iso_code.$url_OK.$url_NOK); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
57% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
741 | $text=$key_to_use.$account_id.$order_id.$amount.$this->context->currency->iso_code. |
||
742 | $url_OK.$url_NOK.$callback_url.$discount.$cancelled_url; |
||
743 | $signature = hash('sha512', $text); |
||
744 | $this->smarty->assign(array( |
||
745 | 'endpoint' => $endpoint, |
||
746 | 'account_id' => $account_id, |
||
747 | 'currency' => $this->context->currency->iso_code, |
||
748 | 'ok_url' => $url_OK, |
||
749 | 'nok_url' => $url_NOK, |
||
750 | 'cancelled_url' => $cancelled_url, |
||
751 | 'order_id' => $order_id, |
||
752 | 'amount' => $amount, |
||
753 | 'description' => $description, |
||
754 | 'items' => $items, |
||
755 | 'signature' => $signature, |
||
756 | 'customer_name' => ($this->context->cookie->logged ? $this->context->cookie->customer_firstname. |
||
757 | ' '.$this->context->cookie->customer_lastname : $customer->firstname." ".$customer->lastname), |
||
758 | 'customer_email' => ($this->context->cookie->logged ? $this->context->cookie->email : $customer->email), |
||
759 | 'locale' => $this->context->language->iso_code, |
||
760 | 'cart_products' => $cart_products, |
||
761 | 'billing_full_name' => $billing_address->firstname. " ".$billing_address->lastname , |
||
762 | 'billing_dni' => $billing_dni, |
||
763 | 'billing_alias' => $billing_address->alias, |
||
764 | 'billing_company' => $billing_address->company, |
||
765 | 'billing_vat' => $billing_address->vat_number, |
||
766 | 'street' => $street, |
||
767 | 'city' => $city, |
||
768 | 'province' => $province, |
||
769 | 'zipcode' => $zipcode, |
||
770 | 'sstreet' => $sstreet, |
||
771 | 'scity' => $scity, |
||
772 | 'sprovince' => $sprovince, |
||
773 | 'szipcode' => $szipcode, |
||
774 | 'phone' => $phone, |
||
775 | 'mobile_phone' => $mobile_phone, |
||
776 | 'shipping_dni' => $shipping_dni, |
||
777 | 'shipping_alias' => $saddress->alias, |
||
778 | 'shipping_company' => $saddress->company, |
||
779 | 'shipping_vat' => $saddress->vat_number, |
||
780 | 'shipping_full_name' => $saddress->firstname. " ".$saddress->lastname , |
||
781 | 'sphone' => $sphone, |
||
782 | 'smobile_phone' => $smobile_phone, |
||
783 | 'dni' => $dni, |
||
784 | 'callback_url' => $callback_url, |
||
785 | 'discount' => $discount, |
||
786 | 'discount_boolean' => $discount_boolean, |
||
787 | 'dob' => $dob, |
||
788 | 'customer_dob' => $customer_dob, |
||
789 | 'iframe' => $iframe, |
||
790 | 'total_paid' => $total_paid, |
||
791 | 'num_prev_orders' => $num_prev_orders, |
||
792 | 'sign_up_date' => $sign_up_date, |
||
793 | 'amount_refunded' => $amount_refunded, |
||
794 | 'num_full_refunds' => $num_full_refunds, |
||
795 | 'num_partial_refunds' => $num_partial_refunds, |
||
796 | 'module_version' => $this->version, |
||
797 | 'customer_last_updated' => $customer_last_updated, |
||
798 | 'billing_last_updated' => $billing_last_updated, |
||
799 | 'billing_date_add' => $billing_date_add, |
||
800 | 'shipping_last_updated' => $shipping_last_updated, |
||
801 | 'shipping_date_add' => $shipping_date_add, |
||
802 | 'customer_gender' => $gender, |
||
803 | 'opc_enabled' => $opc_enabled, |
||
804 | 'is_guest' => $this->context->customer->is_guest, |
||
805 | 'platform' => 'prestashop ' . _PS_VERSION_, |
||
806 | 'version4' => version_compare(_PS_VERSION_, "1.5", "<"), |
||
807 | 'version3' => version_compare(_PS_VERSION_, "1.4", "<"), |
||
808 | 'content' => "javascript:$('#paylater_form').submit();", |
||
809 | )); |
||
810 | |||
811 | if ($super_checkout_enabled) { |
||
812 | return $this->display(__FILE__, 'views/templates/front/payment_supercheckout.tpl'); |
||
813 | } elseif ($onepagecheckoutps_enabled || $onepagecheckout_enabled) { |
||
814 | return $this->display(__FILE__, 'views/templates/front/payment.tpl'); |
||
815 | } elseif ($widget_type) { |
||
816 | return $this->display(__FILE__, 'views/templates/front/payment_widget.tpl'); |
||
817 | } else { |
||
818 | return $this->display(__FILE__, 'views/templates/front/payment.tpl'); |
||
819 | } |
||
820 | } |
||
821 | |||
822 | public function hookDisplayPaymentEU($params) |
||
823 | { |
||
824 | return $this->hookPayment($params); |
||
825 | } |
||
826 | |||
827 | /** |
||
828 | * Not used because pagantis redirect return to ok_url & nok_url |
||
829 | * @param $params |
||
830 | * @return mixed |
||
831 | */ |
||
832 | public function hookPaymentReturn($params) |
||
833 | { |
||
834 | $order = $params['objOrder']; |
||
835 | $this->context->smarty->assign(array( |
||
836 | 'id_order' => $order->id, |
||
837 | 'reference' => $order->reference, |
||
838 | 'params' => $params, |
||
839 | 'total' => $params['total_to_pay'], |
||
840 | )); |
||
841 | |||
842 | if ($order->getCurrentState() === Configuration::get('PS_OS_PAYMENT')) { |
||
843 | return $this->display(__FILE__, 'confirmation_success.tpl'); |
||
844 | } |
||
845 | return $this->display(__FILE__, 'confirmation_failure.tpl'); |
||
846 | } |
||
847 | |||
848 | /** |
||
849 | * Retrocomatibility prestashop 1.4, it's necesary file path because doesn't exists ModuleFrontController |
||
850 | * @param $file |
||
851 | * @param array $params |
||
852 | * @return string |
||
853 | */ |
||
854 | View Code Duplication | public function getPagantisLink($file, array $params = array()) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
855 | { |
||
856 | $protocol = 'http://'; |
||
857 | if (Configuration::get('PS_SSL_ENABLED')) { |
||
858 | $protocol = 'https://'; |
||
859 | } |
||
860 | return $protocol.Tools::getHttpHost()._MODULE_DIR_.$this->name.'/' |
||
861 | .$file.'?'.htmlspecialchars_decode(http_build_query($params)); |
||
862 | } |
||
863 | |||
864 | /** |
||
865 | * Retrocomatibility prestashop 1.4, it's necesary file path because doesn't exists ModuleFrontController |
||
866 | * @param $file |
||
867 | * @param array $params |
||
868 | * @return string |
||
869 | */ |
||
870 | View Code Duplication | public function getPagantisCallbackUrl($file, array $params = array()) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
871 | { |
||
872 | $protocol = 'http://'; |
||
873 | if (Configuration::get('PS_SSL_ENABLED')) { |
||
874 | $protocol = 'https://'; |
||
875 | } |
||
876 | return $protocol.Tools::getHttpHost()._MODULE_DIR_.$this->name.'/'.$file.'?'.http_build_query($params); |
||
877 | } |
||
878 | |||
879 | public static function initModuleAccess() |
||
880 | { |
||
881 | paylater::$modulePath = _PS_MODULE_DIR_.'paylater/'; |
||
882 | } |
||
883 | |||
884 | View Code Duplication | public function hookDisplayProductButtons($params) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
885 | { |
||
886 | $display_widget = (int)Configuration::get('PAYLATER_PRODUCT_WIDGET', null); |
||
887 | if ($display_widget == 0) { |
||
888 | return $this->getProductWidget($params); |
||
889 | } |
||
890 | return false; |
||
891 | } |
||
892 | |||
893 | View Code Duplication | public function hookDisplayRightColumnProduct($params) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
894 | { |
||
895 | $display_widget = (int)Configuration::get('PAYLATER_PRODUCT_WIDGET', null); |
||
896 | if ($display_widget == 1) { |
||
897 | return $this->getProductWidget($params); |
||
898 | } |
||
899 | return false; |
||
900 | } |
||
901 | |||
902 | public function hookDisplayRightColumn($params) |
||
903 | { |
||
904 | if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'product') { |
||
905 | $display_widget = (int)Configuration::get('PAYLATER_PRODUCT_WIDGET', null); |
||
906 | if ($display_widget == 2) { |
||
907 | return $this->getProductWidget($params); |
||
908 | } |
||
909 | } |
||
910 | return false; |
||
911 | } |
||
912 | |||
913 | public function hookDisplayShoppingCart($params) |
||
914 | { |
||
915 | if ($params['total_price'] < Configuration::get('PAYLATER_MIN_AMOUNT')) { |
||
916 | return; |
||
917 | } |
||
918 | if (Configuration::get('PAYLATER_CART_WIDGET') == 'false') { |
||
919 | return false; |
||
920 | } |
||
921 | View Code Duplication | if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
922 | //mode live |
||
923 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'); |
||
924 | } else { |
||
925 | //mode test |
||
926 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_TEST'); |
||
927 | } |
||
928 | |||
929 | $data_pmt_type = 2; |
||
930 | $data_pmt_expanded = 'no'; |
||
931 | $data_pmt_style = 'blue'; |
||
932 | $class = 'PmtSimulator'; |
||
933 | View Code Duplication | switch (Configuration::get('PAYLATER_STYLE_WIDGET')) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
934 | case 0: |
||
935 | $data_pmt_type = 2; |
||
936 | $data_pmt_expanded = 'no'; |
||
937 | break; |
||
938 | case 1: |
||
939 | $data_pmt_type = 2; |
||
940 | $data_pmt_expanded = 'yes'; |
||
941 | break; |
||
942 | case 2: |
||
943 | $data_pmt_type = 3; |
||
944 | $class = 'PmtSimulator PmtSimulatorSelectable--brand'; |
||
945 | break; |
||
946 | case 3: |
||
947 | $data_pmt_type = 3; |
||
948 | $data_pmt_style = 'not_applicable'; |
||
949 | $class = 'PmtSimulator PmtSimulatorSelectable--claim'; |
||
950 | break; |
||
951 | case 4: |
||
952 | $data_pmt_type = 3; |
||
953 | $data_pmt_style = 'not_applicable'; |
||
954 | $class = 'PmtSimulator'; |
||
955 | break; |
||
956 | case 5: |
||
957 | $data_pmt_type = 4; |
||
958 | break; |
||
959 | } |
||
960 | if (Configuration::get('PAYLATER_STYLE_WIDGET') != '') { |
||
961 | $data_pmt_style = Configuration::get('PAYLATER_COLOR_WIDGET'); |
||
962 | } |
||
963 | |||
964 | $discount = Configuration::get('PAYLATER_DISCOUNT'); |
||
965 | $discount_boolean = $discount == 'true' ? 1:0; |
||
966 | $this->smarty->assign(array( |
||
967 | 'price' => ($params['total_price']), |
||
968 | 'discount' => $discount_boolean, |
||
969 | 'account_id' => $account_id, |
||
970 | 'data_pmt_type' => $data_pmt_type, |
||
971 | 'data_pmt_expanded' => $data_pmt_expanded, |
||
972 | 'data_pmt_style' => $data_pmt_style, |
||
973 | 'class' => $class |
||
974 | )); |
||
975 | return $this->display(__FILE__, 'views/templates/hook/shoppingcart.tpl'); |
||
976 | } |
||
977 | |||
978 | public function getProductWidget($params) |
||
979 | { |
||
980 | if (isset($params['product'])) { |
||
981 | $product = $params['product']; |
||
982 | } elseif (Tools::getValue('controller')=='product' && Tools::getValue('id_product')) { |
||
983 | $product = new Product(Tools::getValue('id_product')); |
||
984 | } else { |
||
985 | if (method_exists($this->context->controller, 'getProduct')) { |
||
986 | $product = $this->context->controller->getProduct(); |
||
987 | } |
||
988 | } |
||
989 | if (!isset($product) || !Validate::isLoadedObject($product)) { |
||
990 | return false; |
||
991 | } elseif (!$product->show_price || !$product->available_for_order) { |
||
992 | return false; |
||
993 | } |
||
994 | View Code Duplication | if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
995 | //mode live |
||
996 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'); |
||
997 | } else { |
||
998 | //mode test |
||
999 | $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_TEST'); |
||
1000 | } |
||
1001 | |||
1002 | $priceDisplay = Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer); |
||
1003 | if (!$priceDisplay || $priceDisplay == 2) { |
||
1004 | $price = $product->getPrice(true); |
||
1005 | } else { |
||
1006 | $price = $product->getPrice(false); |
||
1007 | } |
||
1008 | |||
1009 | if ($price < Configuration::get('PAYLATER_MIN_AMOUNT')) { |
||
1010 | return; |
||
1011 | } |
||
1012 | |||
1013 | $data_pmt_type = 2; |
||
1014 | $data_pmt_expanded = 'no'; |
||
1015 | $data_pmt_style = 'blue'; |
||
1016 | $class = 'PmtSimulator'; |
||
1017 | View Code Duplication | switch (Configuration::get('PAYLATER_STYLE_WIDGET')) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
1018 | case 0: |
||
1019 | $data_pmt_type = 2; |
||
1020 | $data_pmt_expanded = 'no'; |
||
1021 | break; |
||
1022 | case 1: |
||
1023 | $data_pmt_type = 2; |
||
1024 | $data_pmt_expanded = 'yes'; |
||
1025 | break; |
||
1026 | case 2: |
||
1027 | $data_pmt_type = 3; |
||
1028 | $class = 'PmtSimulator PmtSimulatorSelectable--brand'; |
||
1029 | break; |
||
1030 | case 3: |
||
1031 | $data_pmt_type = 3; |
||
1032 | $data_pmt_style = 'not_applicable'; |
||
1033 | $class = 'PmtSimulator PmtSimulatorSelectable--claim'; |
||
1034 | break; |
||
1035 | case 4: |
||
1036 | $data_pmt_type = 3; |
||
1037 | $data_pmt_style = 'not_applicable'; |
||
1038 | $class = 'PmtSimulator'; |
||
1039 | break; |
||
1040 | case 5: |
||
1041 | $data_pmt_type = 4; |
||
1042 | break; |
||
1043 | } |
||
1044 | if (Configuration::get('PAYLATER_STYLE_WIDGET') != '') { |
||
1045 | $data_pmt_style = Configuration::get('PAYLATER_COLOR_WIDGET'); |
||
1046 | } |
||
1047 | |||
1048 | $discount = Configuration::get('PAYLATER_DISCOUNT'); |
||
1049 | $discount_boolean = $discount == 'true' ? 1:0; |
||
1050 | $this->smarty->assign(array( |
||
1051 | 'price' => ($price), |
||
1052 | 'discount' => $discount_boolean, |
||
1053 | 'account_id' => $account_id, |
||
1054 | 'data_pmt_type' => $data_pmt_type, |
||
1055 | 'data_pmt_expanded' => $data_pmt_expanded, |
||
1056 | 'data_pmt_style' => $data_pmt_style, |
||
1057 | 'class' => $class |
||
1058 | )); |
||
1059 | return $this->display(__FILE__, 'views/templates/hook/product.tpl'); |
||
1060 | } |
||
1061 | } |
||
1062 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.