Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAgreement.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  protected $_paymentMethodInstance = null;
19 
25  protected $_errors = [];
26 
32  abstract public function initToken();
33 
39  abstract public function verifyToken();
40 
46  abstract public function place();
47 
53  abstract public function cancel();
54 
60  protected $_paymentData = null;
61 
70  public function __construct(
71  \Magento\Framework\Model\Context $context,
72  \Magento\Framework\Registry $registry,
73  \Magento\Payment\Helper\Data $paymentData,
74  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
75  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
76  array $data = []
77  ) {
78  $this->_paymentData = $paymentData;
79  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
80  }
81 
87  public function getPaymentMethodInstance()
88  {
89  if ($this->_paymentMethodInstance === null) {
90  $this->_paymentMethodInstance = $this->_paymentData->getMethodInstance($this->getMethodCode());
91  $this->_paymentMethodInstance->setStore($this->getStoreId());
92  }
94  }
95 
101  public function isValid()
102  {
103  $this->_errors = [];
104  if ($this->getPaymentMethodInstance() === null || !$this->getPaymentMethodInstance()->getCode()) {
105  $this->_errors[] = __('The payment method code is not set.');
106  }
107  if (!$this->getReferenceId()) {
108  $this->_errors[] = __('The reference ID is not set.');
109  }
110  return empty($this->_errors);
111  }
112 
119  public function beforeSave()
120  {
121  if ($this->isValid()) {
122  return parent::beforeSave();
123  }
124  array_unshift($this->_errors, __('Unable to save Billing Agreement:'));
125  throw new \Magento\Framework\Exception\LocalizedException(__(implode(' ', $this->_errors)));
126  }
127 }
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])