Config.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model;
  7. use Magento\Payment\Helper\Formatter;
  8. /**
  9. * Config model that is aware of all \Magento\Paypal payment methods
  10. *
  11. * Works with PayPal-specific system configuration
  12. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  13. * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
  14. */
  15. class Config extends AbstractConfig
  16. {
  17. use Formatter;
  18. /**
  19. * PayPal Express
  20. */
  21. const METHOD_EXPRESS = 'paypal_express';
  22. /**
  23. * PayPal Standard - alias METHOD_WPP_EXPRESS
  24. */
  25. const METHOD_WPS_EXPRESS = 'wps_express';
  26. /**
  27. * PayPal Standard Bml - alias METHOD_WPP_BML
  28. */
  29. const METHOD_WPS_BML = 'wps_express_bml';
  30. /**
  31. * PayPal Bill Me Later - Express Checkout
  32. */
  33. const METHOD_WPP_BML = 'paypal_express_bml';
  34. /**
  35. * PayPal Website Payments Pro - Direct Payments
  36. */
  37. const METHOD_WPP_DIRECT = 'paypal_direct';
  38. /**
  39. * PayPal Website Payments Pro - Direct Payments - alias METHOD_PAYFLOWPRO
  40. */
  41. const METHOD_PAYMENT_PRO = 'paypal_payment_pro';
  42. /**
  43. * Express Checkout (Payflow Edition)
  44. */
  45. const METHOD_WPP_PE_EXPRESS = 'payflow_express';
  46. /**
  47. * PayPal Bill Me Later - Express Checkout (Payflow Edition)
  48. */
  49. const METHOD_WPP_PE_BML = 'payflow_express_bml';
  50. /**
  51. * Payflow Pro Gateway
  52. */
  53. const METHOD_PAYFLOWPRO = 'payflowpro';
  54. const METHOD_PAYFLOWLINK = 'payflow_link';
  55. const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
  56. const METHOD_HOSTEDPRO = 'hosted_pro';
  57. const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
  58. /**#@+
  59. * Buttons and images
  60. */
  61. const EC_FLAVOR_DYNAMIC = 'dynamic';
  62. const EC_FLAVOR_STATIC = 'static';
  63. const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
  64. const EC_BUTTON_TYPE_MARK = 'ecmark';
  65. const PAYMENT_MARK_SMALL = 'small';
  66. const PAYMENT_MARK_MEDIUM = 'medium';
  67. const PAYMENT_MARK_LARGE = 'large';
  68. /**#@-*/
  69. const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
  70. /**#@+
  71. * Payment actions
  72. */
  73. const AUTHORIZATION_AMOUNT_ONE = 1;
  74. const AUTHORIZATION_AMOUNT_FULL = 2;
  75. /**#@-*/
  76. /**#@+
  77. * Require Billing Address
  78. */
  79. const REQUIRE_BILLING_ADDRESS_NO = 0;
  80. const REQUIRE_BILLING_ADDRESS_ALL = 1;
  81. const REQUIRE_BILLING_ADDRESS_VIRTUAL = 2;
  82. /**#@-*/
  83. /**#@+
  84. * Fraud management actions
  85. */
  86. const FRAUD_ACTION_ACCEPT = 'Acept';
  87. const FRAUD_ACTION_DENY = 'Deny';
  88. /**#@-*/
  89. /**#@+
  90. * Refund types
  91. */
  92. const REFUND_TYPE_FULL = 'Full';
  93. const REFUND_TYPE_PARTIAL = 'Partial';
  94. /**#@-*/
  95. /**#@+
  96. * Express Checkout flows
  97. */
  98. const EC_SOLUTION_TYPE_SOLE = 'Sole';
  99. const EC_SOLUTION_TYPE_MARK = 'Mark';
  100. /**#@-*/
  101. /**#@+
  102. * Payment data transfer methods (Standard)
  103. */
  104. const WPS_TRANSPORT_IPN = 'ipn';
  105. const WPS_TRANSPORT_PDT = 'pdt';
  106. const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
  107. /**#@-*/
  108. /**#@+
  109. * Billing Agreement Signup type
  110. */
  111. const EC_BA_SIGNUP_AUTO = 'auto';
  112. const EC_BA_SIGNUP_ASK = 'ask';
  113. const EC_BA_SIGNUP_NEVER = 'never';
  114. /**
  115. * Paypal setting
  116. */
  117. const TRANSFER_CART_LINE_ITEMS = 'lineItemsEnabled';
  118. const TRANSFER_SHIPPING_OPTIONS = 'transferShippingOptions';
  119. /**#@-*/
  120. /**
  121. * Config path for enabling/disabling order review step in express checkout
  122. */
  123. const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
  124. /**
  125. * Instructions for generating proper BN code
  126. *
  127. * @var array
  128. */
  129. protected $_buildNotationPPMap = [
  130. 'paypal_express' => 'EC',
  131. 'paypal_direct' => 'DP',
  132. 'payflow_express' => 'EC',
  133. ];
  134. /**
  135. * Style system config map (Express Checkout)
  136. *
  137. * @var array
  138. */
  139. protected $_ecStyleConfigMap = [
  140. 'page_style' => 'page_style',
  141. 'paypal_hdrimg' => 'hdrimg',
  142. 'paypal_hdrbordercolor' => 'hdrbordercolor',
  143. 'paypal_hdrbackcolor' => 'hdrbackcolor',
  144. 'paypal_payflowcolor' => 'payflowcolor',
  145. ];
  146. /**
  147. * Currency codes supported by PayPal methods
  148. *
  149. * @var string[]
  150. */
  151. protected $_supportedCurrencyCodes = [
  152. 'AUD',
  153. 'CAD',
  154. 'CZK',
  155. 'DKK',
  156. 'EUR',
  157. 'HKD',
  158. 'HUF',
  159. 'ILS',
  160. 'JPY',
  161. 'MXN',
  162. 'NOK',
  163. 'NZD',
  164. 'PLN',
  165. 'GBP',
  166. 'RUB',
  167. 'SGD',
  168. 'SEK',
  169. 'CHF',
  170. 'TWD',
  171. 'THB',
  172. 'USD',
  173. 'INR',
  174. ];
  175. /**
  176. * Merchant country supported by PayPal
  177. *
  178. * @var string[]
  179. */
  180. protected $_supportedCountryCodes = [
  181. 'AE',
  182. 'AR',
  183. 'AT',
  184. 'AU',
  185. 'BE',
  186. 'BG',
  187. 'BR',
  188. 'CA',
  189. 'CN',
  190. 'CH',
  191. 'CL',
  192. 'CR',
  193. 'CY',
  194. 'CZ',
  195. 'DE',
  196. 'DK',
  197. 'DO',
  198. 'EC',
  199. 'EE',
  200. 'ES',
  201. 'FI',
  202. 'FR',
  203. 'GB',
  204. 'GF',
  205. 'GI',
  206. 'GP',
  207. 'GR',
  208. 'HK',
  209. 'HU',
  210. 'ID',
  211. 'IE',
  212. 'IL',
  213. 'IN',
  214. 'IS',
  215. 'IT',
  216. 'JM',
  217. 'JP',
  218. 'KR',
  219. 'LI',
  220. 'LT',
  221. 'LU',
  222. 'LV',
  223. 'MQ',
  224. 'MT',
  225. 'MX',
  226. 'MY',
  227. 'NL',
  228. 'NO',
  229. 'NZ',
  230. 'PH',
  231. 'PL',
  232. 'PT',
  233. 'RU',
  234. 'RE',
  235. 'RO',
  236. 'SE',
  237. 'SG',
  238. 'SI',
  239. 'SK',
  240. 'SM',
  241. 'TH',
  242. 'TR',
  243. 'TW',
  244. 'US',
  245. 'UY',
  246. 'VE',
  247. 'VN',
  248. 'ZA',
  249. ];
  250. /**
  251. * Buyer country supported by PayPal
  252. *
  253. * @var string[]
  254. */
  255. protected $_supportedBuyerCountryCodes = [
  256. 'AF ',
  257. 'AX ',
  258. 'AL ',
  259. 'DZ ',
  260. 'AS ',
  261. 'AD ',
  262. 'AO ',
  263. 'AI ',
  264. 'AQ ',
  265. 'AG ',
  266. 'AR ',
  267. 'AM ',
  268. 'AW ',
  269. 'AU ',
  270. 'AT ',
  271. 'AZ ',
  272. 'BS ',
  273. 'BH ',
  274. 'BD ',
  275. 'BB ',
  276. 'BY ',
  277. 'BE ',
  278. 'BZ ',
  279. 'BJ ',
  280. 'BM ',
  281. 'BT ',
  282. 'BO ',
  283. 'BA ',
  284. 'BW ',
  285. 'BV ',
  286. 'BR ',
  287. 'IO ',
  288. 'BN ',
  289. 'BG ',
  290. 'BF ',
  291. 'BI ',
  292. 'KH ',
  293. 'CM ',
  294. 'CA ',
  295. 'CV ',
  296. 'KY ',
  297. 'CF ',
  298. 'TD ',
  299. 'CL ',
  300. 'CN ',
  301. 'CX ',
  302. 'CC ',
  303. 'CO ',
  304. 'KM ',
  305. 'CG ',
  306. 'CD ',
  307. 'CK ',
  308. 'CR ',
  309. 'CI ',
  310. 'HR ',
  311. 'CU ',
  312. 'CY ',
  313. 'CZ ',
  314. 'DK ',
  315. 'DJ ',
  316. 'DM ',
  317. 'DO ',
  318. 'EC ',
  319. 'EG ',
  320. 'SV ',
  321. 'GQ ',
  322. 'ER ',
  323. 'EE ',
  324. 'ET ',
  325. 'FK ',
  326. 'FO ',
  327. 'FJ ',
  328. 'FI ',
  329. 'FR ',
  330. 'GF ',
  331. 'PF ',
  332. 'TF ',
  333. 'GA ',
  334. 'GM ',
  335. 'GE ',
  336. 'DE ',
  337. 'GH ',
  338. 'GI ',
  339. 'GR ',
  340. 'GL ',
  341. 'GD ',
  342. 'GP ',
  343. 'GU ',
  344. 'GT ',
  345. 'GG ',
  346. 'GN ',
  347. 'GW ',
  348. 'GY ',
  349. 'HT ',
  350. 'HM ',
  351. 'VA ',
  352. 'HN ',
  353. 'HK ',
  354. 'HU ',
  355. 'IS ',
  356. 'IN ',
  357. 'ID ',
  358. 'IR ',
  359. 'IQ ',
  360. 'IE ',
  361. 'IM ',
  362. 'IL ',
  363. 'IT ',
  364. 'JM ',
  365. 'JP ',
  366. 'JE ',
  367. 'JO ',
  368. 'KZ ',
  369. 'KE ',
  370. 'KI ',
  371. 'KP ',
  372. 'KR ',
  373. 'KW ',
  374. 'KG ',
  375. 'LA ',
  376. 'LV ',
  377. 'LB ',
  378. 'LS ',
  379. 'LR ',
  380. 'LY ',
  381. 'LI ',
  382. 'LT ',
  383. 'LU ',
  384. 'MO ',
  385. 'MK ',
  386. 'MG ',
  387. 'MW ',
  388. 'MY ',
  389. 'MV ',
  390. 'ML ',
  391. 'MT ',
  392. 'MH ',
  393. 'MQ ',
  394. 'MR ',
  395. 'MU ',
  396. 'YT ',
  397. 'MX ',
  398. 'FM ',
  399. 'MD ',
  400. 'MC ',
  401. 'MN ',
  402. 'MS ',
  403. 'MA ',
  404. 'MZ ',
  405. 'MM ',
  406. 'NA ',
  407. 'NR ',
  408. 'NP ',
  409. 'NL ',
  410. 'AN ',
  411. 'NC ',
  412. 'NZ ',
  413. 'NI ',
  414. 'NE ',
  415. 'NG ',
  416. 'NU ',
  417. 'NF ',
  418. 'MP ',
  419. 'NO ',
  420. 'OM ',
  421. 'PK ',
  422. 'PW ',
  423. 'PS ',
  424. 'PA ',
  425. 'PG ',
  426. 'PY ',
  427. 'PE ',
  428. 'PH ',
  429. 'PN ',
  430. 'PL ',
  431. 'PT ',
  432. 'PR ',
  433. 'QA ',
  434. 'RE ',
  435. 'RO ',
  436. 'RU ',
  437. 'RW ',
  438. 'SH ',
  439. 'KN ',
  440. 'LC ',
  441. 'PM ',
  442. 'VC ',
  443. 'WS ',
  444. 'SM ',
  445. 'ST ',
  446. 'SA ',
  447. 'SN ',
  448. 'CS ',
  449. 'SC ',
  450. 'SL ',
  451. 'SG ',
  452. 'SK ',
  453. 'SI ',
  454. 'SB ',
  455. 'SO ',
  456. 'ZA ',
  457. 'GS ',
  458. 'ES ',
  459. 'LK ',
  460. 'SD ',
  461. 'SR ',
  462. 'SJ ',
  463. 'SZ ',
  464. 'SE ',
  465. 'CH ',
  466. 'SY ',
  467. 'TW ',
  468. 'TJ ',
  469. 'TZ ',
  470. 'TH ',
  471. 'TL ',
  472. 'TG ',
  473. 'TK ',
  474. 'TO ',
  475. 'TT ',
  476. 'TN ',
  477. 'TR ',
  478. 'TM ',
  479. 'TC ',
  480. 'TV ',
  481. 'UG ',
  482. 'UA ',
  483. 'AE ',
  484. 'GB ',
  485. 'US ',
  486. 'UM ',
  487. 'UY ',
  488. 'UZ ',
  489. 'VU ',
  490. 'VE ',
  491. 'VN ',
  492. 'VG ',
  493. 'VI ',
  494. 'WF ',
  495. 'EH ',
  496. 'YE ',
  497. 'ZM ',
  498. 'ZW',
  499. ];
  500. /**
  501. * Locale codes supported by misc images (marks, shortcuts etc)
  502. *
  503. * @var string[]
  504. * @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration#id089QD0O0TX4__id08AH904I0YK
  505. */
  506. protected $_supportedImageLocales = [
  507. 'de_DE',
  508. 'en_AU',
  509. 'en_GB',
  510. 'en_US',
  511. 'es_ES',
  512. 'es_XC',
  513. 'fr_FR',
  514. 'fr_XC',
  515. 'it_IT',
  516. 'ja_JP',
  517. 'nl_NL',
  518. 'pl_PL',
  519. 'zh_CN',
  520. 'zh_XC',
  521. ];
  522. /**
  523. * Core data
  524. *
  525. * @var \Magento\Directory\Helper\Data
  526. */
  527. protected $directoryHelper;
  528. /**
  529. * @var \Magento\Store\Model\StoreManagerInterface
  530. */
  531. protected $_storeManager;
  532. /**
  533. * @var \Magento\Payment\Model\Source\CctypeFactory
  534. */
  535. protected $_cctypeFactory;
  536. /**
  537. * @var \Magento\Paypal\Model\CertFactory
  538. */
  539. protected $_certFactory;
  540. /**
  541. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  542. * @param \Magento\Directory\Helper\Data $directoryHelper
  543. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  544. * @param \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory
  545. * @param CertFactory $certFactory
  546. * @param array $params
  547. */
  548. public function __construct(
  549. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  550. \Magento\Directory\Helper\Data $directoryHelper,
  551. \Magento\Store\Model\StoreManagerInterface $storeManager,
  552. \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory,
  553. \Magento\Paypal\Model\CertFactory $certFactory,
  554. $params = []
  555. ) {
  556. parent::__construct($scopeConfig);
  557. $this->directoryHelper = $directoryHelper;
  558. $this->_storeManager = $storeManager;
  559. $this->_cctypeFactory = $cctypeFactory;
  560. $this->_certFactory = $certFactory;
  561. if ($params) {
  562. $method = array_shift($params);
  563. $this->setMethod($method);
  564. if ($params) {
  565. $storeId = array_shift($params);
  566. $this->setStoreId($storeId);
  567. }
  568. }
  569. }
  570. /**
  571. * Check whether method available for checkout or not
  572. *
  573. * Logic based on merchant country, methods dependence
  574. *
  575. * @param string|null $methodCode
  576. * @return bool
  577. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  578. */
  579. public function isMethodAvailable($methodCode = null)
  580. {
  581. $result = parent::isMethodAvailable($methodCode);
  582. switch ($methodCode) {
  583. case self::METHOD_WPP_EXPRESS:
  584. case self::METHOD_WPS_EXPRESS:
  585. if ($this->isMethodActive(self::METHOD_PAYFLOWPRO)
  586. || $this->isMethodActive(self::METHOD_PAYMENT_PRO)
  587. ) {
  588. $result = true;
  589. }
  590. break;
  591. case self::METHOD_WPP_BML:
  592. case self::METHOD_WPS_BML:
  593. // check for express payments dependence
  594. if (!$this->isMethodActive(self::METHOD_WPP_EXPRESS)
  595. && !$this->isMethodActive(self::METHOD_WPS_EXPRESS)
  596. ) {
  597. $result = false;
  598. }
  599. break;
  600. case self::METHOD_WPP_PE_EXPRESS:
  601. // check for direct payments dependence
  602. if ($this->isMethodActive(self::METHOD_PAYFLOWLINK)
  603. || $this->isMethodActive(self::METHOD_PAYFLOWADVANCED)
  604. ) {
  605. $result = true;
  606. } elseif (!$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
  607. $result = false;
  608. }
  609. break;
  610. case self::METHOD_WPP_PE_BML:
  611. // check for express payments dependence
  612. if (!$this->isMethodActive(self::METHOD_WPP_PE_EXPRESS)) {
  613. $result = false;
  614. }
  615. break;
  616. case self::METHOD_BILLING_AGREEMENT:
  617. $result = $this->isWppApiAvailable();
  618. break;
  619. }
  620. return $result;
  621. }
  622. /**
  623. * Return merchant country codes supported by PayPal
  624. *
  625. * @return string[]
  626. */
  627. public function getSupportedMerchantCountryCodes()
  628. {
  629. return $this->_supportedCountryCodes;
  630. }
  631. /**
  632. * Return buyer country codes supported by PayPal
  633. *
  634. * @return string[]
  635. */
  636. public function getSupportedBuyerCountryCodes()
  637. {
  638. return $this->_supportedBuyerCountryCodes;
  639. }
  640. /**
  641. * Return merchant country code, use default country if it not specified in General settings
  642. *
  643. * @return string
  644. */
  645. public function getMerchantCountry()
  646. {
  647. $countryCode = $this->_scopeConfig->getValue(
  648. $this->_mapGeneralFieldset('merchant_country'),
  649. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  650. $this->_storeId
  651. );
  652. if (!$countryCode) {
  653. $countryCode = $this->directoryHelper->getDefaultCountry($this->_storeId);
  654. }
  655. return $countryCode;
  656. }
  657. /**
  658. * Check whether method supported for specified country or not
  659. *
  660. * Use $_methodCode and merchant country by default
  661. *
  662. * @param string|null $method
  663. * @param string|null $countryCode
  664. * @return bool
  665. */
  666. public function isMethodSupportedForCountry($method = null, $countryCode = null)
  667. {
  668. if ($method === null) {
  669. $method = $this->getMethodCode();
  670. }
  671. if ($countryCode === null) {
  672. $countryCode = $this->getMerchantCountry();
  673. }
  674. return in_array($method, $this->getCountryMethods($countryCode));
  675. }
  676. /**
  677. * Return list of allowed methods for specified country iso code
  678. *
  679. * @param string|null $countryCode 2-letters iso code
  680. * @return array
  681. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  682. */
  683. public function getCountryMethods($countryCode = null)
  684. {
  685. $countryMethods = [
  686. 'other' => [
  687. self::METHOD_WPP_EXPRESS,
  688. self::METHOD_BILLING_AGREEMENT,
  689. ],
  690. 'US' => [
  691. self::METHOD_PAYFLOWADVANCED,
  692. self::METHOD_PAYFLOWPRO,
  693. self::METHOD_PAYFLOWLINK,
  694. self::METHOD_WPP_EXPRESS,
  695. self::METHOD_WPP_BML,
  696. self::METHOD_BILLING_AGREEMENT,
  697. self::METHOD_WPP_PE_EXPRESS,
  698. self::METHOD_WPP_PE_BML,
  699. ],
  700. 'CA' => [
  701. self::METHOD_PAYFLOWPRO,
  702. self::METHOD_PAYFLOWLINK,
  703. self::METHOD_WPP_EXPRESS,
  704. self::METHOD_BILLING_AGREEMENT,
  705. self::METHOD_WPP_PE_EXPRESS,
  706. ],
  707. 'GB' => [
  708. self::METHOD_HOSTEDPRO,
  709. self::METHOD_WPP_EXPRESS,
  710. self::METHOD_BILLING_AGREEMENT,
  711. ],
  712. 'AU' => [
  713. self::METHOD_PAYFLOWPRO,
  714. self::METHOD_HOSTEDPRO,
  715. self::METHOD_WPP_EXPRESS,
  716. self::METHOD_BILLING_AGREEMENT,
  717. ],
  718. 'NZ' => [
  719. self::METHOD_PAYFLOWPRO,
  720. self::METHOD_WPP_EXPRESS,
  721. self::METHOD_BILLING_AGREEMENT,
  722. ],
  723. 'JP' => [
  724. self::METHOD_HOSTEDPRO,
  725. self::METHOD_WPP_EXPRESS,
  726. self::METHOD_BILLING_AGREEMENT,
  727. ],
  728. 'FR' => [
  729. self::METHOD_HOSTEDPRO,
  730. self::METHOD_WPP_EXPRESS,
  731. self::METHOD_BILLING_AGREEMENT,
  732. ],
  733. 'IT' => [
  734. self::METHOD_HOSTEDPRO,
  735. self::METHOD_WPP_EXPRESS,
  736. self::METHOD_BILLING_AGREEMENT,
  737. ],
  738. 'ES' => [
  739. self::METHOD_HOSTEDPRO,
  740. self::METHOD_WPP_EXPRESS,
  741. self::METHOD_BILLING_AGREEMENT,
  742. ],
  743. 'HK' => [
  744. self::METHOD_HOSTEDPRO,
  745. self::METHOD_WPP_EXPRESS,
  746. self::METHOD_BILLING_AGREEMENT,
  747. ],
  748. 'DE' => [
  749. self::METHOD_WPP_EXPRESS,
  750. self::METHOD_BILLING_AGREEMENT,
  751. ],
  752. ];
  753. if ($countryCode === null) {
  754. return $countryMethods;
  755. }
  756. return isset($countryMethods[$countryCode]) ? $countryMethods[$countryCode] : $countryMethods['other'];
  757. }
  758. /**
  759. * Return start url for PayPal Basic
  760. *
  761. * @param string $token
  762. * @return string
  763. */
  764. public function getPayPalBasicStartUrl($token)
  765. {
  766. $params = [
  767. 'cmd' => '_express-checkout',
  768. 'token' => $token,
  769. ];
  770. if ($this->isOrderReviewStepDisabled()) {
  771. $params['useraction'] = 'commit';
  772. }
  773. return $this->getPaypalUrl($params);
  774. }
  775. /**
  776. * Check whether order review step enabled in configuration
  777. *
  778. * @return bool
  779. */
  780. public function isOrderReviewStepDisabled()
  781. {
  782. return $this->_scopeConfig->getValue(
  783. self::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG,
  784. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  785. $this->_storeId
  786. );
  787. }
  788. /**
  789. * Get url for dispatching customer to express checkout start
  790. *
  791. * @param string $token
  792. * @return string
  793. */
  794. public function getExpressCheckoutStartUrl($token)
  795. {
  796. return sprintf(
  797. 'https://www.%spaypal.com/checkoutnow%s',
  798. $this->getValue('sandboxFlag') ? 'sandbox.' : '',
  799. '?token=' . urlencode($token)
  800. );
  801. }
  802. /**
  803. * Get url for dispatching customer to checkout retrial
  804. *
  805. * @param string $orderId
  806. * @return string
  807. */
  808. public function getExpressCheckoutOrderUrl($orderId)
  809. {
  810. return $this->getPaypalUrl(['cmd' => '_express-checkout', 'order_id' => $orderId]);
  811. }
  812. /**
  813. * Get url that allows to edit checkout details on paypal side
  814. *
  815. * @param \Magento\Paypal\Controller\Express|string $token
  816. * @return string
  817. */
  818. public function getExpressCheckoutEditUrl($token)
  819. {
  820. return $this->getPaypalUrl(['cmd' => '_express-checkout', 'useraction' => 'continue', 'token' => $token]);
  821. }
  822. /**
  823. * Get url for additional actions that PayPal may require customer to do after placing the order.
  824. *
  825. * For instance, redirecting customer to bank for payment confirmation.
  826. *
  827. * @param string $token
  828. * @return string
  829. */
  830. public function getExpressCheckoutCompleteUrl($token)
  831. {
  832. return $this->getPaypalUrl(['cmd' => '_complete-express-checkout', 'token' => $token]);
  833. }
  834. /**
  835. * Retrieve url for initialization of billing agreement
  836. *
  837. * @param string $token
  838. * @return string
  839. */
  840. public function getStartBillingAgreementUrl($token)
  841. {
  842. return $this->getPaypalUrl(['cmd' => '_customer-billing-agreement', 'token' => $token]);
  843. }
  844. /**
  845. * PayPal web URL generic getter
  846. *
  847. * @param array $params
  848. * @return string
  849. */
  850. public function getPaypalUrl(array $params = [])
  851. {
  852. return sprintf(
  853. 'https://www.%spaypal.com/cgi-bin/webscr%s',
  854. $this->getValue('sandboxFlag') ? 'sandbox.' : '',
  855. $params ? '?' . http_build_query($params) : ''
  856. );
  857. }
  858. /**
  859. * PayPal web URL for IPN
  860. *
  861. * @return string
  862. */
  863. public function getPayPalIpnUrl()
  864. {
  865. return sprintf(
  866. 'https://ipnpb.%spaypal.com/cgi-bin/webscr',
  867. $this->getValue('sandboxFlag') ? 'sandbox.' : ''
  868. );
  869. }
  870. /**
  871. * Whether Express Checkout button should be rendered dynamically
  872. *
  873. * @return bool
  874. */
  875. public function areButtonsDynamic()
  876. {
  877. return $this->getValue('buttonFlavor') === self::EC_FLAVOR_DYNAMIC;
  878. }
  879. /**
  880. * Express checkout shortcut pic URL getter
  881. *
  882. * PayPal will ignore "pal", if there is no total amount specified
  883. *
  884. * @param string $localeCode
  885. * @param float|null $orderTotal
  886. * @param string|null $pal encrypted summary about merchant
  887. * @return string
  888. * @see Paypal_Model_Api_Nvp::callGetPalDetails()
  889. */
  890. public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
  891. {
  892. if ($this->areButtonsDynamic()) {
  893. return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
  894. }
  895. if ($this->getValue('buttonType') === self::EC_BUTTON_TYPE_MARK) {
  896. return $this->getPaymentMarkImageUrl($localeCode);
  897. }
  898. return $this->getExpressCheckoutInContextImageUrl($localeCode);
  899. }
  900. /**
  901. * Express in context checkout shortcut pic URL getter
  902. *
  903. * @param string $localeCode
  904. * @return string
  905. */
  906. public function getExpressCheckoutInContextImageUrl($localeCode)
  907. {
  908. $localeCode = $this->_getSupportedLocaleCode($localeCode);
  909. if ($localeCode === 'en_US') {
  910. return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
  911. }
  912. return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $localeCode);
  913. }
  914. /**
  915. * Get PayPal "mark" image URL
  916. *
  917. * Supposed to be used on payment methods selection
  918. * $staticSize is applicable for static images only
  919. *
  920. * @param string $localeCode
  921. * @param float|null $orderTotal
  922. * @param string|null $pal
  923. * @param string|null $staticSize
  924. * @return string
  925. */
  926. public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = null, $staticSize = null)
  927. {
  928. if ($this->areButtonsDynamic()) {
  929. return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_MARK, $localeCode, $orderTotal, $pal);
  930. }
  931. if (null === $staticSize) {
  932. $staticSize = $this->getValue('paymentMarkSize');
  933. }
  934. switch ($staticSize) {
  935. case self::PAYMENT_MARK_SMALL:
  936. case self::PAYMENT_MARK_MEDIUM:
  937. case self::PAYMENT_MARK_LARGE:
  938. break;
  939. default:
  940. $staticSize = self::PAYMENT_MARK_MEDIUM;
  941. }
  942. return sprintf(
  943. 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-%s.png',
  944. $staticSize
  945. );
  946. }
  947. /**
  948. * Get "What Is PayPal" localized URL
  949. *
  950. * Supposed to be used with "mark" as popup window
  951. *
  952. * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
  953. * @return string
  954. */
  955. public function getPaymentMarkWhatIsPaypalUrl(\Magento\Framework\Locale\ResolverInterface $localeResolver = null)
  956. {
  957. $countryCode = 'US';
  958. if (null !== $localeResolver) {
  959. $shouldEmulate = null !== $this->_storeId && $this->_storeManager->getStore()->getId() != $this->_storeId;
  960. if ($shouldEmulate) {
  961. $localeResolver->emulate($this->_storeId);
  962. }
  963. $countryCode = \Locale::getRegion($localeResolver->getLocale());
  964. if ($shouldEmulate) {
  965. $localeResolver->revert();
  966. }
  967. }
  968. return sprintf(
  969. 'https://www.paypal.com/%s/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside',
  970. strtolower($countryCode)
  971. );
  972. }
  973. /**
  974. * Getter for Solution banner images
  975. *
  976. * @param string $localeCode
  977. * @param bool $isVertical
  978. * @param bool $isEcheck
  979. * @return string
  980. */
  981. public function getSolutionImageUrl($localeCode, $isVertical = false, $isEcheck = false)
  982. {
  983. return sprintf(
  984. 'https://www.paypal.com/%s/i/bnr/%s_solution_PP%s.gif',
  985. $this->_getSupportedLocaleCode($localeCode),
  986. $isVertical ? 'vertical' : 'horizontal',
  987. $isEcheck ? 'eCheck' : ''
  988. );
  989. }
  990. /**
  991. * Getter for Payment form logo images
  992. *
  993. * @param string $localeCode
  994. * @return string
  995. */
  996. public function getPaymentFormLogoUrl($localeCode)
  997. {
  998. $locale = $this->_getSupportedLocaleCode($localeCode);
  999. $imageType = 'logo';
  1000. $domain = 'paypal.com';
  1001. list(, $country) = explode('_', $locale);
  1002. $countryPrefix = $country . '/';
  1003. switch ($locale) {
  1004. case 'en_GB':
  1005. $imageName = 'horizontal_solution_PP';
  1006. $imageType = 'bnr';
  1007. $countryPrefix = '';
  1008. break;
  1009. case 'de_DE':
  1010. $imageName = 'lockbox_150x47';
  1011. break;
  1012. case 'fr_FR':
  1013. $imageName = 'bnr_horizontal_solution_PP_327wx80h';
  1014. $imageType = 'bnr';
  1015. $locale = 'en_US';
  1016. $domain = 'paypalobjects.com';
  1017. break;
  1018. case 'it_IT':
  1019. $imageName = 'bnr_horizontal_solution_PP_178wx80h';
  1020. $imageType = 'bnr';
  1021. $domain = 'paypalobjects.com';
  1022. break;
  1023. default:
  1024. $imageName = 'PayPal_mark_60x38';
  1025. $countryPrefix = '';
  1026. break;
  1027. }
  1028. return sprintf('https://www.%s/%s/%si/%s/%s.gif', $domain, $locale, $countryPrefix, $imageType, $imageName);
  1029. }
  1030. /**
  1031. * Return supported types for PayPal logo
  1032. *
  1033. * @return array
  1034. */
  1035. public function getAdditionalOptionsLogoTypes()
  1036. {
  1037. return [
  1038. 'wePrefer_150x60' => __('We prefer PayPal (150 X 60)'),
  1039. 'wePrefer_150x40' => __('We prefer PayPal (150 X 40)'),
  1040. 'nowAccepting_150x60' => __('Now accepting PayPal (150 X 60)'),
  1041. 'nowAccepting_150x40' => __('Now accepting PayPal (150 X 40)'),
  1042. 'paymentsBy_150x60' => __('Payments by PayPal (150 X 60)'),
  1043. 'paymentsBy_150x40' => __('Payments by PayPal (150 X 40)'),
  1044. 'shopNowUsing_150x60' => __('Shop now using (150 X 60)'),
  1045. 'shopNowUsing_150x40' => __('Shop now using (150 X 40)')
  1046. ];
  1047. }
  1048. /**
  1049. * Return PayPal logo URL with additional options
  1050. *
  1051. * @param string $localeCode Supported locale code
  1052. * @param bool|string $type One of supported logo types
  1053. * @return string|bool Logo Image URL or false if logo disabled in configuration
  1054. */
  1055. public function getAdditionalOptionsLogoUrl($localeCode, $type = false)
  1056. {
  1057. $configType = $this->_scopeConfig->getValue(
  1058. $this->_mapGenericStyleFieldset('logo'),
  1059. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1060. $this->_storeId
  1061. );
  1062. if (!$configType) {
  1063. return false;
  1064. }
  1065. $type = $type ? $type : $configType;
  1066. $locale = $this->_getSupportedLocaleCode($localeCode);
  1067. $supportedTypes = array_keys($this->getAdditionalOptionsLogoTypes());
  1068. if (!in_array($type, $supportedTypes)) {
  1069. $type = self::DEFAULT_LOGO_TYPE;
  1070. }
  1071. return sprintf('https://www.paypalobjects.com/%s/i/bnr/bnr_%s.gif', $locale, $type);
  1072. }
  1073. /**
  1074. * Express Checkout button "flavors" source getter
  1075. *
  1076. * @return array
  1077. */
  1078. public function getExpressCheckoutButtonFlavors()
  1079. {
  1080. return [self::EC_FLAVOR_DYNAMIC => __('Dynamic'), self::EC_FLAVOR_STATIC => __('Static')];
  1081. }
  1082. /**
  1083. * Express Checkout button types source getter
  1084. *
  1085. * @return array
  1086. */
  1087. public function getExpressCheckoutButtonTypes()
  1088. {
  1089. return [
  1090. self::EC_BUTTON_TYPE_SHORTCUT => __('Shortcut'),
  1091. self::EC_BUTTON_TYPE_MARK => __('Acceptance Mark Image')
  1092. ];
  1093. }
  1094. /**
  1095. * Payment actions source getter
  1096. *
  1097. * @return array
  1098. */
  1099. public function getPaymentActions()
  1100. {
  1101. $paymentActions = [
  1102. self::PAYMENT_ACTION_AUTH => __('Authorization'),
  1103. self::PAYMENT_ACTION_SALE => __('Sale'),
  1104. ];
  1105. if ($this->_methodCode !== null && $this->_methodCode == self::METHOD_WPP_EXPRESS) {
  1106. $paymentActions[self::PAYMENT_ACTION_ORDER] = __('Order');
  1107. }
  1108. return $paymentActions;
  1109. }
  1110. /**
  1111. * Require Billing Address source getter
  1112. *
  1113. * @return array
  1114. */
  1115. public function getRequireBillingAddressOptions()
  1116. {
  1117. return [
  1118. self::REQUIRE_BILLING_ADDRESS_ALL => __('Yes'),
  1119. self::REQUIRE_BILLING_ADDRESS_NO => __('No'),
  1120. self::REQUIRE_BILLING_ADDRESS_VIRTUAL => __('For Virtual Quotes Only')
  1121. ];
  1122. }
  1123. /**
  1124. * Mapper from PayPal-specific payment actions to Magento payment actions
  1125. *
  1126. * @return string|null
  1127. */
  1128. public function getPaymentAction()
  1129. {
  1130. switch ($this->getValue('paymentAction')) {
  1131. case self::PAYMENT_ACTION_AUTH:
  1132. return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE;
  1133. case self::PAYMENT_ACTION_SALE:
  1134. return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE;
  1135. case self::PAYMENT_ACTION_ORDER:
  1136. return \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER;
  1137. }
  1138. return null;
  1139. }
  1140. /**
  1141. * Express Checkout "solution types" source getter
  1142. * "sole" = "Express Checkout for Auctions" - PayPal allows guest checkout
  1143. * "mark" = "Normal Express Checkout" - PayPal requires to checkout with PayPal buyer account only
  1144. *
  1145. * @return array
  1146. */
  1147. public function getExpressCheckoutSolutionTypes()
  1148. {
  1149. return [self::EC_SOLUTION_TYPE_SOLE => __('Yes'), self::EC_SOLUTION_TYPE_MARK => __('No')];
  1150. }
  1151. /**
  1152. * Retrieve express checkout billing agreement signup options
  1153. *
  1154. * @return array
  1155. */
  1156. public function getExpressCheckoutBASignupOptions()
  1157. {
  1158. return [
  1159. self::EC_BA_SIGNUP_AUTO => __('Auto'),
  1160. self::EC_BA_SIGNUP_ASK => __('Ask Customer'),
  1161. self::EC_BA_SIGNUP_NEVER => __('Never')
  1162. ];
  1163. }
  1164. /**
  1165. * Whether to ask customer to create billing agreements
  1166. *
  1167. * Unilateral payments are incompatible with the billing agreements
  1168. *
  1169. * @return bool
  1170. */
  1171. public function shouldAskToCreateBillingAgreement()
  1172. {
  1173. return $this->getValue('allow_ba_signup') === self::EC_BA_SIGNUP_ASK
  1174. && !$this->shouldUseUnilateralPayments();
  1175. }
  1176. /**
  1177. * Payment data delivery methods getter for PayPal Standard
  1178. *
  1179. * @return array
  1180. */
  1181. public function getWpsPaymentDeliveryMethods()
  1182. {
  1183. return [self::WPS_TRANSPORT_IPN => __('IPN (Instant Payment Notification) Only')];
  1184. }
  1185. /**
  1186. * Return list of supported credit card types by Paypal Direct gateway
  1187. *
  1188. * @return array
  1189. */
  1190. public function getWppCcTypesAsOptionArray()
  1191. {
  1192. return $this->_cctypeFactory->create()->setAllowedTypes(
  1193. ['AE', 'VI', 'MC', 'SM', 'SO', 'DI']
  1194. )->toOptionArray();
  1195. }
  1196. /**
  1197. * Return list of supported credit card types by Paypal Direct (Payflow Edition) gateway
  1198. *
  1199. * @return array
  1200. */
  1201. public function getWppPeCcTypesAsOptionArray()
  1202. {
  1203. return $this->_cctypeFactory->create()->setAllowedTypes(
  1204. ['VI', 'MC', 'SM', 'SO', 'AE']
  1205. )->toOptionArray();
  1206. }
  1207. /**
  1208. * Return list of supported credit card types by Payflow Pro gateway
  1209. *
  1210. * @return array
  1211. */
  1212. public function getPayflowproCcTypesAsOptionArray()
  1213. {
  1214. return $this->_cctypeFactory->create()->setAllowedTypes(['AE', 'VI', 'MC', 'JCB', 'DI', 'DN'])->toOptionArray();
  1215. }
  1216. /**
  1217. * Check whether the specified payment method is a CC-based one
  1218. *
  1219. * @param string $code
  1220. * @return bool
  1221. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  1222. */
  1223. public static function getIsCreditCardMethod($code)
  1224. {
  1225. switch ($code) {
  1226. case self::METHOD_PAYFLOWPRO:
  1227. case self::METHOD_PAYFLOWLINK:
  1228. case self::METHOD_PAYFLOWADVANCED:
  1229. case self::METHOD_HOSTEDPRO:
  1230. return true;
  1231. }
  1232. return false;
  1233. }
  1234. /**
  1235. * Check whether specified currency code is supported
  1236. *
  1237. * @param string $code
  1238. * @return bool
  1239. */
  1240. public function isCurrencyCodeSupported($code)
  1241. {
  1242. if (in_array($code, $this->_supportedCurrencyCodes)) {
  1243. return true;
  1244. }
  1245. if ($this->getMerchantCountry() == 'BR' && $code == 'BRL') {
  1246. return true;
  1247. }
  1248. if ($this->getMerchantCountry() == 'MY' && $code == 'MYR') {
  1249. return true;
  1250. }
  1251. if ($this->getMerchantCountry() == 'TR' && $code == 'TRY') {
  1252. return true;
  1253. }
  1254. return false;
  1255. }
  1256. /**
  1257. * Export page style current settings to specified object
  1258. *
  1259. * @param \Magento\Framework\DataObject $to
  1260. * @return void
  1261. */
  1262. public function exportExpressCheckoutStyleSettings(\Magento\Framework\DataObject $to)
  1263. {
  1264. foreach ($this->_ecStyleConfigMap as $key => $exportKey) {
  1265. $configValue = $this->getValue($key);
  1266. if ($configValue) {
  1267. $to->setData($exportKey, $configValue);
  1268. }
  1269. }
  1270. }
  1271. /**
  1272. * Dynamic PayPal image URL getter
  1273. *
  1274. * Also can render dynamic Acceptance Mark
  1275. *
  1276. * @param string $type
  1277. * @param string $localeCode
  1278. * @param float $orderTotal
  1279. * @param string $pal
  1280. * @return string
  1281. */
  1282. protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
  1283. {
  1284. $params = [
  1285. 'cmd' => '_dynamic-image',
  1286. 'buttontype' => $type,
  1287. 'locale' => $this->_getSupportedLocaleCode($localeCode),
  1288. ];
  1289. if ($orderTotal) {
  1290. $params['ordertotal'] = $this->formatPrice($orderTotal);
  1291. if ($pal) {
  1292. $params['pal'] = $pal;
  1293. }
  1294. }
  1295. if ($params['locale'] == 'en_US') {
  1296. switch ($type) {
  1297. case self::EC_BUTTON_TYPE_MARK:
  1298. return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png';
  1299. case self::EC_BUTTON_TYPE_SHORTCUT:
  1300. default:
  1301. return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
  1302. }
  1303. }
  1304. return sprintf(
  1305. 'https://fpdbs%s.paypal.com/dynamicimageweb?%s',
  1306. $this->getValue('sandboxFlag') ? '.sandbox' : '',
  1307. http_build_query($params)
  1308. );
  1309. }
  1310. /**
  1311. * Check whether specified locale code is supported. Fallback to en_US
  1312. *
  1313. * @param string|null $localeCode
  1314. * @return string
  1315. */
  1316. protected function _getSupportedLocaleCode($localeCode = null)
  1317. {
  1318. if (!$localeCode || !in_array($localeCode, $this->_supportedImageLocales)) {
  1319. return 'en_US';
  1320. }
  1321. return $localeCode;
  1322. }
  1323. /**
  1324. * Map any supported payment method into a config path by specified field name
  1325. *
  1326. * @param string $fieldName
  1327. * @return string|null
  1328. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1329. * @SuppressWarnings(PHPMD.NPathComplexity)
  1330. */
  1331. protected function _getSpecificConfigPath($fieldName)
  1332. {
  1333. $path = null;
  1334. switch ($this->_methodCode) {
  1335. case self::METHOD_WPP_BML:
  1336. $path = $this->_mapBmlFieldset($fieldName);
  1337. break;
  1338. case self::METHOD_WPP_PE_BML:
  1339. $path = $this->_mapBmlPayflowFieldset($fieldName);
  1340. break;
  1341. case self::METHOD_WPP_EXPRESS:
  1342. case self::METHOD_WPP_PE_EXPRESS:
  1343. case self::METHOD_EXPRESS:
  1344. $path = $this->_mapExpressFieldset($fieldName);
  1345. break;
  1346. case self::METHOD_BILLING_AGREEMENT:
  1347. case self::METHOD_HOSTEDPRO:
  1348. $path = $this->_mapMethodFieldset($fieldName);
  1349. break;
  1350. }
  1351. if ($path === null) {
  1352. switch ($this->_methodCode) {
  1353. case self::METHOD_WPP_EXPRESS:
  1354. case self::METHOD_WPP_BML:
  1355. case self::METHOD_BILLING_AGREEMENT:
  1356. case self::METHOD_HOSTEDPRO:
  1357. $path = $this->_mapWppFieldset($fieldName);
  1358. break;
  1359. case self::METHOD_WPP_PE_EXPRESS:
  1360. case self::METHOD_PAYFLOWADVANCED:
  1361. case self::METHOD_PAYFLOWLINK:
  1362. $path = $this->_mapWpukFieldset($fieldName);
  1363. break;
  1364. }
  1365. }
  1366. if ($path === null) {
  1367. $path = $this->_mapGeneralFieldset($fieldName);
  1368. }
  1369. if ($path === null) {
  1370. $path = $this->_mapGenericStyleFieldset($fieldName);
  1371. }
  1372. return $path;
  1373. }
  1374. /**
  1375. * Map PayPal Express config fields
  1376. *
  1377. * @param string $fieldName
  1378. * @return string|null
  1379. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1380. */
  1381. protected function _mapExpressFieldset($fieldName)
  1382. {
  1383. switch ($fieldName) {
  1384. case 'transfer_shipping_options':
  1385. case 'solution_type':
  1386. case 'visible_on_cart':
  1387. case 'visible_on_product':
  1388. case 'require_billing_address':
  1389. case 'authorization_honor_period':
  1390. case 'order_valid_period':
  1391. case 'child_authorization_number':
  1392. case 'allow_ba_signup':
  1393. case 'in_context':
  1394. case 'merchant_id':
  1395. return "payment/{$this->_methodCode}/{$fieldName}";
  1396. default:
  1397. return $this->_mapMethodFieldset($fieldName);
  1398. }
  1399. }
  1400. /**
  1401. * Map PayPal Express Bill Me Later config fields
  1402. *
  1403. * @param string $fieldName
  1404. * @return string|null
  1405. */
  1406. protected function _mapBmlFieldset($fieldName)
  1407. {
  1408. switch ($fieldName) {
  1409. case 'allow_ba_signup':
  1410. return "payment/" . self::METHOD_WPP_EXPRESS . "/{$fieldName}";
  1411. default:
  1412. return $this->_mapExpressFieldset($fieldName);
  1413. }
  1414. }
  1415. /**
  1416. * Map PayPal Express Bill Me Later config fields (Payflow Edition)
  1417. *
  1418. * @param string $fieldName
  1419. * @return string|null
  1420. */
  1421. protected function _mapBmlPayflowFieldset($fieldName)
  1422. {
  1423. switch ($fieldName) {
  1424. case 'allow_ba_signup':
  1425. return "payment/" . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}";
  1426. default:
  1427. return $this->_mapExpressFieldset($fieldName);
  1428. }
  1429. }
  1430. /**
  1431. * Map PayPal Direct config fields
  1432. *
  1433. * @param string $fieldName
  1434. * @return string|null
  1435. */
  1436. protected function _mapDirectFieldset($fieldName)
  1437. {
  1438. switch ($fieldName) {
  1439. case 'useccv':
  1440. return "payment/{$this->_methodCode}/{$fieldName}";
  1441. default:
  1442. return $this->_mapMethodFieldset($fieldName);
  1443. }
  1444. }
  1445. /**
  1446. * Map PayPal Website Payments Pro common config fields
  1447. *
  1448. * @param string $fieldName
  1449. * @return string|null
  1450. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1451. */
  1452. protected function _mapWppFieldset($fieldName)
  1453. {
  1454. switch ($fieldName) {
  1455. case 'api_authentication':
  1456. case 'api_username':
  1457. case 'api_password':
  1458. case 'api_signature':
  1459. case 'api_cert':
  1460. case 'sandbox_flag':
  1461. case 'use_proxy':
  1462. case 'proxy_host':
  1463. case 'proxy_port':
  1464. case 'button_flavor':
  1465. case 'button_type':
  1466. return "paypal/wpp/{$fieldName}";
  1467. default:
  1468. return null;
  1469. }
  1470. }
  1471. /**
  1472. * Map PayPal Website Payments Pro common config fields
  1473. *
  1474. * @param string $fieldName
  1475. * @return string|null
  1476. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1477. */
  1478. protected function _mapWpukFieldset($fieldName)
  1479. {
  1480. $pathPrefix = 'paypal/wpuk';
  1481. if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(self::METHOD_PAYFLOWLINK)) {
  1482. $pathPrefix = 'payment/payflow_link';
  1483. } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(
  1484. self::METHOD_PAYFLOWADVANCED
  1485. )
  1486. ) {
  1487. $pathPrefix = 'payment/payflow_advanced';
  1488. } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS) {
  1489. $pathPrefix = 'payment/payflowpro';
  1490. } elseif ($this->_methodCode == self::METHOD_PAYFLOWADVANCED || $this->_methodCode == self::METHOD_PAYFLOWLINK
  1491. ) {
  1492. return 'payment/' . $this->_methodCode . '/' . $fieldName;
  1493. }
  1494. switch ($fieldName) {
  1495. case 'partner':
  1496. case 'user':
  1497. case 'vendor':
  1498. case 'pwd':
  1499. case 'sandbox_flag':
  1500. case 'use_proxy':
  1501. case 'proxy_host':
  1502. case 'proxy_port':
  1503. return $pathPrefix . '/' . $fieldName;
  1504. default:
  1505. return null;
  1506. }
  1507. }
  1508. /**
  1509. * Map PayPal common style config fields
  1510. *
  1511. * @param string $fieldName
  1512. * @return string|null
  1513. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1514. */
  1515. protected function _mapGenericStyleFieldset($fieldName)
  1516. {
  1517. switch ($fieldName) {
  1518. case 'logo':
  1519. case 'page_style':
  1520. case 'paypal_hdrimg':
  1521. case 'paypal_hdrbackcolor':
  1522. case 'paypal_hdrbordercolor':
  1523. case 'paypal_payflowcolor':
  1524. case 'disable_funding_options':
  1525. return "paypal/style/{$fieldName}";
  1526. default:
  1527. return $this->mapButtonStyles($fieldName);
  1528. }
  1529. }
  1530. /**
  1531. * Map PayPal General Settings
  1532. *
  1533. * @param string $fieldName
  1534. * @return string|null
  1535. */
  1536. protected function _mapGeneralFieldset($fieldName)
  1537. {
  1538. switch ($fieldName) {
  1539. case 'business_account':
  1540. case 'merchant_country':
  1541. return "paypal/general/{$fieldName}";
  1542. default:
  1543. return null;
  1544. }
  1545. }
  1546. /**
  1547. * Map PayPal General Settings
  1548. *
  1549. * @param string $fieldName
  1550. * @return string|null
  1551. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1552. */
  1553. protected function _mapMethodFieldset($fieldName)
  1554. {
  1555. if (!$this->_methodCode) {
  1556. return null;
  1557. }
  1558. switch ($fieldName) {
  1559. case 'active':
  1560. case 'title':
  1561. case 'payment_action':
  1562. case 'allowspecific':
  1563. case 'specificcountry':
  1564. case 'line_items_enabled':
  1565. case 'cctypes':
  1566. case 'sort_order':
  1567. case 'debug':
  1568. case 'verify_peer':
  1569. return "payment/{$this->_methodCode}/{$fieldName}";
  1570. default:
  1571. return null;
  1572. }
  1573. }
  1574. /**
  1575. * Map PayPal button style config fields
  1576. *
  1577. * @param string $fieldName
  1578. * @return null|string
  1579. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  1580. */
  1581. private function mapButtonStyles(string $fieldName)
  1582. {
  1583. $page = substr($fieldName, 0, (int)strpos($fieldName, '_page_button_'));
  1584. if (!$page) {
  1585. return null;
  1586. }
  1587. switch ($fieldName) {
  1588. case "{$page}_page_button_customize":
  1589. case "{$page}_page_button_layout":
  1590. case "{$page}_page_button_size":
  1591. case "{$page}_page_button_color":
  1592. case "{$page}_page_button_shape":
  1593. case "{$page}_page_button_label":
  1594. case "{$page}_page_button_mx_installment_period":
  1595. case "{$page}_page_button_br_installment_period":
  1596. return "paypal/style/{$fieldName}";
  1597. default:
  1598. return null;
  1599. }
  1600. }
  1601. /**
  1602. * Payment API authentication methods source getter
  1603. *
  1604. * @return array
  1605. */
  1606. public function getApiAuthenticationMethods()
  1607. {
  1608. return ['0' => __('API Signature'), '1' => __('API Certificate')];
  1609. }
  1610. /**
  1611. * Api certificate getter
  1612. *
  1613. * @return string
  1614. */
  1615. public function getApiCertificate()
  1616. {
  1617. $websiteId = $this->_storeManager->getStore($this->_storeId)->getWebsiteId();
  1618. return $this->_certFactory->create()->loadByWebsite($websiteId, false)->getCertPath();
  1619. }
  1620. /**
  1621. * Get PublisherId from stored config
  1622. *
  1623. * @return mixed
  1624. */
  1625. public function getBmlPublisherId()
  1626. {
  1627. return $this->_scopeConfig->getValue(
  1628. 'payment/' . self::METHOD_WPP_BML . '/publisher_id',
  1629. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1630. $this->_storeId
  1631. );
  1632. }
  1633. /**
  1634. * Get Display option from stored config
  1635. *
  1636. * @param string $section
  1637. *
  1638. * @return mixed
  1639. */
  1640. public function getBmlDisplay($section)
  1641. {
  1642. $display = $this->_scopeConfig->getValue(
  1643. 'payment/' . self::METHOD_WPP_BML . '/' . $section . '_display',
  1644. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1645. $this->_storeId
  1646. );
  1647. $bmlActive = $this->_scopeConfig->getValue(
  1648. 'payment/' . self::METHOD_WPP_BML . '/active',
  1649. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1650. $this->_storeId
  1651. );
  1652. $bmlUkActive = $this->_scopeConfig->getValue(
  1653. 'payment/' . self::METHOD_WPP_PE_BML . '/active',
  1654. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1655. $this->_storeId
  1656. );
  1657. return (($bmlActive && $this->isMethodActive(self::METHOD_WPP_EXPRESS))
  1658. || ($bmlUkActive && $this->isMethodActive(self::METHOD_WPP_PE_EXPRESS))) ? $display : 0;
  1659. }
  1660. /**
  1661. * Get Position option from stored config
  1662. *
  1663. * @param string $section
  1664. *
  1665. * @return mixed
  1666. */
  1667. public function getBmlPosition($section)
  1668. {
  1669. return $this->_scopeConfig->getValue(
  1670. 'payment/' . self::METHOD_WPP_BML . '/' . $section . '_position',
  1671. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1672. $this->_storeId
  1673. );
  1674. }
  1675. /**
  1676. * Get Size option from stored config
  1677. *
  1678. * @param string $section
  1679. *
  1680. * @return mixed
  1681. */
  1682. public function getBmlSize($section)
  1683. {
  1684. return $this->_scopeConfig->getValue(
  1685. 'payment/' . self::METHOD_WPP_BML . '/' . $section . '_size',
  1686. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  1687. $this->_storeId
  1688. );
  1689. }
  1690. }