forked from OXID-eSales/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.php
806 lines (708 loc) · 18.4 KB
/
Config.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
<?php
/**
* This file is part of OXID eSales PayPal module.
*
* OXID eSales PayPal module is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OXID eSales PayPal module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OXID eSales PayPal module. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.oxid-esales.com
* @copyright (C) OXID eSales AG 2003-2018
*/
namespace OxidEsales\PayPalModule\Core;
/**
* PayPal config class
*/
class Config
{
/**
* PayPal payment was triggered via standard checkout by selecting PP as the payment method.
*
* @var int
*/
const OEPAYPAL_ECS = 1;
/**
* PayPal payment was triggered by shortcut button in basket step.
*
* @var int
*/
const OEPAYPAL_SHORTCUT = 2;
/**
* Name of session variable that marks how payment was triggered.
*
* @var string
*/
const OEPAYPAL_TRIGGER_NAME = 'oepaypal';
/**
* Name of partnercode array key in case payment was triggered by shortcut button.
*
* @var string
*/
const PARTNERCODE_SHORTCUT_KEY = 'SHORTCUT';
/**
* PayPal module id.
*
* @var string
*/
protected $payPalId = 'oepaypal';
/**
* PayPal host.
*
* @var string
*/
protected $payPalHost = 'api-3t.paypal.com';
/**
* PayPal sandbox host.
*
* @var string
*/
protected $payPalSandboxHost = 'api-3t.sandbox.paypal.com';
/**
* PayPal sandbox Url where user must be redirected after his session gets PayPal token.
*
* @var string
*/
protected $payPalSandboxUrl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
/**
* PayPal Url where user must be redirected after his session gets PayPal token.
*
* @var string
*/
protected $payPalUrl = 'https://www.paypal.com/cgi-bin/webscr';
/**
* PayPal sandbox API url.
*
* @var string
*/
protected $payPalSandboxApiUrl = 'https://api-3t.sandbox.paypal.com/nvp';
/**
* PayPal API url.
*
* @var string
*/
protected $payPalApiUrl = 'https://api-3t.paypal.com/nvp';
/**
* Maximum possible delivery costs value.
*
* @var double
*/
protected $maxDeliveryAmount = 30;
/**
* Please do not change this place.
* It is important to guarantee the future development of this OXID eShop extension and to keep it free of charge.
* Thanks!
*
* @var array Partner codes based on edition
*/
protected $partnerCodes = array(
'EE' => 'OXID_Cart_EnterpriseECS',
'PE' => 'OXID_Cart_ProfessionalECS',
'CE' => 'OXID_Cart_CommunityECS',
'SHORTCUT' => 'Oxid_Cart_ECS_Shortcut'
);
/**
* Return PayPal module id.
*
* @return string
*/
public function getModuleId()
{
return $this->payPalId;
}
/**
* Sets PayPal host.
*
* @param string $payPalHost
*/
public function setPayPalHost($payPalHost)
{
$this->payPalHost = $payPalHost;
}
/**
* Returns PayPal host.
*
* @return string
*/
public function getPayPalHost()
{
$host = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalHost');
if ($host) {
$this->setPayPalHost($host);
}
return $this->payPalHost;
}
/**
* Sets PayPal sandbox host.
*
* @param string $payPalSandboxHost
*/
public function setPayPalSandboxHost($payPalSandboxHost)
{
$this->payPalSandboxHost = $payPalSandboxHost;
}
/**
* Returns PayPal sandbox host.
*
* @return string
*/
public function getPayPalSandboxHost()
{
$host = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxHost');
if ($host) {
$this->setPayPalSandboxHost($host);
}
return $this->payPalSandboxHost;
}
/**
* Returns PayPal OR PayPal sandbox host.
*
* @return string
*/
public function getHost()
{
if ($this->isSandboxEnabled()) {
$url = $this->getPayPalSandboxHost();
} else {
$url = $this->getPayPalHost();
}
return $url;
}
/**
* Api Url setter
*
* @param string $payPalApiUrl
*/
public function setPayPalApiUrl($payPalApiUrl)
{
$this->payPalApiUrl = $payPalApiUrl;
}
/**
* Api Url getter
*
* @return string
*/
public function getPayPalApiUrl()
{
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalApiUrl');
if ($url) {
$this->setPayPalApiUrl($url);
}
return $this->payPalApiUrl;
}
/**
* PayPal sandbox api url setter
*
* @param string $payPalSandboxApiUrl
*/
public function setPayPalSandboxApiUrl($payPalSandboxApiUrl)
{
$this->payPalSandboxApiUrl = $payPalSandboxApiUrl;
}
/**
* PayPal sandbox api url getter
*
* @return string
*/
public function getPayPalSandboxApiUrl()
{
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxApiUrl');
if ($url) {
$this->setPayPalSandboxApiUrl($url);
}
return $this->payPalSandboxApiUrl;
}
/**
* Returns end point url
*
* @return string
*/
public function getApiUrl()
{
if ($this->isSandboxEnabled()) {
$url = $this->getPayPalSandboxApiUrl();
} else {
$url = $this->getPayPalApiUrl();
}
return $url;
}
/**
* PayPal Url Setter
*
* @param string $payPalUrl
*/
public function setPayPalUrl($payPalUrl)
{
$this->payPalUrl = $payPalUrl;
}
/**
* PayPal sandbox url setter
*
* @param string $payPalSandboxUrl
*/
public function setPayPalSandboxUrl($payPalSandboxUrl)
{
$this->payPalSandboxUrl = $payPalSandboxUrl;
}
/**
* PayPal sandbox url getter
*
* @return string
*/
public function getPayPalUrl()
{
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalUrl');
if ($url) {
$this->setPayPalUrl($url);
}
return $this->payPalUrl;
}
/**
* PayPal sandbox url getter
*
* @return string
*/
public function getPayPalSandboxUrl()
{
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxUrl');
if ($url) {
$this->setPayPalSandboxUrl($url);
}
return $this->payPalSandboxUrl;
}
/**
* Get PayPal url.
*
* @return string
*/
public function getUrl()
{
if ($this->isSandboxEnabled()) {
$url = $this->getPayPalSandboxUrl();
} else {
$url = $this->getPayPalUrl();
}
return $url;
}
/**
* Returns module config parameter value
*
* @param string $paramName parameter name
*
* @return mixed
*/
public function getParameter($paramName)
{
return \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam($paramName);
}
/**
* Returns true if Express Checkout is ON
*
* @return bool
*/
public function isExpressCheckoutEnabled()
{
return $this->getParameter('blOEPayPalExpressCheckout');
}
/**
* Returns true if Express Checkout is ON in mini basket
*
* @return bool
*/
public function isExpressCheckoutInMiniBasketEnabled()
{
return $this->getParameter('blOEPayPalECheckoutInMiniBasket');
}
/**
* Returns true if Standard PayPal Checkout is ON
*
* @return bool
*/
public function isStandardCheckoutEnabled()
{
return $this->getParameter('blOEPayPalStandardCheckout');
}
/**
* Returns true if logging request/response to PayPal is enabled
*
* @return bool
*/
public function isLoggingEnabled()
{
return $this->getParameter('blPayPalLoggerEnabled');
}
/**
* Returns Brand/Shop name [OXID ESHOP]
*
* @return string
*/
public function getBrandName()
{
$shopName = $this->getParameter('sOEPayPalBrandName');
if (empty($shopName)) {
$shop = \OxidEsales\Eshop\Core\Registry::getConfig()->getActiveShop();
$shopName = $shop->oxshops__oxname->value;
}
return $shopName;
}
/**
* Returns custom cart border color which is displayed in PayPal side
*
* @return string
*/
public function getBorderColor()
{
return $this->getParameter('sOEPayPalBorderColor');
}
/**
* Returns TRUE if order finalization on PayPal side is on
*
* @return bool
*/
public function finalizeOrderOnPayPalSide()
{
$finalize = $this->getParameter('blOEPayPalFinalizeOrderOnPayPal');
return $finalize !== null ? $finalize : false;
}
/**
* Send order info to PayPal or not
*
* @return bool
*/
public function sendOrderInfoToPayPal()
{
return $this->getParameter('blOEPayPalSendToPayPal');
}
/**
* Send order info to PayPal or not config's default value: checked or not
*
* @return bool
*/
public function sendOrderInfoToPayPalDefault()
{
return $this->getParameter('blOEPayPalDefaultUserChoice');
}
/**
* Guest buy mode getter
*
* @return bool
*/
public function isGuestBuyEnabled()
{
return $this->getParameter('blOEPayPalGuestBuyRole');
}
/**
* Returns true of GiroPay is ON (not implemented yet)
*
* @return bool
*/
public function isGiroPayEnabled()
{
return false;
}
/**
* Returns true of sandbox mode is ON
*
* @return bool
*/
public function isSandboxEnabled()
{
return $this->getParameter('blOEPayPalSandboxMode');
}
/**
* Returns Empty Stock Level
*
* @return string
*/
public function getEmptyStockLevel()
{
return $this->getParameter('sOEPayPalEmptyStockLevel');
}
/**
* Returns PayPal password
*
* @return string
*/
public function getPassword()
{
if ($this->isSandboxEnabled()) {
// sandbox password
return $this->getParameter('sOEPayPalSandboxPassword');
}
// password
return $this->getParameter('sOEPayPalPassword');
}
/**
* Returns PayPal user name
*
* @return string
*/
public function getUserName()
{
if ($this->isSandboxEnabled()) {
// sandbox login
return $this->getParameter('sOEPayPalSandboxUsername');
}
// login
return $this->getParameter('sOEPayPalUsername');
}
/**
* Returns PayPal user name
*
* @return string
*/
public function getUserEmail()
{
if ($this->isSandboxEnabled()) {
// sandbox login
return $this->getParameter('sOEPayPalSandboxUserEmail');
}
// login
return $this->getParameter('sOEPayPalUserEmail');
}
/**
* Returns PayPal signature
*
* @return string
*/
public function getSignature()
{
if ($this->isSandboxEnabled()) {
// sandbox signature
return $this->getParameter('sOEPayPalSandboxSignature');
}
// test sandbox signature
return $this->getParameter('sOEPayPalSignature');
}
/**
* Returns PayPal transaction mode
*
* @return string
*/
public function getTransactionMode()
{
return $this->getParameter('sOEPayPalTransactionMode');
}
/**
* Returns redirect url.
*
* @param string $token token to append to redirect url.
* @param string $userAction checkout button action - continue (standard checkout) or commit (express checkout)
*
* @return string
*/
public function getPayPalCommunicationUrl($token = null, $userAction = 'continue')
{
return $this->getUrl() . '&cmd=_express-checkout&token=' . (string) $token . '&useraction=' . (string) $userAction;
}
/**
* Get logo Url based on selected settings
* Returns shop url, or false
*
* @return string|bool
*/
public function getLogoUrl()
{
$logoUrl = false;
$logoName = $this->getLogoImageName();
if (!empty($logoName)) {
$logo = oxNew(\OxidEsales\PayPalModule\Core\ShopLogo::class);
$logo->setImageDir(\OxidEsales\Eshop\Core\Registry::getConfig()->getImageDir());
$logo->setImageDirUrl(\OxidEsales\Eshop\Core\Registry::getConfig()->getImageUrl());
$logo->setImageName($logoName);
$logo->setImageHandler(\OxidEsales\Eshop\Core\Registry::getUtilsPic());
$logoUrl = $logo->getShopLogoUrl();
}
return $logoUrl;
}
/**
* Returns IPN callback url
*
* @return string
*/
public function getIPNCallbackUrl()
{
return $this->getShopUrl() . 'index.php?cl=oepaypalipnhandler&fnc=handleRequest&shp=' . $this->getShopId();
}
/**
* Methods checks if sending of IPN callback url to PayPal is supressed by configuration.
*
* @return bool
*/
public function suppressIPNCallbackUrl()
{
return (bool) \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('OEPayPalDisableIPN');
}
/**
* Returns SSL or non SSL shop URL without index.php depending on Mall
* affecting environment is admin mode and current ssl usage status
*
* @param bool $admin if admin
*
* @return string
*/
public function getShopUrl($admin = null)
{
return \OxidEsales\Eshop\Core\Registry::getConfig()->getCurrentShopUrl($admin);
}
/**
* Wrapper to get language object from registry.
*
* @return \OxidEsales\Eshop\Core\Language
*/
public function getLang()
{
return \OxidEsales\Eshop\Core\Registry::getLang();
}
/**
* Wrapper to get utils object from registry.
*
* @return \OxidEsales\Eshop\Core\Utils
*/
public function getUtils()
{
return \OxidEsales\Eshop\Core\Registry::getUtils();
}
/**
* Returns shop charset
*
* @return string
*/
public function getCharset()
{
$charset = 'UTF-8';
return $charset;
}
/**
* @deprecated in dev-master (2018-04-27); Use OxidEsales\PayPalModule\Core\IPnConfig::getIPNResponseUrl()
*
* Returns Url for IPN response call to notify PayPal
*
* @return string
*/
public function getIPNResponseUrl()
{
return $this->getUrl() . '&cmd=_notify-validate';
}
/**
* Returns true if Express Checkout is in details page
*
* @return bool
*/
public function isExpressCheckoutInDetailsPage()
{
return $this->getParameter('blOEPayPalECheckoutInDetails');
}
/**
* Returns current URL
*
* @return string
*/
public function getCurrentUrl()
{
return \OxidEsales\Eshop\Core\Registry::getUtilsUrl()->getCurrentUrl();
}
/**
* Returns max delivery amount.
*
* @return integer
*/
public function getMaxPayPalDeliveryAmount()
{
$maxDeliveryAmount = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dMaxPayPalDeliveryAmount');
if (!$maxDeliveryAmount) {
$maxDeliveryAmount = $this->maxDeliveryAmount;
}
return $maxDeliveryAmount;
}
/**
* Please do not change this place.
* It is important to guarantee the future development of this OXID eShop extension and to keep it free of charge.
* Thanks!
*
* @return string partner code.
*/
public function getPartnerCode()
{
$facts = new \OxidEsales\Facts\Facts();
$key = $this->isShortcutPayment() ? self::PARTNERCODE_SHORTCUT_KEY : $facts->getEdition();
return $this->partnerCodes[$key];
}
/**
* Detects device type
*
* @return bool
*/
public function isDeviceMobile()
{
$userAgent = oxNew(\OxidEsales\PayPalModule\Core\UserAgent::class);
return ($userAgent->getDeviceType() == 'mobile');
}
/**
* Returns id of shipping assigned for EC for mobile devices
*
* @return string
*/
public function getMobileECDefaultShippingId()
{
return \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sOEPayPalMECDefaultShippingId');
}
/**
* Returns logo image name according to parameter
*
* @return mixed|string
*/
protected function getLogoImageName()
{
$option = $this->getParameter('sOEPayPalLogoImageOption');
switch ($option) {
case 'shopLogo':
$logo = $this->getParameter('sShopLogo');
break;
case 'customLogo':
$logo = $this->getParameter('sOEPayPalCustomShopLogoImage');
break;
case 'noLogo':
default:
$logo = '';
return $logo;
}
return $logo;
}
/**
* Returns active shop id
*
* @return string
*/
protected function getShopId()
{
return \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId();
}
/**
* Returns oxConfig instance
*
* @return \OxidEsales\Eshop\Core\Config
*/
protected function getConfig()
{
return \OxidEsales\Eshop\Core\Registry::getConfig();
}
/**
* Was the payment triggered by shortcut button or not?
*
* @return bool
*/
protected function isShortcutPayment()
{
$trigger = (int) \OxidEsales\Eshop\Core\Registry::getSession()->getVariable(self::OEPAYPAL_TRIGGER_NAME);
return (bool) ($trigger == self::OEPAYPAL_SHORTCUT);
}
}