/** * Update billing agreement status * * @param Mage_Payment_Model_Billing_AgreementAbstract $agreement * @throws Exception|Mage_Core_Exception * @return Mage_Paypal_Model_Method_Agreement */ public function updateBillingAgreementStatus(Mage_Payment_Model_Billing_AgreementAbstract $agreement) { $targetStatus = $agreement->getStatus(); if (Mage_Sales_Model_Billing_Agreement::STATUS_CANCELED == $targetStatus) { $targetStatus = self::STATUS_CANCELED; } $api = $this->_pro->getApi()->setBillingAgreementId($agreement->getReferenceId())->setBillingAgreementStatus($targetStatus); try { $api->callUpdateBillingAgreement(); } catch (Mage_Core_Exception $e) { // when BA was already canceled, just pretend that the operation succeeded if (!(self::STATUS_CANCELED == $targetStatus && $api->getIsBillingAgreementAlreadyCancelled())) { throw $e; } } return $this; }
/** * Update billing agreement status * * @param Adyen_Payment_Model_Billing_Agreement|Mage_Payment_Model_Billing_AgreementAbstract $agreement * * @return $this * @throws Exception * @throws Mage_Core_Exception */ public function updateBillingAgreementStatus(Mage_Payment_Model_Billing_AgreementAbstract $agreement) { Mage::dispatchEvent('adyen_payment_update_billing_agreement_status', array('agreement' => $agreement)); $targetStatus = $agreement->getStatus(); $adyenHelper = Mage::helper('adyen'); if ($targetStatus == Mage_Sales_Model_Billing_Agreement::STATUS_CANCELED) { try { $this->_api()->disableRecurringContract($agreement->getReferenceId(), $agreement->getCustomerReference(), $agreement->getStoreId()); } catch (Adyen_Payment_Exception $e) { Mage::throwException($adyenHelper->__("Error while disabling Billing Agreement #%s: %s", $agreement->getReferenceId(), $e->getMessage())); } } else { throw new Exception(Mage::helper('adyen')->__('Changing billing agreement status to "%s" not yet implemented.', $targetStatus)); } return $this; }