-
Notifications
You must be signed in to change notification settings - Fork 9
/
dotpay.php
executable file
·1764 lines (1670 loc) · 77.4 KB
/
dotpay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
use Prestashop\Dotpay\Model\Instruction;
use Prestashop\Dotpay\Model\CreditCard;
use Prestashop\Dotpay\Model\CardBrand;
use Dotpay\Model\ChannelList;
use Dotpay\Model\Customer as DotpayCustomer;
use Dotpay\Resource\Channel\Agreement;
use Dotpay\Exception\IncompleteDataException;
use Dotpay\Channel\Channel;
use Dotpay\Exception\DotpayException;
use Dotpay\Exception\Resource\Account\NotFoundException as AccountNotFoundException;
use Prestashop\Dotpay\Model\Configuration as DotpayConfiguration;
if (!defined('_PS_VERSION_')) {
exit;
}
include(dirname(__FILE__).'/sdk/dotpay.bootstrap.php');
/**
* Load an overriden class
* @param string $className Full name of class
*/
function dotpayOverrideApiLoader($className)
{
$location = str_replace('Prestashop', 'classes', str_replace('\\', '/', $className));
$path = dirname(__FILE__).'/'.$location.'.php';
if (file_exists($path)) {
include_once($path);
}
}
spl_autoload_register('dotpayOverrideApiLoader');
/**
* Dotpay plugin class
*/
class Dotpay extends PaymentModule
{
protected $config_form = false;
const REPOSITORY_NAME = 'PrestaShop-1.7';
/**
* @var Dotpay\Loader\Loader Instance of SDK Loader
*/
protected $sdkLoader;
/**
* @var Prestashop\Dotpay\Model\Configuration Plugin configuration
*/
protected $config;
/**
* Initialize the plugin
*/
public function __construct()
{
$this->name = 'dotpay';
$this->tab = 'payments_gateways';
$this->version = '1.5.1';
$this->author = 'Dotpay';
$this->need_instance = 1;
$this->is_eu_compatible = 1;
$this->sdkLoader = Dotpay\Loader\Loader::load(
new Dotpay\Loader\Parser(dirname(__FILE__).'/sdk/Dotpay/di.xml'),
new Dotpay\Loader\Parser(dirname(__FILE__).'/classes/Dotpay/di.xml')
);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Przelewy24.pl');
$this->description = $this->l('Przelewy24.pl - Payment Service');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
$this->sdkLoader->parameter('Config:pluginId', $this->name);
$this->config = $dpConfig = $this->sdkLoader->get('Config');
$this->config->setPluginVersion($this->version);
$this->limited_currencies = $dpConfig::$CURRENCIES;
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
/**
* Install the module
* @return boolean
*/
public function install()
{
if (extension_loaded('curl') == false) {
$this->_errors[] = $this->l('You have to enable the cURL extension on your server to install this module');
return false;
}
Module::updateTranslationsAfterInstall(false);
try {
return parent::install() &&
$this->registerHook('displayHeader') &&
$this->registerHook('displayBackOfficeHeader') &&
$this->registerHook('displayCustomerAccount') &&
$this->registerHook('displayAdminOrder') &&
$this->registerHook('displayOrderDetail') &&
$this->registerHook('paymentOptions') &&
$this->addOrderWaitingStatus() &&
$this->addOrderOverpaidStatus() &&
$this->addTotalRefundStatus() &&
$this->addPartialRefundStatus() &&
$this->addWaitingRefundStatus() &&
$this->addFailedRefundStatus() &&
$this->addReturnTab() &&
Instruction::install() &&
CreditCard::install() &&
CardBrand::install();
} catch (\Exception $e) {
return false;
}
}
/**
* Uninstall the module
* @return boolean
*/
public function uninstall()
{
return parent::uninstall() &&
Instruction::uninstall() &&
CreditCard::uninstall() &&
CardBrand::uninstall();
}
/**
* Return an array with channels which are available
* @param \Dotpay\Resource\Payment $paymentResource
* @return array
*/
private function getChannelList($paymentResource)
{
if($this->config->getDefaultCurrency() !== ""){
$defcurrency = $this->config->getDefaultCurrency();
}else{
$defcurrency = "PLN";
}
try {
$config = $this->config;
$seller = $this->sdkLoader->get('Seller', array($this->config->getId(), $this->config->getPin()));
$customer = $this->sdkLoader->get('Customer', array('[email protected]', 'Firstname', 'Lastname'));
$customer->setLanguage($this->getLanguage());
$order = $this->sdkLoader->get('Order', array(null, 317, $defcurrency));
$payment = $this->sdkLoader->get('PaymentModel', array($customer, $order, ''));
$payment->setSeller($seller);
$info = $paymentResource->getChannelInfo($payment);
$availableChannels = $info->getChannelList($config::$SPECIAL_CHANNELS);
unset($info);
$paymentResource->clearBuffer();
return $availableChannels;
} catch (\Exception $e) {
return array();
}
}
/**
* Load the configuration form
*/
public function getContent()
{
/**
* If values have been submitted in the form, process.
*/
if (((bool)Tools::isSubmit('submitDotpayModule')) == true) {
$this->saveConfiguration();
$saved = true;
} else {
$saved = false;
}
try {
$paymentResource = $this->sdkLoader->get('PaymentResource');
$sellerResource = $this->sdkLoader->get('SellerResource');
$testGoodApiData = $this->config->isGoodApiData();
$DotopayMigratedP24 = $this->config->getDProxyP24Migrated();
$testCorrectSellerForApi = true;
$availableChannels = $this->getChannelList($paymentResource);
$DotpayIDSeller = $this->config->getId();
$P24DotpayIDSeller = $this->config->getId();
try {
$testSellerId = $paymentResource->checkSeller($this->config->getId(),'check');
$P24testSellerId = $paymentResource->checkSeller($this->config->getId(),'check','p24_check');
$testSellerIderror = $paymentResource->checkSeller($this->config->getId(),'error_code');
$P24testSellerIderror = $paymentResource->checkSeller($this->config->getId(),'error_code','p24_check');
$DotpayIDSellerName = $paymentResource->checkSeller($this->config->getId(),'receiver');
$P24IDSellerName = $paymentResource->checkSeller($this->config->getId(),'receiver','p24_check');
$testApiAccount = $sellerResource->isAccountRight();
$testSellerPin = $sellerResource->checkPin();
} catch (AccountNotFoundException $e) {
$testSellerPin = true;
$testCorrectSellerForApi = false;
} catch (DotpayException $e) {
$testSellerPin = false;
}
if (!isset($testSellerId)) {
$testSellerId = false;
}
if (!isset($P24testSellerId)) {
$P24testSellerId = false;
}
if (!isset($testSellerIderror)) {
$testSellerIderror = false;
}
if (!isset($P24testSellerIderror)) {
$P24testSellerIderror = false;
}
if (!isset($DotpayIDSellerName)) {
$DotpayIDSellerName = false;
}
if (!isset($P24IDSellerName)) {
$P24IDSellerName = false;
}
if (trim($this->config->getId()) == "") {
$DotpayIDSeller = false;
}
if (trim($this->config->getId()) == "") {
$P24DotpayIDSeller = false;
}
if (!isset($testApiAccount)) {
$testApiAccount = false;
}
try {
$version = $this->sdkLoader->get('Github')->getLatestProjectVersion('dotpay', self::REPOSITORY_NAME);
$number = $version->getNumber();
$number = str_replace('v', '', $number);
$obsoletePlugin = !(version_compare($number, $this->version, '<='));
$canNotCheckPlugin = false;
} catch (RuntimeException $e) {
$obsoletePlugin = true;
$canNotCheckPlugin = true;
$number = $this->version;
}
$baseUrl2 = Context::getContext()->link->getBaseLink();
if (Tools::substr($baseUrl2, -1, 1) !== '/') {
$baseUrl2 .= '/';
}
$templateData = array(
'repositoryName' => self::REPOSITORY_NAME,
'moduleDir' => $this->_path,
'regMessEn' => $this->config->getTestMode() || !$this->config->isGoodAccount(),
'testMode' => $this->config->getTestMode(),
'DefaultCurrency' => $this->config->getDefaultCurrency(),
'badIdMessage' => $this->l('Incorrect ID (required 6 digits)'),
'badPinMessage' => $this->l('Incorrect PIN (minimum 16 and maximum 32 alphanumeric characters)'),
'valueLowerThanZero' => $this->l('The value must be greater than zero.'),
'targetForUrlc' => $this->context->link->getModuleLink(
'dotpay',
'confirm',
array('ajax' => '1'),
$this->isSSLEnabled()
),
'oldVersion' => !version_compare(_PS_VERSION_, "1.7", ">="),
'CurrentVersion' => _PS_VERSION_,
'badPhpVersion' => !version_compare(PHP_VERSION, "5.6", ">="),
'phpVersion' => PHP_VERSION,
'minorPhpVersion' => '5.6',
'confOK' => $this->config->isGoodAccount() && $this->config->getEnable(),
'P24Migrated' => $DotopayMigratedP24,
'errorCodeID' => $testSellerIderror,
'P24errorCodeID' => $P24testSellerIderror,
'SellerIDName' => $DotpayIDSellerName,
'P24SellerIDName' => $P24IDSellerName,
'SellerID' => $DotpayIDSeller,
'P24SellerID' => $P24DotpayIDSeller,
'moduleVersionGH' => $number,
'moduleVersion' => $this->version,
'testSellerId' => $testSellerId,
'P24testSellerId' => $P24testSellerId,
'testApiAccount' => $testGoodApiData && !$testApiAccount,
'testSellerPin' => $testGoodApiData && $testApiAccount && !$testSellerPin,
'testCorrectSellerForApi' => !$testCorrectSellerForApi,
'obsoletePlugin' => $obsoletePlugin,
'canNotCheckPlugin' => $canNotCheckPlugin,
'availableChannels' => $availableChannels
);
if ($saved === false) {
$templateData['universalErrorMessage'] = false;
}
$this->context->smarty->assign($templateData);
$paymentResource->close();
$sellerResource->close();
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output.$this->renderForm();
} catch (RuntimeException $e) {
$this->context->smarty->assign(array(
'class' => get_class($e),
'message' => $e->getMessage()
));
return $this->context->smarty->fetch($this->local_path.'views/templates/admin/error.tpl');
}
}
/**
* Create the form that will be displayed in the configuration of your module.
*/
protected function renderForm()
{
$this->context->controller->addJS($this->_path.'views/js/chooseChannel.js');
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitDotpayModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->config->getFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($this->getConfigForm()));
}
/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Module configuration'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Enable this payment module'),
'name' => 'DP_ENABLED',
'is_bool' => true,
'required' => true,
'desc' => $this->l('You can hide Przelewy24 payments without uninstalling the module'),
'values' => array(
array(
'id' => 'enabled_active_on',
'value' => true,
'label' => $this->l('Enabled')
),array(
'id' => 'enabled_active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
)
,array(
'type' => 'hidden',
'label' => '<span id="p24_migrated">🧑💻 '.$this->l('My account has already been migrated from Dotpay to Przelewy24').'</span>',
'name' => 'DP_P24_PROXY_MIGRATED',
'is_bool' => true,
'desc' => $this->l('My new panel is at:').' <a href="https://panel.przelewy24.pl/" target="_blank" '.
'title="'.$this->l('Przelewy24 Transaction Panel').'">https://panel.przelewy24.pl/</a>',
'values' => array(
array(
'id' => 'dproxy_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'dproxy_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_ID',
'prefix' => '<i style="font-weight: bold; color: #10279b; font-size: 1.4em;">#</i>',
'label' => $this->l('ID (from Dotpay Panel)'),
'hint' => $this->l('The ID is 6 digits copied from the administration panel'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-sm validate-gui',
'desc' => $this->l('Copy only number (without "#" char) from the Dotpay user panel.'),
'required' => true
),array(
'type' => 'text',
'name' => 'DP_PIN',
'prefix' => '<i class="icon-key" style="color: #10279b;"></i>',
'suffix' => '<i class="icon-eye-slash" id="eyelook" style="color: #2eacce; cursor : zoom-in;"></i>',
'label' => $this->l('PIN'),
'maxlength' => 32,
'class' => 'fixed-width-xxl validate-gui',
'desc' => $this->l('Copy from Dotpay user panel'),
'required' => true
),array(
'type' => 'switch',
'label' => '🧪 '.$this->l('Test mode'),
'name' => 'DP_TEST_MODE',
'is_bool' => true,
'desc' => $this->l('I\'m using Dotpay test account (test ID)').
'<br><b>'.$this->l('Required Dotpay test account').'</b>',
'values' => array(
array(
'id' => 'test_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'test_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'select',
'class' => 'fixed-width-xxl api-select',
'label' => $this->l('Set default currency for this account (ID)'),
'name' => 'DP_DEF_CURRENCY',
'required' => true,
'disabled' => false,
'options' => array(
'query' => array(
array(
'id_option_cyrrency' => 'PLN',
'name_option_cyrrency' => 'PLN',
),
array(
'id_option_cyrrency' => 'EUR',
'name_option_cyrrency' => 'EUR',
),
array(
'id_option_cyrrency' => 'USD',
'name_option_cyrrency' => 'USD',
),
array(
'id_option_cyrrency' => 'GBP',
'name_option_cyrrency' => 'GBP',
),
array(
'id_option_cyrrency' => 'JPY',
'name_option_cyrrency' => 'JPY',
) ,
array(
'id_option_cyrrency' => 'CZK',
'name_option_cyrrency' => 'CZK',
) ,
array(
'id_option_cyrrency' => 'SEK',
'name_option_cyrrency' => 'SEK',
) ,
array(
'id_option_cyrrency' => 'UAH',
'name_option_cyrrency' => 'UAH',
) ,
array(
'id_option_cyrrency' => 'RON',
'name_option_cyrrency' => 'RON',
) ,
array(
'id_option_cyrrency' => 'NOK',
'name_option_cyrrency' => 'NOK',
) ,
array(
'id_option_cyrrency' => 'BGN',
'name_option_cyrrency' => 'BGN',
) ,
array(
'id_option_cyrrency' => 'CHF',
'name_option_cyrrency' => 'CHF',
) ,
array(
'id_option_cyrrency' => 'HRK',
'name_option_cyrrency' => 'HRK',
) ,
array(
'id_option_cyrrency' => 'HUF',
'name_option_cyrrency' => 'HUF',
) ,
array(
'id_option_cyrrency' => 'RUB',
'name_option_cyrrency' => 'RUB',
)
),
'id' => 'id_option_cyrrency',
'name' => 'name_option_cyrrency'
),
),array(
'type' => 'switch',
'label' => $this->l('Enabling Dotpay widget'),
'name' => 'DP_WIDGET_EN',
'is_bool' => true,
'desc' => $this->l('Enable Dotpay widget on shop site').'<br><b>'.
$this->l('Disable this feature if you are using modules modifying checkout page').
'</b>',
'values' => array(
array(
'id' => 'widget_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'widget_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'radio',
'label' => '<i class="icon-AdminTools" style="color: #10279b;"></i> <span class="dev-option advanced-mode-switch dotpayadvsett">'.$this->l('Advanced Mode').'</span>',
'name' => 'DP_ADV_MODE',
'is_bool' => true,
'desc' => $this->l('Show advanced plugin settings'),
'values' => array(
array(
'id' => 'adv_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'adv_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),
array(
'type' => 'radio',
'label' => '<span class="dev-option advanced-mode-switch dotpayproxy">💻 '.$this->l('My server does not use a proxy').'</span>',
'name' => 'DP_PROXY_MODE',
'is_bool' => true,
'desc' => $this->l('By default, we recommend that you set it on (no proxy).').'<br>'.$this->l('If you are sure otherwise or you have problems receiving confirmations about the completed payment - set it to off.'),
'values' => array(
array(
'id' => 'adv_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'adv_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'radio',
'label' => $this->l('Enabling renew of payment'),
'is_bool' => true,
'class' => 'renew-enable-option',
'desc' => $this->l('Logged in clients can resume interrupted payments').'<br><b>'.
$this->l(
'Warning! Amount of renewed order will be the same as during '.
'first payment attempt'
)
.'<br>'.$this->l('(changes in product prices will not be taken into account)').'</b>',
'name' => 'DP_RENEW',
'values' => array(
array(
'id' => 'renew_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'renew_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_RENEW_DAYS',
'prefix' => '<i class="icon icon-calendar-o"></i>',
'label' => '<span class="renew-option">'.$this->l('Number of days after creating an order when is possible to renew payments').'</span>',
'size' => 3,
'maxlength' => 3,
'class' => 'fixed-width-sm',
'desc' => $this->l('Enter for how many days customers will be able to renew their payments').
'<br><b>'.$this->l('Leave blank if payment renew should not be restricted by time').
'</b>',
),array(
'type' => 'text',
'prefix' => '<i class="icon-money" style="color: #407786;"></i>',
'label' => '<span class="lastInSection">'.
$this->l('Currencies for which main channel is disabled').'</span>',
'name' => 'DP_WIDGET_CURR',
'class' => 'fixed-width-xxl',
'desc' => $this->l('Enter currency codes separated by commas, for example: EUR,USD,GBP').
'<br><b>'.
$this->l('Leave this field blank to display the channel for all currencies').'</b>',
),array(
'type' => 'switch',
'label' => $this->l('Enabling credit card channel'),
'name' => 'DP_CC',
'is_bool' => true,
'desc' => $this->l('Enable payment cards as separate channel'),
'values' => array(
array(
'id' => 'cc_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'cc_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'switch',
'label' => '<span class="lastInSection">'.$this->l('Enabling Blik channel').'</span>',
'name' => 'DP_BLIK',
'is_bool' => true,
'desc' => $this->l('Enable Blik as separate channel').'<br><b>'.
$this->l('Available only for PLN').'</b>',
'values' => array(
array(
'id' => 'blik_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'blik_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'switch',
'label' => $this->l('Enabling OneClick channel'),
'name' => 'DP_OC',
'is_bool' => true,
'desc' => $this->l('Enable payments with one click for credit card channel (248)').
'<br><b>'.$this->l('Contact Dotpay customer service before using this option').
' <a href="http://www.dotpay.pl/kontakt/biuro-obslugi-klienta/" target="_blank" '.
'title="'.$this->l('Dotpay customer service').'">'.$this->l('Contact').'</a><br>'.
$this->l('Requires Dotpay API username and password (enter below).').'</b>',
'values' => array(
array(
'id' => 'oc_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'oc_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'switch',
'label' => $this->l('Enabling refunds of payment'),
'name' => 'DP_REFUND',
'is_bool' => true,
'desc' => $this->l('Enable sending payments refund requests directly from your shop').
'<br><b>'.$this->l('Contact Dotpay customer service before using this option').
' <a href="http://www.dotpay.pl/kontakt/biuro-obslugi-klienta/" target="_blank" '.
'title="'.$this->l('Dotpay customer service').'">'.$this->l('Contact').'</a><br>'.
$this->l('Requires Dotpay API username and password (enter below).').'</b>',
'values' => array(
array(
'id' => 'refund_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'refund_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'switch',
'label' => $this->l('Payment instructions on shop site'),
'name' => 'DP_INSTR',
'is_bool' => true,
'desc' => $this->l('Display transfer payment instructions without redirecting to Dotpay site').
'<br><b>'.$this->l('Contact Dotpay customer service before using this option').
' <a href="http://www.dotpay.pl/kontakt/biuro-obslugi-klienta/" target="_blank" '.
'title="'.$this->l('Dotpay customer service').'">'.$this->l('Contact').'</a><br>'.
$this->l('Requires Dotpay API username and password (enter below).').'</b>',
'values' => array(
array(
'id' => 'instr_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'instr_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_USERNAME',
'prefix' => '<i class="icon-male" style="color: #9b6610;"></i>',
'label' => $this->l('Dotpay panel username'),
'class' => 'fixed-width-xxl',
'desc' => $this->l('Your username for Dotpay user panel')
),array(
'type' => 'text',
'name' => 'DP_PASSWORD',
'prefix' => '<i class="icon-key" style="color: #9b6610;"></i>',
'label' => $this->l('Dotpay panel password'),
'class' => 'fixed-width-xxl password-field lastInSection',
'desc' => $this->l('Your password for Dotpay user panel'),
),array(
'type' => 'radio',
'label' => $this->l('I have separate ID for foreign currencies'),
'name' => 'DP_FCC',
'is_bool' => true,
'class' => 'fcc-enable-option',
'desc' => $this->l('Enable separate payment channel for foreign currencies'),
'values' => array(
array(
'id' => 'fcc_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'fcc_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_FCC_ID',
'prefix' => '<i style="font-weight: bold; color: #407786; font-size: 1.4em;">#</i>',
'label' => $this->l('ID for foreign currencies account'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-sm fcc-option validate-gui',
'desc' => $this->l('Copy only number (without "#" char) from the Dotpay user panel.').' <div id="infoID" /></div>',
'required' => true
),array(
'type' => 'text',
'name' => 'DP_FCC_PIN',
'prefix' => '<i class="icon-key" style="color: #407786;"></i>',
'maxlength' => 32,
'label' => $this->l('PIN for foreign currencies account'),
'class' => 'fixed-width-xxl fcc-option validate-gui',
'desc' => $this->l('Copy from Dotpay user panel').' <div id="infoPIN" /></div>',
'required' => true
),array(
'type' => 'text',
'name' => 'DP_FCC_CURR',
'prefix' => '<i class="icon-money" style="color: #407786;"></i>',
'label' => $this->l('Currencies used by foreign currencies account'),
'class' => 'fixed-width-xxl fcc-option lastInSection',
'desc' => $this->l('Enter currency codes separated by commas, for example: EUR,USD,GBP').
'<br><b>'.$this->l('It is recommended to hide main channel for entered currencies').
'</b>',
),array(
'type' => 'radio',
'label' => $this->l('Information about surcharge'),
'name' => 'DP_SURCHARGE',
'is_bool' => true,
'class' => 'surcharge-enable-option',
'desc' => $this->l('Enable information about extra fee only on shop site').'<br />'.
$this->l('Enabling this option needs to configure the seller account in Dotpay').
'<br /><b>'.
$this->l('Please contact with the Dotpay Customer Service before using this option').
' '.'<a href="'.$this->l('https://www.dotpay.pl/en/contact/').'">'.
$this->l('Contact').'</a></b><br />'.
$this->l('Any value will not be add on shop site'),
'values' => array(
array(
'id' => 'surcharge_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'surcharge_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),
array(
'type' => 'text',
'name' => 'DP_SUR_AMOUNT',
'prefix' => '<i class="icon icon-money" style="color: #5498b0; font-weight: bold;"></i>',
'label' => $this->l('Show an information about increasing amount of order'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg surcharge-option validate-gui',
'desc' => $this->l('Value of additional fee for given currency (eg. 5.23)')
),array(
'type' => 'text',
'name' => 'DP_SUR_PERC',
'prefix' => '<i style="font-weight: bold; color: #5498b0; font-size: 1.4em;">%</i>',
'label' => $this->l('Show an information about increasing amount of order (in %)'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg surcharge-option lastInSection validate-gui',
'desc' => $this->l('Value of additional fee for given currency in % (eg. 1.90)').'<br><b>'.
$this->l('Bigger amount will be chosen').'</b>',
),array(
'type' => 'radio',
'label' => $this->l('Extracharge option'),
'name' => 'DP_EXCHARGE',
'is_bool' => true,
'class' => 'excharge-enable-option',
'desc' => $this->l('Enable extra fee for Dotpay payment method').'<br><b>'.
$this->l(
'Enabling this option will add required "Online payment - DOTPAYFEE" '.
'to your products'
).'</b>',
'values' => array(
array(
'id' => 'excharge_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'excharge_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_EX_AMOUNT',
'prefix' => '<i class="icon icon-money" style="color: #5498b0; font-weight: bold;"></i>',
'label' => $this->l('Increase amount of order'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg excharge-option validate-gui',
'desc' => $this->l('Value of additional fee for given currency (eg. 5.23)')
),array(
'type' => 'text',
'name' => 'DP_EX_PERC',
'prefix' => '<i style="font-weight: bold; color: #5498b0; font-size: 1.4em;">%</i>',
'label' => $this->l('Increase amount of order (in %)'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg excharge-option lastInSection validate-gui',
'desc' => $this->l('Value of additional fee for given currency in % (eg. 1.90)').'<br><b>'.
$this->l('Bigger amount will be chosen').'</b>',
),array(
'type' => 'radio',
'label' => $this->l('Discount option of shipping costs'),
'name' => 'DP_REDUCT_SHIP',
'prefix' => '<i style="font-weight: bold; color: #5498b0; font-size: 1.4em;">%</i>',
'is_bool' => true,
'class' => 'discount-enable-option',
'desc' => $this->l('Enable discount for Dotpay payment method'),
'values' => array(
array(
'id' => 'reduct_active_on',
'value' => true,
'label' => $this->l('Enable')
),array(
'id' => 'reduct_active_off',
'value' => false,
'label' => $this->l('Disable')
)
)
),array(
'type' => 'text',
'name' => 'DP_RS_AMOUNT',
'prefix' => '<i class="icon icon-money" style="color: #5498b0; font-weight: bold;"></i>',
'label' => $this->l('Reduce amount of shipping costs'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg reduct-option validate-gui',
'desc' => $this->l('Value of discount amount (in current price)')
),array(
'type' => 'text',
'name' => 'DP_RS_PERC',
'prefix' => '<i style="font-weight: bold; color: #5498b0; font-size: 1.4em;">%</i>',
'label' => $this->l('Reduce amount of shipping costs (in %)'),
'size' => 6,
'maxlength' => 6,
'class' => 'fixed-width-lg reduct-option validate-gui lastInSection',
'desc' => $this->l('Value of discount for given currency in % (eg. 1.90)').'<br><b>'.
$this->l('Bigger amount will be chosen').'</b>',
),array(
'label' => $this->l('Isolated channels on the store page'),
'type' => 'text',
'name' => 'DP_CHANNELS',
'class' => 'chosen-channel-list',
'desc' => '<button id="add-new-channel" type="button"><i class="icon icon-plus"></i> '.
$this->l('Add a new channel').'</button>'.
$this->l(
'Select which channels should be presented separately on the store page .The '.
'same order will appear on your payment page.'
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-success center-block',
),
),
);
}
/**
* Returns language code for customer language
* @return string
*/
protected function getLanguage()
{
$lang = Tools::strtolower(LanguageCore::getIsoById($this->context->cookie->id_lang));
if (in_array($lang, DotpayCustomer::$LANGUAGES)) {
return $lang;
} else {
return "en";
}
}
/**
* Save form data.
*/
protected function saveConfiguration()
{
$reductionFlagBefore = $this->config->getReduction();
$extrachargeFlagBefore = $this->config->getExtracharge();
$this->config->readFromForm()->persist();
$reductionFlagAfter = $this->config->getReduction();
$extrachargeFlagAfter = $this->config->getExtracharge();
$universalErrorMessage = false;
if ($extrachargeFlagBefore == false && $extrachargeFlagAfter == true) {
$this->checkVirtualProduct();
if ($this->config->getExtraChargeVirtualProductId() == 0) {
$universalErrorMessage = $this->l(
'The error with switching extracharge option occured. Prease try to turn it on again.'
);
}
}
if ($reductionFlagBefore == false && $reductionFlagAfter == true) {
$this->addShippingReduction();
if ($this->config->getShippingReductionId() == 0) {
$universalErrorMessage = $this->l(
'The error with switching shipping reduction occured. Prease try to turn it on again.'
);
}
}
$this->context->smarty->assign(array(
'universalErrorMessage' => $universalErrorMessage
));
}
/**
* Add the CSS & JavaScript files you want to be loaded in the Back Office.
*/
public function hookDisplayBackOfficeHeader()
{
if (Tools::getValue('controller') == 'AdminOrders') {
$this->context->controller->addJquery();
$this->context->controller->addJS($this->_path.'views/js/refunds.js');
} elseif (Tools::getValue('configure') == $this->name) {
$this->context->controller->addJquery();
$this->context->controller->addJS($this->_path.'views/js/back.js');
$this->context->controller->addCSS($this->_path.'views/css/back.css');
}
}
/**
* Add the CSS & JavaScript files you want to be added on the Front Office.
*/
public function hookDisplayHeader()
{
$this->context->controller->registerJavascript(
'jquery-transit',