Data.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Core\Helper;
  17. use Magento\Framework\App\Helper\AbstractHelper;
  18. use Magento\Framework\App\Helper\Context;
  19. use Magento\Framework\Encryption\EncryptorInterface;
  20. use Magento\Store\Model\ScopeInterface;
  21. use Magento\Store\Model\StoreManagerInterface;
  22. use Magento\Framework\Module\ModuleListInterface;
  23. use Magento\Framework\Module\StatusFactory;
  24. use Amazon\Core\Model\AmazonConfig;
  25. /**
  26. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  27. */
  28. class Data extends AbstractHelper
  29. {
  30. const AMAZON_ACTIVE = 'payment/amazon_payment/active';
  31. /**
  32. * @var EncryptorInterface
  33. */
  34. private $encryptor;
  35. /**
  36. * @var StoreManagerInterface
  37. */
  38. private $storeManager;
  39. /**
  40. * @var \Amazon\Core\Helper\ClientIp
  41. */
  42. private $clientIpHelper;
  43. /**
  44. * @var ModuleListInterface
  45. */
  46. private $moduleList;
  47. /**
  48. * @var StatusFactory
  49. */
  50. private $moduleStatusFactory;
  51. /**
  52. * @var Config
  53. */
  54. private $config;
  55. /**
  56. * Data constructor.
  57. *
  58. * @param ModuleListInterface $moduleList
  59. * @param Context $context
  60. * @param EncryptorInterface $encryptor
  61. * @param StoreManagerInterface $storeManager
  62. * @param ClientIp $clientIpHelper
  63. * @param StatusFactory $moduleStatusFactory
  64. * @param AmazonConfig $config
  65. */
  66. public function __construct(
  67. ModuleListInterface $moduleList,
  68. Context $context,
  69. EncryptorInterface $encryptor,
  70. StoreManagerInterface $storeManager,
  71. ClientIp $clientIpHelper,
  72. StatusFactory $moduleStatusFactory,
  73. AmazonConfig $config
  74. ) {
  75. parent::__construct($context);
  76. $this->moduleList = $moduleList;
  77. $this->encryptor = $encryptor;
  78. $this->storeManager = $storeManager;
  79. $this->clientIpHelper = $clientIpHelper;
  80. $this->moduleStatusFactory = $moduleStatusFactory;
  81. $this->config = $config;
  82. }
  83. /*
  84. * @return string
  85. */
  86. public function getMerchantId($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  87. {
  88. return $this->scopeConfig->getValue(
  89. 'payment/amazon_payment/merchant_id',
  90. $scope,
  91. $scopeCode
  92. );
  93. }
  94. /*
  95. * @return string
  96. */
  97. public function getAccessKey($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  98. {
  99. return $this->scopeConfig->getValue(
  100. 'payment/amazon_payment/access_key',
  101. $scope,
  102. $scopeCode
  103. );
  104. }
  105. /*
  106. * @return string
  107. */
  108. public function getSecretKey($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  109. {
  110. $secretKey = $this->scopeConfig->getValue(
  111. 'payment/amazon_payment/secret_key',
  112. $scope,
  113. $scopeCode
  114. );
  115. $secretKey = $this->encryptor->decrypt($secretKey);
  116. return $secretKey;
  117. }
  118. /*
  119. * @return string
  120. */
  121. public function getClientId($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  122. {
  123. return $this->scopeConfig->getValue(
  124. 'payment/amazon_payment/client_id',
  125. $scope,
  126. $scopeCode
  127. );
  128. }
  129. /*
  130. * @return string
  131. */
  132. public function getClientSecret($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  133. {
  134. $clientSecret = $this->scopeConfig->getValue(
  135. 'payment/amazon_payment/client_secret',
  136. $scope,
  137. $scopeCode
  138. );
  139. $clientSecret = $this->encryptor->decrypt($clientSecret);
  140. return $clientSecret;
  141. }
  142. /*
  143. * @return string
  144. *
  145. * @deprecated - use \Amazon\Core\Model\AmazonConfig::getPaymentRegion() instead
  146. */
  147. public function getPaymentRegion($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  148. {
  149. return $this->scopeConfig->getValue(
  150. 'payment/amazon_payment/payment_region',
  151. $scope,
  152. $scopeCode
  153. );
  154. }
  155. /*
  156. * @return string
  157. */
  158. public function getRegion($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  159. {
  160. return $this->getPaymentRegion($scope, $scopeCode);
  161. }
  162. /*
  163. * @return string
  164. */
  165. public function getCurrencyCode($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  166. {
  167. $paymentRegion = $this->getPaymentRegion($scope, $scopeCode);
  168. $currencyCodeMap = [
  169. 'de' => 'EUR',
  170. 'uk' => 'GBP',
  171. 'us' => 'USD',
  172. 'jp' => 'JPY'
  173. ];
  174. return array_key_exists($paymentRegion, $currencyCodeMap) ? $currencyCodeMap[$paymentRegion] : '';
  175. }
  176. /*
  177. * @return string
  178. */
  179. public function getWidgetUrl($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  180. {
  181. $paymentRegion = $this->getPaymentRegion($scope, $scopeCode);
  182. $sandboxEnabled = $this->isSandboxEnabled($scope, $scopeCode);
  183. $widgetUrlMap = [
  184. 'de' => $this->getWidgetPath('production/de'),
  185. 'uk' => $this->getWidgetPath('production/uk'),
  186. 'us' => $this->getWidgetPath('production/us'),
  187. 'jp' => $this->getWidgetPath('production/jp')
  188. ];
  189. if ($sandboxEnabled) {
  190. $widgetUrlMap = [
  191. 'de' => $this->getWidgetPath('sandbox/de'),
  192. 'uk' => $this->getWidgetPath('sandbox/uk'),
  193. 'us' => $this->getWidgetPath('sandbox/us'),
  194. 'jp' => $this->getWidgetPath('sandbox/jp')
  195. ];
  196. }
  197. return array_key_exists($paymentRegion, $widgetUrlMap) ? $widgetUrlMap[$paymentRegion] : '';
  198. }
  199. /**
  200. * Retrieves region path from config.xml settings
  201. *
  202. * @param $key
  203. * @param null $store
  204. * @return mixed
  205. */
  206. public function getWidgetPath($key, $store = null)
  207. {
  208. return $this->scopeConfig->getValue(
  209. 'widget/' . $key,
  210. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  211. $store
  212. );
  213. }
  214. /**
  215. * @param string $scope
  216. * @param null|string $scopeCode
  217. *
  218. * @return string
  219. */
  220. public function getLoginScope($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  221. {
  222. $paymentRegion = $this->getPaymentRegion($scope, $scopeCode);
  223. $scope = [
  224. 'profile',
  225. 'payments:widget',
  226. 'payments:shipping_address',
  227. 'payments:billing_address'
  228. ];
  229. return implode(' ', $scope);
  230. }
  231. /**
  232. * @param string $scope
  233. *
  234. * @return boolean
  235. */
  236. public function isEuPaymentRegion($scope = ScopeInterface::SCOPE_STORE)
  237. {
  238. $paymentRegion = $this->getPaymentRegion($scope);
  239. return (in_array($paymentRegion, ['uk', 'de']));
  240. }
  241. /*
  242. * @return bool
  243. */
  244. public function isSandboxEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  245. {
  246. return (bool)$this->scopeConfig->getValue(
  247. 'payment/amazon_payment/sandbox',
  248. $scope,
  249. $scopeCode
  250. );
  251. }
  252. /*
  253. * @return bool
  254. */
  255. public function isPwaEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  256. {
  257. if (!$this->moduleList->has('Amazon_Payment') || !$this->moduleList->has('Amazon_Login')) {
  258. $this->updateModuleStatus();
  259. return false;
  260. }
  261. if (!$this->clientIpHelper->clientHasAllowedIp()) {
  262. return false;
  263. }
  264. return $this->scopeConfig->isSetFlag(
  265. self::AMAZON_ACTIVE,
  266. $scope,
  267. $scopeCode
  268. );
  269. }
  270. /*
  271. * @return bool
  272. */
  273. public function isLwaEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  274. {
  275. if (!$this->moduleList->has('Amazon_Payment') || !$this->moduleList->has('Amazon_Login')) {
  276. $this->updateModuleStatus();
  277. return false;
  278. }
  279. if (!$this->clientIpHelper->clientHasAllowedIp()) {
  280. return false;
  281. }
  282. return $this->scopeConfig->isSetFlag(
  283. 'payment/amazon_payment/lwa_enabled',
  284. $scope,
  285. $scopeCode
  286. );
  287. }
  288. /*
  289. * @return bool
  290. */
  291. public function isEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  292. {
  293. if (!$this->moduleList->has('Amazon_Payment') || !$this->moduleList->has('Amazon_Login')) {
  294. $this->updateModuleStatus();
  295. return false;
  296. }
  297. return $this->isLwaEnabled($scope, $scopeCode) || $this->isPwaEnabled($scope, $scopeCode);
  298. }
  299. /*
  300. * @return string
  301. */
  302. public function getPaymentAction($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  303. {
  304. return $this->scopeConfig->getValue(
  305. 'payment/amazon_payment/payment_action',
  306. $scope,
  307. $scopeCode
  308. );
  309. }
  310. /*
  311. * @return string
  312. */
  313. public function getAuthorizationMode($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  314. {
  315. return $this->scopeConfig->getValue(
  316. 'payment/amazon_payment/authorization_mode',
  317. $scope,
  318. $scopeCode
  319. );
  320. }
  321. /*
  322. * @return string
  323. */
  324. public function getUpdateMechanism($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  325. {
  326. return $this->scopeConfig->getValue(
  327. 'payment/amazon_payment/update_mechanism',
  328. $scope,
  329. $scopeCode
  330. );
  331. }
  332. /*
  333. * @return string
  334. */
  335. public function getButtonDisplayLanguage($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  336. {
  337. $buttonConfigLang = $this->scopeConfig
  338. ->getValue('payment/amazon_payment/button_display_language', $scope, $scopeCode);
  339. if (empty($buttonConfigLang)) {
  340. $buttonConfigLang = $this->scopeConfig->getValue('general/locale/code', $scope, $scopeCode);
  341. }
  342. return str_replace('_', '-', $buttonConfigLang);
  343. }
  344. /*
  345. * @return string
  346. */
  347. public function getButtonType($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  348. {
  349. return $this->scopeConfig->getValue(
  350. 'payment/amazon_payment/button_type',
  351. $scope,
  352. $scopeCode
  353. );
  354. }
  355. /*
  356. * @return string
  357. */
  358. public function getButtonTypePwa($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  359. {
  360. $buttonType = $this->getButtonType($scope, $scopeCode);
  361. $buttonTypeMap = [
  362. 'full' => 'PwA',
  363. 'short' => 'Pay',
  364. 'logo' => 'A',
  365. ];
  366. return array_key_exists($buttonType, $buttonTypeMap) ? $buttonTypeMap[$buttonType] : '';
  367. }
  368. /*
  369. * @return string
  370. */
  371. public function getButtonTypeLwa($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  372. {
  373. $buttonType = $this->getButtonType($scope, $scopeCode);
  374. $buttonTypeMap = [
  375. 'full' => 'LwA',
  376. 'short' => 'Login',
  377. 'logo' => 'A',
  378. ];
  379. return array_key_exists($buttonType, $buttonTypeMap) ? $buttonTypeMap[$buttonType] : '';
  380. }
  381. /*
  382. * @return string
  383. */
  384. public function getButtonColor($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  385. {
  386. return $this->scopeConfig->getValue(
  387. 'payment/amazon_payment/button_color',
  388. $scope,
  389. $scopeCode
  390. );
  391. }
  392. /*
  393. * @return string
  394. */
  395. public function getButtonSize($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  396. {
  397. return $this->scopeConfig->getValue(
  398. 'payment/amazon_payment/button_size',
  399. $scope,
  400. $scopeCode
  401. );
  402. }
  403. /*
  404. * @return string
  405. */
  406. public function getEmailStoreName($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  407. {
  408. return $this->scopeConfig->getValue(
  409. 'payment/amazon_payment/email_store_name',
  410. $scope,
  411. $scopeCode
  412. );
  413. }
  414. /*
  415. * @return string
  416. */
  417. public function getAdditionalAccessScope($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  418. {
  419. return $this->scopeConfig->getValue(
  420. 'payment/amazon_payment/additional_access_scope',
  421. $scope,
  422. $scopeCode
  423. );
  424. }
  425. /*
  426. * @return bool
  427. */
  428. public function isLoggingEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  429. {
  430. return (bool)$this->scopeConfig->getValue(
  431. 'payment/amazon_payment/logging',
  432. $scope,
  433. $scopeCode
  434. );
  435. }
  436. /*
  437. * @return string
  438. */
  439. public function getStoreName($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  440. {
  441. return $this->scopeConfig->getValue(
  442. 'payment/amazon_payment/storename',
  443. $scope,
  444. $scopeCode
  445. );
  446. }
  447. /*
  448. * @return string
  449. */
  450. public function getStoreFrontName($storeId)
  451. {
  452. return $this->storeManager->getStore($storeId)->getName();
  453. }
  454. /*
  455. * @return string
  456. */
  457. public function getRedirectUrl()
  458. {
  459. $urlPath = $this->isLwaEnabled() ? 'amazon/login/authorize' : 'amazon/login/guest';
  460. return $this->_getUrl($urlPath, ['_secure' => true]);
  461. }
  462. /**
  463. * @param string|null $context
  464. *
  465. * @return array
  466. */
  467. public function getSandboxSimulationStrings($context = null)
  468. {
  469. $simulationStrings = [
  470. 'default' => null
  471. ];
  472. if (in_array($context, ['authorization', 'authorization_capture'])) {
  473. $simulationStrings['Authorization:Declined:InvalidPaymentMethod']
  474. = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"InvalidPaymentMethod", ' .
  475. '"PaymentMethodUpdateTimeInMins":5}}';
  476. $simulationStrings['Authorization:Declined:AmazonRejected']
  477. = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
  478. $simulationStrings['Authorization:Declined:TransactionTimedOut']
  479. = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"TransactionTimedOut"}}';
  480. }
  481. if (in_array($context, ['capture', 'authorization_capture'])) {
  482. $simulationStrings['Capture:Declined:AmazonRejected']
  483. = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
  484. $simulationStrings['Capture:Pending']
  485. = '{"SandboxSimulation": {"State":"Pending"}}';
  486. }
  487. if (in_array($context, ['refund'])) {
  488. $simulationStrings['Refund:Declined']
  489. = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
  490. }
  491. return $simulationStrings;
  492. }
  493. /**
  494. * @return array
  495. */
  496. public function getSandboxSimulationOptions()
  497. {
  498. $simulationlabels = [
  499. 'default' => __('No Simulation'),
  500. 'Authorization:Declined:InvalidPaymentMethod' => __('Authorization soft decline'),
  501. 'Authorization:Declined:AmazonRejected' => __('Authorization hard decline'),
  502. 'Authorization:Declined:TransactionTimedOut' => __('Authorization timed out')
  503. ];
  504. return $simulationlabels;
  505. }
  506. /**
  507. * @param string $scope
  508. * @param null $scopeCode
  509. * @return bool
  510. */
  511. public function isPaymentButtonEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  512. {
  513. return ($this->isPwaEnabled($scope, $scopeCode) && $this->isCurrentCurrencySupportedByAmazon());
  514. }
  515. /**
  516. * @return bool
  517. */
  518. public function isLoginButtonEnabled()
  519. {
  520. return ($this->isLwaEnabled() && $this->isPwaEnabled() && $this->isCurrentCurrencySupportedByAmazon());
  521. }
  522. /**
  523. * @return bool
  524. */
  525. public function isCurrentCurrencySupportedByAmazon()
  526. {
  527. return $this->config->getBaseCurrencyCode() == $this->getCurrencyCode();
  528. }
  529. /**
  530. * @param string $paymentRegion E.g. "uk", "us", "de", "jp".
  531. *
  532. * @return mixed
  533. */
  534. public function getAmazonAccountUrlByPaymentRegion($paymentRegion)
  535. {
  536. $url = $this->getPaymentRegionUrl($paymentRegion);
  537. if (!$url || empty($url)) {
  538. throw new \InvalidArgumentException("$paymentRegion is not a valid payment region");
  539. }
  540. return $url;
  541. }
  542. /**
  543. * Retrieves region path from config.xml settings
  544. *
  545. * @param $key
  546. * @param null $store
  547. * @return mixed
  548. */
  549. public function getPaymentRegionUrl($key, $store = null)
  550. {
  551. return $this->scopeConfig->getValue(
  552. 'region/country/' . $key,
  553. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  554. $store
  555. );
  556. }
  557. /**
  558. * Retrieves client path from config.xml settings
  559. *
  560. * @param $key
  561. * @param null $store
  562. * @return mixed
  563. */
  564. public function getClientPath($key, $store = null)
  565. {
  566. return $this->scopeConfig->getValue(
  567. 'client/paths/' . $key,
  568. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  569. $store
  570. );
  571. }
  572. /**
  573. * @param string $scope
  574. * @param null|string $scopeCode
  575. *
  576. * @return array
  577. */
  578. public function getBlackListedTerms($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  579. {
  580. $terms = $this->scopeConfig->getValue('payment/amazon_payment/packstation_terms', $scope, $scopeCode);
  581. return explode(',', $terms);
  582. }
  583. /**
  584. * @param string $scope
  585. * @param null|string $scopeCode
  586. *
  587. * @return bool
  588. */
  589. public function isBlacklistedTermValidationEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  590. {
  591. return $this->scopeConfig
  592. ->isSetFlag('payment/amazon_payment/packstation_terms_validation_enabled', $scope, $scopeCode);
  593. }
  594. /**
  595. * @return string
  596. */
  597. public function getOAuthRedirectUrl()
  598. {
  599. return $this->_getUrl('amazon/login/processAuthHash', ['_secure' => true]);
  600. }
  601. /**
  602. * @param string $scope
  603. * @param null|string $scopeCode
  604. *
  605. * @return bool
  606. */
  607. public function isPwaButtonVisibleOnProductPage($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  608. {
  609. return $this->isPaymentButtonEnabled($scope, $scopeCode)
  610. && $this->scopeConfig->isSetFlag('payment/amazon_payment/pwa_pp_button_is_visible', $scope, $scopeCode);
  611. }
  612. /**
  613. * @param string $scope
  614. * @param null $scopeCode
  615. * @return bool
  616. */
  617. public function isPayButtonAvailableInMinicart($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  618. {
  619. return $this->scopeConfig->isSetFlag('payment/amazon_payment/minicart_button_is_visible', $scope, $scopeCode);
  620. }
  621. /**
  622. * @param string $scope
  623. * @param null $scopeCode
  624. * @return bool
  625. */
  626. public function allowAmLoginLoading($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  627. {
  628. return $this->scopeConfig->isSetFlag(
  629. 'payment/amazon_payment/amazon_login_in_popup',
  630. $scope,
  631. $scopeCode
  632. );
  633. }
  634. /**
  635. * @param string $scope
  636. * @param null|string $scopeCode
  637. *
  638. * @return string
  639. */
  640. public function getCredentialsJson($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
  641. {
  642. return $this->scopeConfig
  643. ->getValue('payment/amazon_payment/credentials_json', $scope, $scopeCode);
  644. }
  645. /**
  646. * @return array
  647. */
  648. public function getAmazonCredentialsFields()
  649. {
  650. return [
  651. $this->getClientPath('secretkey'),
  652. $this->getClientPath('accesskey'),
  653. $this->getClientPath('merchantid'),
  654. $this->getClientPath('clientid'),
  655. $this->getClientPath('clientsecret')
  656. ];
  657. }
  658. /**
  659. * @return array
  660. */
  661. public function getAmazonCredentialsEncryptedFields()
  662. {
  663. return [
  664. $this->getClientPath('secretkey'),
  665. $this->getClientPath('clientsecret')
  666. ];
  667. }
  668. /**
  669. * @return null
  670. */
  671. public function getVersion()
  672. {
  673. $version = $this->moduleList->getOne('Amazon_Core');
  674. if ($version && isset($version['setup_version'])) {
  675. return $version['setup_version'];
  676. } else {
  677. return null;
  678. }
  679. }
  680. /**
  681. * Ensures all modules are disabled if one of them is disabled. Amazon Payment or Amazon Login modules will cause
  682. * the frontend to break if they are in different enabled states.
  683. */
  684. private function updateModuleStatus()
  685. {
  686. $isDisabled = $this->moduleList->has('Amazon_Payment') ? 0 : 1;
  687. $isDisabled += $this->moduleList->has('Amazon_Login') ? 0 : 1;
  688. $isDisabled += $this->moduleList->has('Amazon_Core') ? 0 : 1;
  689. // Make sure all of them are disabled if any one of them is disabled.
  690. if ($isDisabled > 0 && $isDisabled != 3) {
  691. $this->moduleStatusFactory->create()->setIsEnabled(false, ['Amazon_Payment', 'Amazon_Login', 'Amazon_Core']);
  692. }
  693. }
  694. }