Config.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\Block;
  17. use Amazon\Core\Helper\CategoryExclusion;
  18. use Amazon\Core\Helper\Data;
  19. use Amazon\Core\Model\AmazonConfig;
  20. use Magento\Customer\Model\Url;
  21. use Magento\Framework\View\Element\Template;
  22. use Magento\Framework\View\Element\Template\Context;
  23. /**
  24. * Config
  25. *
  26. * @api
  27. *
  28. * Provides a block that displays links to available custom error logs in Amazon Pay admin/config section.
  29. */
  30. class Config extends Template
  31. {
  32. /**
  33. * @var Data
  34. */
  35. private $coreHelper;
  36. /**
  37. * @var Url
  38. */
  39. private $url;
  40. /**
  41. * @var CategoryExclusion
  42. */
  43. private $categoryExclusionHelper;
  44. /**
  45. * @var AmazonConfig
  46. */
  47. private $config;
  48. /**
  49. * Config constructor.
  50. * @param Context $context
  51. * @param Data $coreHelper
  52. * @param AmazonConfig $config
  53. * @param Url $url
  54. * @param CategoryExclusion $categoryExclusionHelper
  55. */
  56. public function __construct(
  57. Context $context,
  58. Data $coreHelper,
  59. AmazonConfig $config,
  60. Url $url,
  61. CategoryExclusion $categoryExclusionHelper
  62. ) {
  63. parent::__construct($context);
  64. $this->coreHelper = $coreHelper;
  65. $this->config = $config;
  66. $this->url = $url;
  67. $this->categoryExclusionHelper = $categoryExclusionHelper;
  68. }
  69. /**
  70. * @return string
  71. */
  72. public function getConfig()
  73. {
  74. $config = [
  75. 'widgetUrl' => $this->coreHelper->getWidgetUrl(),
  76. 'merchantId' => $this->coreHelper->getMerchantId(),
  77. 'clientId' => $this->coreHelper->getClientId(),
  78. 'isPwaEnabled' => $this->coreHelper->isPaymentButtonEnabled(),
  79. 'isLwaEnabled' => $this->coreHelper->isLoginButtonEnabled(),
  80. 'isSandboxEnabled' => $this->coreHelper->isSandboxEnabled(),
  81. 'chargeOnOrder' => $this->sanitizePaymentAction(),
  82. 'authorizationMode' => $this->coreHelper->getAuthorizationMode(),
  83. 'displayLanguage' => $this->coreHelper->getButtonDisplayLanguage(),
  84. 'buttonTypePwa' => $this->coreHelper->getButtonTypePwa(),
  85. 'buttonTypeLwa' => $this->coreHelper->getButtonTypeLwa(),
  86. 'buttonColor' => $this->coreHelper->getButtonColor(),
  87. 'buttonSize' => $this->coreHelper->getButtonSize(),
  88. 'redirectUrl' => $this->coreHelper->getRedirectUrl(),
  89. 'loginPostUrl' => $this->url->getLoginPostUrl(),
  90. 'customerLoginPageUrl' => $this->url->getLoginUrl(),
  91. 'sandboxSimulationOptions' => [],
  92. 'loginScope' => $this->coreHelper->getLoginScope(),
  93. 'allowAmLoginLoading' => $this->coreHelper->allowAmLoginLoading(),
  94. 'isEuPaymentRegion' => $this->coreHelper->isEuPaymentRegion(),
  95. 'presentmentCurrency' => $this->config->getPresentmentCurrency(),
  96. 'oAuthHashRedirectUrl' => $this->coreHelper->getOAuthRedirectUrl(),
  97. 'isQuoteDirty' => $this->categoryExclusionHelper->isQuoteDirty(),
  98. 'region' => $this->coreHelper->getRegion(),
  99. 'useMultiCurrency' => $this->config->useMultiCurrency()
  100. ];
  101. if ($this->coreHelper->isSandboxEnabled()) {
  102. $config['sandboxSimulationOptions'] = $this->transformSandboxSimulationOptions();
  103. }
  104. return $config;
  105. }
  106. /**
  107. * @return bool
  108. */
  109. public function isBadgeEnabled()
  110. {
  111. return ($this->coreHelper->isPwaEnabled());
  112. }
  113. /**
  114. * @return bool
  115. */
  116. public function isExtensionEnabled()
  117. {
  118. return ($this->coreHelper->isPwaEnabled() || $this->coreHelper->isLwaEnabled());
  119. }
  120. /**
  121. * @return bool
  122. */
  123. public function sanitizePaymentAction()
  124. {
  125. return ($this->coreHelper->getPaymentAction() === 'authorize_capture');
  126. }
  127. /**
  128. * @return array
  129. */
  130. public function transformSandboxSimulationOptions()
  131. {
  132. $sandboxSimulationOptions = $this->coreHelper->getSandboxSimulationOptions();
  133. $output = [];
  134. foreach ($sandboxSimulationOptions as $key => $value) {
  135. $output[] = [
  136. 'labelText' => $value,
  137. 'simulationValue' => $key,
  138. ];
  139. }
  140. return $output;
  141. }
  142. }