Exemplo n.º 1
0
 /**
  * Update billing agreement status
  *
  * @param \Magento\Paypal\Model\Billing\AbstractAgreement $agreement
  * @return $this
  * @throws \Exception|\Magento\Framework\Model\Exception
  */
 public function updateBillingAgreementStatus(\Magento\Paypal\Model\Billing\AbstractAgreement $agreement)
 {
     $targetStatus = $agreement->getStatus();
     $api = $this->_pro->getApi()->setReferenceId($agreement->getReferenceId())->setBillingAgreementStatus($targetStatus);
     try {
         $api->callUpdateBillingAgreement();
     } catch (\Magento\Framework\Model\Exception $e) {
         // when BA was already canceled, just pretend that the operation succeeded
         if (!(\Magento\Paypal\Model\Billing\Agreement::STATUS_CANCELED == $targetStatus && $api->getIsBillingAgreementAlreadyCancelled())) {
             throw $e;
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Validate data
  *
  * @return bool
  */
 public function isValid()
 {
     $result = parent::isValid();
     if (!$this->getCustomerId()) {
         $this->_errors[] = __('The customer ID is not set.');
     }
     if (!$this->getStatus()) {
         $this->_errors[] = __('The Billing Agreement status is not set.');
     }
     return $result && empty($this->_errors);
 }