CRM-16737 4.7 version, only payment_status_id accepted as return parameter from payme...
authorEileen McNaughton <eileen@fuzion.co.nz>
Fri, 10 Jul 2015 08:25:39 +0000 (20:25 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Fri, 10 Jul 2015 08:32:07 +0000 (20:32 +1200)
CRM/Contribute/Form/Contribution.php
CRM/Core/Payment.php
CRM/Member/BAO/Membership.php
CRM/Member/Form/Membership.php
tests/phpunit/api/v3/ContributionPageTest.php

index bf323fc4b92f013952c9d36e66c4c9939727be88..916faa93075ac6e11b32e0cd2ae852131016a16f 100644 (file)
@@ -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 {
index 5641b102a2478f9622f9de9688d06017a16f2d67..12cb1e904889980f04b03043c0d422e835e2bd39 100644 (file)
@@ -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);
         }
       }
     }
index 9c67bf3f054cbf36c8c161c18be7862544143724..bc4b216bdaee5d068c9ef4e720dc8bd454d37c88 100644 (file)
@@ -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,
index 6a32c25918daa7778acf27782fb42fe87478a821..4eacaa0b770f3dde8c5a68ae7934b248d5e89aa4 100644 (file)
@@ -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
index 077a6fef7121fe5aab2f5174c612baeca8a2a72f..3206a83a2ae0bb7daf543fd2a09561cccd323823 100644 (file)
@@ -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(