1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Controller\Billing;
use Magento\Framework\App\RequestInterface;
/**
* Billing agreements controller
*/
abstract class Agreement extends \Magento\Framework\App\Action\Action
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry
) {
$this->_coreRegistry = $coreRegistry;
parent::__construct($context);
}
/**
* Check customer authentication
*
* @param RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
*/
public function dispatch(RequestInterface $request)
{
if (!$request->isDispatched()) {
return parent::dispatch($request);
}
if (!$this->_getSession()->authenticate()) {
$this->_actionFlag->set('', 'no-dispatch', true);
}
return parent::dispatch($request);
}
/**
* Init billing agreement model from request
*
* @return \Magento\Paypal\Model\Billing\Agreement|false
*/
protected function _initAgreement()
{
$agreementId = $this->getRequest()->getParam('agreement');
if ($agreementId) {
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
$billingAgreement = $this->_objectManager->create(\Magento\Paypal\Model\Billing\Agreement::class)
->load($agreementId);
$currentCustomerId = $this->_getSession()->getCustomerId();
$agreementCustomerId = $billingAgreement->getCustomerId();
if ($billingAgreement->getId() && $agreementCustomerId == $currentCustomerId) {
$this->_coreRegistry->register('current_billing_agreement', $billingAgreement);
return $billingAgreement;
}
}
$this->messageManager->addErrorMessage(
__('Please specify the correct billing agreement ID and try again.')
);
$this->_redirect('*/*/');
return false;
}
/**
* Retrieve customer session model
*
* @return \Magento\Customer\Model\Session
*/
protected function _getSession()
{
return $this->_objectManager->get(\Magento\Customer\Model\Session::class);
}
}