Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Paypal\Model;
8 
9 use Magento\Payment\Helper\Formatter;
10 
18 class Config extends AbstractConfig
19 {
20 
21  use Formatter;
22 
26  const METHOD_EXPRESS = 'paypal_express';
27 
31  const METHOD_WPS_EXPRESS = 'wps_express';
32 
36  const METHOD_WPS_BML = 'wps_express_bml';
37 
41  const METHOD_WPP_BML = 'paypal_express_bml';
42 
46  const METHOD_WPP_DIRECT = 'paypal_direct';
47 
51  const METHOD_PAYMENT_PRO = 'paypal_payment_pro';
52 
56  const METHOD_WPP_PE_EXPRESS = 'payflow_express';
57 
61  const METHOD_WPP_PE_BML = 'payflow_express_bml';
62 
66  const METHOD_PAYFLOWPRO = 'payflowpro';
67 
68  const METHOD_PAYFLOWLINK = 'payflow_link';
69 
70  const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
71 
72  const METHOD_HOSTEDPRO = 'hosted_pro';
73 
74  const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
75 
79  const EC_FLAVOR_DYNAMIC = 'dynamic';
80 
81  const EC_FLAVOR_STATIC = 'static';
82 
83  const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
84 
85  const EC_BUTTON_TYPE_MARK = 'ecmark';
86 
87  const PAYMENT_MARK_SMALL = 'small';
88 
89  const PAYMENT_MARK_MEDIUM = 'medium';
90 
91  const PAYMENT_MARK_LARGE = 'large';
92 
94  const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
95 
100 
102 
109 
111 
113 
119  const FRAUD_ACTION_ACCEPT = 'Acept';
120 
121  const FRAUD_ACTION_DENY = 'Deny';
122 
128  const REFUND_TYPE_FULL = 'Full';
129 
130  const REFUND_TYPE_PARTIAL = 'Partial';
131 
137  const EC_SOLUTION_TYPE_SOLE = 'Sole';
138 
139  const EC_SOLUTION_TYPE_MARK = 'Mark';
140 
146  const WPS_TRANSPORT_IPN = 'ipn';
147 
148  const WPS_TRANSPORT_PDT = 'pdt';
149 
150  const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
151 
157  const EC_BA_SIGNUP_AUTO = 'auto';
158 
159  const EC_BA_SIGNUP_ASK = 'ask';
160 
161  const EC_BA_SIGNUP_NEVER = 'never';
162 
166  const TRANSFER_CART_LINE_ITEMS = 'lineItemsEnabled';
167  const TRANSFER_SHIPPING_OPTIONS = 'transferShippingOptions';
168 
174  const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
175 
181  protected $_buildNotationPPMap = [
182  'paypal_express' => 'EC',
183  'paypal_direct' => 'DP',
184  'payflow_express' => 'EC',
185  ];
186 
192  protected $_ecStyleConfigMap = [
193  'page_style' => 'page_style',
194  'paypal_hdrimg' => 'hdrimg',
195  'paypal_hdrbordercolor' => 'hdrbordercolor',
196  'paypal_hdrbackcolor' => 'hdrbackcolor',
197  'paypal_payflowcolor' => 'payflowcolor',
198  ];
199 
206  'AUD',
207  'CAD',
208  'CZK',
209  'DKK',
210  'EUR',
211  'HKD',
212  'HUF',
213  'ILS',
214  'JPY',
215  'MXN',
216  'NOK',
217  'NZD',
218  'PLN',
219  'GBP',
220  'RUB',
221  'SGD',
222  'SEK',
223  'CHF',
224  'TWD',
225  'THB',
226  'USD',
227  'INR',
228  ];
229 
236  'AE',
237  'AR',
238  'AT',
239  'AU',
240  'BE',
241  'BG',
242  'BR',
243  'CA',
244  'CN',
245  'CH',
246  'CL',
247  'CR',
248  'CY',
249  'CZ',
250  'DE',
251  'DK',
252  'DO',
253  'EC',
254  'EE',
255  'ES',
256  'FI',
257  'FR',
258  'GB',
259  'GF',
260  'GI',
261  'GP',
262  'GR',
263  'HK',
264  'HU',
265  'ID',
266  'IE',
267  'IL',
268  'IN',
269  'IS',
270  'IT',
271  'JM',
272  'JP',
273  'KR',
274  'LI',
275  'LT',
276  'LU',
277  'LV',
278  'MQ',
279  'MT',
280  'MX',
281  'MY',
282  'NL',
283  'NO',
284  'NZ',
285  'PH',
286  'PL',
287  'PT',
288  'RU',
289  'RE',
290  'RO',
291  'SE',
292  'SG',
293  'SI',
294  'SK',
295  'SM',
296  'TH',
297  'TR',
298  'TW',
299  'US',
300  'UY',
301  'VE',
302  'VN',
303  'ZA',
304  ];
305 
312  'AF ',
313  'AX ',
314  'AL ',
315  'DZ ',
316  'AS ',
317  'AD ',
318  'AO ',
319  'AI ',
320  'AQ ',
321  'AG ',
322  'AR ',
323  'AM ',
324  'AW ',
325  'AU ',
326  'AT ',
327  'AZ ',
328  'BS ',
329  'BH ',
330  'BD ',
331  'BB ',
332  'BY ',
333  'BE ',
334  'BZ ',
335  'BJ ',
336  'BM ',
337  'BT ',
338  'BO ',
339  'BA ',
340  'BW ',
341  'BV ',
342  'BR ',
343  'IO ',
344  'BN ',
345  'BG ',
346  'BF ',
347  'BI ',
348  'KH ',
349  'CM ',
350  'CA ',
351  'CV ',
352  'KY ',
353  'CF ',
354  'TD ',
355  'CL ',
356  'CN ',
357  'CX ',
358  'CC ',
359  'CO ',
360  'KM ',
361  'CG ',
362  'CD ',
363  'CK ',
364  'CR ',
365  'CI ',
366  'HR ',
367  'CU ',
368  'CY ',
369  'CZ ',
370  'DK ',
371  'DJ ',
372  'DM ',
373  'DO ',
374  'EC ',
375  'EG ',
376  'SV ',
377  'GQ ',
378  'ER ',
379  'EE ',
380  'ET ',
381  'FK ',
382  'FO ',
383  'FJ ',
384  'FI ',
385  'FR ',
386  'GF ',
387  'PF ',
388  'TF ',
389  'GA ',
390  'GM ',
391  'GE ',
392  'DE ',
393  'GH ',
394  'GI ',
395  'GR ',
396  'GL ',
397  'GD ',
398  'GP ',
399  'GU ',
400  'GT ',
401  'GG ',
402  'GN ',
403  'GW ',
404  'GY ',
405  'HT ',
406  'HM ',
407  'VA ',
408  'HN ',
409  'HK ',
410  'HU ',
411  'IS ',
412  'IN ',
413  'ID ',
414  'IR ',
415  'IQ ',
416  'IE ',
417  'IM ',
418  'IL ',
419  'IT ',
420  'JM ',
421  'JP ',
422  'JE ',
423  'JO ',
424  'KZ ',
425  'KE ',
426  'KI ',
427  'KP ',
428  'KR ',
429  'KW ',
430  'KG ',
431  'LA ',
432  'LV ',
433  'LB ',
434  'LS ',
435  'LR ',
436  'LY ',
437  'LI ',
438  'LT ',
439  'LU ',
440  'MO ',
441  'MK ',
442  'MG ',
443  'MW ',
444  'MY ',
445  'MV ',
446  'ML ',
447  'MT ',
448  'MH ',
449  'MQ ',
450  'MR ',
451  'MU ',
452  'YT ',
453  'MX ',
454  'FM ',
455  'MD ',
456  'MC ',
457  'MN ',
458  'MS ',
459  'MA ',
460  'MZ ',
461  'MM ',
462  'NA ',
463  'NR ',
464  'NP ',
465  'NL ',
466  'AN ',
467  'NC ',
468  'NZ ',
469  'NI ',
470  'NE ',
471  'NG ',
472  'NU ',
473  'NF ',
474  'MP ',
475  'NO ',
476  'OM ',
477  'PK ',
478  'PW ',
479  'PS ',
480  'PA ',
481  'PG ',
482  'PY ',
483  'PE ',
484  'PH ',
485  'PN ',
486  'PL ',
487  'PT ',
488  'PR ',
489  'QA ',
490  'RE ',
491  'RO ',
492  'RU ',
493  'RW ',
494  'SH ',
495  'KN ',
496  'LC ',
497  'PM ',
498  'VC ',
499  'WS ',
500  'SM ',
501  'ST ',
502  'SA ',
503  'SN ',
504  'CS ',
505  'SC ',
506  'SL ',
507  'SG ',
508  'SK ',
509  'SI ',
510  'SB ',
511  'SO ',
512  'ZA ',
513  'GS ',
514  'ES ',
515  'LK ',
516  'SD ',
517  'SR ',
518  'SJ ',
519  'SZ ',
520  'SE ',
521  'CH ',
522  'SY ',
523  'TW ',
524  'TJ ',
525  'TZ ',
526  'TH ',
527  'TL ',
528  'TG ',
529  'TK ',
530  'TO ',
531  'TT ',
532  'TN ',
533  'TR ',
534  'TM ',
535  'TC ',
536  'TV ',
537  'UG ',
538  'UA ',
539  'AE ',
540  'GB ',
541  'US ',
542  'UM ',
543  'UY ',
544  'UZ ',
545  'VU ',
546  'VE ',
547  'VN ',
548  'VG ',
549  'VI ',
550  'WF ',
551  'EH ',
552  'YE ',
553  'ZM ',
554  'ZW',
555  ];
556 
564  'de_DE',
565  'en_AU',
566  'en_GB',
567  'en_US',
568  'es_ES',
569  'es_XC',
570  'fr_FR',
571  'fr_XC',
572  'it_IT',
573  'ja_JP',
574  'nl_NL',
575  'pl_PL',
576  'zh_CN',
577  'zh_XC',
578  ];
579 
585  protected $directoryHelper;
586 
590  protected $_storeManager;
591 
595  protected $_cctypeFactory;
596 
600  protected $_certFactory;
601 
610  public function __construct(
611  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
612  \Magento\Directory\Helper\Data $directoryHelper,
614  \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory,
615  \Magento\Paypal\Model\CertFactory $certFactory,
616  $params = []
617  ) {
618  parent::__construct($scopeConfig);
619  $this->directoryHelper = $directoryHelper;
620  $this->_storeManager = $storeManager;
621  $this->_cctypeFactory = $cctypeFactory;
622  $this->_certFactory = $certFactory;
623  if ($params) {
624  $method = array_shift($params);
625  $this->setMethod($method);
626  if ($params) {
627  $storeId = array_shift($params);
628  $this->setStoreId($storeId);
629  }
630  }
631  }
632 
641  public function isMethodAvailable($methodCode = null)
642  {
643  $result = parent::isMethodAvailable($methodCode);
644 
645  switch ($methodCode) {
648  if ($this->isMethodActive(self::METHOD_PAYFLOWPRO)
649  || $this->isMethodActive(self::METHOD_PAYMENT_PRO)
650  ) {
651  $result = true;
652  }
653  break;
656  // check for express payments dependence
657  if (!$this->isMethodActive(self::METHOD_WPP_EXPRESS)
658  && !$this->isMethodActive(self::METHOD_WPS_EXPRESS)
659  ) {
660  $result = false;
661  }
662  break;
664  // check for direct payments dependence
665  if ($this->isMethodActive(self::METHOD_PAYFLOWLINK)
666  || $this->isMethodActive(self::METHOD_PAYFLOWADVANCED)
667  ) {
668  $result = true;
669  } elseif (!$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
670  $result = false;
671  }
672  break;
674  // check for express payments dependence
675  if (!$this->isMethodActive(self::METHOD_WPP_PE_EXPRESS)) {
676  $result = false;
677  }
678  break;
680  $result = $this->isWppApiAvailabe();
681  break;
682  }
683  return $result;
684  }
685 
692  {
694  }
695 
702  {
704  }
705 
711  public function getMerchantCountry()
712  {
713  $countryCode = $this->_scopeConfig->getValue(
714  $this->_mapGeneralFieldset('merchant_country'),
716  $this->_storeId
717  );
718  if (!$countryCode) {
719  $countryCode = $this->directoryHelper->getDefaultCountry($this->_storeId);
720  }
721  return $countryCode;
722  }
723 
732  public function isMethodSupportedForCountry($method = null, $countryCode = null)
733  {
734  if ($method === null) {
735  $method = $this->getMethodCode();
736  }
737  if ($countryCode === null) {
738  $countryCode = $this->getMerchantCountry();
739  }
740  return in_array($method, $this->getCountryMethods($countryCode));
741  }
742 
750  public function getCountryMethods($countryCode = null)
751  {
752  $countryMethods = [
753  'other' => [
756  ],
757  'US' => [
766  ],
767  'CA' => [
773  ],
774  'GB' => [
778  ],
779  'AU' => [
784  ],
785  'NZ' => [
789  ],
790  'JP' => [
794  ],
795  'FR' => [
799  ],
800  'IT' => [
804  ],
805  'ES' => [
809  ],
810  'HK' => [
814  ],
815  'DE' => [
818  ],
819  ];
820  if ($countryCode === null) {
821  return $countryMethods;
822  }
823  return isset($countryMethods[$countryCode]) ? $countryMethods[$countryCode] : $countryMethods['other'];
824  }
825 
833  {
834  $params = [
835  'cmd' => '_express-checkout',
836  'token' => $token,
837  ];
838 
839  if ($this->isOrderReviewStepDisabled()) {
840  $params['useraction'] = 'commit';
841  }
842 
843  return $this->getPaypalUrl($params);
844  }
845 
851  public function isOrderReviewStepDisabled()
852  {
853  return $this->_scopeConfig->getValue(
854  self::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG,
856  $this->_storeId
857  );
858  }
859 
867  {
868  return sprintf(
869  'https://www.%spaypal.com/checkoutnow%s',
870  $this->getValue('sandboxFlag') ? 'sandbox.' : '',
871  '?token=' . urlencode($token)
872  );
873  }
874 
881  public function getExpressCheckoutOrderUrl($orderId)
882  {
883  return $this->getPaypalUrl(['cmd' => '_express-checkout', 'order_id' => $orderId]);
884  }
885 
893  {
894  return $this->getPaypalUrl(['cmd' => '_express-checkout', 'useraction' => 'continue', 'token' => $token]);
895  }
896 
905  {
906  return $this->getPaypalUrl(['cmd' => '_complete-express-checkout', 'token' => $token]);
907  }
908 
916  {
917  return $this->getPaypalUrl(['cmd' => '_customer-billing-agreement', 'token' => $token]);
918  }
919 
926  public function getPaypalUrl(array $params = [])
927  {
928  return sprintf(
929  'https://www.%spaypal.com/cgi-bin/webscr%s',
930  $this->getValue('sandboxFlag') ? 'sandbox.' : '',
931  $params ? '?' . http_build_query($params) : ''
932  );
933  }
934 
940  public function getPayPalIpnUrl()
941  {
942  return sprintf(
943  'https://ipnpb.%spaypal.com/cgi-bin/webscr',
944  $this->getValue('sandboxFlag') ? 'sandbox.' : ''
945  );
946  }
947 
953  public function areButtonsDynamic()
954  {
955  return $this->getValue('buttonFlavor') === self::EC_FLAVOR_DYNAMIC;
956  }
957 
968  public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
969  {
970  if ($this->areButtonsDynamic()) {
971  return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
972  }
973  if ($this->getValue('buttonType') === self::EC_BUTTON_TYPE_MARK) {
974  return $this->getPaymentMarkImageUrl($localeCode);
975  }
976 
977  return $this->getExpressCheckoutInContextImageUrl($localeCode);
978  }
979 
986  public function getExpressCheckoutInContextImageUrl($localeCode)
987  {
988  $localeCode = $this->_getSupportedLocaleCode($localeCode);
989 
990  if ($localeCode === 'en_US') {
991  return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
992  }
993 
994  return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $localeCode);
995  }
996 
1008  public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = null, $staticSize = null)
1009  {
1010  if ($this->areButtonsDynamic()) {
1011  return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_MARK, $localeCode, $orderTotal, $pal);
1012  }
1013 
1014  if (null === $staticSize) {
1015  $staticSize = $this->getValue('paymentMarkSize');
1016  }
1017 
1018  switch ($staticSize) {
1022  break;
1023  default:
1024  $staticSize = self::PAYMENT_MARK_MEDIUM;
1025  }
1026 
1027  return sprintf(
1028  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-%s.png',
1029  $staticSize
1030  );
1031  }
1032 
1040  public function getPaymentMarkWhatIsPaypalUrl(\Magento\Framework\Locale\ResolverInterface $localeResolver = null)
1041  {
1042  $countryCode = 'US';
1043  if (null !== $localeResolver) {
1044  $shouldEmulate = null !== $this->_storeId && $this->_storeManager->getStore()->getId() != $this->_storeId;
1045  if ($shouldEmulate) {
1046  $localeResolver->emulate($this->_storeId);
1047  }
1048  $countryCode = \Locale::getRegion($localeResolver->getLocale());
1049  if ($shouldEmulate) {
1050  $localeResolver->revert();
1051  }
1052  }
1053  return sprintf(
1054  'https://www.paypal.com/%s/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside',
1055  strtolower($countryCode)
1056  );
1057  }
1058 
1067  public function getSolutionImageUrl($localeCode, $isVertical = false, $isEcheck = false)
1068  {
1069  return sprintf(
1070  'https://www.paypal.com/%s/i/bnr/%s_solution_PP%s.gif',
1071  $this->_getSupportedLocaleCode($localeCode),
1072  $isVertical ? 'vertical' : 'horizontal',
1073  $isEcheck ? 'eCheck' : ''
1074  );
1075  }
1076 
1083  public function getPaymentFormLogoUrl($localeCode)
1084  {
1085  $locale = $this->_getSupportedLocaleCode($localeCode);
1086 
1087  $imageType = 'logo';
1088  $domain = 'paypal.com';
1089  list(, $country) = explode('_', $locale);
1090  $countryPrefix = $country . '/';
1091 
1092  switch ($locale) {
1093  case 'en_GB':
1094  $imageName = 'horizontal_solution_PP';
1095  $imageType = 'bnr';
1096  $countryPrefix = '';
1097  break;
1098  case 'de_DE':
1099  $imageName = 'lockbox_150x47';
1100  break;
1101  case 'fr_FR':
1102  $imageName = 'bnr_horizontal_solution_PP_327wx80h';
1103  $imageType = 'bnr';
1104  $locale = 'en_US';
1105  $domain = 'paypalobjects.com';
1106  break;
1107  case 'it_IT':
1108  $imageName = 'bnr_horizontal_solution_PP_178wx80h';
1109  $imageType = 'bnr';
1110  $domain = 'paypalobjects.com';
1111  break;
1112  default:
1113  $imageName = 'PayPal_mark_60x38';
1114  $countryPrefix = '';
1115  break;
1116  }
1117  return sprintf('https://www.%s/%s/%si/%s/%s.gif', $domain, $locale, $countryPrefix, $imageType, $imageName);
1118  }
1119 
1126  {
1127  return [
1128  'wePrefer_150x60' => __('We prefer PayPal (150 X 60)'),
1129  'wePrefer_150x40' => __('We prefer PayPal (150 X 40)'),
1130  'nowAccepting_150x60' => __('Now accepting PayPal (150 X 60)'),
1131  'nowAccepting_150x40' => __('Now accepting PayPal (150 X 40)'),
1132  'paymentsBy_150x60' => __('Payments by PayPal (150 X 60)'),
1133  'paymentsBy_150x40' => __('Payments by PayPal (150 X 40)'),
1134  'shopNowUsing_150x60' => __('Shop now using (150 X 60)'),
1135  'shopNowUsing_150x40' => __('Shop now using (150 X 40)')
1136  ];
1137  }
1138 
1146  public function getAdditionalOptionsLogoUrl($localeCode, $type = false)
1147  {
1148  $configType = $this->_scopeConfig->getValue(
1149  $this->_mapGenericStyleFieldset('logo'),
1151  $this->_storeId
1152  );
1153  if (!$configType) {
1154  return false;
1155  }
1156  $type = $type ? $type : $configType;
1157  $locale = $this->_getSupportedLocaleCode($localeCode);
1158  $supportedTypes = array_keys($this->getAdditionalOptionsLogoTypes());
1159  if (!in_array($type, $supportedTypes)) {
1161  }
1162  return sprintf('https://www.paypalobjects.com/%s/i/bnr/bnr_%s.gif', $locale, $type);
1163  }
1164 
1171  {
1172  return [self::EC_FLAVOR_DYNAMIC => __('Dynamic'), self::EC_FLAVOR_STATIC => __('Static')];
1173  }
1174 
1181  {
1182  return [
1183  self::EC_BUTTON_TYPE_SHORTCUT => __('Shortcut'),
1184  self::EC_BUTTON_TYPE_MARK => __('Acceptance Mark Image')
1185  ];
1186  }
1187 
1193  public function getPaymentActions()
1194  {
1195  $paymentActions = [
1196  self::PAYMENT_ACTION_AUTH => __('Authorization'),
1197  self::PAYMENT_ACTION_SALE => __('Sale'),
1198  ];
1199  if ($this->_methodCode !== null && $this->_methodCode == self::METHOD_WPP_EXPRESS) {
1200  $paymentActions[self::PAYMENT_ACTION_ORDER] = __('Order');
1201  }
1202  return $paymentActions;
1203  }
1204 
1211  {
1212  return [
1213  self::REQUIRE_BILLING_ADDRESS_ALL => __('Yes'),
1214  self::REQUIRE_BILLING_ADDRESS_NO => __('No'),
1215  self::REQUIRE_BILLING_ADDRESS_VIRTUAL => __('For Virtual Quotes Only')
1216  ];
1217  }
1218 
1224  public function getPaymentAction()
1225  {
1226  switch ($this->getValue('paymentAction')) {
1228  return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE;
1230  return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE;
1232  return \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER;
1233  }
1234  return null;
1235  }
1236 
1245  {
1246  return [self::EC_SOLUTION_TYPE_SOLE => __('Yes'), self::EC_SOLUTION_TYPE_MARK => __('No')];
1247  }
1248 
1255  {
1256  return [
1257  self::EC_BA_SIGNUP_AUTO => __('Auto'),
1258  self::EC_BA_SIGNUP_ASK => __('Ask Customer'),
1259  self::EC_BA_SIGNUP_NEVER => __('Never')
1260  ];
1261  }
1262 
1270  {
1271  return $this->getValue('allow_ba_signup') === self::EC_BA_SIGNUP_ASK
1272  && !$this->shouldUseUnilateralPayments();
1273  }
1274 
1281  {
1282  return [self::WPS_TRANSPORT_IPN => __('IPN (Instant Payment Notification) Only')];
1283  }
1284 
1290  public function getWppCcTypesAsOptionArray()
1291  {
1292  return $this->_cctypeFactory->create()->setAllowedTypes(
1293  ['AE', 'VI', 'MC', 'SM', 'SO', 'DI']
1294  )->toOptionArray();
1295  }
1296 
1303  {
1304  return $this->_cctypeFactory->create()->setAllowedTypes(
1305  ['VI', 'MC', 'SM', 'SO', 'AE']
1306  )->toOptionArray();
1307  }
1308 
1315  {
1316  return $this->_cctypeFactory->create()->setAllowedTypes(['AE', 'VI', 'MC', 'JCB', 'DI', 'DN'])->toOptionArray();
1317  }
1318 
1326  public static function getIsCreditCardMethod($code)
1327  {
1328  switch ($code) {
1333  return true;
1334  }
1335  return false;
1336  }
1337 
1345  {
1346  if (in_array($code, $this->_supportedCurrencyCodes)) {
1347  return true;
1348  }
1349  if ($this->getMerchantCountry() == 'BR' && $code == 'BRL') {
1350  return true;
1351  }
1352  if ($this->getMerchantCountry() == 'MY' && $code == 'MYR') {
1353  return true;
1354  }
1355  if ($this->getMerchantCountry() == 'TR' && $code == 'TRY') {
1356  return true;
1357  }
1358  return false;
1359  }
1360 
1368  {
1369  foreach ($this->_ecStyleConfigMap as $key => $exportKey) {
1370  $configValue = $this->getValue($key);
1371  if ($configValue) {
1372  $to->setData($exportKey, $configValue);
1373  }
1374  }
1375  }
1376 
1387  protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
1388  {
1389  $params = [
1390  'cmd' => '_dynamic-image',
1391  'buttontype' => $type,
1392  'locale' => $this->_getSupportedLocaleCode($localeCode),
1393  ];
1394  if ($orderTotal) {
1395  $params['ordertotal'] = $this->formatPrice($orderTotal);
1396  if ($pal) {
1397  $params['pal'] = $pal;
1398  }
1399  }
1400  if ($params['locale'] == 'en_US') {
1401  switch ($type) {
1403  return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png';
1405  default:
1406  return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
1407  }
1408  }
1409  return sprintf(
1410  'https://fpdbs%s.paypal.com/dynamicimageweb?%s',
1411  $this->getValue('sandboxFlag') ? '.sandbox' : '',
1412  http_build_query($params)
1413  );
1414  }
1415 
1422  protected function _getSupportedLocaleCode($localeCode = null)
1423  {
1424  if (!$localeCode || !in_array($localeCode, $this->_supportedImageLocales)) {
1425  return 'en_US';
1426  }
1427  return $localeCode;
1428  }
1429 
1438  protected function _getSpecificConfigPath($fieldName)
1439  {
1440  $path = null;
1441  switch ($this->_methodCode) {
1442  case self::METHOD_WPP_BML:
1443  $path = $this->_mapBmlFieldset($fieldName);
1444  break;
1446  $path = $this->_mapBmlPayflowFieldset($fieldName);
1447  break;
1450  case self::METHOD_EXPRESS:
1451  $path = $this->_mapExpressFieldset($fieldName);
1452  break;
1455  $path = $this->_mapMethodFieldset($fieldName);
1456  break;
1457  }
1458 
1459  if ($path === null) {
1460  switch ($this->_methodCode) {
1462  case self::METHOD_WPP_BML:
1465  $path = $this->_mapWppFieldset($fieldName);
1466  break;
1470  $path = $this->_mapWpukFieldset($fieldName);
1471  break;
1472  }
1473  }
1474 
1475  if ($path === null) {
1476  $path = $this->_mapGeneralFieldset($fieldName);
1477  }
1478  if ($path === null) {
1479  $path = $this->_mapGenericStyleFieldset($fieldName);
1480  }
1481  return $path;
1482  }
1483 
1491  protected function _mapExpressFieldset($fieldName)
1492  {
1493  switch ($fieldName) {
1494  case 'transfer_shipping_options':
1495  case 'solution_type':
1496  case 'visible_on_cart':
1497  case 'visible_on_product':
1498  case 'require_billing_address':
1499  case 'authorization_honor_period':
1500  case 'order_valid_period':
1501  case 'child_authorization_number':
1502  case 'allow_ba_signup':
1503  case 'in_context':
1504  case 'merchant_id':
1505  return "payment/{$this->_methodCode}/{$fieldName}";
1506  default:
1507  return $this->_mapMethodFieldset($fieldName);
1508  }
1509  }
1510 
1517  protected function _mapBmlFieldset($fieldName)
1518  {
1519  switch ($fieldName) {
1520  case 'allow_ba_signup':
1521  return "payment/" . self::METHOD_WPP_EXPRESS . "/{$fieldName}";
1522  default:
1523  return $this->_mapExpressFieldset($fieldName);
1524  }
1525  }
1526 
1533  protected function _mapBmlPayflowFieldset($fieldName)
1534  {
1535  switch ($fieldName) {
1536  case 'allow_ba_signup':
1537  return "payment/" . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}";
1538  default:
1539  return $this->_mapExpressFieldset($fieldName);
1540  }
1541  }
1542 
1549  protected function _mapDirectFieldset($fieldName)
1550  {
1551  switch ($fieldName) {
1552  case 'useccv':
1553  return "payment/{$this->_methodCode}/{$fieldName}";
1554  default:
1555  return $this->_mapMethodFieldset($fieldName);
1556  }
1557  }
1558 
1566  protected function _mapWppFieldset($fieldName)
1567  {
1568  switch ($fieldName) {
1569  case 'api_authentication':
1570  case 'api_username':
1571  case 'api_password':
1572  case 'api_signature':
1573  case 'api_cert':
1574  case 'sandbox_flag':
1575  case 'use_proxy':
1576  case 'proxy_host':
1577  case 'proxy_port':
1578  case 'button_flavor':
1579  case 'button_type':
1580  return "paypal/wpp/{$fieldName}";
1581  default:
1582  return null;
1583  }
1584  }
1585 
1593  protected function _mapWpukFieldset($fieldName)
1594  {
1595  $pathPrefix = 'paypal/wpuk';
1596  if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(self::METHOD_PAYFLOWLINK)) {
1597  $pathPrefix = 'payment/payflow_link';
1598  } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(
1599  self::METHOD_PAYFLOWADVANCED
1600  )
1601  ) {
1602  $pathPrefix = 'payment/payflow_advanced';
1603  } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS) {
1604  $pathPrefix = 'payment/payflowpro';
1605  } elseif ($this->_methodCode == self::METHOD_PAYFLOWADVANCED || $this->_methodCode == self::METHOD_PAYFLOWLINK
1606  ) {
1607  return 'payment/' . $this->_methodCode . '/' . $fieldName;
1608  }
1609  switch ($fieldName) {
1610  case 'partner':
1611  case 'user':
1612  case 'vendor':
1613  case 'pwd':
1614  case 'sandbox_flag':
1615  case 'use_proxy':
1616  case 'proxy_host':
1617  case 'proxy_port':
1618  return $pathPrefix . '/' . $fieldName;
1619  default:
1620  return null;
1621  }
1622  }
1623 
1630  protected function _mapGenericStyleFieldset($fieldName)
1631  {
1632  switch ($fieldName) {
1633  case 'logo':
1634  case 'page_style':
1635  case 'paypal_hdrimg':
1636  case 'paypal_hdrbackcolor':
1637  case 'paypal_hdrbordercolor':
1638  case 'paypal_payflowcolor':
1639  return "paypal/style/{$fieldName}";
1640  default:
1641  return null;
1642  }
1643  }
1644 
1651  protected function _mapGeneralFieldset($fieldName)
1652  {
1653  switch ($fieldName) {
1654  case 'business_account':
1655  case 'merchant_country':
1656  return "paypal/general/{$fieldName}";
1657  default:
1658  return null;
1659  }
1660  }
1661 
1669  protected function _mapMethodFieldset($fieldName)
1670  {
1671  if (!$this->_methodCode) {
1672  return null;
1673  }
1674  switch ($fieldName) {
1675  case 'active':
1676  case 'title':
1677  case 'payment_action':
1678  case 'allowspecific':
1679  case 'specificcountry':
1680  case 'line_items_enabled':
1681  case 'cctypes':
1682  case 'sort_order':
1683  case 'debug':
1684  case 'verify_peer':
1685  return "payment/{$this->_methodCode}/{$fieldName}";
1686  default:
1687  return null;
1688  }
1689  }
1690 
1697  {
1698  return ['0' => __('API Signature'), '1' => __('API Certificate')];
1699  }
1700 
1706  public function getApiCertificate()
1707  {
1708  $websiteId = $this->_storeManager->getStore($this->_storeId)->getWebsiteId();
1709  return $this->_certFactory->create()->loadByWebsite($websiteId, false)->getCertPath();
1710  }
1711 
1717  public function getBmlPublisherId()
1718  {
1719  return $this->_scopeConfig->getValue(
1720  'payment/' . self::METHOD_WPP_BML . '/publisher_id',
1722  $this->_storeId
1723  );
1724  }
1725 
1732  public function getBmlDisplay($section)
1733  {
1734  $display = $this->_scopeConfig->getValue(
1735  'payment/' . self::METHOD_WPP_BML . '/' . $section . '_display',
1737  $this->_storeId
1738  );
1739  $bmlActive = $this->_scopeConfig->getValue(
1740  'payment/' . self::METHOD_WPP_BML . '/active',
1742  $this->_storeId
1743  );
1744  $bmlUkActive = $this->_scopeConfig->getValue(
1745  'payment/' . self::METHOD_WPP_PE_BML . '/active',
1747  $this->_storeId
1748  );
1749  return (($bmlActive && $this->isMethodActive(self::METHOD_WPP_EXPRESS))
1750  || ($bmlUkActive && $this->isMethodActive(self::METHOD_WPP_PE_EXPRESS))) ? $display : 0;
1751  }
1752 
1759  public function getBmlPosition($section)
1760  {
1761  return $this->_scopeConfig->getValue(
1762  'payment/' . self::METHOD_WPP_BML . '/' . $section . '_position',
1764  $this->_storeId
1765  );
1766  }
1767 
1774  public function getBmlSize($section)
1775  {
1776  return $this->_scopeConfig->getValue(
1777  'payment/' . self::METHOD_WPP_BML . '/' . $section . '_size',
1779  $this->_storeId
1780  );
1781  }
1782 }
_mapGenericStyleFieldset($fieldName)
Definition: Config.php:1630
_mapWppFieldset($fieldName)
Definition: Config.php:1566
_mapExpressFieldset($fieldName)
Definition: Config.php:1491
getExpressCheckoutEditUrl($token)
Definition: Config.php:892
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getCountryMethods($countryCode=null)
Definition: Config.php:750
_mapWpukFieldset($fieldName)
Definition: Config.php:1593
_getSupportedLocaleCode($localeCode=null)
Definition: Config.php:1422
getPaypalUrl(array $params=[])
Definition: Config.php:926
$storeManager
getExpressCheckoutStartUrl($token)
Definition: Config.php:866
getAdditionalOptionsLogoUrl($localeCode, $type=false)
Definition: Config.php:1146
_mapDirectFieldset($fieldName)
Definition: Config.php:1549
__()
Definition: __.php:13
getPaymentMarkImageUrl($localeCode, $orderTotal=null, $pal=null, $staticSize=null)
Definition: Config.php:1008
_mapBmlPayflowFieldset($fieldName)
Definition: Config.php:1533
const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG
Definition: Config.php:174
const REQUIRE_BILLING_ADDRESS_VIRTUAL
Definition: Config.php:112
exportExpressCheckoutStyleSettings(\Magento\Framework\DataObject $to)
Definition: Config.php:1367
getExpressCheckoutOrderUrl($orderId)
Definition: Config.php:881
_getSpecificConfigPath($fieldName)
Definition: Config.php:1438
_mapBmlFieldset($fieldName)
Definition: Config.php:1517
getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal=null, $pal=null)
Definition: Config.php:968
getPaymentFormLogoUrl($localeCode)
Definition: Config.php:1083
$type
Definition: item.phtml:13
_mapMethodFieldset($fieldName)
Definition: Config.php:1669
_getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
Definition: Config.php:1387
static getIsCreditCardMethod($code)
Definition: Config.php:1326
$method
Definition: info.phtml:13
getPaymentMarkWhatIsPaypalUrl(\Magento\Framework\Locale\ResolverInterface $localeResolver=null)
Definition: Config.php:1040
isMethodSupportedForCountry($method=null, $countryCode=null)
Definition: Config.php:732
getExpressCheckoutCompleteUrl($token)
Definition: Config.php:904
__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=[])
Definition: Config.php:610
isMethodAvailable($methodCode=null)
Definition: Config.php:641
getStartBillingAgreementUrl($token)
Definition: Config.php:915
getSolutionImageUrl($localeCode, $isVertical=false, $isEcheck=false)
Definition: Config.php:1067
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
_mapGeneralFieldset($fieldName)
Definition: Config.php:1651
$code
Definition: info.phtml:12
getExpressCheckoutInContextImageUrl($localeCode)
Definition: Config.php:986