Payment.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Block;
  7. use Magento\Braintree\Model\Ui\ConfigProvider;
  8. use Magento\Checkout\Model\ConfigProviderInterface;
  9. use Magento\Framework\View\Element\Template;
  10. use Magento\Framework\View\Element\Template\Context;
  11. /**
  12. * Class Payment
  13. *
  14. * @api
  15. * @since 100.1.0
  16. */
  17. class Payment extends Template
  18. {
  19. /**
  20. * @var ConfigProviderInterface
  21. */
  22. private $config;
  23. /**
  24. * Constructor
  25. *
  26. * @param Context $context
  27. * @param ConfigProviderInterface $config
  28. * @param array $data
  29. */
  30. public function __construct(
  31. Context $context,
  32. ConfigProviderInterface $config,
  33. array $data = []
  34. ) {
  35. parent::__construct($context, $data);
  36. $this->config = $config;
  37. }
  38. /**
  39. * @return string
  40. * @since 100.1.0
  41. */
  42. public function getPaymentConfig()
  43. {
  44. $payment = $this->config->getConfig()['payment'];
  45. $config = $payment[$this->getCode()];
  46. $config['code'] = $this->getCode();
  47. $config['clientTokenUrl'] = $this->_urlBuilder->getUrl(
  48. 'braintree/payment/getClientToken',
  49. ['_secure' => true]
  50. );
  51. return json_encode($config, JSON_UNESCAPED_SLASHES);
  52. }
  53. /**
  54. * @return string
  55. * @since 100.1.0
  56. */
  57. public function getCode()
  58. {
  59. return ConfigProvider::CODE;
  60. }
  61. }