Config.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Gateway\Config\PayPal;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Payment\Model\CcConfig;
  9. /**
  10. * Class Config
  11. */
  12. class Config extends \Magento\Payment\Gateway\Config\Config
  13. {
  14. const KEY_ACTIVE = 'active';
  15. const KEY_TITLE = 'title';
  16. const KEY_DISPLAY_ON_SHOPPING_CART = 'display_on_shopping_cart';
  17. const KEY_ALLOW_TO_EDIT_SHIPPING_ADDRESS = 'allow_shipping_address_override';
  18. const KEY_MERCHANT_NAME_OVERRIDE = 'merchant_name_override';
  19. const KEY_REQUIRE_BILLING_ADDRESS = 'require_billing_address';
  20. /**
  21. * @var CcConfig
  22. */
  23. private $ccConfig;
  24. /**
  25. * @var array
  26. */
  27. private $icon = [];
  28. /**
  29. * Initialize dependencies.
  30. *
  31. * @param ScopeConfigInterface $scopeConfig
  32. * @param CcConfig $ccConfig
  33. * @param null $methodCode
  34. * @param string $pathPattern
  35. */
  36. public function __construct(
  37. ScopeConfigInterface $scopeConfig,
  38. CcConfig $ccConfig,
  39. $methodCode = null,
  40. $pathPattern = self::DEFAULT_PATH_PATTERN
  41. ) {
  42. parent::__construct($scopeConfig, $methodCode, $pathPattern);
  43. $this->ccConfig = $ccConfig;
  44. }
  45. /**
  46. * Get Payment configuration status
  47. *
  48. * @return bool
  49. */
  50. public function isActive()
  51. {
  52. return (bool) $this->getValue(self::KEY_ACTIVE);
  53. }
  54. /**
  55. * @return bool
  56. */
  57. public function isDisplayShoppingCart()
  58. {
  59. return (bool) $this->getValue(self::KEY_DISPLAY_ON_SHOPPING_CART);
  60. }
  61. /**
  62. * Is shipping address can be editable on PayPal side
  63. *
  64. * @return bool
  65. */
  66. public function isAllowToEditShippingAddress()
  67. {
  68. return (bool) $this->getValue(self::KEY_ALLOW_TO_EDIT_SHIPPING_ADDRESS);
  69. }
  70. /**
  71. * Get merchant name to display in PayPal popup
  72. *
  73. * @return string
  74. */
  75. public function getMerchantName()
  76. {
  77. return $this->getValue(self::KEY_MERCHANT_NAME_OVERRIDE);
  78. }
  79. /**
  80. * Is billing address can be required
  81. *
  82. * @return string
  83. */
  84. public function isRequiredBillingAddress()
  85. {
  86. return $this->getValue(self::KEY_REQUIRE_BILLING_ADDRESS);
  87. }
  88. /**
  89. * Get title of payment
  90. *
  91. * @return string
  92. */
  93. public function getTitle()
  94. {
  95. return $this->getValue(self::KEY_TITLE);
  96. }
  97. /**
  98. * Is need to skip order review
  99. * @return bool
  100. */
  101. public function isSkipOrderReview()
  102. {
  103. return (bool) $this->getValue('skip_order_review');
  104. }
  105. /**
  106. * Get PayPal icon
  107. * @return array
  108. */
  109. public function getPayPalIcon()
  110. {
  111. if (empty($this->icon)) {
  112. $asset = $this->ccConfig->createAsset('Magento_Braintree::images/paypal.png');
  113. list($width, $height) = getimagesize($asset->getSourceFile());
  114. $this->icon = [
  115. 'url' => $asset->getUrl(),
  116. 'width' => $width,
  117. 'height' => $height
  118. ];
  119. }
  120. return $this->icon;
  121. }
  122. }