3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Event_BAO_AdditionalPaymentTest
32 class CRM_Event_BAO_AdditionalPaymentTest
extends CiviUnitTestCase
{
34 public function setUp() {
36 $this->_contactId
= $this->individualCreate();
37 $event = $this->eventCreate();
38 $this->_eventId
= $event['id'];
41 public function tearDown() {
42 $this->eventDelete($this->_eventId
);
46 'civicrm_contribution',
47 'civicrm_participant',
48 'civicrm_participant_payment',
50 'civicrm_financial_item',
51 'civicrm_financial_trxn',
53 'civicrm_entity_financial_trxn',
60 * Helper function to record participant with paid contribution.
62 * @param int $feeTotal
63 * @param int $actualPaidAmt
68 protected function addParticipantWithPayment($feeTotal, $actualPaidAmt) {
69 $priceSetId = $this->eventPriceSetCreate($feeTotal);
70 CRM_Price_BAO_PriceSet
::addTo('civicrm_event', $this->_eventId
, $priceSetId);
72 // create participant record
73 $eventId = $this->_eventId
;
74 $participantParams = array(
78 'event_id' => $eventId,
79 'register_date' => date('Y-m-d') . " 00:00:00",
82 'source' => 'Event_' . $eventId,
83 'contact_id' => $this->_contactId
,
84 'note' => 'Note added for Event_' . $eventId,
85 'fee_level' => '\ 1Price_Field - 55\ 1',
87 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
88 $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
89 // create participant contribution with partial payment
90 $contributionParams = array(
91 'total_amount' => $actualPaidAmt,
92 'source' => 'Fall Fundraiser Dinner: Offline registration',
94 'non_deductible_amount' => 'null',
95 'receipt_date' => date('Y-m-d') . " 00:00:00",
96 'contact_id' => $this->_contactId
,
97 'financial_type_id' => 4,
98 'payment_instrument_id' => 4,
99 'contribution_status_id' => 1,
100 'receive_date' => date('Y-m-d') . " 00:00:00",
102 'partial_payment_total' => $feeTotal,
103 'partial_amount_to_pay' => $actualPaidAmt,
106 $contribution = CRM_Contribute_BAO_Contribution
::create($contributionParams);
107 $contributionId = $contribution->id
;
108 $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
110 // add participant payment entry
111 $this->callAPISuccess('participant_payment', 'create', array(
112 'participant_id' => $participant['id'],
113 'contribution_id' => $contributionId,
116 // -- processing priceSet using the BAO
118 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, FALSE);
119 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
120 $feeBlock = CRM_Utils_Array
::value('fields', $priceSet);
121 $params['price_2'] = $feeTotal;
122 $tempParams = $params;
123 $templineItems = $lineItem;
124 CRM_Price_BAO_PriceSet
::processAmount($feeBlock,
127 $lineItemVal[$priceSetId] = $lineItem;
128 CRM_Price_BAO_LineItem
::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
131 'participant' => $participant,
132 'contribution' => $contribution,
133 'lineItem' => $templineItems,
134 'params' => $tempParams,
135 'feeBlock' => $feeBlock,
136 'priceSetId' => $priceSetId,
143 public function testAddPartialPayment() {
146 $balance = $feeAmt - $amtPaid;
147 $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
149 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($participant['id'], 'event');
152 $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper');
153 $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper');
154 $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper');
157 $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant');
158 $this->assertEquals($contribution->contribution_status_id
, 8, 'Status record is not proper for contribution');
162 * Test owed/refund info is listed on view payments.
164 public function testTransactionInfo() {
167 $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
170 //Complete the partial payment.
171 $submittedValues = array(
172 'total_amount' => 20,
173 'payment_instrument_id' => 3,
175 CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($contribution->id
, $submittedValues, 'owed', $participant['id']);
177 //Change selection to a lower amount.
178 $params['price_2'] = 50;
179 CRM_Event_BAO_Participant
::changeFeeSelections($params, $participant['id'], $contribution->id
, $feeBlock, $lineItem, $feeAmt, $priceSetId);
181 //Record a refund of the remaining amount.
182 $submittedValues['total_amount'] = 50;
183 CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($contribution->id
, $submittedValues, 'refund', $participant['id']);
184 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($participant['id'], 'event', TRUE);
185 $transaction = $paymentInfo['transaction'];
187 //Assert all transaction(owed and refund) are listed on view payments.
188 $this->assertEquals(count($transaction), 3, 'Transaction Details is not proper');
189 $this->assertEquals($transaction[0]['total_amount'], 80.00);
190 $this->assertEquals($transaction[0]['status'], 'Completed');
192 $this->assertEquals($transaction[1]['total_amount'], 20.00);
193 $this->assertEquals($transaction[1]['status'], 'Completed');
195 $this->assertEquals($transaction[2]['total_amount'], -50.00);
196 $this->assertEquals($transaction[2]['status'], 'Refunded');