Config.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\AuthorizenetAcceptjs\Gateway;
  8. use Magento\AuthorizenetAcceptjs\Model\Adminhtml\Source\Environment;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. /**
  11. * Houses configuration for this gateway
  12. */
  13. class Config extends \Magento\Payment\Gateway\Config\Config
  14. {
  15. const METHOD = 'authorizenet_acceptjs';
  16. private const KEY_LOGIN_ID = 'login';
  17. private const KEY_TRANSACTION_KEY = 'trans_key';
  18. private const KEY_ENVIRONMENT = 'environment';
  19. private const KEY_LEGACY_TRANSACTION_HASH = 'trans_md5';
  20. private const KEY_SIGNATURE_KEY = 'trans_signature_key';
  21. private const KEY_PAYMENT_ACTION = 'payment_action';
  22. private const KEY_SHOULD_EMAIL_CUSTOMER = 'email_customer';
  23. private const KEY_ADDITIONAL_INFO_KEYS = 'paymentInfoKeys';
  24. private const KEY_CLIENT_KEY = 'public_client_key';
  25. private const KEY_CVV_ENABLED = 'cvv_enabled';
  26. private const KEY_TRANSACTION_SYNC_KEYS = 'transactionSyncKeys';
  27. private const ENDPOINT_URL_SANDBOX = 'https://apitest.authorize.net/xml/v1/request.api';
  28. private const ENDPOINT_URL_PRODUCTION = 'https://api.authorize.net/xml/v1/request.api';
  29. private const SOLUTION_ID_SANDBOX = 'AAA102993';
  30. private const SOLUTION_ID_PRODUCTION = 'AAA175350';
  31. /**
  32. * @param ScopeConfigInterface $scopeConfig
  33. * @param null|string $methodCode
  34. * @param string $pathPattern
  35. */
  36. public function __construct(
  37. ScopeConfigInterface $scopeConfig,
  38. $methodCode = null,
  39. $pathPattern = self::DEFAULT_PATH_PATTERN
  40. ) {
  41. parent::__construct($scopeConfig, $methodCode, $pathPattern);
  42. }
  43. /**
  44. * Gets the login id
  45. *
  46. * @param int|null $storeId
  47. * @return string
  48. */
  49. public function getLoginId($storeId = null): ?string
  50. {
  51. return $this->getValue(Config::KEY_LOGIN_ID, $storeId);
  52. }
  53. /**
  54. * Gets the current environment
  55. *
  56. * @param int|null $storeId
  57. * @return string
  58. */
  59. public function getEnvironment($storeId = null): string
  60. {
  61. return $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
  62. }
  63. /**
  64. * Gets the transaction key
  65. *
  66. * @param int|null $storeId
  67. * @return string
  68. */
  69. public function getTransactionKey($storeId = null): ?string
  70. {
  71. return $this->getValue(Config::KEY_TRANSACTION_KEY, $storeId);
  72. }
  73. /**
  74. * Gets the API endpoint URL
  75. *
  76. * @param int|null $storeId
  77. * @return string
  78. */
  79. public function getApiUrl($storeId = null): string
  80. {
  81. $environment = $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
  82. return $environment === Environment::ENVIRONMENT_SANDBOX
  83. ? self::ENDPOINT_URL_SANDBOX
  84. : self::ENDPOINT_URL_PRODUCTION;
  85. }
  86. /**
  87. * Gets the configured signature key
  88. *
  89. * @param int|null $storeId
  90. * @return string
  91. */
  92. public function getTransactionSignatureKey($storeId = null): ?string
  93. {
  94. return $this->getValue(Config::KEY_SIGNATURE_KEY, $storeId);
  95. }
  96. /**
  97. * Gets the configured legacy transaction hash
  98. *
  99. * @param int|null $storeId
  100. * @return string
  101. */
  102. public function getLegacyTransactionHash($storeId = null): ?string
  103. {
  104. return $this->getValue(Config::KEY_LEGACY_TRANSACTION_HASH, $storeId);
  105. }
  106. /**
  107. * Gets the configured payment action
  108. *
  109. * @param int|null $storeId
  110. * @return string
  111. */
  112. public function getPaymentAction($storeId = null): ?string
  113. {
  114. return $this->getValue(Config::KEY_PAYMENT_ACTION, $storeId);
  115. }
  116. /**
  117. * Gets the configured client key
  118. *
  119. * @param int|null $storeId
  120. * @return string
  121. */
  122. public function getClientKey($storeId = null): ?string
  123. {
  124. return $this->getValue(Config::KEY_CLIENT_KEY, $storeId);
  125. }
  126. /**
  127. * Should authorize.net email the customer their receipt.
  128. *
  129. * @param int|null $storeId
  130. * @return bool
  131. */
  132. public function shouldEmailCustomer($storeId = null): bool
  133. {
  134. return (bool)$this->getValue(Config::KEY_SHOULD_EMAIL_CUSTOMER, $storeId);
  135. }
  136. /**
  137. * Should the cvv field be shown
  138. *
  139. * @param int|null $storeId
  140. * @return bool
  141. */
  142. public function isCvvEnabled($storeId = null): bool
  143. {
  144. return (bool)$this->getValue(Config::KEY_CVV_ENABLED, $storeId);
  145. }
  146. /**
  147. * Retrieves the solution id for the given store based on environment
  148. *
  149. * @param int|null $storeId
  150. * @return string
  151. */
  152. public function getSolutionId($storeId = null): ?string
  153. {
  154. $environment = $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
  155. return $environment === Environment::ENVIRONMENT_SANDBOX
  156. ? self::SOLUTION_ID_SANDBOX
  157. : self::SOLUTION_ID_PRODUCTION;
  158. }
  159. /**
  160. * Returns the keys to be pulled from the transaction and displayed
  161. *
  162. * @param int|null $storeId
  163. * @return string[]
  164. */
  165. public function getAdditionalInfoKeys($storeId = null): array
  166. {
  167. return explode(',', $this->getValue(Config::KEY_ADDITIONAL_INFO_KEYS, $storeId) ?? '');
  168. }
  169. /**
  170. * Returns the keys to be pulled from the transaction and displayed when syncing the transaction
  171. *
  172. * @param int|null $storeId
  173. * @return string[]
  174. */
  175. public function getTransactionInfoSyncKeys($storeId = null): array
  176. {
  177. return explode(',', $this->getValue(Config::KEY_TRANSACTION_SYNC_KEYS, $storeId) ?? '');
  178. }
  179. }