From: eileenmcnaugton Date: Wed, 26 Aug 2015 08:13:21 +0000 (+1200) Subject: CRM-11338 ensure fee_amount set from membership form & add test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=77623a96bd30cd82d855bfc14699bc17d44a407c;p=civicrm-core.git CRM-11338 ensure fee_amount set from membership form & add test --- diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 212f7593af..c6f8545be5 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2354,6 +2354,7 @@ WHERE civicrm_membership.is_test = 0"; $contributionSoftParams = CRM_Utils_Array::value('soft_credit', $params); $recordContribution = array( 'contact_id', + 'fee_amount', 'total_amount', 'receive_date', 'financial_type_id', diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 9cc6afff2e..c47f496c98 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1531,6 +1531,9 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { if (!empty($softParams) && empty($paymentParams['is_recur'])) { $membershipParams['soft_credit'] = $softParams; } + if (isset($result['fee_amount'])) { + $membershipParams['fee_amount'] = $result['fee_amount']; + } // This is required to trigger the recording of the membership contribution in the // CRM_Member_BAO_Membership::Create function. // @todo stop setting this & 'teach' the create function to respond to something diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index d6ba3dc80b..06748da47e 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -420,6 +420,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'record_contribution' => TRUE, 'trxn_id' => 777, 'contribution_status_id' => 1, + 'fee_amount' => .5, ); $form->_contactID = $this->_individualId; @@ -433,6 +434,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { )); $this->assertEquals($contribution['trxn_id'], 777); + $this->assertEquals(.5, $contribution['fee_amount']); $this->callAPISuccessGetCount('LineItem', array( 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 91862b1d85..ae19247929 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -584,7 +584,11 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $form = $this->getForm(); $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); - $processor->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'kettles boil water')); + $processor->setDoDirectPaymentResult(array( + 'payment_status_id' => 1, + 'trxn_id' => 'kettles boil water', + 'fee_amount' => .14, + )); $this->callAPISuccess('MembershipType', 'create', array( 'id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', @@ -600,11 +604,14 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); - $contribution = $this->callAPISuccess('Contribution', 'get', array( + $contribution = $this->callAPISuccess('Contribution', 'getsingle', array( 'contact_id' => $this->_individualId, 'is_test' => TRUE, )); + $this->assertEquals(.14, $contribution['fee_amount']); + $this->assertEquals('kettles boil water', $contribution['trxn_id']); + $this->callAPISuccessGetCount('LineItem', array( 'entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership',