72 \
Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory,
78 $this->_billingAgreementFactory = $billingAgreementFactory;
79 $this->_dateFactory = $dateFactory;
99 $date = $this->_dateFactory->create()->gmtDate();
100 if ($this->
isObjectNew() && !$this->getCreatedAt()) {
101 $this->setCreatedAt($date);
103 $this->setUpdatedAt($date);
105 return parent::beforeSave();
115 if (!empty($this->_relatedOrders)) {
118 return parent::afterSave();
128 switch ($this->getStatus()) {
132 return __(
'Canceled');
146 ->initBillingAgreementToken($this);
148 return $this->getRedirectUrl();
160 ->getBillingAgreementTokenInfo($this);
175 $paymentMethodInstance->placeBillingAgreement($this);
177 $this->setCustomerId($this->getCustomerId())
178 ->setMethodCode($this->getMethodCode())
179 ->setReferenceId($this->getBillingAgreementId())
180 ->setStatus(self::STATUS_ACTIVE)
181 ->setAgreementLabel($paymentMethodInstance->getTitle())
194 $this->setStatus(self::STATUS_CANCELED);
196 return $this->
save();
217 self::STATUS_ACTIVE =>
__(
'Active'),
218 self::STATUS_CANCELED =>
__(
'Canceled')
230 if (!$this->getCustomerId()) {
231 $this->_errors[] =
__(
'The customer ID is not set.');
233 if (!$this->getStatus()) {
234 $this->_errors[] =
__(
'The Billing Agreement status is not set.');
236 return $result && empty($this->_errors);
251 $baData =
$payment->getBillingAgreementData();
253 $this->_paymentMethodInstance = (isset($baData[
'method_code']))
254 ? $this->_paymentData->getMethodInstance($baData[
'method_code'])
257 $this->_paymentMethodInstance->setStore(
$payment->getMethodInstance()->getStore());
258 $this->setCustomerId(
$payment->getOrder()->getCustomerId())
259 ->setMethodCode($this->_paymentMethodInstance->getCode())
260 ->setReferenceId($baData[
'billing_agreement_id'])
261 ->setStatus(self::STATUS_ACTIVE)
262 ->setAgreementLabel($this->_paymentMethodInstance->getTitle());
275 $collection = $this->_billingAgreementFactory->create();
277 ->addFieldToFilter(
'status', self::STATUS_ACTIVE)
278 ->setOrder(
'agreement_id');
301 $this->_relatedOrders[] = $orderId;
312 foreach ($this->_relatedOrders as
$order) {
313 $orderId =
$order instanceof \Magento\Sales\Model\Order ?
$order->getId() : (int)
$order;
addOrderRelation($orderId)
getPaymentMethodInstance()
importOrderPayment(Payment $payment)
$_billingAgreementFactory
getAvailableCustomerBillingAgreements($customerId)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Payment\Helper\Data $paymentData, \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementFactory, \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
needToCreateForCustomer($customerId)