From: Eileen McNaughton Date: Wed, 24 Jun 2015 13:05:28 +0000 (+1200) Subject: CRM-16417 tests passing on not deleting failed transaction from contribution page, X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2e59ea4870e1ea33b6e51724b0519e299717e171;p=civicrm-core.git CRM-16417 tests passing on not deleting failed transaction from contribution page, also towards CRM-16737 & the general principle of 2-step payment creating --- diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index ddf23e8f8e..f0c89a2fec 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -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') { diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 16a2dd912a..b6db40298a 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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) {