CRM-16417 tests passing on not deleting failed transaction from contribution page,
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 24 Jun 2015 13:05:28 +0000 (01:05 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 24 Jun 2015 13:05:28 +0000 (01:05 +1200)
also towards CRM-16737 & the general principle of 2-step payment creating

CRM/Contribute/BAO/Contribution/Utils.php
CRM/Member/BAO/Membership.php

index ddf23e8f8e2fc1707d6c3b4726aadbed72297329..f0c89a2fecfa670f51cc4437087c0d314d786bdf 100644 (file)
@@ -144,8 +144,7 @@ class CRM_Contribute_BAO_Contribution_Utils {
         // add qfKey so we can send to paypal
         $form->_params['qfKey'] = $form->controller->_key;
         if ($component == 'membership') {
-          $membershipResult = array(1 => $contribution);
-          return $membershipResult;
+          return array('contribution' => $contribution);
         }
         else {
           if (!$isPayLater) {
@@ -265,20 +264,10 @@ class CRM_Contribute_BAO_Contribution_Utils {
           CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($paymentParams['contributionRecurID']);
         }
 
-        if ($component !== 'membership') {
-          // This is only called from contribution form.
-          // Not sure if there is any reason not to just throw an exception up to it.
-          $result['is_payment_failure'] = TRUE;
-          return $result;
-        }
-        $membershipResult[1] = $result;
+        $result['is_payment_failure'] = TRUE;
       }
     }
 
-    if ($component == 'membership') {
-      $membershipResult = array();
-    }
-
     if ($result || ($form->_amount == 0.0 && !$form->_params['is_pay_later'])) {
       if ($result) {
         $form->_params = array_merge($form->_params, $result);
@@ -297,13 +286,8 @@ class CRM_Contribute_BAO_Contribution_Utils {
       if (is_array($result) && !empty($result['trxn_id'])) {
         $contribution->trxn_id = $result['trxn_id'];
       }
-      $membershipResult[1] = $contribution;
+      $result['contribution'] = $contribution;
     }
-
-    if ($component == 'membership') {
-      return $membershipResult;
-    }
-
     //Do not send an email if Recurring contribution is done via Direct Mode
     //We will send email once the IPN is received.
     if ($form->_contributeMode == 'direct') {
index 16a2dd912a3ebf8016389f9147e8e3fbfb2607dd..b6db40298ad694ea53cf3a6d796ad14535c3fb2d 100644 (file)
@@ -1329,7 +1329,12 @@ AND civicrm_membership.is_test = %2";
     }
 
     if ($isPaidMembership) {
-      $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams,
+      if ($isProcessSeparateMembershipTransaction) {
+        // If we have 2 transactions only one can use the invoice id.
+        $membershipParams['invoiceID'] .= '-2';
+      }
+
+      $paymentResult = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams,
         $premiumParams, $contactID,
         $financialTypeID,
         'membership',
@@ -1340,12 +1345,16 @@ AND civicrm_membership.is_test = %2";
       if (is_a($result[1], 'CRM_Core_Error')) {
         $errors[1] = CRM_Core_Error::getMessages($result[1]);
       }
-      elseif (!empty($result[1])) {
+
+      if (is_a($paymentResult, 'CRM_Core_Error')) {
+        $errors[1] = CRM_Core_Error::getMessages($paymentResult);
+      }
+      elseif (!empty($paymentResult['contribution'])) {
+        //note that this will be over-written if we are using a separate membership transaction. Otherwise there is only one
+        $membershipContribution = $paymentResult['contribution'];
         // Save the contribution ID so that I can be used in email receipts
         // For example, if you need to generate a tax receipt for the donation only.
-        $form->_values['contribution_other_id'] = $result[1]->id;
-        //note that this will be over-written if we are using a separate membership transaction. Otherwise there is only one
-        $membershipContribution = $result[1];
+        $form->_values['contribution_other_id'] = $membershipContribution->id;
       }
     }
 
@@ -1438,14 +1447,13 @@ AND civicrm_membership.is_test = %2";
       $form->_values['contribution_id'] = $membershipContributionID;
     }
 
-    // Do not send an email if Recurring transaction is done via Direct Mode
-    // Email will we sent when the IPN is received.
-    if (!empty($form->_params['is_recur']) && $form->_contributeMode == 'direct') {
-      if (!empty($membershipContribution->trxn_id)) {
+    if ($form->_contributeMode == 'direct') {
+      if (CRM_Utils_Array::value('contribution_status_id', $paymentResult) == 1) {
         try {
           civicrm_api3('contribution', 'completetransaction', array(
-            'id' => $membershipContribution->id,
-            'trxn_id' => $membershipContribution->trxn_id,
+            'id' => $paymentResult['contribution']->id,
+            'trxn_id' => $paymentResult['contribution']->trxn_id,
+            'is_transactional' => FALSE,
           ));
         }
         catch (CiviCRM_API3_Exception $e) {