/
paypalwpp.php
3160 lines (2848 loc) · 189 KB
/
paypalwpp.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
/**
* paypalwpp.php payment module class for PayPal Express Checkout payment method
*
* @copyright Copyright 2003-2021 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: 2021-03-26 Modified in v1.5.7d $
*/
/**
* load the communications layer code
*/
require_once(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_curl.php');
/**
* the PayPal payment module with Express Checkout
*/
class paypalwpp extends base {
/**
* name of this module
*
* @var string
*/
var $code;
/**
* displayed module title
*
* @var string
*/
var $title;
/**
* displayed module description
*
* @var string
*/
var $description;
/**
* module status - set based on various config and zone criteria
*
* @var string
*/
var $enabled;
/**
* the zone to which this module is restricted for use
*
* @var string
*/
var $zone;
/**
* debugging flag
*
* @var boolean
*/
var $enableDebugging = false;
/**
* Determines whether payment page is displayed or not
*
* @var boolean
*/
var $showPaymentPage = false;
var $flagDisablePaymentAddressChange = false;
/**
* sort order of display
*
* @var int
*/
var $sort_order = 0;
/**
* Button Source / BN code -- enables the module to work for Zen Cart
*
* @var string
*/
var $buttonSourceEC = 'ZenCart-EC_us';
/**
* order status setting for pending orders
*
* @var int
*/
var $order_pending_status = 1;
/**
* order status setting for completed orders
*
* @var int
*/
var $order_status = DEFAULT_ORDERS_STATUS_ID;
/**
* Debug tools
*/
var $_logDir = DIR_FS_LOGS;
var $_logLevel = 0;
/**
* FMF
*/
var $fmfResponse = '';
var $fmfErrors = array();
/**
* Flag to enable the modern in-context checkout.
* https://developer.paypal.com/docs/classic/express-checkout/in-context/integration/
* @var boolean
*/
var $use_incontext_checkout = true;
/**
* class constructor
*/
function __construct() {
include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
global $order;
$this->code = 'paypalwpp';
$this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
$this->codeVersion = '1.5.7';
$this->enableDirectPayment = FALSE;
$this->enabled = (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
// Set the title & description text based on the mode we're in ... EC vs US/UK vs admin
if (IS_ADMIN_FLAG === true) {
$this->description = sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_DESCRIPTION, ' (rev' . $this->codeVersion . ')');
switch (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE) {
case ('PayPal'):
$this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
break;
case ('Payflow-UK'):
$this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PRO20;
break;
case ('Payflow-US'):
if (defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes') {
$this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_EC;
} else {
$this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_GATEWAY;
}
break;
default:
$this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
}
$this->sort_order = defined('MODULE_PAYMENT_PAYPALWPP_SORT_ORDER') ? MODULE_PAYMENT_PAYPALWPP_SORT_ORDER : null;
if (null === $this->sort_order) return false;
if ($this->enabled) {
if ( (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'PayPal' && (MODULE_PAYMENT_PAYPALWPP_APISIGNATURE == '' || MODULE_PAYMENT_PAYPALWPP_APIUSERNAME == '' || MODULE_PAYMENT_PAYPALWPP_APIPASSWORD == ''))
|| (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' && (MODULE_PAYMENT_PAYPALWPP_PFPARTNER == '' || MODULE_PAYMENT_PAYPALWPP_PFVENDOR == '' || MODULE_PAYMENT_PAYPALWPP_PFUSER == '' || MODULE_PAYMENT_PAYPALWPP_PFPASSWORD == ''))
) $this->title .= '<span class="alert"><strong> NOT CONFIGURED YET</strong></span>';
if (MODULE_PAYMENT_PAYPALWPP_SERVER =='sandbox') $this->title .= '<strong><span class="alert"> (sandbox active)</span></strong>';
if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email') $this->title .= '<strong> (Debug)</strong>';
if (!function_exists('curl_init')) $this->title .= '<strong><span class="alert"> CURL NOT FOUND. Cannot Use.</span></strong>';
}
} else {
$this->description = MODULE_PAYMENT_PAYPALWPP_TEXT_DESCRIPTION;
$this->title = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TITLE; //pp
}
if ((!defined('PAYPAL_OVERRIDE_CURL_WARNING') || (defined('PAYPAL_OVERRIDE_CURL_WARNING') && PAYPAL_OVERRIDE_CURL_WARNING != 'True')) && !function_exists('curl_init')) $this->enabled = false;
$this->enableDebugging = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email');
$this->emailAlerts = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Alerts Only');
$this->doDPonly = (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE =='Payflow-US' && !(defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes'));
$this->showPaymentPage = (MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE == 'No') ? true : false;
$this->buttonSourceEC = 'ZenCart-EC_us';
$this->buttonSourceDP = 'ZenCart-DP_us';
if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') {
$this->buttonSourceEC = 'ZenCart-EC_uk';
$this->buttonSourceDP = 'ZenCart-DP_uk';
}
if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-US') {
$this->buttonSourceEC = 'ZenCart-ECGW_us';
$this->buttonSourceDP = 'ZenCart-GW_us';
}
$this->order_pending_status = MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID;
if ((int)MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID;
}
$this->new_acct_notify = MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY;
$this->zone = (int)MODULE_PAYMENT_PAYPALWPP_ZONE;
if (is_object($order)) $this->update_status();
if (PROJECT_VERSION_MAJOR != '1' && substr(PROJECT_VERSION_MINOR, 0, 3) != '5.6') $this->enabled = false;
$this->cards = array();
// if operating in markflow mode, start EC process when submitting order
if (!$this->in_special_checkout()) {
$this->form_action_url = zen_href_link('ipn_main_handler.php', 'type=ec&markflow=1&clearSess=1&stage=final', 'SSL', true, true, true);
}
if (!defined('MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE') || MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE != 'InContext') {
$this->use_incontext_checkout = false;
}
if (!defined('MODULE_PAYMENT_PAYPALWPP_MERCHANTID') || MODULE_PAYMENT_PAYPALWPP_MERCHANTID == '') {
$this->use_incontext_checkout = false;
}
// debug setup
if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_CATALOG . $this->_logDir;
if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_LOGS;
if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_SQL_CACHE;
// Regular mode:
if ($this->enableDebugging) $this->_logLevel = 2;
// DEV MODE:
if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $this->_logLevel = 3;
if (IS_ADMIN_FLAG === true) $this->tableCheckup();
}
/**
* Sets payment module status based on zone restrictions etc
*/
function update_status() {
global $order, $db;
// $this->zcLog('update_status', 'Checking whether module should be enabled or not.');
if ($this->enabled && (int)$this->zone > 0 && isset($order->billing['country']['id'])) {
$check_flag = false;
$sql = "SELECT zone_id
FROM " . TABLE_ZONES_TO_GEO_ZONES . "
WHERE geo_zone_id = :zoneId
AND zone_country_id = :countryId
ORDER BY zone_id";
$sql = $db->bindVars($sql, ':zoneId', $this->zone, 'integer');
$sql = $db->bindVars($sql, ':countryId', $order->billing['country']['id'], 'integer');
$check = $db->Execute($sql);
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if (!$check_flag) {
$this->enabled = false;
$this->zcLog('update_status', 'Module disabled due to zone restriction. Billing address is not within the Payment Zone selected in the module settings.');
}
}
// module cannot be used for purchase > 1000000 JPY
if ($order->info['total'] > 1000000 && $order->info['currency'] == 'JPY') {
$this->enabled = false;
$this->zcLog('update_status', 'Module disabled because purchase price (' . $order->info['total'] . ') exceeds PayPal-imposed maximum limit of 1000000 JPY.');
}
// module cannot be used for purchase > $10,000 USD equiv
$order_amount = $this->calc_order_amount($order->info['total'], 'USD', false);
if ($order_amount > 10000) {
$this->enabled = false;
$this->zcLog('update_status', 'Module disabled because purchase price (' . $order_amount . ') exceeds PayPal-imposed maximum limit of 10,000 USD or equivalent.');
}
if ($order->info['total'] == 0) {
$this->enabled = false;
$this->zcLog('update_status', 'Module disabled because purchase amount is set to 0.00.' . "\n" . print_r($order, true));
}
// other status checks?
if ($this->enabled) {
// other checks here
}
}
/**
* Validate the credit card information via javascript (Number, Owner, and CVV Lengths)
*/
function javascript_validation() {
return false;
}
/**
* Display Credit Card Information Submission Fields on the Checkout Payment Page
*/
function selection() {
$this->cc_type_check = '';
/**
* since we are NOT processing via the gateway, we will only display MarkFlow payment option, and no CC fields
*/
return array('id' => $this->code,
'module' => '<img src="' . MODULE_PAYMENT_PAYPALEC_MARK_BUTTON_IMG . '" alt="' . MODULE_PAYMENT_PAYPALWPP_TEXT_BUTTON_ALTTEXT . '" /><span style="font-size:11px; font-family: Arial, Verdana;"> ' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT . '</span>');
}
function pre_confirmation_check() {
// Since this is an EC checkout, do nothing.
return false;
}
/**
* Display Payment Information for review on the Checkout Confirmation Page
*/
function confirmation() {
$confirmation = array('title' => '', 'fields' => array());
return $confirmation;
}
/**
* Prepare the hidden fields comprising the parameters for the Submit button on the checkout confirmation page
*/
function process_button() {
// When hitting the checkout-confirm button, we are going into markflow mode
$_SESSION['paypal_ec_markflow'] = 1;
// if we have a token, we want to avoid incontext checkout, so we return no special markup
if (isset($_SESSION['paypal_ec_token']) && !empty($_SESSION['paypal_ec_token'])) {
return '';
}
// if incontext checkout is not enabled (ie: not configured), we return no special incontext markup
if ($this->use_incontext_checkout == false) return '';
// send the PayPal-provided javascript to trigger the incontext checkout experience
return " <script>
window.paypalCheckoutReady = function () {
paypal.checkout.setup('" . MODULE_PAYMENT_PAYPALWPP_MERCHANTID . "', {
//locale: '" . $this->getLanguageCode('incontext') . "',"
. (MODULE_PAYMENT_PAYPALWPP_SERVER == 'live' ? '' : "\n environment: 'sandbox',") . "
container: 'checkout_confirmation',
button: 'btn_submit'
});
};
</script>
<script src=\"https://www.paypalobjects.com/api/checkout.js\" async></script>";
}
/**
* Prepare and submit the final authorization to PayPal via the appropriate means as configured
*/
function before_process() {
global $order, $doPayPal, $messageStack;
$options = array();
$optionsShip = array();
$optionsNVP = array();
$options = $this->getLineItemDetails($this->selectCurrency($order->info['currency']));
// Allow delayed payments such as eCheck? (can only use InstantPayment if Action is Sale)
// Payment Transaction/Authorization Mode
$options['PAYMENTREQUEST_0_PAYMENTACTION'] = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Sale';
// for future:
if (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Order') $options['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Order';
if (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE != 'Auth Only' && MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE != 'Sale' && $options['PAYMENTREQUEST_0_PAYMENTACTION'] == 'Sale' && defined('MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT') && MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT == 'Instant Only') {
$options['ALLOWEDPAYMENTMETHOD'] = 'InstantPaymentOnly';
}
//$this->zcLog('before_process - 1', 'Have line-item details:' . "\n" . print_r($options, true));
// Initializing DESC field: using for comments related to tax-included pricing, populated by getLineItemDetails()
$options['PAYMENTREQUEST_0_DESC'] = '';
$doPayPal = $this->paypal_init();
$this->zcLog('before_process - EC-1', 'Beginning EC mode');
/****************************************
* Do EC checkout
****************************************/
// do not allow blank address to be sent to PayPal
if ($_SESSION['paypal_ec_payer_info']['ship_street_1'] != '' && strtoupper($_SESSION['paypal_ec_payer_info']['ship_address_status']) != 'NONE') {
$options = array_merge($options,
array('PAYMENTREQUEST_0_SHIPTONAME' => $_SESSION['paypal_ec_payer_info']['ship_name'],
'PAYMENTREQUEST_0_SHIPTOSTREET' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
'PAYMENTREQUEST_0_SHIPTOSTREET2'=> $_SESSION['paypal_ec_payer_info']['ship_street_2'],
'PAYMENTREQUEST_0_SHIPTOCITY' => $_SESSION['paypal_ec_payer_info']['ship_city'],
'PAYMENTREQUEST_0_SHIPTOSTATE' => $_SESSION['paypal_ec_payer_info']['ship_state'],
'PAYMENTREQUEST_0_SHIPTOZIP' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'=> $_SESSION['paypal_ec_payer_info']['ship_country_code'],
));
$this->zcLog('before_process - EC-2', 'address overrides added:' . "\n" . print_r($options, true));
}
$this->zcLog('before_process - EC-3', 'address info added:' . "\n" . print_r($options, true));
$options['BUTTONSOURCE'] = $this->buttonSourceEC;
// If the customer has changed their shipping address,
// override the shipping address in PayPal with the shipping
// address that is selected in Zen Cart.
if ($order->delivery['street_address'] != '' && $order->delivery['street_address'] != $_SESSION['paypal_ec_payer_info']['ship_street_1'] && $_SESSION['paypal_ec_payer_info']['ship_street_1'] != '') {
$_GET['markflow'] = 2;
if (($address_arr = $this->getOverrideAddress()) !== false) {
// set the override var
$options['ADDROVERRIDE'] = 1;
// set the address info
$options['PAYMENTREQUEST_0_SHIPTONAME'] = $address_arr['entry_firstname'] . ' ' . $address_arr['entry_lastname'];
$options['PAYMENTREQUEST_0_SHIPTOSTREET'] = $address_arr['entry_street_address'];
if ($address_arr['entry_suburb'] != '') $options['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $address_arr['entry_suburb'];
$options['PAYMENTREQUEST_0_SHIPTOCITY'] = $address_arr['entry_city'];
$options['PAYMENTREQUEST_0_SHIPTOZIP'] = $address_arr['entry_postcode'];
$options['PAYMENTREQUEST_0_SHIPTOSTATE'] = $address_arr['zone_code'];
$options['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $address_arr['countries_iso_code_2'];
}
}
// if these optional parameters are blank, remove them from transaction
if (isset($options['PAYMENTREQUEST_0_SHIPTOSTREET2']) && trim($options['PAYMENTREQUEST_0_SHIPTOSTREET2']) == '') unset($options['PAYMENTREQUEST_0_SHIPTOSTREET2']);
if (isset($options['PAYMENTREQUEST_0_SHIPTOPHONENUM']) && trim($options['PAYMENTREQUEST_0_SHIPTOPHONENUM']) == '') unset($options['PAYMENTREQUEST_0_SHIPTOPHONENUM']);
// if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
if ((!isset($options['PAYMENTREQUEST_0_SHIPTOSTATE']) || trim($options['PAYMENTREQUEST_0_SHIPTOSTATE']) == '') && !empty($options['PAYMENTREQUEST_0_SHIPTOCITY'])) {
$options['PAYMENTREQUEST_0_SHIPTOSTATE'] = $options['PAYMENTREQUEST_0_SHIPTOCITY'];
}
// FMF support
$options['RETURNFMFDETAILS'] = (MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS == 'Yes') ? 1 : 0;
// Add note to track that this was an EC transaction (used in properly handling update IPNs related to EC transactions):
$options['PAYMENTREQUEST_0_CUSTOM'] = 'EC-' . (int)$_SESSION['customer_id'] . '-' . time();
// send the store name as transaction identifier, to help distinguish payments between multiple stores:
$options['PAYMENTREQUEST_0_INVNUM'] = (int)$_SESSION['customer_id'] . '-' . time() . '-[' . substr(preg_replace('/[^a-zA-Z0-9_]/', '', STORE_NAME), 0, 30) . ']'; // (cannot send actual invoice number because it's not assigned until after payment is completed)
$options['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->selectCurrency($order->info['currency']);
// $order->info['total'] = zen_round($order->info['total'], 2);
$order_amount = $this->calc_order_amount($order->info['total'], $options['PAYMENTREQUEST_0_CURRENCYCODE'], FALSE);
if (isset($options['PAYMENTREQUEST_0_DESC']) && $options['PAYMENTREQUEST_0_DESC'] == '') unset($options['PAYMENTREQUEST_0_DESC']);
if (!isset($options['PAYMENTREQUEST_0_AMT'])) $options['PAYMENTREQUEST_0_AMT'] = round($order_amount, 2);
if (false) { // disabled until clarification is received about coupons in PayPal Wallet
// report details of coupons used
$j=0;
global $order_totals;
if (sizeof($order_totals)) {
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
if (in_array($order_totals[$i]['code'], array('ot_coupon','ot_gv'))) {
$j++;
$options["L_PAYMENTREQUEST_0_REDEEMEDOFFERTYPE$j"] = 'MERCHANT_COUPON';
$options["L_PAYMENTREQUEST_0_REDEEMEDOFFERNAME$j"] = substr($order_totals[$i]['title'], 0, 127);
$options["L_PAYMENTREQUEST_0_REDEEMEDOFFERDESCRIPTION$j"] = substr($order_totals[$i]['title'], 0, 127);
$options["L_PAYMENTREQUEST_0_REDEEMEDOFFERAMOUNT$j"] = $order_totals[$i]['value'];
}
}
}
// end coupons
}
// debug output
$this->zcLog('before_process - EC-4', 'info being submitted:' . "\n" . $_SESSION['paypal_ec_token'] . ' ' . $_SESSION['paypal_ec_payer_id'] . ' ' . round($order_amount, 2) . "\n" . print_r($options, true));
$this->notify('NOTIFY_PAYPALWPP_BEFORE_DOEXPRESSCHECKOUT');
// in case of funding error, set the redirect URL which is used by the _errorHandler
$this->ec_redirect_url = $this->getPayPalLoginServer() . "?cmd=_express-checkout&token=" . $_SESSION['paypal_ec_token'] . "&useraction=continue";
$response = $doPayPal->DoExpressCheckoutPayment($_SESSION['paypal_ec_token'],
$_SESSION['paypal_ec_payer_id'],
$options);
$this->zcLog('before_process - EC-5', 'resultset:' . "\n" . urldecode(print_r($response, true)));
// CHECK RESPONSE -- if error, actions are taken in the errorHandler
$errorHandlerMessage = $this->_errorHandler($response, 'DoExpressCheckoutPayment');
if ($this->fmfResponse != '') {
$this->order_status = $this->order_pending_status;
}
// SUCCESS
$this->payment_type = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TYPE;
$this->responsedata = $response;
if ($response['PAYMENTINFO_0_PAYMENTTYPE'] != '') $this->payment_type .= ' (' . urldecode($response['PAYMENTINFO_0_PAYMENTTYPE']) . ')';
$this->transaction_id = trim((isset($response['PNREF']) ? $response['PNREF'] : '') . ' ' . $response['PAYMENTINFO_0_TRANSACTIONID']);
if (empty($response['PAYMENTINFO_0_PENDINGREASON']) ||
$response['PAYMENTINFO_0_PENDINGREASON'] == 'none' ||
$response['PAYMENTINFO_0_PENDINGREASON'] == 'completed' ||
$response['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Completed') {
$this->payment_status = 'Completed';
if ($this->order_status > 0) $order->info['order_status'] = $this->order_status;
} else {
if ($response['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Pending')
{
if ($response['L_ERRORCODE0'] == 11610 && $response['PAYMENTINFO_0_PENDINGREASON'] == '') $response['PAYMENTINFO_0_PENDINGREASON'] = 'Pending FMF Review by Storeowner';
}
$this->payment_status = 'Pending (' . $response['PAYMENTINFO_0_PENDINGREASON'] . ')';
$order->info['order_status'] = $this->order_pending_status;
}
$this->avs = 'N/A';
$this->cvv2 = 'N/A';
$this->correlationid = $response['CORRELATIONID'];
$this->transactiontype = $response['PAYMENTINFO_0_TRANSACTIONTYPE'];
$this->payment_time = urldecode($response['PAYMENTINFO_0_ORDERTIME']);
$this->feeamt = urldecode($response['PAYMENTINFO_0_FEEAMT']);
$this->taxamt = urldecode($response['PAYMENTINFO_0_TAXAMT']);
$this->pendingreason = $response['PAYMENTINFO_0_PENDINGREASON'];
$this->reasoncode = $response['PAYMENTINFO_0_REASONCODE'];
$this->numitems = sizeof($order->products);
$this->amt = urldecode($response['PAYMENTINFO_0_AMT'] . ' ' . $response['PAYMENTINFO_0_CURRENCYCODE']);
$this->auth_code = (isset($response['AUTHCODE'])) ? $response['AUTHCODE'] : $response['TOKEN'];
$this->notify('NOTIFY_PAYPALWPP_BEFORE_PROCESS_FINISHED', $response);
}
/**
* When the order returns from the processor, this stores the results in order-status-history and logs data for subsequent use
*/
function after_process() {
global $insert_id, $order;
// FMF
if ($this->fmfResponse != '') {
$detailedMessage = $insert_id . "\n" . $this->fmfResponse . "\n" . MODULES_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_INTRO . "\n" . print_r($this->fmfErrors, TRUE);
zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, MODULES_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_SUBJECT . ' (' . $insert_id . ')', $detailedMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($detailedMessage)), 'paymentalert');
}
// add a new OSH record for this order's PP details
$commentString = "Transaction ID: " . $this->transaction_id .
(isset($this->responsedata['PPREF']) ? "\nPPRef: " . $this->responsedata['PPREF'] : '') .
(isset($this->responsedata['AUTHCODE'])? "\nAuthCode: " . $this->responsedata['AUTHCODE'] : '') .
"\nPayment Type: " . $this->payment_type .
($this->payment_time != '' ? ("\nTimestamp: " . $this->payment_time) : '') .
"\nPayment Status: " . $this->payment_status .
(isset($this->responsedata['auth_exp']) ? "\nAuth-Exp: " . $this->responsedata['auth_exp'] : '') .
($this->avs != 'N/A' ? "\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2 : '') .
(trim($this->amt) != '' ? ("\nAmount: " . $this->amt) : '');
zen_update_orders_history($insert_id, $commentString, null, $order->info['order_status'], 0);
// store the PayPal order meta data -- used for later matching and back-end processing activities
$paypal_order = array('order_id' => $insert_id,
'txn_type' => $this->transactiontype,
'module_name' => $this->code,
'module_mode' => MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,
'reason_code' => $this->reasoncode,
'payment_type' => $this->payment_type,
'payment_status' => $this->payment_status,
'pending_reason' => $this->pendingreason,
'invoice' => urldecode($_SESSION['paypal_ec_token'] . (isset($this->responsedata['PPREF']) ? $this->responsedata['PPREF'] : '')),
'first_name' => $_SESSION['paypal_ec_payer_info']['payer_firstname'],
'last_name' => $_SESSION['paypal_ec_payer_info']['payer_lastname'],
'payer_business_name' => $_SESSION['paypal_ec_payer_info']['payer_business'],
'address_name' => $_SESSION['paypal_ec_payer_info']['ship_name'],
'address_street' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
'address_city' => $_SESSION['paypal_ec_payer_info']['ship_city'],
'address_state' => $_SESSION['paypal_ec_payer_info']['ship_state'],
'address_zip' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
'address_country' => $_SESSION['paypal_ec_payer_info']['ship_country_name'],
'address_status' => $_SESSION['paypal_ec_payer_info']['ship_address_status'],
'payer_email' => $_SESSION['paypal_ec_payer_info']['payer_email'],
'payer_id' => $_SESSION['paypal_ec_payer_id'],
'payer_status' => $_SESSION['paypal_ec_payer_info']['payer_status'],
'payment_date' => trim(preg_replace('/[^0-9-:]/', ' ', $this->payment_time)),
'business' => '',
'receiver_email' => (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' ? MODULE_PAYMENT_PAYPALWPP_PFVENDOR : str_replace('_api1', '', MODULE_PAYMENT_PAYPALWPP_APIUSERNAME)),
'receiver_id' => '',
'txn_id' => $this->transaction_id,
'parent_txn_id' => '',
'num_cart_items' => (float)$this->numitems,
'mc_gross' => (float)$this->amt,
'mc_fee' => (float)urldecode($this->feeamt),
'mc_currency' => $this->responsedata['PAYMENTINFO_0_CURRENCYCODE'],
'settle_amount' => (float)(isset($this->responsedata['PAYMENTINFO_0_SETTLEAMT']) ? urldecode($this->responsedata['PAYMENTINFO_0_SETTLEAMT']) : $this->amt),
'settle_currency' => $this->responsedata['PAYMENTINFO_0_CURRENCYCODE'],
'exchange_rate' => (isset($this->responsedata['PAYMENTINFO_0_EXCHANGERATE']) && urldecode($this->responsedata['PAYMENTINFO_0_EXCHANGERATE']) > 0) ? urldecode($this->responsedata['PAYMENTINFO_0_EXCHANGERATE']) : 1.0,
'notify_version' => '0',
'verify_sign' =>'',
'date_added' => 'now()',
'memo' => (sizeof($this->fmfErrors) > 0 ? 'FMF Details ' . print_r($this->fmfErrors, TRUE) : '{Record generated by payment module}'),
);
zen_db_perform(TABLE_PAYPAL, $paypal_order);
$this->notify('NOTIFY_PAYPALWPP_AFTER_PROCESS_FINISHED', $paypal_order);
// Unregister the paypal session variables, making it necessary to start again for another purchase
unset($_SESSION['paypal_ec_temp']);
unset($_SESSION['paypal_ec_token']);
unset($_SESSION['paypal_ec_payer_id']);
unset($_SESSION['paypal_ec_payer_info']);
unset($_SESSION['paypal_ec_final']);
unset($_SESSION['paypal_ec_markflow']);
}
/**
* Build admin-page components
*
* @param int $zf_order_id
* @return string
*/
function admin_notification($zf_order_id) {
if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) return '';
global $db;
$module = $this->code;
$output = '';
$response = $this->_GetTransactionDetails($zf_order_id);
//$response = $this->_TransactionSearch('2006-12-01T00:00:00Z', $zf_order_id);
$sql = "SELECT * from " . TABLE_PAYPAL . " WHERE order_id = :orderID
AND parent_txn_id = '' AND order_id > 0
ORDER BY paypal_ipn_id DESC LIMIT 1";
$sql = $db->bindVars($sql, ':orderID', $zf_order_id, 'integer');
$ipn = $db->Execute($sql);
if ($ipn->EOF) {
$ipn = new stdClass;
$ipn->fields = array();
}
if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php')) require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php');
return $output;
}
/**
* Used to read details of an existing transaction. FOR FUTURE USE.
*/
function _GetTransactionDetails($oID, $last_txn = true) {
if ($oID == '' || $oID < 1) return FALSE;
global $db, $messageStack, $doPayPal;
$doPayPal = $this->paypal_init();
// look up history on this order from PayPal table
$sql = "SELECT * FROM " . TABLE_PAYPAL . " WHERE order_id = :orderID order by last_modified DESC, date_added DESC, parent_txn_id DESC, paypal_ipn_id " . ($last_txn ? "DESC " : "ASC ");
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
if ($txnID == '' || $txnID === 0) return FALSE;
/**
* Read data from PayPal
*/
$response = $doPayPal->GetTransactionDetails($txnID);
// $this->zcLog("_GetTransactionDetails($oID):", print_r($response, true));
$error = $this->_errorHandler($response, 'GetTransactionDetails', 10007);
if ($error === false) {
return false;
} else {
return $response;
}
}
/**
* Used to read details of existing transactions. FOR FUTURE USE.
*/
function _TransactionSearch($startDate = '', $oID = '', $criteria = '') {
global $db, $messageStack, $doPayPal;
$doPayPal = $this->paypal_init();
// look up history on this order from PayPal table
$sql = "SELECT * FROM " . TABLE_PAYPAL . " WHERE order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
$startDate = $zc_ppHist->fields['payment_date'];
$timeval = time();
if ($startDate == '') $startDate = date('Y-m-d', $timeval) . 'T' . date('h:i:s', $timeval) . 'Z';
/**
* Read data from PayPal
*/
$response = $doPayPal->TransactionSearch($startDate, $txnID, $email, $criteria);
//$this->zcLog("_TransactionSearch($startDate, $oID, $criteria):", print_r($response, true));
$error = $this->_errorHandler($response, 'TransactionSearch');
if ($error === false) {
return false;
} else {
return $response;
}
}
/**
* Evaluate installation status of this module. Returns true if the status key is found.
*/
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_PAYMENT_PAYPALWPP_STATUS'");
$this->_check = !$check_query->EOF;
}
if ($this->_check) $this->keys(); // install any missing keys
return $this->_check;
}
/**
* Installs all the configuration keys for this module
*/
function install() {
global $db, $messageStack;
if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
$messageStack->add_session('Express Checkout module already installed.', 'error');
zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
return 'failed';
}
if (defined('MODULE_PAYMENT_PAYPAL_STATUS')) {
$messageStack->add_session('NOTE: You already have the PayPal Website Payments Standard module installed. You should REMOVE it if you want to install Express Checkout.', 'error');
zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypal', 'NONSSL'));
return 'failed';
}
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable this Payment Module', 'MODULE_PAYMENT_PAYPALWPP_STATUS', 'True', 'Do you want to enable this payment module?', '6', '25', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Live or Sandbox', 'MODULE_PAYMENT_PAYPALWPP_SERVER', 'live', '<strong>Live: </strong> Used to process Live transactions<br><strong>Sandbox: </strong>For developers and testing', '6', '25', 'zen_cfg_select_option(array(\'live\', \'sandbox\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout Shortcut Button', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', 'On', 'The Express Checkout Shortcut button shows up on your shopping cart page to invite your customers to pay using PayPal without having to give all their address details on your site first before selecting shipping options.<br />It has been shown to increase sales and conversions when enabled.<br />Default: On ', '6', '25', 'zen_cfg_select_option(array(\'On\', \'Off\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout: Require Confirmed Address', 'MODULE_PAYMENT_PAYPALWPP_CONFIRMED_ADDRESS', 'No', 'Do you want to require that your (not-logged-in) customers use a *confirmed* address when choosing their shipping address in PayPal?<br />(this is ignored for logged-in customers)', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout: Select Cheapest Shipping Automatically', 'MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING', 'Yes', 'When customer returns from PayPal, do we want to automatically select the Cheapest shipping method and skip the shipping page? (making it more *express*)<br />Note: enabling this means the customer does *not* have easy access to select an alternate shipping method (without going back to the Checkout-Step-1 page)', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout: Skip Payment Page', 'MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE', 'Yes', 'If the customer is checking out with Express Checkout, do you want to skip the checkout payment page, making things more *express*? <br /><strong>(NOTE: The Payment Page will auto-display regardless of this setting if you have Coupons or Gift Certificates enabled in your store.)</strong>', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout: Automatic Account Creation', 'MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY', 'Yes', 'If a visitor is not an existing customer, a Zen Cart account is created for them. Would you like make it a permanent account and send them an email containing their login information?<br />NOTE: Permanent accounts are auto-created if the customer purchases downloads or gift certificates, regardless of this setting.', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Sort order of display.', 'MODULE_PAYMENT_PAYPALWPP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Payment Zone', 'MODULE_PAYMENT_PAYPALWPP_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '25', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) VALUES ('Set Order Status', 'MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID', '2', 'Set the status of orders paid with this payment module to this value. <br /><strong>Recommended: Processing[2]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) VALUES ('Set Unpaid Order Status', 'MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID', '1', 'Set the status of unpaid orders made with this payment module to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) VALUES ('Set Refund Order Status', 'MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID', '1', 'Set the status of refunded orders to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PayPal Page Style', 'MODULE_PAYMENT_PAYPALWPP_PAGE_STYLE', 'Primary', 'The page-layout style you want customers to see when they visit the PayPal site. You can configure your <strong>Custom Page Styles</strong> in your PayPal Profile settings. This value is case-sensitive.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Store (Brand) Name at PayPal', 'MODULE_PAYMENT_PAYPALWPP_BRANDNAME', '', 'The name of your store as it should appear on the PayPal login page. If blank, your store name will be used.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Payment Action', 'MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE', 'Final Sale', 'How do you want to obtain payment?<br /><strong>Default: Final Sale</strong>', '6', '25', 'zen_cfg_select_option(array(\'Auth Only\', \'Final Sale\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Transaction Currency', 'MODULE_PAYMENT_PAYPALWPP_CURRENCY', 'Selected Currency', 'Which currency should the order be sent to PayPal as? <br />NOTE: if an unsupported currency is sent to PayPal, it will be auto-converted to USD (or GBP if using UK account)<br /><strong>Default: Selected Currency</strong>', '6', '25', 'zen_cfg_select_option(array(\'Selected Currency\', \'Only USD\', \'Only AUD\', \'Only CAD\', \'Only EUR\', \'Only GBP\', \'Only CHF\', \'Only CZK\', \'Only DKK\', \'Only HKD\', \'Only HUF\', \'Only JPY\', \'Only NOK\', \'Only NZD\', \'Only PLN\', \'Only SEK\', \'Only SGD\', \'Only THB\', \'Only MXN\', \'Only ILS\', \'Only PHP\', \'Only TWD\', \'Only BRL\', \'Only MYR\', \'Only TRY\', \'Only INR\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Allow eCheck?', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', 'Any', 'Do you want to allow non-instant payments like eCheck/EFT/ELV?', '6', '25', 'zen_cfg_select_option(array(\'Any\', \'Instant Only\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Fraud Mgmt Filters - FMF', 'MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS', 'No', 'If you have enabled FMF support in your PayPal account and wish to utilize it in your transactions, set this to yes. Otherwise, leave it at No.', '6', '25','zen_cfg_select_option(array(\'No\', \'Yes\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('API Signature -- Username', 'MODULE_PAYMENT_PAYPALWPP_APIUSERNAME', '', 'The API Username from your PayPal API Signature settings under *API Access*. This value typically looks like an email address and is case-sensitive.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) VALUES ('API Signature -- Password', 'MODULE_PAYMENT_PAYPALWPP_APIPASSWORD', '', 'The API Password from your PayPal API Signature settings under *API Access*. This value is a 16-character code and is case-sensitive.', '6', '25', now(), 'zen_cfg_password_input(', 'zen_cfg_password_display')");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) VALUES ('API Signature -- Signature Code', 'MODULE_PAYMENT_PAYPALWPP_APISIGNATURE', '', 'The API Signature from your PayPal API Signature settings under *API Access*. This value is a 56-character code, and is case-sensitive.', '6', '25', now(), '', 'zen_cfg_password_display')");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PAYFLOW: User', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', '', 'If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. Otherwise it should be the same value as VENDOR. This value is case-sensitive.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PAYFLOW: Partner', 'MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'ZenCart', 'Your Payflow Partner name linked to your Payflow account. This value is case-sensitive.<br />Typical values: <strong>PayPal</strong> or <strong>ZenCart</strong>', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PAYFLOW: Vendor', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', '', 'Your merchant login ID that you created when you registered for the Payflow Pro account. This value is case-sensitive.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) VALUES ('PAYFLOW: Password', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD', '', 'The 6- to 32-character password that you defined while registering for the account. This value is case-sensitive.', '6', '25', now(), 'zen_cfg_password_input(', 'zen_cfg_password_display')");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('PayPal Mode', 'MODULE_PAYMENT_PAYPALWPP_MODULE_MODE', 'PayPal', 'Which PayPal API system should be used for processing? <br /><u>Choices:</u><br /><font color=green>For choice #1, you need to supply <strong>API Settings</strong> above.</font><br /><strong>1. PayPal</strong> = Express Checkout with a regular PayPal account<br />or<br /><font color=green>for choices 2 & 3 you need to supply <strong>PAYFLOW settings</strong>, below (and have a Payflow account)</font><br /><strong>2. Payflow-UK</strong> = Website Payments Pro UK Payflow Edition<br /><strong>3. Payflow-US</strong> = Payflow Pro Gateway only<!--<br /><strong>4. PayflowUS+EC</strong> = Payflow Pro with Express Checkout-->', '6', '25', 'zen_cfg_select_option(array(\'PayPal\', \'Payflow-UK\', \'Payflow-US\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Debug Mode', 'MODULE_PAYMENT_PAYPALWPP_DEBUGGING', 'Off', 'Would you like to enable debug mode? A complete detailed log of failed transactions will be emailed to the store owner.', '6', '25', 'zen_cfg_select_option(array(\'Off\', \'Alerts Only\', \'Log File\', \'Log and Email\'), ', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PayPal Merchant ID', 'MODULE_PAYMENT_PAYPALWPP_MERCHANTID', '', 'Enter your PayPal Merchant ID here. This is used for the more user-friendly In-Context checkout mode. You can obtain this value by going to your PayPal account, clicking on your account name at the top right, then clicking Account Settings, and navigating to the Business Information section; You will find your Merchant Account ID on that screen. A typical Merchant ID looks like FDEFDEFDEFDE11.', '6', '25', now())");
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Use InContext Checkout?', 'MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE', 'InContext', 'PayPal now offers a newer friendlier InContext (in-page) checkout mode (Requires that you enter your MerchantID in the Merchant ID Setting above). Or you can use the older checkout style which offers Pay Without Account by default but with a full-page-redirect.', '6', '25', 'zen_cfg_select_option(array(\'InContext\', \'Old\'), ', now())");
$this->notify('NOTIFY_PAYMENT_PAYPALWPP_INSTALLED');
}
function keys() {
if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
global $db;
if (!defined('MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON')) {
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Express Checkout Shortcut Button', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', 'On', 'The Express Checkout Shortcut button shows up on your shopping cart page to invite your customers to pay using PayPal without having to give all their address details on your site first before selecting shipping options.<br />It has been shown to increase sales and conversions when enabled.<br />Default: On ', '6', '25', 'zen_cfg_select_option(array(\'On\', \'Off\'), ', now())");
}
if (!defined('MODULE_PAYMENT_PAYPALWPP_BRANDNAME')) {
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Store Brand Name at PayPal', 'MODULE_PAYMENT_PAYPALWPP_BRANDNAME', '', 'The name of your store as it should appear on the PayPal login page. If blank, your store name will be used.', '6', '25', now())");
}
if (!defined('MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT')) {
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Allow eCheck?', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', 'Any', 'Do you want to allow non-instant payments like eCheck/EFT/ELV?', '6', '25', 'zen_cfg_select_option(array(\'Any\', \'Instant Only\'), ', now())");
}
if (!defined('MODULE_PAYMENT_PAYPALWPP_MERCHANTID')) {
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('PayPal Merchant ID', 'MODULE_PAYMENT_PAYPALWPP_MERCHANTID', '', 'Enter your PayPal Merchant ID here. This is used for the more user-friendly In-Context checkout mode. You can obtain this value by going to your PayPal account, clicking on your account name at the top right, then clicking Account Settings, and navigating to the Business Information section; You will find your Merchant Account ID on that screen. A typical Merchant ID looks like FDEFDEFDEFDE11.', '6', '25', now())");
}
if (!defined('MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE')) {
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Use InContext Checkout?', 'MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE', 'InContext', 'PayPal now offers a newer friendlier InContext (in-page) checkout mode (Requires that you enter your MerchantID in the Merchant ID Setting above). Or you can use the older checkout style which offers Pay Without Account by default but with a full-page-redirect.', '6', '25', 'zen_cfg_select_option(array(\'InContext\', \'Old\'), ', now())");
}
}
$keys_list = array('MODULE_PAYMENT_PAYPALWPP_STATUS', 'MODULE_PAYMENT_PAYPALWPP_SORT_ORDER', 'MODULE_PAYMENT_PAYPALWPP_ZONE', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', 'MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_CONFIRMED_ADDRESS', 'MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING', 'MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE', 'MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY', 'MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE', 'MODULE_PAYMENT_PAYPALWPP_CURRENCY', 'MODULE_PAYMENT_PAYPALWPP_BRANDNAME', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', 'MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS', 'MODULE_PAYMENT_PAYPALWPP_PAGE_STYLE', 'MODULE_PAYMENT_PAYPALWPP_APIUSERNAME', 'MODULE_PAYMENT_PAYPALWPP_APIPASSWORD', 'MODULE_PAYMENT_PAYPALWPP_APISIGNATURE', 'MODULE_PAYMENT_PAYPALWPP_MERCHANTID', 'MODULE_PAYMENT_PAYPALWPP_MODULE_MODE', 'MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE', 'MODULE_PAYMENT_PAYPALWPP_SERVER', 'MODULE_PAYMENT_PAYPALWPP_DEBUGGING');
if (defined('PAYPAL_DEV_MODE') && IS_ADMIN_FLAG === true && (PAYPAL_DEV_MODE == 'true' || strstr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE, 'Payflow'))) {
$keys_list = array_merge($keys_list, array('MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD'));
}
return $keys_list;
}
/**
* De-install this module
*/
function remove() {
global $messageStack;
// cannot remove EC if DP installed:
if (defined('MODULE_PAYMENT_PAYPALDP_STATUS')) {
// this language text is hard-coded in english since Website Payments Pro is not yet available in any countries that speak any other language at this time.
$messageStack->add_session('<strong>Sorry, you must remove PayPal Payments Pro (paypaldp) first.</strong> PayPal Payments Pro (Website Payments Pro) requires that you offer Express Checkout to your customers.<br /><a href="' . zen_href_link('modules.php?set=payment&module=paypaldp', '', 'NONSSL') . '">Click here to edit or remove your PayPal Payments Pro module.</a>' , 'error');
zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
return 'failed';
}
global $db;
$db->Execute("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key LIKE 'MODULE\_PAYMENT\_PAYPALWPP\_%' OR configuration_key LIKE 'MODULE\_PAYMENT\_PAYPALEC\_%'");
$this->notify('NOTIFY_PAYMENT_PAYPALWPP_UNINSTALLED');
}
/**
* Check settings and conditions to determine whether we are in an Express Checkout phase or not
*/
function in_special_checkout() {
if ((defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') &&
!empty($_SESSION['paypal_ec_token']) &&
!empty($_SESSION['paypal_ec_payer_id']) &&
!empty($_SESSION['paypal_ec_payer_info'])) {
$this->flagDisablePaymentAddressChange = true;
return true;
}
}
/**
* Determine whether the shipping-edit button should be displayed or not
*/
function alterShippingEditButton() {
return false;
if ($this->in_special_checkout() && empty($_SESSION['paypal_ec_markflow'])) {
return zen_href_link('ipn_main_handler.php', 'type=ec&clearSess=1', 'SSL', true,true, true);
}
}
/**
* Debug Logging support
*/
function zcLog($stage, $message) {
static $tokenHash;
if ($tokenHash == '') $tokenHash = '_' . zen_create_random_value(4);
if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File') {
$token = (isset($_SESSION['paypal_ec_token'])) ? $_SESSION['paypal_ec_token'] : ((isset($_GET['token'])) ? preg_replace('/[^0-9.A-Z\-]/', '', $_GET['token']) : '');
$token = ($token == '') ? date('m-d-Y-H-i') : $token; // or time()
$token .= $tokenHash;
$file = $this->_logDir . '/' . $this->code . '_Paypal_Action_' . $token . '.log';
if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $file = $this->_logDir . '/' . $this->code . '_Paypal_Debug_' . $token . '.log';
$fp = @fopen($file, 'a');
@fwrite($fp, date('M-d-Y H:i:s') . ' (' . time() . ')' . "\n" . $stage . "\n" . $message . "\n=================================\n\n");
@fclose($fp);
}
$this->_doDebug($stage, $message, false);
}
/**
* Debug Emailing support
*/
function _doDebug($subject = 'PayPal debug data', $data = '', $useSession = true) {
if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email') {
$data = urldecode($data) . "\n\n";
if ($useSession) $data .= "\nSession data: " . print_r($_SESSION, true);
zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, $subject, $this->code . "\n" . $data, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($this->code . "\n" . $data)), 'debug');
}
}
/**
* Initialize the PayPal/PayflowPro object for communication to the processing gateways
*/
function paypal_init() {
if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS') || !defined('MODULE_PAYMENT_PAYPALWPP_SERVER')) {
$doPayPal = new paypal_curl(array('mode' => 'NOTCONFIGURED'));
return $doPayPal;
}
$ec_uses_gateway = (defined('MODULE_PAYMENT_PAYPALWPP_PRO20_EC_METHOD') && MODULE_PAYMENT_PAYPALWPP_PRO20_EC_METHOD == 'Payflow') ? true : false;
if (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow') {
$doPayPal = new paypal_curl(array('mode' => 'payflow',
'user' => trim(MODULE_PAYMENT_PAYPALWPP_PFUSER),
'vendor' => trim(MODULE_PAYMENT_PAYPALWPP_PFVENDOR),
'partner'=> trim(MODULE_PAYMENT_PAYPALWPP_PFPARTNER),
'pwd' => trim(MODULE_PAYMENT_PAYPALWPP_PFPASSWORD),
'server' => MODULE_PAYMENT_PAYPALWPP_SERVER));
$doPayPal->_endpoints = array('live' => 'https://payflowpro.paypal.com/transaction',
'sandbox' => 'https://pilot-payflowpro.paypal.com/transaction');
} else {
$doPayPal = new paypal_curl(array('mode' => 'nvp',
'user' => trim(MODULE_PAYMENT_PAYPALWPP_APIUSERNAME),
'pwd' => trim(MODULE_PAYMENT_PAYPALWPP_APIPASSWORD),
'signature' => trim(MODULE_PAYMENT_PAYPALWPP_APISIGNATURE),
'version' => '124.0',
'server' => MODULE_PAYMENT_PAYPALWPP_SERVER));
$doPayPal->_endpoints = array('live' => 'https://api-3t.paypal.com/nvp',
'sandbox' => 'https://api-3t.sandbox.paypal.com/nvp');
}
// set logging options
$doPayPal->_logDir = $this->_logDir;
$doPayPal->_logLevel = $this->_logLevel;
// set proxy options if configured
if (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '') {
$proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
$doPayPal->setCurlOption(CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
$doPayPal->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
$doPayPal->setCurlOption(CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
}
// transaction processing mode
$doPayPal->_trxtype = (in_array(MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE, array('Auth Only', 'Order'))) ? 'A' : 'S';
return $doPayPal;
}
/**
* Determine which PayPal URL to direct the customer's browser to when needed
*/
function getPayPalLoginServer() {
if (MODULE_PAYMENT_PAYPALWPP_SERVER == 'live') {
// live url
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
} else {
// sandbox url
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
return $paypal_url;
}
/**
* Used to submit a refund for a given transaction. FOR FUTURE USE.
* @TODO: Add option to specify shipping/tax amounts for refund instead of just total. Ref: https://developer.paypal.com/docs/classic/release-notes/merchant/PayPal_Merchant_API_Release_Notes_119/
*/
function _doRefund($oID, $amount = 'Full', $note = '') {
global $db, $doPayPal, $messageStack;
$new_order_status = (int)MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID;
$orig_order_amount = 0;
$doPayPal = $this->paypal_init();
$proceedToRefund = false;
$refundNote = strip_tags(zen_db_input($_POST['refnote']));
if (isset($_POST['fullrefund']) && $_POST['fullrefund'] == MODULE_PAYMENT_PAYPAL_ENTRY_REFUND_BUTTON_TEXT_FULL) {
$refundAmt = 'Full';
if (isset($_POST['reffullconfirm']) && $_POST['reffullconfirm'] == 'on') {
$proceedToRefund = true;
} else {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_REFUND_FULL_CONFIRM_ERROR, 'error');
}
}
if (isset($_POST['partialrefund']) && $_POST['partialrefund'] == MODULE_PAYMENT_PAYPAL_ENTRY_REFUND_BUTTON_TEXT_PARTIAL) {
$refundAmt = (float)$_POST['refamt'];
$proceedToRefund = true;
if ($refundAmt == 0) {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_INVALID_REFUND_AMOUNT, 'error');
$proceedToRefund = false;
}
}
// look up history on this order from PayPal table
$sql = "SELECT * FROM " . TABLE_PAYPAL . " WHERE order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
$curCode = $zc_ppHist->fields['mc_currency'];
$PFamt = $zc_ppHist->fields['mc_gross'];
if ($doPayPal->_mode == 'payflow' && $refundAmt == 'Full') $refundAmt = $PFamt;
/**
* Submit refund request to PayPal
*/
if ($proceedToRefund) {
$response = $doPayPal->RefundTransaction($oID, $txnID, $refundAmt, $refundNote, $curCode);
//$this->zcLog("_doRefund($oID, $amount, $note):", print_r($response, true));
$error = $this->_errorHandler($response, 'DoRefund');
$new_order_status = ($new_order_status > 0 ? $new_order_status : 1);
if (!$error) {
if (!isset($response['GROSSREFUNDAMT'])) $response['GROSSREFUNDAMT'] = $refundAmt;
// Success, so save the results
$comments = 'REFUND INITIATED. Trans ID:' . $response['REFUNDTRANSACTIONID'] . (isset($response['PNREF']) ? $response['PNREF'] : '') . "\n" . ' Gross Refund Amt: ' . urldecode($response['GROSSREFUNDAMT']) . (isset($response['PPREF']) ? "\nPPRef: " . $response['PPREF'] : '') . "\n" . $refundNote;
zen_update_orders_history($oID, $comments, null, $new_order_status, 0);
$messageStack->add_session(sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_REFUND_INITIATED, urldecode($response['GROSSREFUNDAMT']), urldecode($response['REFUNDTRANSACTIONID']). (isset($response['PNREF']) ? $response['PNREF'] : '')), 'success');
return true;
}
}
}
/**
* Used to authorize part of a given previously-initiated transaction. FOR FUTURE USE.
*/
function _doAuth($oID, $amt, $currency = 'USD') {
global $db, $doPayPal, $messageStack;
$doPayPal = $this->paypal_init();
$authAmt = $amt;
$new_order_status = (int)MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID;
if (isset($_POST['orderauth']) && $_POST['orderauth'] == MODULE_PAYMENT_PAYPAL_ENTRY_AUTH_BUTTON_TEXT_PARTIAL) {
$authAmt = (float)$_POST['authamt'];
$new_order_status = MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID;
if (isset($_POST['authconfirm']) && $_POST['authconfirm'] == 'on') {
$proceedToAuth = true;
} else {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_AUTH_CONFIRM_ERROR, 'error');
$proceedToAuth = false;
}
if ($authAmt == 0) {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_INVALID_AUTH_AMOUNT, 'error');
$proceedToAuth = false;
}
}
// look up history on this order from PayPal table
$sql = "SELECT * FROM " . TABLE_PAYPAL . " WHERE order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
/**
* Submit auth request to PayPal
*/
if ($proceedToAuth) {
$response = $doPayPal->DoAuthorization($txnID, $authAmt, $currency);
//$this->zcLog("_doAuth($oID, $amt, $currency):", print_r($response, true));
$error = $this->_errorHandler($response, 'DoAuthorization');
$new_order_status = ($new_order_status > 0 ? $new_order_status : 1);
if (!$error) {
// Success, so save the results
$comments = 'AUTHORIZATION ADDED. Trans ID: ' . urldecode($response['TRANSACTIONID']) . "\n" . ' Amount:' . urldecode($response['AMT']) . ' ' . $currency;
zen_update_orders_history($oID, $comments, null, $new_order_status, -1);
$messageStack->add_session(sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_AUTH_INITIATED, urldecode($response['AMT'])), 'success');
return true;
}
}
}
/**
* Used to capture part or all of a given previously-authorized transaction. FOR FUTURE USE.
* (alt value for $captureType = 'NotComplete')
*/
function _doCapt($oID, $captureType = 'Complete', $amt = 0, $currency = 'USD', $note = '') {
global $db, $doPayPal, $messageStack;
$doPayPal = $this->paypal_init();
//@TODO: Read current order status and determine best status to set this to
$new_order_status = (int)MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID;
$orig_order_amount = 0;
$doPayPal = $this->paypal_init();
$proceedToCapture = false;
$captureNote = strip_tags(zen_db_input($_POST['captnote']));
if (isset($_POST['captfullconfirm']) && $_POST['captfullconfirm'] == 'on') {
$proceedToCapture = true;
} else {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_CAPTURE_FULL_CONFIRM_ERROR, 'error');
}
if (isset($_POST['captfinal']) && $_POST['captfinal'] == 'on') {
$captureType = 'Complete';
} else {
$captureType = 'NotComplete';
}
if (isset($_POST['btndocapture']) && $_POST['btndocapture'] == MODULE_PAYMENT_PAYPAL_ENTRY_CAPTURE_BUTTON_TEXT_FULL) {
$captureAmt = (float)$_POST['captamt'];
if ($captureAmt == 0) {
$messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_INVALID_CAPTURE_AMOUNT, 'error');
$proceedToCapture = false;
}
}
// look up history on this order from PayPal table
$sql = "SELECT * FROM " . TABLE_PAYPAL . " WHERE order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];