Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Paypal\Helper;
7 
13 use Magento\Paypal\Model\Billing\Agreement\MethodInterface as BillingAgreementMethodInterface;
14 
19 {
21  '<a target="_blank" href="https://www%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
22 
28  protected static $_shouldAskToCreateBillingAgreement = null;
29 
33  protected $_paymentData;
34 
38  protected $_agreementFactory;
39 
43  private $methodCodes;
44 
48  private $configFactory;
49 
53  private $paymentMethodList;
54 
58  private $paymentMethodInstanceFactory;
59 
67  public function __construct(
68  \Magento\Framework\App\Helper\Context $context,
69  \Magento\Payment\Helper\Data $paymentData,
70  \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory,
71  \Magento\Paypal\Model\ConfigFactory $configFactory,
72  array $methodCodes
73  ) {
74  $this->_paymentData = $paymentData;
75  $this->_agreementFactory = $agreementFactory;
76  $this->methodCodes = $methodCodes;
77  $this->configFactory = $configFactory;
78  parent::__construct($context);
79  }
80 
89  {
90  if (null === self::$_shouldAskToCreateBillingAgreement) {
91  self::$_shouldAskToCreateBillingAgreement = false;
92  if ($customerId && $config->shouldAskToCreateBillingAgreement()) {
93  if ($this->_agreementFactory->create()->needToCreateForCustomer($customerId)) {
94  self::$_shouldAskToCreateBillingAgreement = true;
95  }
96  }
97  }
98  return self::$_shouldAskToCreateBillingAgreement;
99  }
100 
108  public function getBillingAgreementMethods($store = null, $quote = null)
109  {
110  $activeMethods = array_map(
111  function (PaymentMethodInterface $method) {
112  return $this->getPaymentMethodInstanceFactory()->create($method);
113  },
114  $this->getPaymentMethodList()->getActiveList($store)
115  );
116 
117  $result = array_filter(
118  $activeMethods,
119  function (MethodInterface $method) use ($quote) {
120  return $method instanceof BillingAgreementMethodInterface && $method->isAvailable($quote);
121  }
122  );
123 
124  return $result;
125  }
126 
134  public function getHtmlTransactionId($methodCode, $txnId)
135  {
136  if (in_array($methodCode, $this->methodCodes)) {
138  $config = $this->configFactory->create()->setMethod($methodCode);
139  $sandboxFlag = ($config->getValue('sandboxFlag') ? '.sandbox' : '');
140  return sprintf(self::HTML_TRANSACTION_ID, $sandboxFlag, $txnId);
141  }
142  return $txnId;
143  }
144 
151  private function getPaymentMethodList()
152  {
153  if ($this->paymentMethodList === null) {
154  $this->paymentMethodList = ObjectManager::getInstance()->get(
155  PaymentMethodListInterface::class
156  );
157  }
158  return $this->paymentMethodList;
159  }
160 
167  private function getPaymentMethodInstanceFactory()
168  {
169  if ($this->paymentMethodInstanceFactory === null) {
170  $this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
171  InstanceFactory::class
172  );
173  }
174  return $this->paymentMethodInstanceFactory;
175  }
176 }
getBillingAgreementMethods($store=null, $quote=null)
Definition: Data.php:108
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Payment\Helper\Data $paymentData, \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory, \Magento\Paypal\Model\ConfigFactory $configFactory, array $methodCodes)
Definition: Data.php:67
getPaymentMethodList($sorted=true, $asLabelValue=false, $withGroups=false, $store=null)
Definition: Data.php:255
$config
Definition: fraud_order.php:17
$quote
static $_shouldAskToCreateBillingAgreement
Definition: Data.php:28
shouldAskToCreateBillingAgreement(\Magento\Paypal\Model\Config $config, $customerId)
Definition: Data.php:88
$method
Definition: info.phtml:13
$configFactory
Definition: config_data.php:43