3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 'receipt_date' => date('Y-m-d') . " 00:00:00",
95 'contact_id' => $this->_contactId
,
96 'financial_type_id' => 4,
97 'payment_instrument_id' => 4,
98 'contribution_status_id' => 1,
99 'receive_date' => date('Y-m-d') . " 00:00:00",
101 'partial_payment_total' => $feeTotal,
102 'partial_amount_to_pay' => $actualPaidAmt,
105 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
106 $contributionId = $contribution['id'];
107 $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
109 // add participant payment entry
110 $this->callAPISuccess('participant_payment', 'create', array(
111 'participant_id' => $participant['id'],
112 'contribution_id' => $contributionId,
115 // -- processing priceSet using the BAO
117 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, FALSE);
118 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
119 $feeBlock = CRM_Utils_Array
::value('fields', $priceSet);
120 $params['price_2'] = $feeTotal;
121 $tempParams = $params;
122 $templineItems = $lineItem;
123 CRM_Price_BAO_PriceSet
::processAmount($feeBlock,
126 $lineItemVal[$priceSetId] = $lineItem;
127 CRM_Price_BAO_LineItem
::processPriceSet($participant['id'], $lineItemVal, $this->getContributionObject($contributionId), 'civicrm_participant');
130 'participant' => $participant,
131 'contribution' => $contribution['values'][$contribution['id']],
132 'lineItem' => $templineItems,
133 'params' => $tempParams,
134 'feeBlock' => $feeBlock,
135 'priceSetId' => $priceSetId,
142 public function testAddPartialPayment() {
145 $balance = $feeAmt - $amtPaid;
146 $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
148 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($participant['id'], 'event');
151 $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper');
152 $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper');
153 $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper');
156 $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant');
157 $this->assertEquals($result['contribution']['contribution_status_id'], 8, 'Status record is not proper for contribution');
161 * Test owed/refund info is listed on view payments.
163 public function testTransactionInfo() {
166 $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
167 $contributionID = $result['contribution']['id'];
170 //Complete the partial payment.
171 $submittedValues = array(
172 'total_amount' => 20,
173 'payment_instrument_id' => 3,
175 CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($contributionID, $submittedValues, 'owed', $participant['id']);
177 //Change selection to a lower amount.
178 $params['price_2'] = 50;
179 CRM_Price_BAO_LineItem
::changeFeeSelections($params, $participant['id'], 'participant', $contributionID, $feeBlock, $lineItem, $feeAmt);
181 //Record a refund of the remaining amount.
182 $submittedValues['total_amount'] = 50;
183 CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($contributionID, $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');