CRM-11338 ensure fee_amount set from membership form & add test
authoreileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 08:13:21 +0000 (20:13 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 09:47:12 +0000 (21:47 +1200)
CRM/Member/BAO/Membership.php
CRM/Member/Form/Membership.php
tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
tests/phpunit/CRM/Member/Form/MembershipTest.php

index 212f7593af3779c8aa41b33d85f36db1ff6f1e1a..c6f8545be549dcf0dd0a69cab7a759be4bdc4c66 100644 (file)
@@ -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',
index 9cc6afff2e9de6d6b1c300f4f856eb132832c6aa..c47f496c98794995e126df070402d15545d07f91 100644 (file)
@@ -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
index d6ba3dc80be14bc4d3893c4981a47d87b41d22a4..06748da47e06fd8a092c862f58d3c45cfabe6d2e 100644 (file)
@@ -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',
index 91862b1d850794941cd5732c8cc7ee7bd2cbefe7..ae19247929756799f14688ebf5aa490a718489c7 100644 (file)
@@ -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',