From: Eileen McNaughton Date: Tue, 28 Jul 2015 21:21:50 +0000 (+1200) Subject: CRM-16926 complete recurring transactions when payment_status_id = 1, X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5569379ae9d5f26018935288462e9cd72cc12d3a;p=civicrm-core.git CRM-16926 complete recurring transactions when payment_status_id = 1, carefully to grandfather in --- diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 174e122181..8b390fab83 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -345,9 +345,24 @@ class CRM_Contribute_BAO_Contribution_Utils { return $membershipResult; } - //Do not send an email if Recurring contribution is done via Direct Mode - //We will send email once the IPN is received. + // Email is done when the payment is completed (now or later) + // by completetransaction, rather than the form. + // We are moving towards it being done for all payment methods in completetransaction. if (!empty($paymentParams['is_recur']) && $form->_contributeMode == 'direct') { + if (CRM_Utils_Array::value('payment_status_id', $result) == 1) { + try { + civicrm_api3('contribution', 'completetransaction', array( + 'id' => $contribution->id, + 'trxn_id' => CRM_Utils_Array::value('trxn_id', $result), + 'is_transactional' => FALSE, + )); + } + catch (CiviCRM_API3_Exception $e) { + if ($e->getErrorCode() != 'contribution_completed') { + throw new CRM_Core_Exception('Failed to update contribution in database'); + } + } + } return TRUE; } diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index b19302837e..8d1df05359 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -423,19 +423,16 @@ function civicrm_api3_contribution_completetransaction(&$params) { if (!$contribution->id == $params['id']) { throw new API_Exception('A valid contribution ID is required', 'invalid_data'); } - try { - if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) { - throw new API_Exception('failed to load related objects'); - } - elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) { - throw new API_Exception(ts('Contribution already completed')); - } - $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id; - $params = _ipn_process_transaction($params, $contribution, $input, $ids); + + if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) { + throw new API_Exception('failed to load related objects'); } - catch(Exception $e) { - throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString()); + elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) { + throw new API_Exception(ts('Contribution already completed'), 'contribution_completed'); } + $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id; + $params = _ipn_process_transaction($params, $contribution, $input, $ids); + } /**