This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
forked from PAYCOMET/prestashop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaytpv.php
2911 lines (2476 loc) · 114 KB
/
paytpv.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-2019 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 PAYCOMET <[email protected]>
* @copyright 2019 PAYTPV ON LINE ENTIDAD DE PAGO S.L
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
if (!defined('_PS_VERSION_')) {
exit;
}
include_once dirname(__FILE__) . '/classes/ClassRegistro.php';
include_once dirname(__FILE__) . '/classes/PaytpvTerminal.php';
include_once dirname(__FILE__) . '/classes/PaytpvOrder.php';
include_once dirname(__FILE__) . '/classes/PaytpvOrderInfo.php';
include_once dirname(__FILE__) . '/classes/PaytpvCustomer.php';
include_once dirname(__FILE__) . '/classes/PaytpvSuscription.php';
include_once dirname(__FILE__) . '/classes/PaytpvRefund.php';
include_once dirname(__FILE__) . '/classes/PaytpvPaymentsHelperForm.php';
include_once dirname(__FILE__) . '/classes/PaycometApiRest.php';
class Paytpv extends PaymentModule
{
private $html = '';
private $postErrors = array();
public function __construct()
{
$this->name = 'paytpv';
$this->tab = 'payments_gateways';
$this->author = 'Paycomet';
$this->version = '7.6.2';
$this->module_key = 'deef285812f52026197223a4c07221c4';
$this->is_eu_compatible = 1;
$this->ps_versions_compliancy = array('min' => '1.7');
$this->controllers = array('payment', 'validation');
$this->bootstrap = true;
// Array config: configuration values
$config = $this->getConfigValues();
$this->url_paytpv = "https://api.paycomet.com/gateway/ifr-bankstore";
$this->endpoint_paytpv = "https://api.paycomet.com/gateway/xml-bankstore";
$this->jet_paytpv = "https://api.paycomet.com/gateway/paycomet.jetiframe.js";
if (isset($config['PAYTPV_INTEGRATION'])) {
$this->integration = $config['PAYTPV_INTEGRATION'];
}
if (isset($config['PAYTPV_CLIENTCODE'])) {
$this->clientcode = $config['PAYTPV_CLIENTCODE'];
}
if (array_key_exists('PAYTPV_APIKEY', $config)) {
$this->apikey = $config['PAYTPV_APIKEY'];
}
if (isset($config['PAYTPV_NEWPAGEPAYMENT'])) {
$this->newpage_payment = $config['PAYTPV_NEWPAGEPAYMENT'];
}
if (array_key_exists('PAYTPV_IFRAME_HEIGHT', $config) && $config['PAYTPV_IFRAME_HEIGHT']>=440) {
$this->iframe_height = $config['PAYTPV_IFRAME_HEIGHT'];
} else {
$this->iframe_height = "440"; // Valor por defecto
}
if (isset($config['PAYTPV_SUSCRIPTIONS'])) {
$this->suscriptions = $config['PAYTPV_SUSCRIPTIONS'];
}
if (isset($config['PAYTPV_REG_ESTADO'])) {
$this->reg_estado = $config['PAYTPV_REG_ESTADO'];
}
if (isset($config['PAYTPV_FIRSTPURCHASE_SCORING'])) {
$this->firstpurchase_scoring = $config['PAYTPV_FIRSTPURCHASE_SCORING'];
}
if (isset($config['PAYTPV_FIRSTPURCHASE_SCORING_SCO'])) {
$this->firstpurchase_scoring_score = $config['PAYTPV_FIRSTPURCHASE_SCORING_SCO'];
}
if (isset($config['PAYTPV_SESSIONTIME_SCORING'])) {
$this->sessiontime_scoring = $config['PAYTPV_SESSIONTIME_SCORING'];
}
if (isset($config['PAYTPV_SESSIONTIME_SCORING_VAL'])) {
$this->sessiontime_scoring_val = $config['PAYTPV_SESSIONTIME_SCORING_VAL'];
}
if (isset($config['PAYTPV_SESSIONTIME_SCORING_SCORE'])) {
$this->sessiontime_scoring_score = $config['PAYTPV_SESSIONTIME_SCORING_SCORE'];
}
if (isset($config['PAYTPV_DCOUNTRY_SCORING'])) {
$this->dcountry_scoring = $config['PAYTPV_DCOUNTRY_SCORING'];
}
if (isset($config['PAYTPV_DCOUNTRY_SCORING_VAL'])) {
$this->dcountry_scoring_val = $config['PAYTPV_DCOUNTRY_SCORING_VAL'];
}
if (isset($config['PAYTPV_DCOUNTRY_SCORING_SCORE'])) {
$this->dcountry_scoring_score = $config['PAYTPV_DCOUNTRY_SCORING_SCORE'];
}
if (isset($config['PAYTPV_IPCHANGE_SCORING'])) {
$this->ip_change_scoring = $config['PAYTPV_IPCHANGE_SCORING'];
}
if (isset($config['PAYTPV_IPCHANGE_SCORING_SCORE'])) {
$this->ip_change_scoring_score = $config['PAYTPV_IPCHANGE_SCORING_SCORE'];
}
if (isset($config['PAYTPV_BROWSER_SCORING'])) {
$this->browser_scoring = $config['PAYTPV_BROWSER_SCORING'];
}
if (isset($config['PAYTPV_BROWSER_SCORING_SCORE'])) {
$this->browser_scoring_score = $config['PAYTPV_BROWSER_SCORING_SCORE'];
}
if (isset($config['PAYTPV_SO_SCORING'])) {
$this->so_scoring = $config['PAYTPV_SO_SCORING'];
}
if (isset($config['PAYTPV_SO_SCORING_SCORE'])) {
$this->so_scoring_score = $config['PAYTPV_SO_SCORING_SCORE'];
}
if (isset($config['PAYTPV_DISABLEOFFERSAVECARD'])) {
$this->disableoffersavecard = $config['PAYTPV_DISABLEOFFERSAVECARD'];
}
parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Paycomet');
$this->description = $this->l('This module allows you to accept card payments via www.paycomet.com');
try {
if (!isset($this->clientcode) or !PaytpvTerminal::existTerminal()) {
$this->warning = $this->l('Missing data when configuring the module PAYCOMET');
}
} catch (exception $e) {
}
}
public function runUpgradeModule()
{
parent::runUpgradeModule();
}
public function install()
{
include_once(_PS_MODULE_DIR_ . '/' . $this->name . '/paytpv_install.php');
$paypal_install = new PayTpvInstall();
$res = $paypal_install->createTables();
if (!$res) {
$this->error = $this->l('Missing data when configuring the module PAYCOMET');
return false;
}
$paypal_install->updateConfiguration();
// Valores por defecto al instalar el módulo
if (!parent::install() ||
!$this->registerHook('displayPayment') ||
!$this->registerHook('displayPaymentTop') ||
!$this->registerHook('displayPaymentReturn') ||
!$this->registerHook('displayMyAccountBlock') ||
!$this->registerHook('displayAdminOrder') ||
!$this->registerHook('displayCustomerAccount') ||
!$this->registerHook('actionProductCancel') ||
!$this->registerHook('displayShoppingCart') ||
!$this->registerHook('paymentOptions') ||
!$this->registerHook('actionFrontControllerSetMedia') ||
!$this->registerHook('header')
|| !$this->registerHook('displayOrderConfirmation')
) {
return false;
}
return true;
}
public function uninstall()
{
include_once(_PS_MODULE_DIR_ . '/' . $this->name . '/paytpv_install.php');
$paypal_install = new PayTpvInstall();
$paypal_install->deleteConfiguration();
return parent::uninstall();
}
public function getPath()
{
return $this->_path;
}
private function postValidation()
{
// Show error when required fields.
if (Tools::getIsset('btnSubmit')) {
if (!Tools::getIsset('clientcode')) {
$this->postErrors[] = $this->l('Client Code required');
}
if (!Tools::getIsset('pass')) {
$this->postErrors[] = $this->l('User Password required');
}
if (Tools::getValue('newpage_payment') != 2
&& (!filter_var(Tools::getValue('iframe_height'), FILTER_VALIDATE_INT) ||
Tools::getValue('iframe_height') < 440)
) {
$this->postErrors[] = $this->l('The height of the iframe must be at least 440');
}
// Check Terminal empty fields SECURE
foreach (Tools::getValue('term') as $key => $term) {
if ((Tools::getValue('terminales')[$key] == 0 ||
Tools::getValue('terminales')[$key] == 2) && ($term == "" || !is_numeric($term))) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [3D SECURE] " .
$this->l('Terminal number invalid');
}
if ((Tools::getValue('terminales')[$key] == 0 ||
Tools::getValue('terminales')[$key] == 2) && Tools::getValue('pass')[$key] == "") {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [3D SECURE] " .
$this->l('Password invalid');
}
if ((Tools::getValue('terminales')[$key] == 0 ||
Tools::getValue('terminales')[$key] == 2) && Tools::getValue('jetid')[$key] == "" &&
Tools::getValue('integration') == 1) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [3D SECURE] " .
$this->l('JET ID number invalid');
}
}
// Check Terminal empty fields NO SECURE
foreach (Tools::getValue('term_ns') as $key => $term_ns) {
if ((Tools::getValue('terminales')[$key] == 1 ||
Tools::getValue('terminales')[$key] == 2) && ($term_ns == "" || !is_numeric($term_ns))) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [NO 3D SECURE] " .
$this->l('Terminal number invalid');
}
if ((Tools::getValue('terminales')[$key] == 1 ||
Tools::getValue('terminales')[$key] == 2) && Tools::getValue('pass_ns')[$key] == "") {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [NO 3D SECURE] " .
$this->l('Password invalid');
}
if ((Tools::getValue('terminales')[$key] == 1 ||
Tools::getValue('terminales')[$key] == 2) &&
Tools::getValue('jetid_ns')[$key] == "" &&
Tools::getValue('integration') == 1) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. [NO 3D SECURE] " .
$this->l('JET ID number invalid');
}
}
// Check 3Dmin and Currency
foreach (Tools::getValue('term_ns') as $key => $term_ns) {
if (Tools::getValue('terminales')[$key] == 2 &&
(Tools::getValue('tdmin')[$key] != "" &&
!is_numeric(Tools::getValue('tdmin')[$key]))) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. " .
$this->l('Use 3D Secure on purchases over invalid');
}
if (empty(Tools::getValue('moneda')[$key])) {
$this->postErrors[] = $this->l('Terminal') . " " . ($key + 1) . "º. " .
$this->l('Currency required');
}
}
// Check Duplicate Terms
$arrTerminales = array_unique(Tools::getValue('term'));
if (sizeof($arrTerminales) != sizeof(Tools::getValue('term'))) {
$this->postErrors[] = $this->l('Duplicate Terminals');
}
// Check Duplicate Currency
$arrMonedas = array_unique(Tools::getValue('moneda'));
if (sizeof($arrMonedas) != sizeof(Tools::getValue('moneda'))) {
$this->postErrors[] = $this->l('Duplicate Currency. Specify a different currency for each terminal');
}
// Si no hay errores previos se contrastan los datos
if (!sizeof($this->postErrors)) {
$arrValidatePaycomet = $this->validatePaycomet();
if ($arrValidatePaycomet["error"] != 0) {
$this->postErrors[] = $arrValidatePaycomet["error_txt"];
}
}
}
}
private function validatePaycomet()
{
include_once(_PS_MODULE_DIR_ . '/paytpv/classes/PaytpvApi.php');
$api = new PaytpvApi();
$arrDatos = array();
$arrDatos["error"] = 0;
// Validación de los datos en Paycomet
foreach (array_keys(Tools::getValue("term")) as $key) {
$term = (Tools::getValue('term')[$key] == '') ? "" : Tools::getValue('term')[$key];
$term_ns = (Tools::getValue('term_ns')[$key] == '') ? "" : Tools::getValue('term_ns')[$key];
switch (Tools::getValue("terminales")[$key]) {
case 0: // Seguro
$terminales_txt = $this->l('Secure');
$resp = $api->validatePaycomet(
Tools::getValue('clientcode'),
$term,
Tools::getValue("pass")[$key],
"CES"
);
break;
case 1: // No Seguro
$terminales_txt = $this->l('Non-Secure');
$resp = $api->validatePaycomet(
Tools::getValue('clientcode'),
$term_ns,
Tools::getValue("pass_ns")[$key],
"NO-CES"
);
break;
case 2: // Ambos
$terminales_txt = $this->l('Both');
$resp = $api->validatePaycomet(
Tools::getValue('clientcode'),
$term,
Tools::getValue("pass")[$key],
"BOTH"
);
break;
}
if ($resp["DS_RESPONSE"] != 1) {
$arrDatos["error"] = 1;
switch ($resp["DS_ERROR_ID"]) {
case 1121: // No se encuentra el cliente
case 1130: // No se encuentra el producto
case 1003: // Credenciales inválidas
case 127: // Parámetro no válido.
$arrDatos["error_txt"] = $this->l('Check that the Client Code, Terminal and Password are correct.');
break;
case 1337: // Ruta de notificación no configurada
$arrDatos["error_txt"] = $this->l('Notification URL is not defined in the product configuration of your account PAYCOMET account.');
break;
case 28: // Curl
case 1338: // Ruta de notificación no responde correctamente
$ssl = Configuration::get('PS_SSL_ENABLED');
$arrDatos["error_txt"] = $this->l('The notification URL defined in the product configuration of your PAYCOMET account does not respond correctly. Verify that it has been defined as: ')
. Context::getContext()->link->getModuleLink($this->name, 'url', array(), $ssl);
break;
case 1339: // Configuración de terminales incorrecta
$arrDatos["error_txt"] = $this->l('Your Product in PAYCOMET account is not set up with the Available Terminals option: ')
. $terminales_txt;
break;
}
}
}
return $arrDatos;
}
private function postProcess()
{
// Update databse configuration
if (Tools::getIsset('btnSubmit')) {
Configuration::updateValue('PAYTPV_CLIENTCODE', Tools::getValue('clientcode'));
Configuration::updateValue('PAYTPV_APIKEY', trim(Tools::getValue('apikey')));
Configuration::updateValue('PAYTPV_NEWPAGEPAYMENT', Tools::getValue('newpage_payment'));
Configuration::updateValue('PAYTPV_IFRAME_HEIGHT', Tools::getValue('iframe_height'));
Configuration::updateValue('PAYTPV_SUSCRIPTIONS', Tools::getValue('suscriptions'));
Configuration::updateValue('PAYTPV_INTEGRATION', Tools::getValue('integration'));
// Save Paytpv Terminals
PaytpvTerminal::removeTerminals();
foreach (array_keys(Tools::getValue("term")) as $key) {
$aux_tdmin =
(Tools::getValue('tdmin')[$key]=='' || Tools::getValue("terminales")[$key]!=2) ? 0 :
Tools::getValue('tdmin')[$key];
$aux_term = (Tools::getValue('term')[$key]=='')?"":Tools::getValue('term')[$key];
$aux_term_ns =
(Tools::getValue('term_ns')[$key]=='')?"":Tools::getValue('term_ns')[$key];
PaytpvTerminal::addTerminal(
$key+1,
$aux_term,
$aux_term_ns,
Tools::getValue("pass")[$key],
Tools::getValue("pass_ns")[$key],
Tools::getValue("jetid")[$key],
Tools::getValue("jetid_ns")[$key],
Tools::getValue("moneda")[$key],
Tools::getValue("terminales")[$key],
Tools::getValue("tdfirst")[$key],
$aux_tdmin
);
}
// Datos Scoring
Configuration::updateValue('PAYTPV_FIRSTPURCHASE_SCORING', Tools::getValue('firstpurchase_scoring'));
Configuration::updateValue(
'PAYTPV_FIRSTPURCHASE_SCORING_SCO',
Tools::getValue('firstpurchase_scoring_score')
);
Configuration::updateValue('PAYTPV_SESSIONTIME_SCORING', Tools::getValue('sessiontime_scoring'));
Configuration::updateValue('PAYTPV_SESSIONTIME_SCORING_VAL', Tools::getValue('sessiontime_scoring_val'));
Configuration::updateValue(
'PAYTPV_SESSIONTIME_SCORING_SCORE',
Tools::getValue('sessiontime_scoring_score')
);
Configuration::updateValue('PAYTPV_DCOUNTRY_SCORING', Tools::getValue('dcountry_scoring'));
Configuration::updateValue(
'PAYTPV_DCOUNTRY_SCORING_VAL',
Tools::getIsset('dcountry_scoring_val') ? implode(",", Tools::getValue('dcountry_scoring_val')) : ''
);
Configuration::updateValue('PAYTPV_DCOUNTRY_SCORING_SCORE', Tools::getValue('dcountry_scoring_score'));
Configuration::updateValue('PAYTPV_IPCHANGE_SCORING', Tools::getValue('ip_change_scoring'));
Configuration::updateValue('PAYTPV_IPCHANGE_SCORING_SCORE', Tools::getValue('ip_change_scoring_score'));
Configuration::updateValue('PAYTPV_BROWSER_SCORING', Tools::getValue('browser_scoring'));
Configuration::updateValue('PAYTPV_BROWSER_SCORING_SCORE', Tools::getValue('browser_scoring_score'));
Configuration::updateValue('PAYTPV_SO_SCORING', Tools::getValue('so_scoring'));
Configuration::updateValue('PAYTPV_SO_SCORING_SCORE', Tools::getValue('so_scoring_score'));
Configuration::updateValue('PAYTPV_DISABLEOFFERSAVECARD', Tools::getValue('disableoffersavecard'));
return '<div class="bootstrap"><div class="alert alert-success">' . $this->l('Configuration updated') .
'</div></div>';
}
}
public function transactionScore($cart)
{
include_once(_PS_MODULE_DIR_ . '/paytpv/classes/PaytpvApi.php');
$api = new PaytpvApi();
$config = $this->getConfigValues();
// Initialize array Score
$arrScore = array();
$arrScore["score"] = null;
$arrScore["scoreCalc"] = null;
$shipping_address_country = "";
$shippingAddressData = new Address($cart->id_address_delivery);
if ($shippingAddressData) {
$address_country = new Country($shippingAddressData->id_country);
$shipping_address_country = $address_country->iso_code;
}
// First Purchase
if ($config["PAYTPV_FIRSTPURCHASE_SCORING"]) {
$firstpurchase_scoring_score = $config["PAYTPV_FIRSTPURCHASE_SCORING_SCO"];
if (PaytpvOrder::isFirstPurchaseCustomer($this->context->customer->id)) {
$arrScore["scoreCalc"]["firstpurchase"] = $firstpurchase_scoring_score;
}
}
// Complete Session Time
if ($config["PAYTPV_SESSIONTIME_SCORING"]) {
$sessiontime_scoring_val = $config["PAYTPV_SESSIONTIME_SCORING_VAL"];
$sessiontime_scoring_score = $config["PAYTPV_SESSIONTIME_SCORING_SCORE"];
$cookie = $this->context->cookie;
if ($cookie && $cookie->id_connections) {
$connection = new Connection($cookie->id_connections);
$first_visit_at = $connection->date_add;
$now = date('Y-m-d H:i:s');
$time_ss = strtotime($now) - strtotime($first_visit_at);
$time_mm = floor($time_ss / 60);
if ($time_mm > $sessiontime_scoring_val) {
$arrScore["scoreCalc"]["completesessiontime"] = $sessiontime_scoring_score;
}
}
}
// Destination
if ($config["PAYTPV_DCOUNTRY_SCORING"]) {
$dcountry_scoring_val = explode(",", $config["PAYTPV_DCOUNTRY_SCORING_VAL"]);
$dcountry_scoring_score = $config["PAYTPV_DCOUNTRY_SCORING_SCORE"];
if (in_array($shipping_address_country, $dcountry_scoring_val)) {
$arrScore["scoreCalc"]["destination"] = $dcountry_scoring_score;
}
}
// Ip Change
if ($config["PAYTPV_IPCHANGE_SCORING"]) {
$connection = new Connection($cookie->id_connections);
$ip_change_scoring = $config["PAYTPV_IPCHANGE_SCORING_SCORE"];
$ip = Tools::getRemoteAddr() ? (int) ip2long(Tools::getRemoteAddr()) : '';
$ip_session = $connection->ip_address ? (int) ip2long($connection->ip_address) : '';
if ($ip != $ip_session) {
$arrScore["scoreCalc"]["ipchange"] = $ip_change_scoring;
}
}
// Browser Unidentified
if ($config["PAYTPV_BROWSER_SCORING"]) {
$browser_scoring_score = $config["PAYTPV_BROWSER_SCORING_SCORE"];
if ($api->browserDetection('browser_name') == "") {
$arrScore["scoreCalc"]["browser_unidentified"] = $browser_scoring_score;
}
}
// Operating System Unidentified
if ($config["PAYTPV_SO_SCORING"]) {
$so_scoring_score = $config["PAYTPV_SO_SCORING_SCORE"];
if ($api->browserDetection('os') == "") {
$arrScore["scoreCalc"]["operating_system_unidentified"] = $so_scoring_score;
}
}
// CALC ORDER SCORE
if (isset($arrScore["scoreCalc"]) && sizeof($arrScore["scoreCalc"]) > 0) {
//$score = floor(array_sum($arrScore["scoreCalc"]) / sizeof($arrScore["scoreCalc"])); // Media
$score = floor(array_sum($arrScore["scoreCalc"])); // Suma de valores. Si es superior a 100 asignamos 100
if ($score > 100) {
$score = 100;
}
$arrScore["score"] = $score;
}
return $arrScore;
}
public function threeDSRequestorAuthenticationInfo()
{
$customerStats = $this->context->customer->getStats();
$threeDSReqAuthTimestamp = strftime('%Y%m%d%H%M', strtotime($customerStats['last_visit']));
$threeDSRequestorAuthenticationInfo = array();
$threeDSRequestorAuthenticationInfo["threeDSReqAuthData"] = "";
$logged = $this->context->customer->isLogged();
$threeDSRequestorAuthenticationInfo["threeDSReqAuthMethod"] = ($logged) ? "02" : "01";
$threeDSRequestorAuthenticationInfo["threeDSReqAuthTimestamp"] = $threeDSReqAuthTimestamp;
return $threeDSRequestorAuthenticationInfo;
}
public function acctInfo($cart)
{
$acctInfoData = array();
$date_now = new DateTime("now");
$isGuest = $this->context->customer->isGuest();
if ($isGuest) {
$acctInfoData["chAccAgeInd"] = "01";
} else {
$date_customer = new DateTime(strftime('%Y%m%d', strtotime($this->context->customer->date_add)));
$diff = $date_now->diff($date_customer);
$dias = $diff->days;
if ($dias == 0) {
$acctInfoData["chAccAgeInd"] = "02";
} elseif ($dias < 30) {
$acctInfoData["chAccAgeInd"] = "03";
} elseif ($dias < 60) {
$acctInfoData["chAccAgeInd"] = "04";
} else {
$acctInfoData["chAccAgeInd"] = "05";
}
}
$acctInfoData["chAccChange"] = strftime('%Y%m%d', strtotime($this->context->customer->date_upd));
$date_customer_upd = new DateTime(strftime('%Y%m%d', strtotime($this->context->customer->date_upd)));
$diff = $date_now->diff($date_customer_upd);
$dias_upd = $diff->days;
if ($dias_upd == 0) {
$acctInfoData["chAccChangeInd"] = "01";
} elseif ($dias_upd < 30) {
$acctInfoData["chAccChangeInd"] = "02";
} elseif ($dias_upd < 60) {
$acctInfoData["chAccChangeInd"] = "03";
} else {
$acctInfoData["chAccChangeInd"] = "04";
}
$acctInfoData["chAccDate"] = strftime('%Y%m%d', strtotime($this->context->customer->date_upd));
//$acctInfoData["chAccPwChange"] = "";
//$acctInfoData["chAccPwChangeInd"] = "";
$acctInfoData["nbPurchaseAccount"] = PaytpvOrder::numPurchaseCustomer(
$this->context->customer->id,
1,
6,
"MONTH"
);
//$acctInfoData["provisionAttemptsDay"] = "";
$acctInfoData["txnActivityDay"] = PaytpvOrder::numPurchaseCustomer(
$this->context->customer->id,
0,
1,
"DAY"
);
$acctInfoData["txnActivityYear"] = PaytpvOrder::numPurchaseCustomer(
$this->context->customer->id,
0,
1,
"YEAR"
);
//$acctInfoData["paymentAccAge"] = "";
//$acctInfoData["paymentAccInd"] = "";
$firstAddressDelivery = PaytpvOrder::firstAddressDelivery(
$this->context->customer->id,
$cart->id_address_delivery
);
if ($firstAddressDelivery != "") {
$acctInfoData["shipAddressUsage"] = date("Ymd", strtotime($firstAddressDelivery));
$date_firstAddressDelivery = new DateTime(strftime('%Y%m%d', strtotime($firstAddressDelivery)));
$diff = $date_now->diff($date_firstAddressDelivery);
$dias_firstAddressDelivery = $diff->days;
if ($dias_firstAddressDelivery == 0) {
$acctInfoData["shipAddressUsageInd"] = "01";
} elseif ($dias_upd < 30) {
$acctInfoData["shipAddressUsageInd"] = "02";
} elseif ($dias_upd < 60) {
$acctInfoData["shipAddressUsageInd"] = "03";
} else {
$acctInfoData["shipAddressUsageInd"] = "04";
}
}
// Shiping info
$shipping = new Address($cart->id_address_delivery);
if (($this->context->customer->firstname != $shipping->firstname) ||
($this->context->customer->lastname != $shipping->lastname)
) {
$acctInfoData["shipNameIndicator"] = "02";
} else {
$acctInfoData["shipNameIndicator"] = "01";
}
$acctInfoData["suspiciousAccActivity"] = "01";
return $acctInfoData;
}
public function getShoppingCart($cart)
{
$shoppingCartData = array();
foreach ($cart->getProducts() as $key => $product) {
$shoppingCartData[$key]["sku"] = $product["reference"];
$shoppingCartData[$key]["quantity"] = $product["cart_quantity"];
$shoppingCartData[$key]["unitPrice"] = number_format($product["price"] * 100, 0, '.', '');
$shoppingCartData[$key]["name"] = $product["name"];
$shoppingCartData[$key]["category"] = $product["category"];
}
return array("shoppingCart" => array_values($shoppingCartData));
}
public function isoCodeToNumber($code)
{
$arrCode = array(
"AF" => "004", "AX" => "248", "AL" => "008", "DE" => "276", "AD" => "020", "AO" => "024", "AI" => "660",
"AQ" => "010", "AG" => "028", "SA" => "682", "DZ" => "012", "AR" => "032", "AM" => "051", "AW" => "533",
"AU" => "036", "AT" => "040", "AZ" => "031", "BS" => "044", "BD" => "050", "BB" => "052", "BH" => "048",
"BE" => "056", "BZ" => "084", "BJ" => "204", "BM" => "060", "BY" => "112", "BO" => "068", "BQ" => "535",
"BA" => "070", "BW" => "072", "BR" => "076", "BN" => "096", "BG" => "100", "BF" => "854", "BI" => "108",
"BT" => "064", "CV" => "132", "KH" => "116", "CM" => "120", "CA" => "124", "QA" => "634", "TD" => "148",
"CL" => "52", "CN" => "156", "CY" => "196", "CO" => "170", "KM" => "174", "KP" => "408", "KR" => "410",
"CI" => "384", "CR" => "188", "HR" => "191", "CU" => "192", "CW" => "531", "DK" => "208", "DM" => "212",
"EC" => "218", "EG" => "818", "SV" => "222", "AE" => "784", "ER" => "232", "SK" => "703", "SI" => "705",
"ES" => "724", "US" => "840", "EE" => "233", "ET" => "231", "PH" => "608", "FI" => "246", "FJ" => "242",
"FR" => "250", "GA" => "266", "GM" => "270", "GE" => "268", "GH" => "288", "GI" => "292", "GD" => "308",
"GR" => "300", "GL" => "304", "GP" => "312", "GU" => "316", "GT" => "320", "GF" => "254", "GG" => "831",
"GN" => "324", "GW" => "624", "GQ" => "226", "GY" => "328", "HT" => "332", "HN" => "340", "HK" => "344",
"HU" => "348", "IN" => "356", "ID" => "360", "IQ" => "368", "IR" => "364", "IE" => "372", "BV" => "074",
"IM" => "833", "CX" => "162", "IS" => "352", "KY" => "136", "CC" => "166", "CK" => "184", "FO" => "234",
"GS" => "239", "HM" => "334", "FK" => "238", "MP" => "580", "MH" => "584", "PN" => "612", "SB" => "090",
"TC" => "796", "UM" => "581", "VG" => "092", "VI" => "850", "IL" => "376", "IT" => "380", "JM" => "388",
"JP" => "392", "JE" => "832", "JO" => "400", "KZ" => "398", "KE" => "404", "KG" => "417", "KI" => "296",
"KW" => "414", "LA" => "418", "LS" => "426", "LV" => "428", "LB" => "422", "LR" => "430", "LY" => "434",
"LI" => "438", "LT" => "440", "LU" => "442", "MO" => "446", "MK" => "807", "MG" => "450", "MY" => "458",
"MW" => "454", "MV" => "462", "ML" => "466", "MT" => "470", "MA" => "504", "MQ" => "474", "MU" => "480",
"MR" => "478", "YT" => "175", "MX" => "484", "FM" => "583", "MD" => "498", "MC" => "492", "MN" => "496",
"ME" => "499", "MS" => "500", "MZ" => "508", "MM" => "104", "NA" => "516", "NR" => "520", "NP" => "524",
"NI" => "558", "NE" => "562", "NG" => "566", "NU" => "570", "NF" => "574", "NO" => "578", "NC" => "540",
"NZ" => "554", "OM" => "512", "NL" => "528", "PK" => "586", "PW" => "585", "PS" => "275", "PA" => "591",
"PG" => "598", "PY" => "600", "PE" => "604", "PF" => "258", "PL" => "616", "PT" => "620", "PR" => "630",
"GB" => "826", "EH" => "732", "CF" => "140", "CZ" => "203", "CG" => "178", "CD" => "180", "DO" => "214",
"RE" => "638", "RW" => "646", "RO" => "642", "RU" => "643", "WS" => "882", "AS" => "016", "BL" => "652",
"KN" => "659", "SM" => "674", "MF" => "663", "PM" => "666", "VC" => "670", "SH" => "654", "LC" => "662",
"ST" => "678", "SN" => "686", "RS" => "688", "SC" => "690", "SL" => "694", "SG" => "702", "SX" => "534",
"SY" => "760", "SO" => "706", "LK" => "144", "SZ" => "748", "ZA" => "710", "SD" => "729", "SS" => "728",
"SE" => "752", "CH" => "756", "SR" => "740", "SJ" => "744", "TH" => "764", "TW" => "158", "TZ" => "834",
"TJ" => "762", "IO" => "086", "TF" => "260", "TL" => "626", "TG" => "768", "TK" => "772", "TO" => "776",
"TT" => "780", "TN" => "788", "TM" => "795", "TR" => "792", "TV" => "798", "UA" => "804", "UG" => "800",
"UY" => "858", "UZ" => "860", "VU" => "548", "VA" => "336", "VE" => "862", "VN" => "704", "WF" => "876",
"YE" => "887", "DJ" => "262", "ZM" => "894", "ZW" => "716");
return $arrCode[$code];
}
public function getEMV3DS($cart)
{
$Merchant_EMV3DS = array();
$Merchant_EMV3DS["customer"]["id"] = $this->context->customer->id;
$Merchant_EMV3DS["customer"]["name"] = $this->context->customer->firstname;
$Merchant_EMV3DS["customer"]["surname"] = $this->context->customer->lastname;
$Merchant_EMV3DS["customer"]["email"] = $this->context->customer->email;
// Billing info
$billing = new Address((int) $cart->id_address_invoice);
if ($billing) {
$billing_address_country = new Country($billing->id_country);
$billing_address_state = new State($billing->id_state);
$Merchant_EMV3DS["billing"]["billAddrCity"] = ($billing) ? $billing->city : "";
$Merchant_EMV3DS["billing"]["billAddrCountry"] = ($billing) ? $billing_address_country->iso_code : "";
if ($Merchant_EMV3DS["billing"]["billAddrCountry"] != "") {
$Merchant_EMV3DS["billing"]["billAddrCountry"] =
$this->isoCodeToNumber($Merchant_EMV3DS["billing"]["billAddrCountry"]);
}
$Merchant_EMV3DS["billing"]["billAddrLine1"] = ($billing) ? $billing->address1 : "";
$Merchant_EMV3DS["billing"]["billAddrLine2"] = ($billing) ? $billing->address2 : "";
//$Merchant_EMV3DS["billing"]["billAddrLine3"] = "";
$Merchant_EMV3DS["billing"]["billAddrPostCode"] = ($billing) ? $billing->postcode : "";
if ($billing_address_state->iso_code != "") {
$billAddState = explode("-", $billing_address_state->iso_code);
$billAddState = end($billAddState);
$Merchant_EMV3DS["billing"]["billAddrState"] = $billAddState;
}
$arrDatosHomePhone = array();
if ($billing->phone) {
$arrDatosHomePhone["cc"] = $billing_address_country->call_prefix;
$suscriber_phone = preg_replace('/[^0-9]/', '', $billing->phone);
$arrDatosHomePhone["subscriber"] = $suscriber_phone;
$Merchant_EMV3DS["customer"]["homePhone"] = $arrDatosHomePhone;
}
$arrDatosMobilePhone = array();
if ($billing->phone_mobile) {
$arrDatosMobilePhone["cc"] = $billing_address_country->call_prefix;
$suscriber_phone_mobile = preg_replace('/[^0-9]/', '', $billing->phone_mobile);
$arrDatosMobilePhone["subscriber"] = $suscriber_phone_mobile;
$Merchant_EMV3DS["customer"]["mobilePhone"] = $arrDatosMobilePhone;
}
}
// Shiping info
$shipping = new Address($cart->id_address_delivery);
if ($shipping) {
$shipping_address_country = new Country($shipping->id_country);
$shipping_address_state = new State($shipping->id_state);
$Merchant_EMV3DS["shipping"]["shipAddrCity"] = ($shipping) ? $shipping->city : "";
$Merchant_EMV3DS["shipping"]["shipAddrCountry"] = ($shipping) ? $shipping_address_country->iso_code : "";
if ($Merchant_EMV3DS["shipping"]["shipAddrCountry"] != "") {
$Merchant_EMV3DS["shipping"]["shipAddrCountry"] =
$this->isoCodeToNumber($Merchant_EMV3DS["shipping"]["shipAddrCountry"]);
}
$Merchant_EMV3DS["shipping"]["shipAddrLine1"] = ($shipping) ? $shipping->address1 : "";
$Merchant_EMV3DS["shipping"]["shipAddrLine2"] = ($shipping) ? $shipping->address2 : "";
//$Merchant_EMV3DS["shipping"]["shipAddrLine3"] = "";
$Merchant_EMV3DS["shipping"]["shipAddrPostCode"] = ($shipping) ? $shipping->postcode : "";
if ($shipping_address_state->iso_code != "") {
$shipAddrState = explode("-", $shipping_address_state->iso_code);
$shipAddrState = end($shipAddrState);
$Merchant_EMV3DS["shipping"]["shipAddrState"] = $shipAddrState;
}
$arrDatosWorkPhone = array();
if ($shipping->phone) {
$arrDatosWorkPhone["cc"] = $billing_address_country->call_prefix;
$arrDatosWorkPhone["subscriber"] = $shipping->phone;
$Merchant_EMV3DS["customer"]["workPhone"] = $arrDatosWorkPhone;
}
}
// acctInfo
$Merchant_EMV3DS["acctInfo"] = $this->acctInfo($cart);
// threeDSRequestorAuthenticationInfo
$Merchant_EMV3DS["threeDSRequestorAuthenticationInfo"] = $this->threeDSRequestorAuthenticationInfo();
// AddrMatch
$Merchant_EMV3DS["addrMatch"] = ($cart->id_address_invoice == $cart->id_address_delivery) ? "Y" : "N";
$Merchant_EMV3DS["challengeWindowSize"] = 05;
return $Merchant_EMV3DS;
}
public function getContent()
{
$errorMessage = '';
if (!empty($_POST)) {
$this->postValidation();
if (!sizeof($this->postErrors)) {
$errorMessage = $this->postProcess();
} else {
$errorMessage .= '<div class="bootstrap"><div class="alert alert-danger"><strong>' .
$this->l('Error') . '</strong><ol>';
foreach ($this->postErrors as $err) {
$errorMessage .= '<li>' . $err . '</li>';
}
$errorMessage .= '</ol></div></div>';
}
} else {
$errorMessage = '';
}
if (Tools::isSubmit('id_cart')) {
$this->validateOrder(
Tools::getValue('id_cart'),
_PS_OS_PAYMENT_,
Tools::getValue('amount'),
$this->displayName,
null
);
}
if (Tools::isSubmit('id_registro')) {
ClassRegistro::remove(Tools::getValue('id_registro'));
}
$this->currency_array = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
$this->countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
} else {
$this->countries = Country::getCountries($this->context->language->id, true);
}
$this->terminales_paytpv = $this->obtenerTerminalesConfigurados();
$ssl = Configuration::get('PS_SSL_ENABLED');
$this->context->smarty->assign(
'NOTIFICACION',
Context::getContext()->link->getModuleLink($this->name, 'url', array(), $ssl)
);
$this->context->smarty->assign('displayName', Tools::safeOutput($this->displayName));
$this->context->smarty->assign('description', Tools::safeOutput($this->description));
$this->context->smarty->assign('errorMessage', $errorMessage);
$this->context->controller->addJS($this->_path . 'views/js/admin.js', 'all');
$this->context->controller->addCSS($this->_path . 'views/css/admin.css', 'all');
$this->context->smarty->assign('configform', str_replace('</form>', '', $this->displayForm()));
$output = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/admin.tpl');
return $output;
}
private function displayForm()
{
$helper = new PaytpvPaymentsHelperForm();
$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 = 'submitPaytpvpaymentsModule';
$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->getConfigFormValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generatePaytpvForm($this->context->smarty, $this->getConfigForm());
}
public function getConfigFormValues()
{
$config = $this->getConfigValues();
$arrValues = array();
$arrValues["clientcode"] = $config["PAYTPV_CLIENTCODE"];
$arrValues["apikey"] = $config["PAYTPV_APIKEY"];
$arrValues["integration"] = $config["PAYTPV_INTEGRATION"];
$arrValues["newpage_payment"] = $config["PAYTPV_NEWPAGEPAYMENT"];
$arrValues["iframe_height"] = ($config["PAYTPV_IFRAME_HEIGHT"]!="")?$config["PAYTPV_IFRAME_HEIGHT"] : 440;
$arrValues["suscriptions"] = $config["PAYTPV_SUSCRIPTIONS"];
$arrValues["reg_estado"] = $config["PAYTPV_REG_ESTADO"];
$arrValues["firstpurchase_scoring"] = $config["PAYTPV_FIRSTPURCHASE_SCORING"];
$arrValues["firstpurchase_scoring_score"] = $config["PAYTPV_FIRSTPURCHASE_SCORING_SCO"];
$arrValues["sessiontime_scoring"] = $config["PAYTPV_SESSIONTIME_SCORING"];
$arrValues["sessiontime_scoring_val"] = $config["PAYTPV_SESSIONTIME_SCORING_VAL"];
$arrValues["sessiontime_scoring_score"] = $config["PAYTPV_SESSIONTIME_SCORING_SCORE"];
$arrValues["dcountry_scoring"] = $config["PAYTPV_DCOUNTRY_SCORING"];
$arrValues["dcountry_scoring_val[]"] = explode(",", $config["PAYTPV_DCOUNTRY_SCORING_VAL"]);
$arrValues["dcountry_scoring_score"] = $config["PAYTPV_DCOUNTRY_SCORING_SCORE"];
$arrValues["ip_change_scoring"] = $config["PAYTPV_IPCHANGE_SCORING"];
$arrValues["ip_change_scoring_score"] = $config["PAYTPV_IPCHANGE_SCORING_SCORE"];
$arrValues["browser_scoring"] = $config["PAYTPV_BROWSER_SCORING"];
$arrValues["browser_scoring_score"] = $config["PAYTPV_BROWSER_SCORING_SCORE"];
$arrValues["so_scoring"] = $config["PAYTPV_SO_SCORING"];
$arrValues["so_scoring_score"] = $config["PAYTPV_SO_SCORING_SCORE"];
$arrValues["disableoffersavecard"] = $config["PAYTPV_DISABLEOFFERSAVECARD"];
foreach ($this->terminales_paytpv as $key => $term) {
$arrValues["term[".$key."]"] = $term["idterminal"];
$arrValues["pass[".$key."]"] = $term["password"];
$arrValues["jetid[".$key."]"] = $term["jetid"];
$arrValues["term_ns[".$key."]"] = $term["idterminal_ns"];
$arrValues["pass_ns[".$key."]"] = $term["password_ns"];
$arrValues["jetid_ns[".$key."]"] = $term["jetid_ns"];
$arrValues["terminales[".$key."]"] = $term["terminales"];
$arrValues["tdfirst[".$key."]"] = $term["tdfirst"];
$arrValues["tdmin[".$key."]"] = $term["tdmin"];
$arrValues["moneda[".$key."]"] = $term["currency_iso_code"];
}
return $arrValues;
}
public function getConfigForm()
{
$arrCurrency = array();
foreach ($this->currency_array as $key => $datos) {
$arrCurrency[$key]["id"] = $datos["iso_code"];
$arrCurrency[$key]["name"] = $datos["name"];
}
$arrFields = array();
$general_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('General'),
'icon' => 'icon-cogs'
),