CRM-16523 towards fixing test issues on this
authoreileenmcnaugton <eileen@fuzion.co.nz>
Tue, 4 Aug 2015 05:27:02 +0000 (17:27 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Tue, 4 Aug 2015 05:30:30 +0000 (17:30 +1200)
CRM/Contribute/Form/Contribution/Confirm.php
tests/phpunit/api/v3/ContributionPageTest.php

index 23e4bc5e30ed8f773e2fc6c64435cd80096133cc..19c7217eeea6e57f357045774ec8c34fb6de62f8 100644 (file)
@@ -1694,23 +1694,23 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
         $form->postProcessHook();
       }
       $payment = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor);
-      $result = $payment->doPayment($form->_params, 'contribute');
+      $paymentActionResult = $payment->doPayment($form->_params, 'contribute');
 
-      if (CRM_Utils_Array::value('payment_status_id', $result) == 1) {
+      if (CRM_Utils_Array::value('payment_status_id', $paymentActionResult) == 1) {
         // Refer to CRM-16737. Payment processors 'should' return payment_status_id
         // to denote the outcome of the transaction.
         try {
           civicrm_api3('contribution', 'completetransaction', array(
             'id' => $paymentResult['contribution']->id,
-            'trxn_id' => $paymentResult['contribution']->trxn_id,
+            'trxn_id' => CRM_Utils_Array::value('trxn_id', $paymentActionResult, $paymentResult['contribution']->trxn_id),
             'is_transactional' => FALSE,
             'payment_processor_id' => $form->_paymentProcessor['id'],
           ));
         }
         catch (CiviCRM_API3_Exception $e) {
-          // if for any reason it is already completed this will fail - e.g extensions hacking around core not completing transactions prior to CRM-15296
-          // so let's be gentle here
-          CRM_Core_Error::debug_log_message('contribution ' . $membershipContribution->id . ' not completed with trxn_id ' . $membershipContribution->trxn_id . ' and message ' . $e->getMessage());
+          if ($e->getErrorCode() != 'contribution_completed') {
+            throw new CRM_Core_Exception('Failed to update contribution in database');
+          }
         }
       }
       // Do not send an email if Recurring transaction is done via Direct Mode
index ee77343408d91faf6e9885629683cbaa21dd63b4..748171755591f2b691bb2c2e80cc23f609622a96 100644 (file)
@@ -369,6 +369,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'contribution_page_id' => $this->_ids['contribution_page'],
       'contribution_status_id' => 1,
     ));
+
+    $this->assertEquals('create_first_success', $contribution['trxn_id']);
     $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
     $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
     $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));