Commit | Line | Data |
---|---|---|
a5f2ebe4 PJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
a5f2ebe4 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
a5f2ebe4 PJ |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
a5f2ebe4 | 27 | |
4cbe18b8 EM |
28 | /** |
29 | * Class CRM_Event_BAO_AdditionalPaymentTest | |
acb109b7 | 30 | * @group headless |
4cbe18b8 | 31 | */ |
a5f2ebe4 | 32 | class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { |
a5f2ebe4 | 33 | |
00be9182 | 34 | public function setUp() { |
a5f2ebe4 | 35 | parent::setUp(); |
6ae19242 | 36 | $this->_contactId = $this->individualCreate(); |
37 | $event = $this->eventCreate(); | |
38 | $this->_eventId = $event['id']; | |
a5f2ebe4 PJ |
39 | } |
40 | ||
00be9182 | 41 | public function tearDown() { |
7b167a00 AH |
42 | $this->eventDelete($this->_eventId); |
43 | $this->quickCleanup( | |
44 | array( | |
45 | 'civicrm_contact', | |
46 | 'civicrm_contribution', | |
47 | 'civicrm_participant', | |
48 | 'civicrm_participant_payment', | |
49 | 'civicrm_line_item', | |
50 | 'civicrm_financial_item', | |
51 | 'civicrm_financial_trxn', | |
52 | 'civicrm_entity_financial_trxn', | |
53 | ), | |
54 | TRUE | |
55 | ); | |
56 | } | |
57 | ||
4cbe18b8 | 58 | /** |
c039f658 | 59 | * Helper function to record participant with paid contribution. |
60 | * | |
61 | * @param int $feeTotal | |
62 | * @param int $actualPaidAmt | |
4cbe18b8 EM |
63 | * |
64 | * @return array | |
65 | * @throws Exception | |
66 | */ | |
c039f658 | 67 | protected function addParticipantWithPayment($feeTotal, $actualPaidAmt) { |
68 | $priceSetId = $this->eventPriceSetCreate($feeTotal); | |
69 | CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId); | |
a5f2ebe4 PJ |
70 | |
71 | // create participant record | |
72 | $eventId = $this->_eventId; | |
73 | $participantParams = array( | |
74 | 'send_receipt' => 1, | |
75 | 'is_test' => 0, | |
76 | 'is_pay_later' => 0, | |
77 | 'event_id' => $eventId, | |
78 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
79 | 'role_id' => 1, | |
80 | 'status_id' => 14, | |
81 | 'source' => 'Event_' . $eventId, | |
82 | 'contact_id' => $this->_contactId, | |
83 | 'note' => 'Note added for Event_' . $eventId, | |
84 | 'fee_level' => '\ 1Price_Field - 55\ 1', | |
85 | ); | |
172b82d1 EM |
86 | $participant = $this->callAPISuccess('participant', 'create', $participantParams); |
87 | $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); | |
a5f2ebe4 PJ |
88 | // create participant contribution with partial payment |
89 | $contributionParams = array( | |
90 | 'total_amount' => $actualPaidAmt, | |
91 | 'source' => 'Fall Fundraiser Dinner: Offline registration', | |
92 | 'currency' => 'USD', | |
93 | 'non_deductible_amount' => 'null', | |
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", | |
100 | 'skipLineItem' => 1, | |
101 | 'partial_payment_total' => $feeTotal, | |
21dfd5f5 | 102 | 'partial_amount_pay' => $actualPaidAmt, |
a5f2ebe4 | 103 | ); |
172b82d1 EM |
104 | |
105 | $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams); | |
a5f2ebe4 | 106 | $contributionId = $contribution->id; |
172b82d1 | 107 | $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); |
a5f2ebe4 PJ |
108 | |
109 | // add participant payment entry | |
92915c55 TO |
110 | $this->callAPISuccess('participant_payment', 'create', array( |
111 | 'participant_id' => $participant['id'], | |
e7483cbe | 112 | 'contribution_id' => $contributionId, |
92915c55 | 113 | )); |
a5f2ebe4 PJ |
114 | |
115 | // -- processing priceSet using the BAO | |
116 | $lineItem = array(); | |
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 | CRM_Price_BAO_PriceSet::processAmount($feeBlock, | |
122 | $params, $lineItem | |
123 | ); | |
124 | $lineItemVal[$priceSetId] = $lineItem; | |
172b82d1 | 125 | CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant'); |
a5f2ebe4 PJ |
126 | return array($participant, $contribution); |
127 | } | |
128 | ||
546b78fa CW |
129 | /** |
130 | * CRM-13964 | |
131 | */ | |
00be9182 | 132 | public function testAddPartialPayment() { |
a5f2ebe4 PJ |
133 | $feeAmt = 100; |
134 | $amtPaid = 60; | |
135 | $balance = $feeAmt - $amtPaid; | |
c039f658 | 136 | list($participant, $contribution) = $this->addParticipantWithPayment($feeAmt, $amtPaid); |
172b82d1 | 137 | $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event'); |
a5f2ebe4 PJ |
138 | |
139 | // amount checking | |
140 | $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper'); | |
141 | $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper'); | |
142 | $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper'); | |
143 | ||
144 | // status checking | |
172b82d1 | 145 | $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant'); |
a5f2ebe4 PJ |
146 | $this->assertEquals($contribution->contribution_status_id, 8, 'Status record is not proper for contribution'); |
147 | } | |
96025800 | 148 | |
7b167a00 | 149 | } |