-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPluginPaypal.php
More file actions
1536 lines (1300 loc) · 72.8 KB
/
PluginPaypal.php
File metadata and controls
1536 lines (1300 loc) · 72.8 KB
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
require_once 'modules/admin/models/GatewayPlugin.php';
require_once 'modules/billing/models/class.gateway.plugin.php';
require_once 'modules/billing/models/Currency.php';
require_once 'modules/billing/models/BillingCycle.php';
require_once 'modules/billing/models/Coupon.php';
/**
* @package Plugins
*/
class PluginPaypal extends GatewayPlugin
{
function getVariables()
{
$variables = array(
lang('Plugin Name') => array(
'type' => 'hidden',
'description' => lang('How CE sees this plugin (not to be confused with the Signup Name)'),
'value' => lang('Paypal')
),
lang('User ID') => array(
'type' => 'text',
'description' => lang('The email used to identify you to PayPal.<br>NOTE: The email is required if you have selected PayPal as a payment gateway for any of your clients.'),
'value' => ''
),
lang('Signup Name') => array(
'type' => 'text',
'description' => lang('Select the name to display in the signup process for this payment type. Example: eCheck or Credit Card.'),
'value' => 'Credit Card, eCheck, or Paypal'
),
lang('Invoice After Signup') => array(
'type' => 'yesno',
'description' => lang('Select YES if you want an invoice sent to the client after signup is complete.'),
'value' => '1'
),
lang('Use PayPal Sandbox') => array(
'type' => 'yesno',
'description' => lang('Select YES if you want to use Paypal\'s testing server, so no actual monetary transactions are made. You need to have a developer account with Paypal, and be logged-in in the developer panel in another browser window for the transaction to be successful.'),
'value' => '0'
),
lang('Paypal Subscriptions Option')=> array(
'type' => 'options',
'description' => lang('Determine if you are going to use subscriptions for recurring charges.<ul><li>Please avoid using <b>"Duration in months"</b> in your recurring fees if you are planning to use Paypal Subscriptions. The subscription will be unlimited until manually canceled either by you, your client or Paypal if lack of funds, etc.</li><li>Subscriptions will be created after a payment is completed by the client, as long as the invoice was paid before becoming overdue.</li><li>Subscriptions will not be created if the invoice has prorated items, or with billing cycles greater than 5 years (Old API), or with billing cycles greater than 1 year (New API).</li></ul>'),
'options' => array(
0 => lang('Use subscriptions'),
1 => lang('Do not use subscriptions')
)
),
lang('Image URL') => array(
'type' => 'text',
'description' => lang('Please enter the URL of the image you would like displayed. The recommended dimensions are 150 x 50 px. PayPal now consider the image as a logo to display in the upper left corner.'),
'value' => ''
),
lang('Separate Taxes') => array(
'type' => 'yesno',
'description' => lang('Select YES if you want to pass amount and taxes separated to this payment processor.'),
'value' => '0'
),
lang('Check CVV2') => array(
'type' => 'hidden',
'description' => lang('Select YES if you want to accept CVV2 for this plugin.'),
'value' => '0'
),
lang('API Username') => array(
'type' => 'text',
'description' => lang('Please enter your API Username.<br><b>Required to do refunds or cancel subscriptions.</b>'),
'value' => ''
),
lang('API Password') => array(
'type' => 'text',
'description' => lang('Please enter your API Password.<br><b>Required to do refunds or cancel subscriptions.</b>'),
'value' => ''
),
lang('API Signature') => array(
'type' => 'text',
'description' => lang('Please enter your API Signature.<br><b>Required to do refunds or cancel subscriptions.</b>'),
'value' => ''
),
lang('API Client ID') => array(
'type' => 'text',
'description' => lang('Please enter your API Client ID.<br><b>Required to use the new API.</b><br>To get this value, you need to login to <a href="https://developer.paypal.com" target="_blank">https://developer.paypal.com</a> using your live PayPal account credentials and then follow the instructions below:<ul><li>Go to Dashboard > My Apps & Credentials</li><li>Go to REST API Apps > Create App</li><li>Enter a name for the app and generate an app</li><li>Once the App is generated, click on the App > Select "Live" mode and then you will see the live "Client ID" and "Secret"</li></ul><b>NOTE:</b> Make sure to create one app per each Clientexec installation you use, or it could lead to issues.'),
'value' => ''
),
lang('Form') => array(
'type' => 'hidden',
'description' => lang('Has a form to be loaded? 1 = YES, 0 = NO<br><b>Required to use the new API.</b>'),
'value' => '1'
),
lang('API Secret') => array(
'type' => 'text',
'description' => lang('Please enter your API Secret.<br><b>Required to do subscriptions using the new API.</b><br>To get this value, you need to login to <a href="https://developer.paypal.com" target="_blank">https://developer.paypal.com</a> using your live PayPal account credentials and then follow the instructions below:<ul><li>Go to Dashboard > My Apps & Credentials</li><li>Go to REST API Apps > Create App</li><li>Enter a name for the app and generate an app</li><li>Once the App is generated, click on the App > Select "Live" mode and then you will see the live "Client ID" and "Secret"</li></ul><b>NOTE:</b> Make sure to create one app per each Clientexec installation you use, or it could lead to issues.'),
'value' => ''
),
);
return $variables;
}
function cancelSubscription($params)
{
//NEW API CODE
if ($params['plugin_paypal_API Client ID'] != '') {
return $this->newAPIcancelSubscription($params);
}
//NEW API CODE
return $this->oldAPIcancelSubscription($params);
}
function oldAPIcancelSubscription($params)
{
if ($params['plugin_paypal_API Username'] == '' || $params['plugin_paypal_API Password'] == '' || $params['plugin_paypal_API Signature'] == '') {
throw new CE_Exception('You must fill out the API Section of the PayPal configuration to Cancel Paypal Subscriptions.');
}
$subscriptionId = urlencode($params['subscriptionId']);
$memo = urlencode('Cancelled due to client requesting cancellation of package');
$requestString = "&PROFILEID={$subscriptionId}&ACTION=Cancel&NOTE={$memo}";
$response = $this->sendRequest('ManageRecurringPaymentsProfileStatus ', $requestString, $params);
//If it has an invalid status, assume it was already canceled
//https://developer.paypal.com/docs/nvp-soap-api/errors/
if (isset($response['L_ERRORCODE0']) && in_array($response['L_ERRORCODE0'], array(11556))) {
$this->removeSubscriptionReference($subscriptionId);
return;
}
//If "The profile ID is invalid" or "Merchant account is denied" and not using the new API, ask to configure it
//https://developer.paypal.com/docs/nvp-soap-api/errors/
if (isset($response['L_ERRORCODE0']) && in_array($response['L_ERRORCODE0'], array(11552, 11546)) && $params['plugin_paypal_API Client ID'] == '') {
$errorMessage = 'Error with PayPal Cancel Subscription. Please take a look at your Paypal plugin configuration and set valid values for "API Client ID" and "API Secret", then try canceling again.';
CE_Lib::log(4, $errorMessage);
return $errorMessage;
}
if (!in_array(strtoupper($response["ACK"]), array('SUCCESS', 'SUCCESSWITHWARNING'))) {
$errorMessage = urldecode($response['L_LONGMESSAGE0']);
CE_Lib::log(4, 'Error with PayPal Cancel Subscription: ' . print_r($response, true));
return $errorMessage;
}
}
function removeSubscriptionReference($subscription_id)
{
$response = "%Started paypal subscription. Subscription ID: " . $subscription_id . "%";
$query = "SELECT `invoiceid` FROM `invoicetransaction` WHERE `response` LIKE ? ";
$result = $this->db->query($query, $response);
$row = $result->fetch();
if ($row) {
$tInvoiceID = $row['invoiceid'];
$tRecurringExclude = '';
// Create Plugin class object to interact with CE.
$cPlugin = new Plugin($tInvoiceID, 'paypal', $this->user);
CE_Lib::log(4, "Subscription has been cancelled.");
$tUser = new User($cPlugin->m_Invoice->m_UserID);
if (in_array($tUser->getStatus(), StatusAliasGateway::getInstance($this->user)->getUserStatusIdsFor(USER_STATUS_CANCELLED))) {
CE_Lib::log(4, 'User is already cancelled. Ignore callback.');
} else {
$subject = 'Gateway recurring payment cancelled';
$message = "Recurring payment for invoice $tInvoiceID has been cancelled.";
// If createTicket returns false it's because this transaction has already been done
if (!$cPlugin->createTicket($subscription_id, $subject, $message, $tUser)) {
exit;
}
}
$transaction = "Paypal subscription cancelled. Original Signup Invoice: $tInvoiceID";
$old_processorid = '';
$cPlugin->resetRecurring($transaction, $subscription_id, $tRecurringExclude, $tInvoiceID, $old_processorid);
} else {
$query2 = "UPDATE recurringfee SET subscription_id = '', disablegenerate = 0 WHERE subscription_id = ? ";
$this->db->query($query2, $subscription_id);
//Clear Subscription id from Unpaid, Pending or Partially Paid invoices
$query3 = "UPDATE invoice SET subscription_id = '' WHERE status IN (0, 4, 5) AND subscription_id = ? ";
$this->db->query($query3, $subscription_id);
}
}
function credit($params)
{
//NEW API CODE
if ($params['plugin_paypal_API Client ID'] != '') {
$this->newAPIcredit($params);
return;
}
//NEW API CODE
if ($params['plugin_paypal_API Username'] == '' || $params['plugin_paypal_API Password'] == '' || $params['plugin_paypal_API Signature'] == '') {
throw new CE_Exception('You must fill out the API Section of the PayPal configuration to do PayPal refunds.');
}
$transactionID = $params['invoiceRefundTransactionId'];
$currency = urlencode($params['userCurrency']);
$refundType = urlencode('Full');
$memo = urlencode('Refund of Invoice #' . $params['invoiceNumber']);
$requestString = "&TRANSACTIONID={$transactionID}&REFUNDTYPE={$refundType}&CURRENCYCODE={$currency}&NOTE={$memo}";
$response = $this->sendRequest('RefundTransaction', $requestString, $params);
if ("SUCCESS" == strtoupper($response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($response["ACK"])) {
return array('AMOUNT' => $params['invoiceTotal']);
} else {
$errorMessage = urldecode($response['L_LONGMESSAGE0']);
CE_Lib::log(4, 'Error with PayPal Refund: ' . print_r($response, true));
return 'Error with PayPal Refund: ' . $errorMessage;
}
}
private function sendRequest($methodName, $requestString, $params)
{
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode($params['plugin_paypal_API Username']);
$API_Password = urlencode($params['plugin_paypal_API Password']);
$API_Signature = urlencode($params['plugin_paypal_API Signature']);
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if ($params['plugin_paypal_Use PayPal Sandbox'] == '1') {
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
}
$version = urlencode('51.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD={$methodName}&VERSION={$version}&PWD={$API_Password}&USER={$API_UserName}&SIGNATURE={$API_Signature}{$requestString}";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if (!$httpResponse) {
throw new CE_Exception("PayPal $methodName failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if (count($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if ((0 == count($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
throw new CE_Exception("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
function singlepayment($params, $test = false)
{
$billingCycleObject = new BillingCycle($params['billingCycle']);
//NEW API CODE
if ($params['plugin_paypal_API Client ID'] != '') {
$subscriptionsUsed = false;
// use subscriptions only if has package fee
if ($params['usingRecurringPlugin'] == '1' && isset($params['invoicePackageUnproratedFee'])) {
// If prorating, avoid creating a subscription
// If period is greather than 5 years (60 months), avoid creating a subscription as Paypal does not support it
// Paypal currently only support subscriptions up to 5 Years
// https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
// Allowable values for t1 and t3 are:
// D – for days; allowable range for p1 and p3 is 1 to 90
// W - for weeks; allowable range for p1 and p3 is 1 to 52
// M – for months; allowable range for p1 and p3 is 1 to 24
// Y – for years; allowable range for p1 and p3 is 1 to 5
// However, in the new API, for frequency_interval, value cannot be greater than 12 months.
if ($params['plugin_paypal_API Secret'] != '' && !$params['invoiceProratingDays'] && $billingCycleObject->amount_of_units > 0
&& (($billingCycleObject->time_unit == 'd' && $billingCycleObject->amount_of_units <= 90)
|| ($billingCycleObject->time_unit == 'w' && $billingCycleObject->amount_of_units <= 52)
|| ($billingCycleObject->time_unit == 'm' && $billingCycleObject->amount_of_units <= 12)
|| ($billingCycleObject->time_unit == 'y' && $billingCycleObject->amount_of_units <= 1))) {
$subscriptionsUsed = true;
}
if ($subscriptionsUsed) {
CE_Lib::log(4, 'Paypal will try to create a new subscription using the new API');
if ($test) {
return $this->newAPIcreateSubscription($params);
} else {
echo $this->newAPIcreateSubscription($params);
exit;
}
}
}
if (!$subscriptionsUsed) {
CE_Lib::log(4, 'Paypal will try to charge a new payment using the new API');
$this->newAPIsinglePayment($params);
exit;
}
}
//NEW API CODE
$currency = new Currency($this->user);
//Function needs to build the url to the payment processor, then redirect
$stat_url = mb_substr($params['clientExecURL'], -1, 1) == "//" ? $params['clientExecURL']."plugins/gateways/paypal/callback.php" : $params['clientExecURL']."/plugins/gateways/paypal/callback.php";
if ($params['plugin_paypal_Use PayPal Sandbox'] == '1') {
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
} else {
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
}
$strRet = "<html>\n";
$strRet .= "<head></head>\n";
$strRet .= "<body>\n";
$strRet .= "<form name=frmPayPal action=\"$paypal_url\" method=\"post\">\n";
$strRet .= "<input type=hidden name=\"business\" value=\"".trim($params["plugin_paypal_User ID"])."\">\n";
//determine if this is a single payment
// We will ignore the domain subscription. Billing has become complicated.
// Good part is, the subcription will be created in the next payment, and using the renewal value
if ($billingCycleObject->amount_of_units == 0) {
$params['usingRecurringPlugin'] = 0;
}
//echo "<pre>";print_r($params);echo "</pre>\n";
$subscriptionsUsed = false;
// This var will be used to pass the excluded recurring fees ids for the subscription if any
$tRecurringExclude = '';
// use subscriptions only if has package fee
if ($params['usingRecurringPlugin'] == '1' && isset($params['invoicePackageUnproratedFee'])) {
// paypal only accepts two decimals
$initialAmount = sprintf("%01.2f", round($params['invoiceTotal'], 2));
// if invoicePackageUnproratedFee is 0, it means this is not a package invoice, so the invoiceTotal will be the same charge always
$tRecurringTotal = 0;
if (!$params['invoicePackageUnproratedFee']) {
$tRecurringTotal = $params['invoiceTotal'];
} else {
$tRecurringTotal = $params['invoicePackageUnproratedFee'];
if (count($params['invoiceExcludedRecurrings']) > 0) {
$tRecurringExclude = '_'.implode(',', $params['invoiceExcludedRecurrings']);
}
}
$tRecurringTotal = sprintf("%01.2f", round($tRecurringTotal, 2));
// If prorating, avoid creating a subscription
// If period is greather than 5 years (60 months), avoid creating a subscription as Paypal does not support it
// Paypal currently only support subscriptions up to 5 Years
// https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
// Allowable values for t1 and t3 are:
// D – for days; allowable range for p1 and p3 is 1 to 90
// W - for weeks; allowable range for p1 and p3 is 1 to 52
// M – for months; allowable range for p1 and p3 is 1 to 24
// Y – for years; allowable range for p1 and p3 is 1 to 5
if (!$params['invoiceProratingDays'] && $billingCycleObject->amount_of_units > 0
&& (($billingCycleObject->time_unit == 'd' && $billingCycleObject->amount_of_units <= 90)
|| ($billingCycleObject->time_unit == 'w' && $billingCycleObject->amount_of_units <= 52)
|| ($billingCycleObject->time_unit == 'm' && $billingCycleObject->amount_of_units <= 24)
|| ($billingCycleObject->time_unit == 'y' && $billingCycleObject->amount_of_units <= 5))) {
// First we normalize the timestamps to midnight
$dueDate = mktime(0, 0, 0, date('m', $params['invoiceDueDate']), date('d', $params['invoiceDueDate']), date('Y', $params['invoiceDueDate']));
switch ($billingCycleObject->time_unit) {
case 'd':
//D – for days; allowable range for p1 and p3 is 1 to 90
$initialPeriodLength = $billingCycleObject->amount_of_units;
$initialPeriodUnits = 'D';
$subscriptionsUsed = true;
break;
case 'w':
//W - for weeks; allowable range for p1 and p3 is 1 to 52
$initialPeriodLength = $billingCycleObject->amount_of_units;
$initialPeriodUnits = 'W';
$subscriptionsUsed = true;
break;
case 'm':
//M – for months; allowable range for p1 and p3 is 1 to 24
$initialPeriodLength = $billingCycleObject->amount_of_units;
$initialPeriodUnits = 'M';
$subscriptionsUsed = true;
break;
case 'y':
//Y – for years; allowable range for p1 and p3 is 1 to 5
$initialPeriodLength = $billingCycleObject->amount_of_units;
$initialPeriodUnits = 'Y';
$subscriptionsUsed = true;
break;
}
}
if ($subscriptionsUsed) {
$strRet .= "<input type=hidden name=\"cmd\" value=\"_xclick-subscriptions\">\n";
// Trial Period 1 used for initial signup payment.
// So we can include the total cost of Domain + Hosting + Setup.
$strRet .= "<input type=hidden name=\"a1\" value=\"$initialAmount\">\n";
$strRet .= "<input type=hidden name=\"p1\" value=\"".$initialPeriodLength."\">\n";
$strRet .= "<input type=hidden name=\"t1\" value=\"$initialPeriodUnits\">\n";
// Normal Billing cycle information including Recurring Payment (only the cost of service).
$strRet .= "<input type=hidden name=\"a3\" value=\"".$tRecurringTotal."\">\n";
$strRet .= "<input type=hidden name=\"p3\" value=\"$initialPeriodLength\">\n";
$strRet .= "<input type=hidden name=\"t3\" value=\"$initialPeriodUnits\">\n";
// Recurring and retry options. Set retry until Paypal's system gives up. And set recurring indefinately.)
$strRet .= "<input type=hidden name=\"src\" value=\"1\">\n";
$strRet .= "<input type=hidden name=\"sra\" value=\"1\">\n";
$strRet .= "<input type=hidden name=\"item_name\" value=\"".$params["companyName"]." - Subscription\">\n";
}
}
if (!$subscriptionsUsed) {
$params['usingRecurringPlugin'] = 0;
$strRet .= "<input type=hidden name=\"cmd\" value=\"_ext-enter\">\n";
$strRet .= "<input type=hidden name=\"redirect_cmd\" value=\"_xclick\">\n";
$strRet .= "<input type=hidden name=\"item_name\" value=\"".$params["companyName"]." Invoice\">\n";
$strRet .= "<input type=hidden name=\"item_number\" value=\"".$params['invoiceNumber']."\">\n";
if ($params['plugin_paypal_Separate Taxes'] == '1') {
$amount = sprintf("%01.2f", round($params['invoiceRawAmount'], 2));
$tax = sprintf("%01.2f", round($params['invoiceTaxes'], 2));
$strRet .= "<input type=hidden name=\"tax\" value=\"$tax\">\n";
} else {
$amount = sprintf("%01.2f", round($params['invoiceTotal'], 2));
}
$strRet .= "<input type=hidden name=\"amount\" value=\"$amount\">\n";
}
//Need to check to see if user is coming from signup
if ($params['isSignup']==1) {
// Actually handle the signup URL setting
if ($this->settings->get('Signup Completion URL') != '') {
$returnURL=$this->settings->get('Signup Completion URL'). '?success=1';
$returnURL_Cancel=$this->settings->get('Signup Completion URL');
} else {
$returnURL=$params["clientExecURL"]."/order.php?step=complete&pass=1";
$returnURL_Cancel=$params["clientExecURL"]."/order.php?step=3";
}
} else {
$returnURL=$params["invoiceviewURLSuccess"];
$returnURL_Cancel=$params["invoiceviewURLCancel"];
}
$strRet .= "<input type=hidden name=\"custom\" value=\"".$params['invoiceNumber']."_".$params['usingRecurringPlugin']."_1".$tRecurringExclude."\">\n";
$strRet .= "<input type=hidden name=\"return\" value=\"".$returnURL."\">\n";
$strRet .= "<input type=hidden name=\"rm\" value=\"2\">\n";
$strRet .= "<input type=hidden name=\"cancel_return\" value=\"".$returnURL_Cancel."\">\n";
$strRet .= "<input type=hidden name=\"notify_url\" value=\"".$stat_url."\">\n";
$strRet .= "<input type=hidden name=\"first_name\" value=\"".$params["userFirstName"]."\">\n";
$strRet .= "<input type=hidden name=\"last_name\" value=\"".$params["userLastName"]."\">\n";
$strRet .= "<input type=hidden name=\"address1\" value=\"".$params["userAddress"]."\">\n";
$strRet .= "<input type=hidden name=\"city\" value=\"".$params["userCity"]."\">\n";
$strRet .= "<input type=hidden name=\"state\" value=\"".$params["userState"]."\">\n";
$strRet .= "<input type=hidden name=\"zip\" value=\"".$params["userZipcode"]."\">\n";
$strRet .= "<input type=hidden name=\"no_shipping\" value=\"1\">\n";
$strRet .= "<input type=hidden name=\"no_note\" value=\"1\">\n";
$strRet .= "<input type=hidden name=\"bn\" value=\"Clientexec_SP\">\n";
$strRet .= "<input type=hidden name=\"currency_code\" value=\"".$params["currencytype"]."\">\n";
$strRet .= "<input type=hidden name=\"image_url\" value=\"".$params["plugin_paypal_Image URL"]."\">\n";
$strRet .= "<input type=hidden name=\"email\" value=\"".$params["userEmail"]."\">\n";
//The next 2 fields are to get the phone number on the form for new customers. It was not working with just one of them
$strRet .= "<input type=hidden name=\"night_phone_a\" value=\""."\">\n";
$strRet .= "<input type=hidden name=\"night_phone_b\" value=\"".$params["userPhone"]."\">\n";
//The previous 2 fields were to get the phone number on the form for new customers. It was not working with just one of them
$strRet .= "<input type=hidden name=\"country\" value=\"".$params["userCountry"]."\">\n";
//die($strRet);
$strRet .= "<script language=\"JavaScript\">\n";
$strRet .= "document.forms['frmPayPal'].submit();\n";
$strRet .= "</script>\n";
$strRet .= "</form>\n";
$strRet .= "</body>\n</html>\n";
if ($test) {
return $strRet;
} else {
echo $strRet;
exit;
}
}
//NEW API CODE
function newAPIsinglePayment($params)
{
//Get the values of the custom fields defined in the top of the file form.phtml
$pluginFolderName = basename(dirname(__FILE__));
$Transaction_ID = $params['plugincustomfields'][$pluginFolderName.'_Transaction_ID'];
$Transaction_State = strtolower($params['plugincustomfields'][$pluginFolderName.'_Transaction_State']);
$Transaction_Amount = $params['plugincustomfields'][$pluginFolderName.'_Transaction_Amount'];
$Transaction_Currency = $params['plugincustomfields'][$pluginFolderName.'_Transaction_Currency'];
//Set this variable later to false if something fails.
$success = true;
//Set in this variable the values you will use in the callback.
$newParams = array();
$newParams['newApi'] = 1;
$newParams['invoiceId'] = $params['invoiceNumber'];
//Make sure to get and assign the transaction amount from the parameters returned from the gateway.
//Please take in count $params['invoiceTotal'] has the amount of the transaction that will be refunded, while it has the balance due of the invoice when doing a payment
$newParams['transactionAmount'] = $Transaction_Amount;
//Make sure to get and assign the credit card last four digits from the parameters returned from the gateway, or set it as 'NA' if not available.
//Allowed values: 'NA', credit card last four digits.
$newParams['transactionLast4'] = 'NA';
//If something failed, set this variable to false.
if ($Transaction_State == 'denied') {
$success = false;
}
//Make sure to get and assign the type of transaction from the parameters returned from the gateway.
//Allowed values: charge, refund
$newParams['transactionAction'] = 'charge';
//Make sure to get and assign the transaction id from the parameters returned from the gateway.
$newParams['transactionId'] = $Transaction_ID;
//Make sure to get and assign the transaction status from the parameters returned from the gateway.
//Possible values: completed, partially_refunded, pending, refunded, denied.
$newParams['transactionStatus'] = $Transaction_State;
//This code will be calling the callback file directly
$pluginFolderName = basename(dirname(__FILE__));
include 'plugins/gateways/'.$pluginFolderName.'/Plugin'.ucfirst($pluginFolderName).'Callback.php';
$callbackClassName = 'Plugin'.ucfirst($pluginFolderName).'Callback';
$callback = new $callbackClassName;
$callback->setCallbackParams($newParams);
$callback->processCallback();
//Need to check to see if user is coming from signup
if ($params['fromDirectLink']) {
if ($success === true) {
$strMsg = $this->user->lang("Invoice(s) were processed successfully");
} else {
$strMsg = $this->user->lang("There was an error processing this invoice.");
}
$url = 'index.php';
CE_Lib::redirectPage($url, $strMsg);
exit;
} elseif ($params['isSignup'] == 1) {
// Actually handle the signup URL setting
if ($this->settings->get('Signup Completion URL') != '') {
if ($success === true) {
$returnUrl = $this->settings->get('Signup Completion URL').'?success=1';
} else {
$returnUrl = $this->settings->get('Signup Completion URL');
}
} else {
if ($success === true) {
$returnUrl = $params["clientExecURL"]."/order.php?step=complete&pass=1";
} else {
$returnUrl = $params["clientExecURL"]."/order.php?step=3";
}
}
} else {
if ($success === true) {
$returnUrl = $params["invoiceviewURLSuccess"];
} else {
$returnUrl = $params["invoiceviewURLCancel"];
}
}
header("Location: " . $returnUrl);
}
//NEW API CODE
public function getForm($params)
{
if ($params['from'] == 'paymentmethod') {
return '';
}
if ($params['from'] == 'signup') {
$fakeForm = '<a style="margin-left:0px;cursor:pointer;" class="app-btns primary customButton" onclick="cart.submit_form('.$params['loggedIn'].');" id="submitButton"></a>';
} else {
$fakeForm = '<button class="app-btns primary" id="submitButton">'.$this->user->lang('Pay Invoice').'</button>';
}
//NEW API CODE
$params['plugin_paypal_API Client ID'] = trim($this->settings->get('plugin_paypal_API Client ID'));
if ($params['plugin_paypal_API Client ID'] != '') {
$subscriptionsUsed = false;
if ($params['from'] == 'signup') {
$useRecurringPlugin = 0;
if ($this->user->getID() != 0) {
$useRecurringPlugin = $this->user->getUsePaypalSubscriptions();
} elseif (!is_null($this->settings->get('plugin_paypal_Paypal Subscriptions Option')) && $this->settings->get('plugin_paypal_Paypal Subscriptions Option') == 0) {
$useRecurringPlugin = 1;
}
$invoiceBillingCycleInDays = 0;
$invoiceBillingCycle = 0;
$billingCycleInDays = 0;
$billingCycle = 0;
foreach ($params['cartsummary']['cartItems'] as $cartItem) {
if ($cartItem['hasCoupon']) {
$coupon = new Coupon($cartItem['appliedCouponId']);
//monthly usage
$monthlyusage = $coupon->recurringmonths;
if (isset($monthlyusage) && is_numeric($monthlyusage) && $monthlyusage > 0) {
$useRecurringPlugin = 0;
}
}
$billingCycleObject = new BillingCycle($cartItem['trueTerm']);
$periodLengthInDays = 0;
switch ($billingCycleObject->time_unit) {
case 'd':
$periodLengthInDays = 1;
break;
case 'w':
$periodLengthInDays = 7;
break;
case 'm':
$periodLengthInDays = 30;
break;
case 'y':
$periodLengthInDays = 365;
break;
}
if ($invoiceBillingCycleInDays < ($billingCycleObject->amount_of_units * $periodLengthInDays)) {
$invoiceBillingCycleInDays = $billingCycleObject->amount_of_units * $periodLengthInDays;
$invoiceBillingCycle = $cartItem['trueTerm'];
}
if ($billingCycleInDays < ($billingCycleObject->amount_of_units * $periodLengthInDays)) {
$billingCycleInDays = $billingCycleObject->amount_of_units * $periodLengthInDays;
$billingCycle = $cartItem['trueTerm'];
}
if (isset($cartItem['hasAddons']) && $cartItem['hasAddons']) {
foreach ($cartItem['addons'] as $cartAddon) {
$addonBillingCycleObject = new BillingCycle($cartAddon['recurringprice_cyle']);
$addonPeriodLengthInDays = 0;
switch ($addonBillingCycleObject->time_unit) {
case 'd':
$addonPeriodLengthInDays = 1;
break;
case 'w':
$addonPeriodLengthInDays = 7;
break;
case 'm':
$addonPeriodLengthInDays = 30;
break;
case 'y':
$addonPeriodLengthInDays = 365;
break;
}
if ($invoiceBillingCycleInDays < ($addonBillingCycleObject->amount_of_units * $addonPeriodLengthInDays)) {
$invoiceBillingCycleInDays = $addonBillingCycleObject->amount_of_units * $addonPeriodLengthInDays;
$invoiceBillingCycle = $cartAddon['recurringprice_cyle'];
}
}
}
}
if (!$billingCycleInDays) {
$billingCycle = $invoiceBillingCycle;
}
$params['billingCycle'] = $billingCycle;
$newBillingCycleObject = new BillingCycle($params['billingCycle']);
$params['usingRecurringPlugin'] = $useRecurringPlugin;
$params['plugin_paypal_API Secret'] = trim($this->settings->get('plugin_paypal_API Secret'));
$params['invoiceProratingDays'] = (isset($params['cartsummary']['isProRating']))? $params['cartsummary']['isProRating'] : 0;
// use subscriptions only if has package fee
if ($params['usingRecurringPlugin'] == '1') {
// If prorating, avoid creating a subscription
// If period is greather than 5 years (60 months), avoid creating a subscription as Paypal does not support it
// Paypal currently only support subscriptions up to 5 Years
// https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
// Allowable values for t1 and t3 are:
// D – for days; allowable range for p1 and p3 is 1 to 90
// W - for weeks; allowable range for p1 and p3 is 1 to 52
// M – for months; allowable range for p1 and p3 is 1 to 24
// Y – for years; allowable range for p1 and p3 is 1 to 5
// However, in the new API, for frequency_interval, value cannot be greater than 12 months.
if ($params['plugin_paypal_API Secret'] != '' && !$params['invoiceProratingDays'] && $newBillingCycleObject->amount_of_units > 0
&& (($newBillingCycleObject->time_unit == 'd' && $newBillingCycleObject->amount_of_units <= 90)
|| ($newBillingCycleObject->time_unit == 'w' && $newBillingCycleObject->amount_of_units <= 52)
|| ($newBillingCycleObject->time_unit == 'm' && $newBillingCycleObject->amount_of_units <= 12)
|| ($newBillingCycleObject->time_unit == 'y' && $newBillingCycleObject->amount_of_units <= 1))) {
$subscriptionsUsed = true;
}
}
} else {
$tempInvoice = new Invoice($params['invoiceId']);
$tempUser = new User($tempInvoice->getUserID());
// if corresponding recurringfee entry has been set to disablegenereate=0 (after a subscription cancellation),
// or if it has a monthly usage
// then don't use paypal subscriptions even if the user settings say so
$useRecurringPlugin = $tempUser->getUsePaypalSubscriptions();
if ($useRecurringPlugin) {
$invoiceEntries = $tempInvoice->getInvoiceEntries();
foreach ($invoiceEntries as $invoiceEntry) {
if ($invoiceEntry->getRecurringAppliesTo() != 0) {
//** Removed old status field from recurringfee .. We need to check if
//maybe we need to add to sql to check for package status of 1 as a where clause
$query = "SELECT disablegenerate, monthlyusage FROM recurringfee WHERE id = ? ";
$result = $this->db->query($query, $invoiceEntry->getRecurringAppliesTo());
$row = $result->fetch();
if ($row) {
//recurringfee
if ($row['disablegenerate'] == '0') {
$useRecurringPlugin = 0;
break;
}
//monthly usage
$monthlyusage = explode("|", $row['monthlyusage']);
if (isset($monthlyusage[1]) && is_numeric($monthlyusage[1]) && $monthlyusage[1] > 0) {
$useRecurringPlugin = 0;
break;
}
}
}
}
}
// Do not start subscription if:
// - paying after due date
// - the invoice is partialy paid
// - there are multiple invoice entries for the same item
// - the invoice entries have different period start
// - it is an upgrade/downgrade invoice with invoice entries having different biling cycles
if ($useRecurringPlugin && ($tempInvoice->isPartiallyPaid() || $tempInvoice->isOverdue() || $tempInvoice->hasMultipleEntriesForSameItem() || !$tempInvoice->samePeriodStartAmongEntries() || ($tempInvoice->hasUpgradeDowngradeItems() && !$tempInvoice->sameCycleAmongEntries(true)))) {
$useRecurringPlugin = 0;
}
$invoiceBillingCycle = $tempInvoice->GetBillingCycle();
$invoiceEntriesBillingTypes = $tempInvoice->getInvoiceEntriesBillingTypes();
$invoiceEntriesBillingCycles = $tempInvoice->getBillingCycles();
$nonRecurringInvoices = true;
$manuallyEnteredInvoice = false;
for ($i = 0; $i < count($invoiceEntriesBillingTypes); $i++) {
$invoiceEntryBillingCycleObject = new BillingCycle($invoiceEntriesBillingCycles[$i]);
if ($invoiceEntriesBillingTypes[$i] < 0 || $invoiceEntryBillingCycleObject->amount_of_units > 0) {
$nonRecurringInvoices = false;
}
if ($invoiceEntriesBillingTypes[$i] > 0) {
$manuallyEnteredInvoice = true;
}
}
if ((!$billingCycle = $tempInvoice->getRelatedPackageBillingCycle()) || $nonRecurringInvoices || $manuallyEnteredInvoice || $tempInvoice->hasUpgradeDowngradeItems()) {
$billingCycle = $invoiceBillingCycle;
}
$params['billingCycle'] = $billingCycle;
$anotherBillingCycleObject = new BillingCycle($params['billingCycle']);
$params['usingRecurringPlugin'] = $useRecurringPlugin;
$params['invoicePackageUnproratedFee'] = $tempInvoice->getPackageUnproratedRecurringFee($billingCycle);
$params['plugin_paypal_API Secret'] = trim($this->settings->get('plugin_paypal_API Secret'));
$params['invoiceProratingDays'] = $tempInvoice->hasProratedCharges();
// use subscriptions only if has package fee
if ($params['usingRecurringPlugin'] == '1' && isset($params['invoicePackageUnproratedFee'])) {
// If prorating, avoid creating a subscription
// If period is greather than 5 years (60 months), avoid creating a subscription as Paypal does not support it
// Paypal currently only support subscriptions up to 5 Years
// https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
// Allowable values for t1 and t3 are:
// D – for days; allowable range for p1 and p3 is 1 to 90
// W - for weeks; allowable range for p1 and p3 is 1 to 52
// M – for months; allowable range for p1 and p3 is 1 to 24
// Y – for years; allowable range for p1 and p3 is 1 to 5
// However, in the new API, for frequency_interval, value cannot be greater than 12 months.
if ($params['plugin_paypal_API Secret'] != '' && !$params['invoiceProratingDays'] && $anotherBillingCycleObject->amount_of_units > 0
&& (($anotherBillingCycleObject->time_unit == 'd' && $anotherBillingCycleObject->amount_of_units <= 90)
|| ($anotherBillingCycleObject->time_unit == 'w' && $anotherBillingCycleObject->amount_of_units <= 52)
|| ($anotherBillingCycleObject->time_unit == 'm' && $anotherBillingCycleObject->amount_of_units <= 12)
|| ($anotherBillingCycleObject->time_unit == 'y' && $anotherBillingCycleObject->amount_of_units <= 1))) {
$subscriptionsUsed = true;
}
}
}
if ($subscriptionsUsed) {
CE_Lib::log(4, 'Paypal getForm subscription new API');
return $fakeForm;
} else {
$this->view->sandboxClientID = $this->getVariable('API Client ID');
$this->view->productionClientID = $this->getVariable('API Client ID');
if ($this->getVariable('Use PayPal Sandbox')) {
$this->view->environment = 'sandbox';
} else {
$this->view->environment = 'production';
}
$this->view->amount = $params['invoiceBalanceDue'];
$this->view->invoiceId = $params['invoiceId'];
$this->view->currency = $params['currency'];
$this->view->from = $params['from'];
$this->view->termsConditions = $params['termsConditions'];
$this->view->fromDirectLink = (isset($params['fromDirectLink']))? $params['fromDirectLink']: false;
CE_Lib::log(4, 'Paypal getForm singlepayment new API');
return $this->view->render('form.phtml');
}
}
//NEW API CODE
CE_Lib::log(4, 'Paypal getForm old API');
return $fakeForm;
}
//NEW API CODE
function newAPIcreateSubscription($params)
{
// This var will be used to pass the excluded recurring fees ids for the subscription if any
$tRecurringExclude = '';
if ($params['invoicePackageUnproratedFee'] && count($params['invoiceExcludedRecurrings']) > 0) {
$tRecurringExclude = '_'.implode(',', $params['invoiceExcludedRecurrings']);
}
$params['new_api_custom'] = $params['invoiceNumber']."_".$params['usingRecurringPlugin']."_1".$tRecurringExclude;
$access_token = '';
$webhooks = array();
$webhookfound = false;
$plan_id = '';
$links = array();
$approval_url = '';
$execute = '';
$token = '';
$agreement_id = '';
//Get an access token
//https://developer.paypal.com/docs/api/overview/#get-an-access-token
$access_token = $this->getAnAccessToken($params);
//Pass this variable to your gateway to let it know where to send a callback.
$urlFix = mb_substr($params['clientExecURL'], -1, 1) == "//" ? '' : '/';
$callbackUrl = $params['clientExecURL'].$urlFix.'plugins/gateways/paypal/callback.php?newApi=1';
//List all webhooks
//https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get-all
$webhooks = $this->listAllWebhooks($params, $access_token);
foreach ($webhooks as $webhook) {
if ($webhook['url'] == $callbackUrl) {
$webhookfound = true;
break;
}
}
if (!$webhookfound) {
//Create webhook
//https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_create
$this->createWebhook($params, $access_token, $callbackUrl);
}
//Create a plan
//https://developer.paypal.com/docs/subscriptions/integrate/integrate-steps/#1-create-a-plan
$plan_id = $this->createAPlan($params, $access_token, $callbackUrl);
//Activate a plan
//https://developer.paypal.com/docs/subscriptions/integrate/integrate-steps/#2-activate-a-plan
$this->activateAPlan($params, $access_token, $plan_id);
//Create an agreement
//https://developer.paypal.com/docs/subscriptions/integrate/integrate-steps/#3-create-an-agreement
$links = $this->createAnAgreement($params, $access_token, $plan_id);
foreach ($links as $link) {
switch ($link['rel']) {
case 'approval_url':
$approval_url = $link['href'];
break;
case 'execute':
$execute = $link['href'];
break;
}
}
//Get customer approval
//https://developer.paypal.com/docs/subscriptions/integrate/integrate-steps/#4-get-customer-approval
$this->getCustomerApproval($params, $approval_url);
}
//NEW API CODE
function newAPIcancelSubscription($params)
{
$access_token = '';
$agreement_id = $params['subscriptionId'];
//Get an access token
//https://developer.paypal.com/docs/api/overview/#get-an-access-token
$access_token = $this->getAnAccessToken($params);
//Pass this variable to your gateway to let it know where to send a callback.
$params['clientExecURL'] = CE_Lib::getSoftwareURL();
$urlFix = mb_substr($params['clientExecURL'], -1, 1) == "//" ? '' : '/';
$callbackUrl = $params['clientExecURL'].$urlFix.'plugins/gateways/paypal/callback.php?newApi=1';
//List all webhooks
//https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get-all
$webhooks = $this->listAllWebhooks($params, $access_token);
foreach ($webhooks as $webhook) {
if ($webhook['url'] == $callbackUrl) {
$webhookfound = true;
break;
}
}
if (!$webhookfound) {
//Create webhook
//https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_create
$this->createWebhook($params, $access_token, $callbackUrl);
}
//Cancel agreement
//https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_cancel
$response = $this->cancelAgreement($params, $access_token, $agreement_id);
//If it has an invalid status, assume it was already canceled
if (isset($response['name']) && in_array($response['name'], array('STATUS_INVALID'))) {
$this->removeSubscriptionReference($agreement_id);
return;
}
//If "The profile ID is invalid" or "Merchant account is denied", try to cancel using the old API
if (isset($response['name']) && in_array($response['name'], array('INVALID_PROFILE_ID', 'MERCHANT_ACCOUNT_DENIED'))) {
return $this->oldAPIcancelSubscription($params);
}
$agreement = array();
//Show agreement details
//https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_get
$agreement = $this->showAgreementDetails($access_token, $agreement_id);
$customValues = explode("_", $agreement['description']);
$tInvoiceID = $customValues[0];
$tIsRecurring = $customValues[1];
$tGenerateInvoice = $customValues[2];
$tRecurringExclude = '';
if (isset($customValues[3])) {
$tRecurringExclude = $customValues[3];
}
// Create Plugin class object to interact with CE.
$cPlugin = new Plugin($tInvoiceID, 'paypal', $this->user);
CE_Lib::log(4, "Subscription has been cancelled.");
$tUser = new User($cPlugin->m_Invoice->m_UserID);
if (in_array($tUser->getStatus(), StatusAliasGateway::getInstance($this->user)->getUserStatusIdsFor(USER_STATUS_CANCELLED))) {