示例#1
0
/**
 * Cancel a recurring contribution of existing ContributionRecur given its id.
 *
 * @param array $params
 *   Array containing id of the recurring contribution.
 *
 * @return bool
 *   returns true is successfully cancelled
 */
function civicrm_api3_contribution_recur_cancel($params)
{
    civicrm_api3_verify_one_mandatory($params, NULL, array('id'));
    return CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution($params['id'], CRM_Core_DAO::$_nullObject) ? civicrm_api3_create_success() : civicrm_api3_create_error(ts('Error while cancelling recurring contribution'));
}
示例#2
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $status = $message = NULL;
     $cancelSubscription = TRUE;
     $params = $this->controller->exportValues($this->_name);
     if ($this->_selfService) {
         // for self service force sending-request & notify
         if ($this->_paymentProcessorObj->isSupported('cancelSubscription')) {
             $params['send_cancel_request'] = 1;
         }
         if ($this->_donorEmail) {
             $params['is_notify'] = 1;
         }
     }
     if (CRM_Utils_Array::value('send_cancel_request', $params) == 1) {
         $cancelParams = array('subscriptionId' => $this->_subscriptionDetails->subscription_id);
         $cancelSubscription = $this->_paymentProcessorObj->cancelSubscription($message, $cancelParams);
     }
     if (is_a($cancelSubscription, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($cancelSubscription);
     } elseif ($cancelSubscription) {
         $activityParams = array('subject' => $this->_mid ? ts('Auto-renewal membership cancelled') : ts('Recurring contribution cancelled'), 'details' => $message);
         $cancelStatus = CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution($this->_subscriptionDetails->recur_id, CRM_Core_DAO::$_nullObject, $activityParams);
         if ($cancelStatus) {
             $tplParams = array();
             if ($this->_mid) {
                 $inputParams = array('id' => $this->_mid);
                 CRM_Member_BAO_Membership::getValues($inputParams, $tplParams);
                 $tplParams = $tplParams[$this->_mid];
                 $tplParams['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $tplParams['status_id']);
                 $tplParams['membershipType'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $tplParams['membership_type_id']);
                 $status = ts('The automatic renewal of your %1 membership has been cancelled as requested. This does not affect the status of your membership - you will receive a separate notification when your membership is up for renewal.', array(1 => $tplParams['membershipType']));
                 $msgTitle = 'Membership Renewal Cancelled';
                 $msgType = 'info';
             } else {
                 $tplParams['recur_frequency_interval'] = $this->_subscriptionDetails->frequency_interval;
                 $tplParams['recur_frequency_unit'] = $this->_subscriptionDetails->frequency_unit;
                 $tplParams['amount'] = $this->_subscriptionDetails->amount;
                 $tplParams['contact'] = array('display_name' => $this->_donorDisplayName);
                 $status = ts('The recurring contribution of %1, every %2 %3 has been cancelled.', array(1 => $this->_subscriptionDetails->amount, 2 => $this->_subscriptionDetails->frequency_interval, 3 => $this->_subscriptionDetails->frequency_unit));
                 $msgTitle = 'Contribution Cancelled';
                 $msgType = 'success';
             }
             if (CRM_Utils_Array::value('is_notify', $params) == 1) {
                 if ($this->_subscriptionDetails->contribution_page_id) {
                     CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $this->_subscriptionDetails->contribution_page_id, $value, array('title', 'receipt_from_name', 'receipt_from_email'));
                     $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
                 } else {
                     $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
                     $receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>";
                 }
                 // send notification
                 $sendTemplateParams = array('groupName' => $this->_mode == 'auto_renew' ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled', 'contactId' => $this->_subscriptionDetails->contact_id, 'tplParams' => $tplParams, 'PDFFilename' => 'receipt.pdf', 'from' => $receiptFrom, 'toName' => $this->_donorDisplayName, 'toEmail' => $this->_donorEmail);
                 list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             }
         } else {
             $msgType = 'error';
             $msgTitle = ts('Error');
             if ($params['send_cancel_request'] == 1) {
                 $status = ts('Recurring contribution was cancelled successfully by the processor, but could not be marked as cancelled in the database.');
             } else {
                 $status = ts('Recurring contribution could not be cancelled in the database.');
             }
         }
     } else {
         $status = ts('The recurring contribution could not be cancelled.');
         $msgTitle = 'Error Cancelling Contribution';
         $msgType = 'error';
     }
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if ($userID && $status) {
         $session->setStatus($status, $msgTitle, $msgType);
     } elseif (!$userID) {
         if ($status) {
             CRM_Utils_System::setUFMessage($status);
         }
         // keep result as 1, since we not displaying anything on the redirected page anyway
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=cancel&result=1"));
     }
 }
 /**
  * Test cancellation works per CRM-14986.
  *
  * We are checking for absence of error.
  */
 public function testCancelRecur()
 {
     $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params);
     CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution($contributionRecur['id'], CRM_Core_DAO::$_nullObject);
 }
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     $status = null;
     $this->_paymentObject->_setParam('subscriptionId', $this->_subscriptionId);
     $cancelSubscription = $this->_paymentObject->cancelSubscription();
     if (is_a($cancelSubscription, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($cancelSubscription);
     } else {
         if ($cancelSubscription) {
             $status = ts('The auto-renewal option for your membership has been successfully cancelled. Your membership has not been cancelled. However you will need to arrange payment for renewal when your membership expires.');
             require_once 'CRM/Contribute/BAO/ContributionRecur.php';
             $cancelled = CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution($this->_contributionRecurId, $this->_objects);
         } else {
             $status = ts('Auto renew could not be cancelled.');
         }
     }
     if ($status) {
         $session = CRM_Core_Session::singleton();
         if ($session->get('userID')) {
             CRM_Core_Session::setStatus($status);
         } else {
             if (function_exists('drupal_set_message')) {
                 drupal_set_message($status);
             }
         }
     }
 }