CheckmoConfigProvider.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\OfflinePayments\Model;
  7. use Magento\Checkout\Model\ConfigProviderInterface;
  8. use Magento\Framework\Escaper;
  9. use Magento\Payment\Helper\Data as PaymentHelper;
  10. class CheckmoConfigProvider implements ConfigProviderInterface
  11. {
  12. /**
  13. * @var string[]
  14. */
  15. protected $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
  16. /**
  17. * @var Checkmo
  18. */
  19. protected $method;
  20. /**
  21. * @var Escaper
  22. */
  23. protected $escaper;
  24. /**
  25. * @param PaymentHelper $paymentHelper
  26. * @param Escaper $escaper
  27. */
  28. public function __construct(
  29. PaymentHelper $paymentHelper,
  30. Escaper $escaper
  31. ) {
  32. $this->escaper = $escaper;
  33. $this->method = $paymentHelper->getMethodInstance($this->methodCode);
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getConfig()
  39. {
  40. return $this->method->isAvailable() ? [
  41. 'payment' => [
  42. 'checkmo' => [
  43. 'mailingAddress' => $this->getMailingAddress(),
  44. 'payableTo' => $this->getPayableTo(),
  45. ],
  46. ],
  47. ] : [];
  48. }
  49. /**
  50. * Get mailing address from config
  51. *
  52. * @return string
  53. */
  54. protected function getMailingAddress()
  55. {
  56. return nl2br($this->escaper->escapeHtml($this->method->getMailingAddress()));
  57. }
  58. /**
  59. * Get payable to from config
  60. *
  61. * @return string
  62. */
  63. protected function getPayableTo()
  64. {
  65. return $this->method->getPayableTo();
  66. }
  67. }