-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Copy pathConfig.php
1871 lines (1731 loc) · 49 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
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
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Model;
use Magento\Csp\Helper\CspNonceProvider;
use Magento\Framework\App\ObjectManager;
use Magento\Payment\Helper\Formatter;
/**
* Config model that is aware of all \Magento\Paypal payment methods
*
* Works with PayPal-specific system configuration
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Config extends AbstractConfig
{
use Formatter;
/**
* PayPal Express
*/
public const METHOD_EXPRESS = 'paypal_express';
/**
* PayPal Standard - alias METHOD_WPP_EXPRESS
*/
public const METHOD_WPS_EXPRESS = 'wps_express';
/**
* PayPal Standard Bml - alias METHOD_WPP_BML
*/
public const METHOD_WPS_BML = 'wps_express_bml';
/**
* PayPal Bill Me Later - Express Checkout
*/
public const METHOD_WPP_BML = 'paypal_express_bml';
/**
* PayPal Website Payments Pro - Direct Payments
*/
public const METHOD_WPP_DIRECT = 'paypal_direct';
/**
* PayPal Website Payments Pro - Direct Payments - alias METHOD_PAYFLOWPRO
*/
public const METHOD_PAYMENT_PRO = 'paypal_payment_pro';
/**
* Express Checkout (Payflow Edition)
*/
public const METHOD_WPP_PE_EXPRESS = 'payflow_express';
/**
* PayPal Bill Me Later - Express Checkout (Payflow Edition)
*/
public const METHOD_WPP_PE_BML = 'payflow_express_bml';
/**
* Payflow Pro Gateway
*/
public const METHOD_PAYFLOWPRO = 'payflowpro';
public const METHOD_PAYFLOWLINK = 'payflow_link';
public const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
public const METHOD_HOSTEDPRO = 'hosted_pro';
public const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
/**#@+
* Buttons and images
*/
public const EC_FLAVOR_DYNAMIC = 'dynamic';
public const EC_FLAVOR_STATIC = 'static';
public const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
public const EC_BUTTON_TYPE_MARK = 'ecmark';
public const PAYMENT_MARK_SMALL = 'small';
public const PAYMENT_MARK_MEDIUM = 'medium';
public const PAYMENT_MARK_LARGE = 'large';
/**#@-*/
public const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
/**#@+
* Payment actions
*/
public const AUTHORIZATION_AMOUNT_ONE = 1;
public const AUTHORIZATION_AMOUNT_FULL = 2;
/**#@-*/
/**#@+
* Require Billing Address
*/
public const REQUIRE_BILLING_ADDRESS_NO = 0;
public const REQUIRE_BILLING_ADDRESS_ALL = 1;
public const REQUIRE_BILLING_ADDRESS_VIRTUAL = 2;
/**#@-*/
/**#@+
* Fraud management actions
*/
public const FRAUD_ACTION_ACCEPT = 'Acept';
public const FRAUD_ACTION_DENY = 'Deny';
/**#@-*/
/**#@+
* Refund types
*/
public const REFUND_TYPE_FULL = 'Full';
public const REFUND_TYPE_PARTIAL = 'Partial';
/**#@-*/
/**#@+
* Express Checkout flows
*/
public const EC_SOLUTION_TYPE_SOLE = 'Sole';
public const EC_SOLUTION_TYPE_MARK = 'Mark';
/**#@-*/
/**#@+
* Payment data transfer methods (Standard)
*/
public const WPS_TRANSPORT_IPN = 'ipn';
public const WPS_TRANSPORT_PDT = 'pdt';
public const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
/**#@-*/
/**#@+
* Billing Agreement Signup type
*/
public const EC_BA_SIGNUP_AUTO = 'auto';
public const EC_BA_SIGNUP_ASK = 'ask';
public const EC_BA_SIGNUP_NEVER = 'never';
/**
* Paypal setting
*/
public const TRANSFER_CART_LINE_ITEMS = 'lineItemsEnabled';
public const TRANSFER_SHIPPING_OPTIONS = 'transferShippingOptions';
/**#@-*/
/**
* Config path for enabling/disabling order review step in express checkout
*/
public const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
/**
* PayPal PayLater
*/
public const PAYLATER = 'paypal_paylater';
/**
*
* @var array
*/
protected $_buildNotationPPMap = [
'paypal_express' => 'EC',
'paypal_direct' => 'DP',
'payflow_express' => 'EC',
];
/**
*
* @var array
*/
protected $_ecStyleConfigMap = [
'page_style' => 'page_style',
'paypal_hdrimg' => 'hdrimg',
'paypal_hdrbordercolor' => 'hdrbordercolor',
'paypal_hdrbackcolor' => 'hdrbackcolor',
'paypal_payflowcolor' => 'payflowcolor',
];
/**
*
* @var string[]
*/
protected $_supportedCurrencyCodes = [
'AUD',
'CAD',
'CZK',
'DKK',
'EUR',
'HKD',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PLN',
'GBP',
'RUB',
'SGD',
'SEK',
'CHF',
'TWD',
'THB',
'USD',
'INR',
];
/**
*
* @var string[]
*/
protected $_supportedCountryCodes = [
'AE',
'AR',
'AT',
'AU',
'BE',
'BG',
'BR',
'CA',
'CN',
'CH',
'CL',
'CR',
'CY',
'CZ',
'DE',
'DK',
'DO',
'EC',
'EE',
'ES',
'FI',
'FR',
'GB',
'GF',
'GI',
'GP',
'GR',
'HK',
'HU',
'ID',
'IE',
'IL',
'IN',
'IS',
'IT',
'JM',
'JP',
'KR',
'LI',
'LT',
'LU',
'LV',
'MQ',
'MT',
'MX',
'MY',
'NL',
'NO',
'NZ',
'PH',
'PL',
'PT',
'RU',
'RE',
'RO',
'SE',
'SG',
'SI',
'SK',
'SM',
'TH',
'TR',
'TW',
'US',
'UY',
'VE',
'VN',
'ZA',
];
/**
*
* @var string[]
*/
protected $_supportedBuyerCountryCodes = [
'AF ',
'AX ',
'AL ',
'DZ ',
'AS ',
'AD ',
'AO ',
'AI ',
'AQ ',
'AG ',
'AR ',
'AM ',
'AW ',
'AU ',
'AT ',
'AZ ',
'BS ',
'BH ',
'BD ',
'BB ',
'BY ',
'BE ',
'BZ ',
'BJ ',
'BM ',
'BT ',
'BO ',
'BA ',
'BW ',
'BV ',
'BR ',
'IO ',
'BN ',
'BG ',
'BF ',
'BI ',
'KH ',
'CM ',
'CA ',
'CV ',
'KY ',
'CF ',
'TD ',
'CL ',
'CN ',
'CX ',
'CC ',
'CO ',
'KM ',
'CG ',
'CD ',
'CK ',
'CR ',
'CI ',
'HR ',
'CU ',
'CY ',
'CZ ',
'DK ',
'DJ ',
'DM ',
'DO ',
'EC ',
'EG ',
'SV ',
'GQ ',
'ER ',
'EE ',
'ET ',
'FK ',
'FO ',
'FJ ',
'FI ',
'FR ',
'GF ',
'PF ',
'TF ',
'GA ',
'GM ',
'GE ',
'DE ',
'GH ',
'GI ',
'GR ',
'GL ',
'GD ',
'GP ',
'GU ',
'GT ',
'GG ',
'GN ',
'GW ',
'GY ',
'HT ',
'HM ',
'VA ',
'HN ',
'HK ',
'HU ',
'IS ',
'IN ',
'ID ',
'IR ',
'IQ ',
'IE ',
'IM ',
'IL ',
'IT ',
'JM ',
'JP ',
'JE ',
'JO ',
'KZ ',
'KE ',
'KI ',
'KP ',
'KR ',
'KW ',
'KG ',
'LA ',
'LV ',
'LB ',
'LS ',
'LR ',
'LY ',
'LI ',
'LT ',
'LU ',
'MO ',
'MK ',
'MG ',
'MW ',
'MY ',
'MV ',
'ML ',
'MT ',
'MH ',
'MQ ',
'MR ',
'MU ',
'YT ',
'MX ',
'FM ',
'MD ',
'MC ',
'MN ',
'MS ',
'MA ',
'MZ ',
'MM ',
'NA ',
'NR ',
'NP ',
'NL ',
'AN ',
'NC ',
'NZ ',
'NI ',
'NE ',
'NG ',
'NU ',
'NF ',
'MP ',
'NO ',
'OM ',
'PK ',
'PW ',
'PS ',
'PA ',
'PG ',
'PY ',
'PE ',
'PH ',
'PN ',
'PL ',
'PT ',
'PR ',
'QA ',
'RE ',
'RO ',
'RU ',
'RW ',
'SH ',
'KN ',
'LC ',
'PM ',
'VC ',
'WS ',
'SM ',
'ST ',
'SA ',
'SN ',
'CS ',
'SC ',
'SL ',
'SG ',
'SK ',
'SI ',
'SB ',
'SO ',
'ZA ',
'GS ',
'ES ',
'LK ',
'SD ',
'SR ',
'SJ ',
'SZ ',
'SE ',
'CH ',
'SY ',
'TW ',
'TJ ',
'TZ ',
'TH ',
'TL ',
'TG ',
'TK ',
'TO ',
'TT ',
'TN ',
'TR ',
'TM ',
'TC ',
'TV ',
'UG ',
'UA ',
'AE ',
'GB ',
'US ',
'UM ',
'UY ',
'UZ ',
'VU ',
'VE ',
'VN ',
'VG ',
'VI ',
'WF ',
'EH ',
'YE ',
'ZM ',
'ZW',
];
/**
* Locale codes supported by misc images (marks, shortcuts etc)
*
* @var string[]
* @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration#id089QD0O0TX4__id08AH904I0YK
*/
protected $_supportedImageLocales = [
'de_DE',
'en_AU',
'en_GB',
'en_US',
'es_ES',
'es_XC',
'fr_FR',
'fr_XC',
'it_IT',
'ja_JP',
'nl_NL',
'pl_PL',
'zh_CN',
'zh_XC',
];
/**
* Core data
*
* @var \Magento\Directory\Helper\Data
*/
protected $directoryHelper;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @var \Magento\Payment\Model\Source\CctypeFactory
*/
protected $_cctypeFactory;
/**
* @var \Magento\Paypal\Model\CertFactory
*/
protected $_certFactory;
/**
* @var CspNonceProvider
*/
protected $cspNonceProvider;
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Directory\Helper\Data $directoryHelper
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory
* @param CertFactory $certFactory
* @param array $params
* @param CspNonceProvider|null $cspNonceProvider
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Directory\Helper\Data $directoryHelper,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Payment\Model\Source\CctypeFactory $cctypeFactory,
\Magento\Paypal\Model\CertFactory $certFactory,
$params = [],
?CspNonceProvider $cspNonceProvider = null
) {
parent::__construct($scopeConfig);
$this->directoryHelper = $directoryHelper;
$this->_storeManager = $storeManager;
$this->_cctypeFactory = $cctypeFactory;
$this->_certFactory = $certFactory;
if ($params) {
$method = array_shift($params);
$this->setMethod($method);
if ($params) {
$storeId = array_shift($params);
$this->setStoreId($storeId);
}
}
$this->cspNonceProvider = $cspNonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
}
/**
* Check whether method available for checkout or not
*
* Logic based on merchant country, methods dependence
*
* @param string|null $methodCode
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function isMethodAvailable($methodCode = null)
{
$result = parent::isMethodAvailable($methodCode);
switch ($methodCode) {
case self::METHOD_WPP_EXPRESS:
case self::METHOD_WPS_EXPRESS:
if ($this->isMethodActive(self::METHOD_PAYFLOWPRO)
|| $this->isMethodActive(self::METHOD_PAYMENT_PRO)
) {
$result = true;
}
break;
case self::METHOD_WPP_BML:
case self::METHOD_WPS_BML:
// check for express payments dependence
if (!$this->isMethodActive(self::METHOD_WPP_EXPRESS)
&& !$this->isMethodActive(self::METHOD_WPS_EXPRESS)
) {
$result = false;
}
break;
case self::METHOD_WPP_PE_EXPRESS:
// check for direct payments dependence
if ($this->isMethodActive(self::METHOD_PAYFLOWLINK)
|| $this->isMethodActive(self::METHOD_PAYFLOWADVANCED)
) {
$result = true;
} elseif (!$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
$result = false;
}
break;
case self::METHOD_WPP_PE_BML:
// check for express payments dependence
if (!$this->isMethodActive(self::METHOD_WPP_PE_EXPRESS)) {
$result = false;
}
break;
case self::METHOD_BILLING_AGREEMENT:
$result = $this->isWppApiAvailable();
break;
}
return $result;
}
/**
* Return merchant country codes supported by PayPal
*
* @return string[]
*/
public function getSupportedMerchantCountryCodes()
{
return $this->_supportedCountryCodes;
}
/**
* Return buyer country codes supported by PayPal
*
* @return string[]
*/
public function getSupportedBuyerCountryCodes()
{
return $this->_supportedBuyerCountryCodes;
}
/**
* Return merchant country code, use default country if it not specified in General settings
*
* @return string
*/
public function getMerchantCountry()
{
$countryCode = $this->_scopeConfig->getValue(
$this->_mapGeneralFieldset('merchant_country'),
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_storeId
);
if (!$countryCode) {
$countryCode = $this->directoryHelper->getDefaultCountry($this->_storeId);
}
return $countryCode;
}
/**
* Check whether method supported for specified country or not
*
* Use $_methodCode and merchant country by default
*
* @param string|null $method
* @param string|null $countryCode
* @return bool
*/
public function isMethodSupportedForCountry($method = null, $countryCode = null)
{
if ($method === null) {
$method = $this->getMethodCode();
}
if ($countryCode === null) {
$countryCode = $this->getMerchantCountry();
}
return in_array($method, $this->getCountryMethods($countryCode));
}
/**
* Return list of allowed methods for specified country iso code
*
* @param string|null $countryCode 2-letters iso code
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getCountryMethods($countryCode = null)
{
$countryMethods = [
'other' => [
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'US' => [
self::METHOD_PAYFLOWADVANCED,
self::METHOD_PAYFLOWPRO,
self::METHOD_PAYFLOWLINK,
self::METHOD_WPP_EXPRESS,
self::METHOD_WPP_BML,
self::METHOD_BILLING_AGREEMENT,
self::METHOD_WPP_PE_EXPRESS,
self::METHOD_WPP_PE_BML,
],
'CA' => [
self::METHOD_PAYFLOWPRO,
self::METHOD_PAYFLOWLINK,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
self::METHOD_WPP_PE_EXPRESS,
],
'GB' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'AU' => [
self::METHOD_PAYFLOWPRO,
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'NZ' => [
self::METHOD_PAYFLOWPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'JP' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'FR' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'IT' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'ES' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'HK' => [
self::METHOD_HOSTEDPRO,
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
'DE' => [
self::METHOD_WPP_EXPRESS,
self::METHOD_BILLING_AGREEMENT,
],
];
if ($countryCode === null) {
return $countryMethods;
}
return $countryMethods[$countryCode] ?? $countryMethods['other'];
}
/**
* Return start url for PayPal Basic
*
* @param string $token
* @return string
*/
public function getPayPalBasicStartUrl($token): string
{
$params = [
'cmd' => '_express-checkout',
'token' => $token,
];
if ($this->isOrderReviewStepDisabled()) {
$params['useraction'] = 'commit';
}
return $this->getPaypalUrl($params);
}
/**
* Check whether order review step enabled in configuration
*
* @return bool
*/
public function isOrderReviewStepDisabled()
{
return $this->_scopeConfig->getValue(
self::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_storeId
);
}
/**
* Get url for dispatching customer to express checkout start
*
* @param string $token
* @return string
*/
public function getExpressCheckoutStartUrl($token)
{
return sprintf(
'https://www.%spaypal.com/checkoutnow%s',
$this->getValue('sandboxFlag') ? 'sandbox.' : '',
'?token=' . urlencode($token)
);
}
/**
* Get url for dispatching customer to checkout retrial
*
* @param string $orderId
* @return string
*/
public function getExpressCheckoutOrderUrl($orderId)
{
return $this->getPaypalUrl(['cmd' => '_express-checkout', 'order_id' => $orderId]);
}
/**
* Get url that allows to edit checkout details on paypal side
*
* @param \Magento\Paypal\Controller\Express|string $token
* @return string
*/
public function getExpressCheckoutEditUrl($token)
{
return $this->getPaypalUrl(['cmd' => '_express-checkout', 'useraction' => 'continue', 'token' => $token]);
}
/**
* Get url for additional actions that PayPal may require customer to do after placing the order.
*
* For instance, redirecting customer to bank for payment confirmation.
*
* @param string $token
* @return string
*/
public function getExpressCheckoutCompleteUrl($token)
{
return $this->getPaypalUrl(['cmd' => '_complete-express-checkout', 'token' => $token]);
}
/**
* Retrieve url for initialization of billing agreement
*
* @param string $token
* @return string
*/
public function getStartBillingAgreementUrl($token)
{
return $this->getPaypalUrl(['cmd' => '_customer-billing-agreement', 'token' => $token]);
}
/**
* PayPal web URL generic getter
*
* @param array $params
* @return string
*/
public function getPaypalUrl(array $params = [])
{
return sprintf(
'https://www.%spaypal.com/cgi-bin/webscr%s',
$this->getValue('sandboxFlag') ? 'sandbox.' : '',
$params ? '?' . http_build_query($params) : ''
);
}
/**
* PayPal web URL for IPN
*
* @return string
*/
public function getPayPalIpnUrl()
{
return sprintf(
'https://ipnpb.%spaypal.com/cgi-bin/webscr',
$this->getValue('sandboxFlag') ? 'sandbox.' : ''
);
}
/**
* Whether Express Checkout button should be rendered dynamically
*
* @return bool
*/
public function areButtonsDynamic()
{
return $this->getValue('buttonFlavor') === self::EC_FLAVOR_DYNAMIC;
}
/**
* Express checkout shortcut pic URL getter
*
* PayPal will ignore "pal", if there is no total amount specified
*
* @param string $localeCode
* @param float|null $orderTotal
* @param string|null $pal encrypted summary about merchant
* @return string
* @see Paypal_Model_Api_Nvp::callGetPalDetails()
*/
public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
{
if ($this->areButtonsDynamic()) {
return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
}
if ($this->getValue('buttonType') === self::EC_BUTTON_TYPE_MARK) {
return $this->getPaymentMarkImageUrl($localeCode);
}
return $this->getExpressCheckoutInContextImageUrl($localeCode);
}
/**
* Express in context checkout shortcut pic URL getter
*
* @param string $localeCode
* @return string