Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BillingAgreement.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  protected $_checkoutSession;
20 
24  protected $_customerSession;
25 
29  protected $_agreementFactory;
30 
38  public function __construct(
39  \Magento\Framework\View\Element\Template\Context $context,
40  \Magento\Checkout\Model\Session $checkoutSession,
41  \Magento\Customer\Model\Session $customerSession,
42  \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory,
43  array $data = []
44  ) {
45  $this->_checkoutSession = $checkoutSession;
46  $this->_customerSession = $customerSession;
47  $this->_agreementFactory = $agreementFactory;
48  parent::__construct($context, $data);
49  }
50 
56  protected function _toHtml()
57  {
58  $agreementReferenceId = $this->_checkoutSession->getLastBillingAgreementReferenceId();
59  $customerId = $this->_customerSession->getCustomerId();
60  if (!$agreementReferenceId || !$customerId) {
61  return '';
62  }
63  $agreement = $this->_agreementFactory->create()->load($agreementReferenceId, 'reference_id');
64  if ($agreement->getId() && $customerId == $agreement->getCustomerId()) {
65  $this->addData(
66  [
67  'agreement_ref_id' => $agreement->getReferenceId(),
68  'agreement_url' => $this->getUrl(
69  'paypal/billing_agreement/view',
70  ['agreement' => $agreement->getId()]
71  ),
72  ]
73  );
74  return parent::_toHtml();
75  }
76  return '';
77  }
78 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory, array $data=[])