Payment.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Block;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Config;
  9. use Magento\Framework\Serialize\Serializer\Json;
  10. use Magento\Framework\View\Element\Template;
  11. use Magento\Checkout\Model\ConfigProviderInterface;
  12. use Magento\Framework\View\Element\Template\Context;
  13. /**
  14. * Represents the payment block for the admin checkout form
  15. *
  16. * @api
  17. * @since 100.3.0
  18. */
  19. class Payment extends Template
  20. {
  21. /**
  22. * @var ConfigProviderInterface
  23. */
  24. private $config;
  25. /**
  26. * @var Json
  27. */
  28. private $json;
  29. /**
  30. * @param Context $context
  31. * @param ConfigProviderInterface $config
  32. * @param Json $json
  33. * @param array $data
  34. */
  35. public function __construct(
  36. Context $context,
  37. ConfigProviderInterface $config,
  38. Json $json,
  39. array $data = []
  40. ) {
  41. parent::__construct($context, $data);
  42. $this->config = $config;
  43. $this->json = $json;
  44. }
  45. /**
  46. * Retrieves the config that should be used by the block
  47. *
  48. * @return string
  49. * @since 100.3.0
  50. */
  51. public function getPaymentConfig(): string
  52. {
  53. $payment = $this->config->getConfig()['payment'];
  54. $config = $payment[$this->getMethodCode()];
  55. $config['code'] = $this->getMethodCode();
  56. return $this->json->serialize($config);
  57. }
  58. /**
  59. * Returns the method code for this payment method
  60. *
  61. * @return string
  62. * @since 100.3.0
  63. */
  64. public function getMethodCode(): string
  65. {
  66. return Config::METHOD;
  67. }
  68. }