_checkoutSession = $checkoutSession; $this->_customerSession = $customerSession; $this->_agreementFactory = $agreementFactory; parent::__construct($context, $data); } /** * Return billing agreement information * * @return string */ protected function _toHtml() { $agreementReferenceId = $this->_checkoutSession->getLastBillingAgreementReferenceId(); $customerId = $this->_customerSession->getCustomerId(); if (!$agreementReferenceId || !$customerId) { return ''; } $agreement = $this->_agreementFactory->create()->load($agreementReferenceId, 'reference_id'); if ($agreement->getId() && $customerId == $agreement->getCustomerId()) { $this->addData( [ 'agreement_ref_id' => $agreement->getReferenceId(), 'agreement_url' => $this->getUrl( 'paypal/billing_agreement/view', ['agreement' => $agreement->getId()] ), ] ); return parent::_toHtml(); } return ''; } }