CRM-16926 backoffice version of respecting payment_status_id
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 29 Jul 2015 02:48:58 +0000 (14:48 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 30 Jul 2015 00:28:12 +0000 (12:28 +1200)
Conflicts:
CRM/Contribute/Form/Contribution.php

CRM/Contribute/Form/Contribution.php

index c86eb49f041fa550365cc271d78bd75a3fd4696c..9962143750ea8c6541c9baba3f16bb655c0f9410 100644 (file)
@@ -1242,11 +1242,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
          * = error or success, unless it is a recurring contribution in which case it is pending.
          */
         if ($result['payment_status_id'] == array_search('Completed', $statuses)) {
-          civicrm_api3('contribution', 'completetransaction', array(
-            'id' => $contribution->id,
-            'trxn_id' => $result['trxn_id'],
-            'payment_processor_id' => $this->_paymentProcessor['id'],
-          ));
+          try {
+            civicrm_api3('contribution', 'completetransaction', array(
+              'id' => $contribution->id,
+              'trxn_id' => $result['trxn_id'],
+              'payment_processor_id' => $this->_paymentProcessor['id'],
+              'is_transactional' => FALSE,
+            ));
+            // This has now been set to 1 in the DB - declare it here also
+            $contribution->contribution_status_id = 1;
+          }
+          catch (CiviCRM_API3_Exception $e) {
+            if ($e->getErrorCode() != 'contribution_completed') {
+              throw new CRM_Core_Exception('Failed to update contribution in database');
+            }
+          }
         }
         else {
           // Save the trxn_id.