From: Eileen McNaughton Date: Fri, 10 Jul 2015 08:25:39 +0000 (+1200) Subject: CRM-16737 4.7 version, only payment_status_id accepted as return parameter from payme... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7c85dc65cf5d49b62ce1c1a36af2df1d945969d3;p=civicrm-core.git CRM-16737 4.7 version, only payment_status_id accepted as return parameter from payment processor --- diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index bf323fc4b9..916faa9307 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1025,7 +1025,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function processCreditCard($submittedValues, $lineItem, $contactID) { - $contribution = FALSE; $isTest = ($this->_mode == 'test') ? 1 : 0; // CRM-12680 set $_lineItem if its not set @@ -1226,12 +1225,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * with a delayed start) * 3) the payment succeeded with an immediate payment. * - * The doPayment function ensures that contribution_status_id is always set + * The doPayment function ensures that payment_status_id is always set * as historically we have had to guess from the context - ie doDirectPayment * = error or success, unless it is a recurring contribution in which case it is pending. */ - if (!isset($result['contribution_status_id']) || $result['contribution_status_id'] == - array_search('Completed', $statuses)) { + if ($result['payment_status_id'] == array_search('Completed', $statuses)) { civicrm_api3('contribution', 'completetransaction', array('id' => $contribution->id, 'trxn_id' => $result['trxn_id'])); } else { diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 5641b102a2..12cb1e9048 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -651,19 +651,19 @@ abstract class CRM_Core_Payment { $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'); if ($this->_paymentProcessor['billing_mode'] == 4) { $result = $this->doTransferCheckout($params, $component); - if (is_array($result) && !isset($result['contribution_status_id'])) { - $result['contribution_status_id'] = array_search('Pending', $statuses); + if (is_array($result) && !isset($result['payment_status_id'])) { + $result['payment_status_id'] = array_search('Pending', $statuses); } } else { $result = $this->doDirectPayment($params, $component); - if (is_array($result) && !isset($result['contribution_status_id'])) { + if (is_array($result) && !isset($result['payment_status_id'])) { if (!empty($params['is_recur'])) { // See comment block. - $paymentParams['contribution_status_id'] = array_search('Pending', $statuses); + $paymentParams['payment_status_id'] = array_search('Pending', $statuses); } else { - $result['contribution_status_id'] = array_search('Completed', $statuses); + $result['payment_status_id'] = array_search('Completed', $statuses); } } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 9c67bf3f05..bc4b216bda 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1307,15 +1307,10 @@ AND civicrm_membership.is_test = %2"; $form->_values['contribution_id'] = $membershipContributionID; } - // Refer to CRM-16737. Payment processors 'should' return payment_status_id - // to denote the outcome of the transaction. - // - // In 4.7 trxn_id will no longer denote the outcome & all processor transactions must return an array - // containing payment_status_id. - // In 4.6 support (such as there was) for other ways of denoting payment outcome is retained but the use - // of payment_status_id is strongly encouraged. - if (!empty($form->_params['is_recur']) && $form->_contributeMode == 'direct') { - if (!isset($membershipContribution->payment_status_id) && $membershipContribution->payment_status_id == 1) { + if ($form->_contributeMode == 'direct') { + if (CRM_Utils_Array::value('payment_status_id', $paymentResult) == 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, diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 6a32c25918..4eacaa0b77 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1557,11 +1557,10 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->assign('amount', $params['total_amount']); } - // if the payment processor returns a contribution_status_id -> use it! - if (isset($result['contribution_status_id'])) { - $params['contribution_status_id'] = $result['contribution_status_id']; - } - elseif (isset($result['payment_status_id'])) { + // if the payment processor returns a payment_status_id -we assume this + // applies to the whole contribution. + // At this stage this form is not processing separate payments. + if (isset($result['payment_status_id'])) { // CRM-16737 $result['contribution_status_id'] is deprecated in favour // of payment_status_id as the payment processor only knows whether the payment is complete // not whether payment completes the contribution diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 077a6fef71..3206a83a2a 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -301,10 +301,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment() { $this->params['is_recur'] = 1; - $var = array(); $this->params['recur_frequency_unit'] = 'month'; $this->setUpMembershipContributionPage(); - $dummyPP = CRM_Core_Payment::singleton('live', $this->_paymentProcessor); + $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); $submitParams = array(