From 0739d6cfa7abcacf9918c2925e3c2b15b42034ba Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Tue, 4 Aug 2015 17:27:02 +1200 Subject: [PATCH] CRM-16523 towards fixing test issues on this --- CRM/Contribute/Form/Contribution/Confirm.php | 12 ++++++------ tests/phpunit/api/v3/ContributionPageTest.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 23e4bc5e30..19c7217eee 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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 diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index ee77343408..7481717555 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -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'])); -- 2.25.1