ChannelDataBuilder.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Gateway\Request;
  7. use Magento\Framework\App\ObjectManager;
  8. use Magento\Framework\App\ProductMetadataInterface;
  9. use Magento\Payment\Gateway\Config\Config;
  10. use Magento\Payment\Gateway\Request\BuilderInterface;
  11. /**
  12. * Class BnCodeDataBuilder
  13. */
  14. class ChannelDataBuilder implements BuilderInterface
  15. {
  16. /**
  17. * @var string
  18. */
  19. private static $channel = 'channel';
  20. /**
  21. * @var string
  22. */
  23. private static $channelValue = 'Magento2_Cart_%s_BT';
  24. /**
  25. * @var ProductMetadataInterface
  26. */
  27. private $productMetadata;
  28. /**
  29. * @var Config
  30. */
  31. private $config;
  32. /**
  33. * Constructor
  34. *
  35. * @param ProductMetadataInterface $productMetadata
  36. * @param Config $config
  37. */
  38. public function __construct(ProductMetadataInterface $productMetadata, Config $config = null)
  39. {
  40. $this->productMetadata = $productMetadata;
  41. $this->config = $config ?: ObjectManager::getInstance()->get(Config::class);
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function build(array $buildSubject)
  47. {
  48. $channel = $this->config->getValue('channel');
  49. return [
  50. self::$channel => $channel ?: sprintf(self::$channelValue, $this->productMetadata->getEdition())
  51. ];
  52. }
  53. }