Commit | Line | Data |
---|---|---|
a084385f EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
a084385f | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
a084385f EM |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
a084385f EM |
28 | /** |
29 | * Test APIv3 civicrm_contribute_* functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Contribution | |
acb109b7 | 33 | * @group headless |
a084385f EM |
34 | */ |
35 | class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { | |
36 | ||
37 | /** | |
38 | * Assume empty database with just civicrm_data. | |
39 | */ | |
40 | protected $_individualId; | |
41 | protected $_contribution; | |
42 | protected $_financialTypeId = 1; | |
43 | protected $_apiversion; | |
44 | protected $_entity = 'Contribution'; | |
45 | protected $_params; | |
46 | protected $_ids = array(); | |
47 | protected $_pageParams = array(); | |
48 | ||
49 | /** | |
50 | * Parameters to create payment processor. | |
51 | * | |
52 | * @var array | |
53 | */ | |
54 | protected $_processorParams = array(); | |
55 | ||
56 | /** | |
57 | * ID of created event. | |
58 | * | |
59 | * @var int | |
60 | */ | |
61 | protected $_eventID; | |
62 | ||
63 | /** | |
64 | * Payment instrument mapping. | |
65 | * | |
66 | * @var array | |
67 | */ | |
68 | protected $paymentInstruments = array(); | |
69 | ||
3e6a1f4a EM |
70 | /** |
71 | * Products. | |
72 | * | |
73 | * @var array | |
74 | */ | |
75 | protected $products = array(); | |
76 | ||
39f47c0d EM |
77 | /** |
78 | * Dummy payment processor. | |
79 | * | |
7758bd2b | 80 | * @var CRM_Core_Payment_Dummy |
39f47c0d | 81 | */ |
7758bd2b | 82 | protected $paymentProcessor; |
39f47c0d | 83 | |
22e39333 | 84 | /** |
85 | * Payment processor ID. | |
86 | * | |
87 | * @var int | |
88 | */ | |
89 | protected $paymentProcessorID; | |
90 | ||
a084385f EM |
91 | /** |
92 | * Setup function. | |
93 | */ | |
94 | public function setUp() { | |
39f47c0d | 95 | $this->_apiversion = 3; |
a084385f | 96 | parent::setUp(); |
39f47c0d | 97 | $this->createLoggedInUser(); |
a084385f | 98 | |
a084385f | 99 | $this->_individualId = $this->individualCreate(); |
a084385f EM |
100 | $this->_params = array( |
101 | 'contact_id' => $this->_individualId, | |
102 | 'receive_date' => '20120511', | |
103 | 'total_amount' => 100.00, | |
104 | 'financial_type_id' => $this->_financialTypeId, | |
105 | 'non_deductible_amount' => 10.00, | |
106 | 'fee_amount' => 5.00, | |
107 | 'net_amount' => 95.00, | |
108 | 'source' => 'SSF', | |
109 | 'contribution_status_id' => 1, | |
110 | ); | |
111 | $this->_processorParams = array( | |
112 | 'domain_id' => 1, | |
113 | 'name' => 'Dummy', | |
114 | 'payment_processor_type_id' => 10, | |
115 | 'financial_account_id' => 12, | |
116 | 'is_active' => 1, | |
117 | 'user_name' => '', | |
118 | 'url_site' => 'http://dummy.com', | |
119 | 'url_recur' => 'http://dummy.com', | |
120 | 'billing_mode' => 1, | |
121 | ); | |
7758bd2b | 122 | |
a084385f EM |
123 | $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); |
124 | $this->paymentInstruments = $instruments['values']; | |
3e6a1f4a EM |
125 | $product1 = $this->callAPISuccess('product', 'create', array( |
126 | 'name' => 'Smurf', | |
127 | 'options' => 'brainy smurf, clumsy smurf, papa smurf', | |
128 | )); | |
129 | ||
130 | $this->products[] = $product1['values'][$product1['id']]; | |
22e39333 | 131 | $this->paymentProcessor = $this->dummyProcessorCreate(); |
132 | $processor = $this->paymentProcessor->getPaymentProcessor(); | |
133 | $this->paymentProcessorID = $processor['id']; | |
a084385f EM |
134 | } |
135 | ||
136 | /** | |
137 | * Clean up after each test. | |
138 | */ | |
139 | public function tearDown() { | |
140 | $this->quickCleanUpFinancialEntities(); | |
739a8336 | 141 | $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address')); |
a084385f EM |
142 | } |
143 | ||
144 | /** | |
145 | * Test the submit function on the contribution page. | |
146 | */ | |
147 | public function testSubmit() { | |
148 | $form = new CRM_Contribute_Form_Contribution(); | |
149 | $form->testSubmit(array( | |
150 | 'total_amount' => 50, | |
151 | 'financial_type_id' => 1, | |
152 | 'receive_date' => '04/21/2015', | |
153 | 'receive_date_time' => '11:27PM', | |
154 | 'contact_id' => $this->_individualId, | |
155 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
5e27919e | 156 | 'contribution_status_id' => 1, |
31760f81 EM |
157 | ), |
158 | CRM_Core_Action::ADD); | |
2b308818 DG |
159 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); |
160 | $this->assertEmpty($contribution['amount_level']); | |
a084385f EM |
161 | } |
162 | ||
163 | /** | |
164 | * Test the submit function on the contribution page. | |
165 | */ | |
166 | public function testSubmitCreditCard() { | |
167 | $form = new CRM_Contribute_Form_Contribution(); | |
168 | $form->testSubmit(array( | |
169 | 'total_amount' => 50, | |
170 | 'financial_type_id' => 1, | |
171 | 'receive_date' => '04/21/2015', | |
172 | 'receive_date_time' => '11:27PM', | |
173 | 'contact_id' => $this->_individualId, | |
174 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
5e27919e | 175 | 'contribution_status_id' => 1, |
31760f81 | 176 | ), CRM_Core_Action::ADD); |
7758bd2b EM |
177 | $this->callAPISuccessGetCount('Contribution', array( |
178 | 'contact_id' => $this->_individualId, | |
179 | 'contribution_status_id' => 'Completed', | |
180 | ), | |
181 | 1); | |
a084385f EM |
182 | } |
183 | ||
f8453bef | 184 | /** |
185 | * Test the submit function on the contribution page. | |
186 | */ | |
187 | public function testSubmitCreditCardPayPal() { | |
188 | $form = new CRM_Contribute_Form_Contribution(); | |
189 | $paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0)); | |
190 | $form->_mode = 'Live'; | |
16f3bd02 | 191 | $error = FALSE; |
f8453bef | 192 | try { |
193 | $form->testSubmit(array( | |
194 | 'total_amount' => 50, | |
195 | 'financial_type_id' => 1, | |
196 | 'receive_date' => '04/21/2015', | |
197 | 'receive_date_time' => '11:27PM', | |
198 | 'contact_id' => $this->_individualId, | |
f8453bef | 199 | 'contribution_status_id' => 1, |
200 | 'credit_card_number' => 4444333322221111, | |
201 | 'cvv2' => 123, | |
202 | 'credit_card_exp_date' => array( | |
203 | 'M' => 9, | |
204 | 'Y' => 2025, | |
205 | ), | |
206 | 'credit_card_type' => 'Visa', | |
207 | 'billing_first_name' => 'Junko', | |
208 | 'billing_middle_name' => '', | |
209 | 'billing_last_name' => 'Adams', | |
210 | 'billing_street_address-5' => '790L Lincoln St S', | |
211 | 'billing_city-5' => 'Maryknoll', | |
212 | 'billing_state_province_id-5' => 1031, | |
213 | 'billing_postal_code-5' => 10545, | |
214 | 'billing_country_id-5' => 1228, | |
215 | 'frequency_interval' => 1, | |
216 | 'frequency_unit' => 'month', | |
217 | 'installments' => '', | |
218 | 'hidden_AdditionalDetail' => 1, | |
219 | 'hidden_Premium' => 1, | |
220 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
221 | 'receipt_date' => '', | |
222 | 'receipt_date_time' => '', | |
223 | 'payment_processor_id' => $paymentProcessorID, | |
224 | 'currency' => 'USD', | |
dc0ca56c | 225 | 'source' => 'bob sled race', |
f8453bef | 226 | ), CRM_Core_Action::ADD); |
227 | } | |
228 | catch (Civi\Payment\Exception\PaymentProcessorException $e) { | |
16f3bd02 | 229 | $error = TRUE; |
f8453bef | 230 | } |
632196ea | 231 | |
f8453bef | 232 | $this->callAPISuccessGetCount('Contribution', array( |
233 | 'contact_id' => $this->_individualId, | |
5e67c92d | 234 | 'contribution_status_id' => $error ? 'Failed' : 'Completed', |
16f3bd02 | 235 | 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( |
236 | 'return' => 'payment_instrument_id', | |
237 | 'id' => $paymentProcessorID, | |
238 | )), | |
f8453bef | 239 | ), 1); |
dc0ca56c | 240 | $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); |
48e27df7 | 241 | $this->assertTrue(empty($contact['source'])); |
f8453bef | 242 | } |
243 | ||
22e39333 | 244 | /** |
245 | * Test the submit function on the contribution page. | |
246 | */ | |
247 | public function testSubmitCreditCardFee() { | |
248 | $form = new CRM_Contribute_Form_Contribution(); | |
22e39333 | 249 | $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08)); |
250 | $form->_mode = 'Live'; | |
251 | $form->testSubmit(array( | |
252 | 'total_amount' => 50, | |
253 | 'financial_type_id' => 1, | |
254 | 'receive_date' => '04/21/2015', | |
255 | 'receive_date_time' => '11:27PM', | |
256 | 'contact_id' => $this->_individualId, | |
257 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
258 | 'contribution_status_id' => 1, | |
259 | 'credit_card_number' => 4444333322221111, | |
260 | 'cvv2' => 123, | |
261 | 'credit_card_exp_date' => array( | |
262 | 'M' => 9, | |
263 | 'Y' => 2025, | |
264 | ), | |
265 | 'credit_card_type' => 'Visa', | |
266 | 'billing_first_name' => 'Junko', | |
267 | 'billing_middle_name' => '', | |
268 | 'billing_last_name' => 'Adams', | |
269 | 'billing_street_address-5' => '790L Lincoln St S', | |
270 | 'billing_city-5' => 'Maryknoll', | |
271 | 'billing_state_province_id-5' => 1031, | |
272 | 'billing_postal_code-5' => 10545, | |
273 | 'billing_country_id-5' => 1228, | |
274 | 'frequency_interval' => 1, | |
275 | 'frequency_unit' => 'month', | |
276 | 'installments' => '', | |
277 | 'hidden_AdditionalDetail' => 1, | |
278 | 'hidden_Premium' => 1, | |
279 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
280 | 'receipt_date' => '', | |
281 | 'receipt_date_time' => '', | |
282 | 'payment_processor_id' => $this->paymentProcessorID, | |
283 | 'currency' => 'USD', | |
284 | 'source' => '', | |
285 | ), CRM_Core_Action::ADD); | |
286 | ||
287 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
288 | 'contact_id' => $this->_individualId, | |
289 | 'contribution_status_id' => 'Completed', | |
290 | )); | |
291 | $this->assertEquals('50', $contribution['total_amount']); | |
292 | $this->assertEquals(.08, $contribution['fee_amount']); | |
293 | $this->assertEquals(49.92, $contribution['net_amount']); | |
294 | $this->assertEquals('tx', $contribution['trxn_id']); | |
2b308818 | 295 | $this->assertEmpty($contribution['amount_level']); |
22e39333 | 296 | } |
297 | ||
11829025 JMW |
298 | /** |
299 | * Test a fully deductible contribution submitted by credit card (CRM-16669). | |
300 | */ | |
301 | public function testSubmitCreditCardFullyDeductible() { | |
302 | $form = new CRM_Contribute_Form_Contribution(); | |
303 | $form->_mode = 'Live'; | |
304 | $form->testSubmit(array( | |
305 | 'total_amount' => 50, | |
306 | 'financial_type_id' => 1, | |
307 | 'receive_date' => '04/21/2015', | |
308 | 'receive_date_time' => '11:27PM', | |
309 | 'contact_id' => $this->_individualId, | |
310 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
311 | 'contribution_status_id' => 1, | |
312 | 'credit_card_number' => 4444333322221111, | |
313 | 'cvv2' => 123, | |
314 | 'credit_card_exp_date' => array( | |
315 | 'M' => 9, | |
316 | 'Y' => 2025, | |
317 | ), | |
318 | 'credit_card_type' => 'Visa', | |
319 | 'billing_first_name' => 'Junko', | |
320 | 'billing_middle_name' => '', | |
321 | 'billing_last_name' => 'Adams', | |
322 | 'billing_street_address-5' => '790L Lincoln St S', | |
323 | 'billing_city-5' => 'Maryknoll', | |
324 | 'billing_state_province_id-5' => 1031, | |
325 | 'billing_postal_code-5' => 10545, | |
326 | 'billing_country_id-5' => 1228, | |
327 | 'frequency_interval' => 1, | |
328 | 'frequency_unit' => 'month', | |
329 | 'installments' => '', | |
330 | 'hidden_AdditionalDetail' => 1, | |
331 | 'hidden_Premium' => 1, | |
332 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
333 | 'receipt_date' => '', | |
334 | 'receipt_date_time' => '', | |
335 | 'payment_processor_id' => $this->paymentProcessorID, | |
336 | 'currency' => 'USD', | |
337 | 'source' => '', | |
338 | ), CRM_Core_Action::ADD); | |
339 | ||
340 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
341 | 'contact_id' => $this->_individualId, | |
342 | 'contribution_status_id' => 'Completed', | |
343 | )); | |
344 | $this->assertEquals('50', $contribution['total_amount']); | |
345 | $this->assertEquals(0, $contribution['non_deductible_amount']); | |
346 | } | |
347 | ||
7126b55c | 348 | /** |
7758bd2b EM |
349 | * Test the submit function with an invalid payment. |
350 | * | |
351 | * We expect the contribution to be created but left pending. The payment has failed. | |
352 | * | |
353 | * Test covers CRM-16417 change to keep failed transactions. | |
354 | * | |
355 | * We are left with | |
356 | * - 1 Contribution with status = Pending | |
357 | * - 1 Line item | |
358 | * - 1 civicrm_financial_item. This is linked to the line item and has a status of 3 | |
7126b55c | 359 | */ |
7758bd2b | 360 | public function testSubmitCreditCardInvalid() { |
7126b55c | 361 | $form = new CRM_Contribute_Form_Contribution(); |
7758bd2b EM |
362 | $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1)); |
363 | try { | |
364 | $form->testSubmit(array( | |
365 | 'total_amount' => 50, | |
366 | 'financial_type_id' => 1, | |
367 | 'receive_date' => '04/21/2015', | |
368 | 'receive_date_time' => '11:27PM', | |
369 | 'contact_id' => $this->_individualId, | |
370 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 371 | 'payment_processor_id' => $this->paymentProcessorID, |
7758bd2b EM |
372 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), |
373 | 'credit_card_number' => '411111111111111', | |
374 | ), CRM_Core_Action::ADD, | |
739a8336 | 375 | 'live' |
376 | ); | |
7758bd2b EM |
377 | } |
378 | catch (\Civi\Payment\Exception\PaymentProcessorException $e) { | |
40f5ec68 EM |
379 | $this->callAPISuccessGetCount('Contribution', array( |
380 | 'contact_id' => $this->_individualId, | |
382c5680 | 381 | 'contribution_status_id' => 'Failed', |
40f5ec68 | 382 | ), 1); |
7758bd2b EM |
383 | $lineItem = $this->callAPISuccessGetSingle('line_item', array()); |
384 | $this->assertEquals('50.00', $lineItem['unit_price']); | |
385 | $this->assertEquals('50.00', $lineItem['line_total']); | |
386 | $this->assertEquals(1, $lineItem['qty']); | |
387 | $this->assertEquals(1, $lineItem['financial_type_id']); | |
388 | $financialItem = $this->callAPISuccessGetSingle('financial_item', array( | |
389 | 'civicrm_line_item' => $lineItem['id'], | |
390 | 'entity_id' => $lineItem['id'], | |
391 | )); | |
392 | $this->assertEquals('50.00', $financialItem['amount']); | |
393 | $this->assertEquals(3, $financialItem['status_id']); | |
394 | return; | |
395 | } | |
396 | $this->fail('An expected exception has not been raised.'); | |
7126b55c EM |
397 | } |
398 | ||
739a8336 | 399 | /** |
400 | * Test the submit function creates a billing address if provided. | |
401 | */ | |
402 | public function testSubmitCreditCardWithBillingAddress() { | |
403 | $form = new CRM_Contribute_Form_Contribution(); | |
404 | $form->testSubmit(array( | |
405 | 'total_amount' => 50, | |
406 | 'financial_type_id' => 1, | |
407 | 'receive_date' => '04/21/2015', | |
408 | 'receive_date_time' => '11:27PM', | |
409 | 'contact_id' => $this->_individualId, | |
410 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 411 | 'payment_processor_id' => $this->paymentProcessorID, |
739a8336 | 412 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), |
413 | 'credit_card_number' => '411111111111111', | |
414 | 'billing_city-5' => 'Vancouver', | |
415 | ), CRM_Core_Action::ADD, | |
416 | 'live' | |
417 | ); | |
418 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); | |
419 | $this->assertNotEmpty($contribution['address_id']); | |
989a6bb8 | 420 | // CRM-18490 : There is a unwanted test leakage due to below getsingle Api as it only fails in Jenkin |
421 | // for now we are only fetching address on based on Address ID (removed filter location_type_id and city) | |
739a8336 | 422 | $this->callAPISuccessGetSingle('Address', array( |
739a8336 | 423 | 'id' => $contribution['address_id'], |
424 | )); | |
425 | ||
426 | } | |
427 | ||
428 | /** | |
429 | * Test the submit function does not create a billing address if no details provided. | |
430 | */ | |
431 | public function testSubmitCreditCardWithNoBillingAddress() { | |
432 | $form = new CRM_Contribute_Form_Contribution(); | |
433 | $form->testSubmit(array( | |
434 | 'total_amount' => 50, | |
435 | 'financial_type_id' => 1, | |
436 | 'receive_date' => '04/21/2015', | |
437 | 'receive_date_time' => '11:27PM', | |
438 | 'contact_id' => $this->_individualId, | |
439 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 440 | 'payment_processor_id' => $this->paymentProcessorID, |
739a8336 | 441 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), |
442 | 'credit_card_number' => '411111111111111', | |
443 | ), CRM_Core_Action::ADD, | |
444 | 'live' | |
445 | ); | |
446 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); | |
447 | $this->assertEmpty($contribution['address_id']); | |
448 | $this->callAPISuccessGetCount('Address', array( | |
449 | 'city' => 'Vancouver', | |
450 | 'location_type_id' => 5, | |
451 | ), 0); | |
739a8336 | 452 | } |
453 | ||
a084385f EM |
454 | /** |
455 | * Test the submit function on the contribution page. | |
456 | */ | |
457 | public function testSubmitEmailReceipt() { | |
458 | $form = new CRM_Contribute_Form_Contribution(); | |
a084385f EM |
459 | $mut = new CiviMailUtils($this, TRUE); |
460 | $form->testSubmit(array( | |
461 | 'total_amount' => 50, | |
462 | 'financial_type_id' => 1, | |
463 | 'receive_date' => '04/21/2015', | |
464 | 'receive_date_time' => '11:27PM', | |
465 | 'contact_id' => $this->_individualId, | |
466 | 'is_email_receipt' => TRUE, | |
467 | 'from_email_address' => 'test@test.com', | |
5e27919e | 468 | 'contribution_status_id' => 1, |
31760f81 | 469 | ), CRM_Core_Action::ADD); |
a084385f EM |
470 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); |
471 | $mut->checkMailLog(array( | |
472 | '<p>Please print this receipt for your records.</p>', | |
473 | ) | |
474 | ); | |
475 | $mut->stop(); | |
476 | } | |
df729ab1 | 477 | |
0335c5f1 | 478 | /** |
479 | * Ensure that price field are shown during pay later/pending Contribution | |
480 | */ | |
481 | public function testEmailReceiptOnPayLater() { | |
482 | $donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name'); | |
483 | $paramsSet = array( | |
484 | 'title' => 'Price Set' . substr(sha1(rand()), 0, 4), | |
485 | 'is_active' => TRUE, | |
486 | 'financial_type_id' => $donationFT, | |
487 | 'extends' => 2, | |
488 | ); | |
489 | $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); | |
490 | ||
491 | $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); | |
492 | $priceSetId = $priceset->id; | |
493 | ||
494 | //Checking for priceset added in the table. | |
495 | $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', | |
496 | 'id', $paramsSet['title'], 'Check DB for created priceset' | |
497 | ); | |
498 | $paramsField = array( | |
499 | 'label' => 'Price Field', | |
500 | 'name' => CRM_Utils_String::titleToVar('Price Field'), | |
501 | 'html_type' => 'CheckBox', | |
502 | 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), | |
503 | 'option_value' => array('1' => 100, '2' => 200), | |
504 | 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), | |
505 | 'option_weight' => array('1' => 1, '2' => 2), | |
506 | 'option_amount' => array('1' => 100, '2' => 200), | |
507 | 'is_display_amounts' => 1, | |
508 | 'weight' => 1, | |
509 | 'options_per_line' => 1, | |
510 | 'is_active' => array('1' => 1, '2' => 1), | |
511 | 'price_set_id' => $priceset->id, | |
512 | 'is_enter_qty' => 1, | |
513 | 'financial_type_id' => $donationFT, | |
514 | ); | |
515 | $priceField = CRM_Price_BAO_PriceField::create($paramsField); | |
516 | $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); | |
517 | ||
518 | $params = array( | |
519 | 'total_amount' => 100, | |
520 | 'financial_type_id' => $donationFT, | |
521 | 'receive_date' => '04/21/2015', | |
522 | 'receive_date_time' => '11:27PM', | |
523 | 'contact_id' => $this->_individualId, | |
524 | 'is_email_receipt' => TRUE, | |
525 | 'from_email_address' => 'test@test.com', | |
526 | 'price_set_id' => $priceSetId, | |
f527e012 | 527 | 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), |
0335c5f1 | 528 | ); |
529 | ||
530 | foreach ($priceFieldValue['values'] as $id => $price) { | |
531 | if ($price['amount'] == 100) { | |
532 | $params['price_' . $priceField->id] = array($id => 1); | |
533 | } | |
534 | } | |
535 | $form = new CRM_Contribute_Form_Contribution(); | |
536 | $mut = new CiviMailUtils($this, TRUE); | |
537 | $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); | |
538 | $form->testSubmit($params, CRM_Core_Action::ADD); | |
539 | ||
540 | $mut->checkMailLog(array( | |
541 | 'Financial Type: Donation | |
542 | --------------------------------------------------------- | |
543 | Item Qty Each Total | |
544 | ---------------------------------------------------------- | |
545 | Price Field - Price Field 1 1 $ 100.00 $ 100.00 | |
546 | ', | |
547 | ) | |
548 | ); | |
549 | $mut->stop(); | |
550 | } | |
551 | ||
31760f81 EM |
552 | /** |
553 | * Test that a contribution is assigned against a pledge. | |
554 | */ | |
555 | public function testUpdatePledge() { | |
556 | $pledge = $this->callAPISuccess('pledge', 'create', array( | |
557 | 'contact_id' => $this->_individualId, | |
558 | 'pledge_create_date' => date('Ymd'), | |
559 | 'start_date' => date('Ymd'), | |
560 | 'amount' => 100.00, | |
561 | 'pledge_status_id' => '2', | |
562 | 'pledge_financial_type_id' => '1', | |
563 | 'pledge_original_installment_amount' => 20, | |
564 | 'frequency_interval' => 5, | |
565 | 'frequency_unit' => 'year', | |
566 | 'frequency_day' => 15, | |
567 | 'installments' => 2, | |
568 | 'sequential' => 1, | |
569 | )); | |
570 | $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array( | |
571 | 'pledge_id' => $pledge['id'], | |
572 | 'options' => array('limit' => 1), | |
573 | 'return' => 'id', | |
574 | )); | |
575 | $form = new CRM_Contribute_Form_Contribution(); | |
576 | $form->testSubmit(array( | |
577 | 'total_amount' => 50, | |
578 | 'financial_type_id' => 1, | |
579 | 'receive_date' => '04/21/2015', | |
580 | 'receive_date_time' => '11:27PM', | |
581 | 'contact_id' => $this->_individualId, | |
582 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
583 | 'pledge_payment_id' => $pledgePaymentID, | |
5e27919e | 584 | 'contribution_status_id' => 1, |
31760f81 EM |
585 | ), CRM_Core_Action::ADD); |
586 | $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID)); | |
587 | $this->assertNotEmpty($pledgePayment['contribution_id']); | |
588 | $this->assertEquals($pledgePayment['actual_amount'], 50); | |
589 | $this->assertEquals(1, $pledgePayment['status_id']); | |
590 | } | |
ef353929 | 591 | |
3e6a1f4a EM |
592 | /** |
593 | * Test functions involving premiums. | |
594 | */ | |
595 | public function testPremiumUpdate() { | |
596 | $form = new CRM_Contribute_Form_Contribution(); | |
43bf07d6 | 597 | $mut = new CiviMailUtils($this, TRUE); |
3e6a1f4a EM |
598 | $form->testSubmit(array( |
599 | 'total_amount' => 50, | |
600 | 'financial_type_id' => 1, | |
601 | 'receive_date' => '04/21/2015', | |
602 | 'receive_date_time' => '11:27PM', | |
603 | 'contact_id' => $this->_individualId, | |
604 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
605 | 'contribution_status_id' => 1, | |
606 | 'product_name' => array($this->products[0]['id'], 1), | |
607 | 'fulfilled_date' => '', | |
43bf07d6 EM |
608 | 'is_email_receipt' => TRUE, |
609 | 'from_email_address' => 'test@test.com', | |
3e6a1f4a EM |
610 | ), CRM_Core_Action::ADD); |
611 | $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); | |
612 | $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); | |
43bf07d6 EM |
613 | $mut->checkMailLog(array( |
614 | 'Premium Information', | |
615 | 'Smurf', | |
616 | 'clumsy smurf', | |
617 | )); | |
618 | $mut->stop(); | |
3e6a1f4a EM |
619 | } |
620 | ||
39f47c0d EM |
621 | /** |
622 | * Test functions involving premiums. | |
623 | */ | |
624 | public function testPremiumUpdateCreditCard() { | |
625 | $form = new CRM_Contribute_Form_Contribution(); | |
626 | $mut = new CiviMailUtils($this, TRUE); | |
627 | $form->testSubmit(array( | |
628 | 'total_amount' => 50, | |
629 | 'financial_type_id' => 1, | |
630 | 'receive_date' => '04/21/2015', | |
631 | 'receive_date_time' => '11:27PM', | |
632 | 'contact_id' => $this->_individualId, | |
633 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
634 | 'contribution_status_id' => 1, | |
635 | 'product_name' => array($this->products[0]['id'], 1), | |
636 | 'fulfilled_date' => '', | |
637 | 'is_email_receipt' => TRUE, | |
638 | 'from_email_address' => 'test@test.com', | |
22e39333 | 639 | 'payment_processor_id' => $this->paymentProcessorID, |
7758bd2b | 640 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026), |
39f47c0d EM |
641 | 'credit_card_number' => '411111111111111', |
642 | ), CRM_Core_Action::ADD, | |
643 | 'live'); | |
644 | $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); | |
645 | $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); | |
646 | $mut->checkMailLog(array( | |
647 | 'Premium Information', | |
648 | 'Smurf', | |
649 | 'clumsy smurf', | |
650 | )); | |
651 | $mut->stop(); | |
652 | } | |
653 | ||
945f423d EM |
654 | /** |
655 | * Test the submit function on the contribution page. | |
656 | */ | |
657 | public function testSubmitWithNote() { | |
658 | $form = new CRM_Contribute_Form_Contribution(); | |
659 | $form->testSubmit(array( | |
660 | 'total_amount' => 50, | |
661 | 'financial_type_id' => 1, | |
662 | 'receive_date' => '04/21/2015', | |
663 | 'receive_date_time' => '11:27PM', | |
664 | 'contact_id' => $this->_individualId, | |
665 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
666 | 'contribution_status_id' => 1, | |
667 | 'note' => 'Super cool and interesting stuff', | |
668 | ), | |
669 | CRM_Core_Action::ADD); | |
670 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
671 | $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); | |
672 | $this->assertEquals($note['note'], 'Super cool and interesting stuff'); | |
673 | } | |
674 | ||
675 | /** | |
676 | * Test the submit function on the contribution page. | |
677 | */ | |
678 | public function testSubmitWithNoteCreditCard() { | |
679 | $form = new CRM_Contribute_Form_Contribution(); | |
680 | ||
681 | $form->testSubmit(array( | |
682 | 'total_amount' => 50, | |
683 | 'financial_type_id' => 1, | |
684 | 'receive_date' => '04/21/2015', | |
685 | 'receive_date_time' => '11:27PM', | |
686 | 'contact_id' => $this->_individualId, | |
687 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
688 | 'contribution_status_id' => 1, | |
689 | 'note' => 'Super cool and interesting stuff', | |
1ea0b4ac | 690 | ) + $this->getCreditCardParams(), |
945f423d EM |
691 | CRM_Core_Action::ADD); |
692 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
693 | $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); | |
694 | $this->assertEquals($note['note'], 'Super cool and interesting stuff'); | |
695 | } | |
696 | ||
fa18b745 | 697 | /** |
71a3f5f9 | 698 | * Test that if a negative contribution is entered it does not get reset to $0. |
699 | * | |
700 | * Note that this fails locally for me & I believe there may be an issue for some sites | |
701 | * with negative numbers. Grep for CRM-16460 to find the places I think that might | |
702 | * be affected if you hit this. | |
fa18b745 K |
703 | */ |
704 | public function testEnterNegativeContribution() { | |
705 | $form = new CRM_Contribute_Form_Contribution(); | |
706 | $form->testSubmit(array( | |
707 | 'total_amount' => -5, | |
708 | 'financial_type_id' => 1, | |
709 | 'receive_date' => '04/24/2016', | |
710 | 'receive_date_time' => '11:27PM', | |
711 | 'contact_id' => $this->_individualId, | |
712 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
713 | 'contribution_status_id' => 1, | |
714 | ), | |
715 | CRM_Core_Action::ADD); | |
716 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
717 | ||
718 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
719 | 'contact_id' => $this->_individualId, | |
720 | )); | |
721 | $this->assertEquals(-5, $contribution['total_amount']); | |
722 | } | |
723 | ||
55e55e84 | 724 | /** |
725 | * Test the submit function on the contribution page. | |
726 | */ | |
727 | public function testSubmitUpdate() { | |
728 | $form = new CRM_Contribute_Form_Contribution(); | |
729 | ||
730 | $form->testSubmit(array( | |
731 | 'total_amount' => 50, | |
732 | 'financial_type_id' => 1, | |
733 | 'receive_date' => '04/21/2015', | |
734 | 'receive_date_time' => '11:27PM', | |
735 | 'contact_id' => $this->_individualId, | |
736 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
737 | 'contribution_status_id' => 1, | |
738 | 'price_set_id' => 0, | |
739 | ), | |
740 | CRM_Core_Action::ADD); | |
741 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); | |
742 | $form->testSubmit(array( | |
743 | 'total_amount' => 45, | |
744 | 'net_amount' => 45, | |
745 | 'financial_type_id' => 1, | |
746 | 'receive_date' => '04/21/2015', | |
747 | 'receive_date_time' => '11:27PM', | |
748 | 'contact_id' => $this->_individualId, | |
749 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
750 | 'contribution_status_id' => 1, | |
751 | 'price_set_id' => 0, | |
752 | 'id' => $contribution['id'], | |
753 | ), | |
754 | CRM_Core_Action::UPDATE); | |
da77cbbd EM |
755 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); |
756 | $this->assertEquals(45, (int) $contribution['total_amount']); | |
757 | ||
55e55e84 | 758 | $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE)); |
759 | $this->assertEquals(2, $financialTransactions['count']); | |
760 | $this->assertEquals(50, $financialTransactions['values'][0]['total_amount']); | |
a4ed7706 EM |
761 | $this->assertEquals(-5, $financialTransactions['values'][1]['total_amount']); |
762 | $this->assertEquals(-5, $financialTransactions['values'][1]['net_amount']); | |
55e55e84 | 763 | $lineItem = $this->callAPISuccessGetSingle('LineItem', array()); |
764 | $this->assertEquals(45, $lineItem['line_total']); | |
765 | } | |
766 | ||
945f423d EM |
767 | /** |
768 | * Get parameters for credit card submit calls. | |
769 | * | |
770 | * @return array | |
771 | * Credit card specific parameters. | |
772 | */ | |
1ea0b4ac | 773 | protected function getCreditCardParams() { |
945f423d | 774 | return array( |
22e39333 | 775 | 'payment_processor_id' => $this->paymentProcessorID, |
945f423d EM |
776 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), |
777 | 'credit_card_number' => '411111111111111', | |
778 | ); | |
779 | } | |
945f423d | 780 | |
9beed6cf PN |
781 | /** |
782 | * Test the submit function that completes the partially paid payment using Credit Card | |
783 | */ | |
784 | public function testPartialPaymentWithCreditCard() { | |
785 | // create a partially paid contribution by using back-office form | |
786 | $form = new CRM_Contribute_Form_Contribution(); | |
787 | $form->testSubmit( | |
788 | array( | |
789 | 'total_amount' => 50, | |
790 | 'financial_type_id' => 1, | |
791 | 'receive_date' => '04/21/2015', | |
792 | 'receive_date_time' => '11:27PM', | |
793 | 'contact_id' => $this->_individualId, | |
794 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
795 | 'check_number' => substr(sha1(rand()), 0, 7), | |
796 | 'billing_city-5' => 'Vancouver', | |
797 | 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'), | |
798 | ), CRM_Core_Action::ADD | |
799 | ); | |
800 | ||
801 | $contribution = $this->callAPISuccessGetSingle('Contribution', array()); | |
802 | $this->assertNotEmpty($contribution); | |
803 | $this->assertEquals('Partially paid', $contribution['contribution_status']); | |
804 | // pay additional amount by using Credit Card | |
805 | $form = new CRM_Contribute_Form_AdditionalPayment(); | |
806 | $form->testSubmit(array( | |
807 | 'contribution_id' => $contribution['id'], | |
808 | 'contact_id' => $this->_individualId, | |
809 | 'total_amount' => 50, | |
810 | 'currency' => 'USD', | |
811 | 'financial_type_id' => 1, | |
812 | 'receive_date' => '04/21/2015', | |
813 | 'receive_date_time' => '11:27PM', | |
814 | 'contact_id' => $this->_individualId, | |
815 | 'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments), | |
816 | 'payment_processor_id' => $this->paymentProcessorID, | |
817 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), | |
818 | 'credit_card_number' => '411111111111111', | |
819 | 'cvv2' => 234, | |
820 | 'credit_card_type' => 'Visa', | |
821 | 'billing_city-5' => 'Vancouver', | |
822 | 'billing_state_province_id-5' => 1059, | |
823 | 'billing_postal_code-5' => 1321312, | |
824 | 'billing_country_id-5' => 1228, | |
825 | 'trxn_date' => '2017-04-11 13:05:11', | |
826 | ), 'live'); | |
827 | $contribution = $this->callAPISuccessGetSingle('Contribution', array()); | |
828 | $this->assertNotEmpty($contribution); | |
829 | $this->assertEquals('Completed', $contribution['contribution_status']); | |
830 | } | |
831 | ||
7a1f3919 PN |
832 | /** |
833 | * Test the submit function for FT with tax. | |
834 | */ | |
835 | public function testSubmitSaleTax() { | |
836 | $this->enableTaxAndInvoicing(); | |
837 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
838 | $form = new CRM_Contribute_Form_Contribution(); | |
839 | ||
840 | $form->testSubmit(array( | |
841 | 'total_amount' => 100, | |
842 | 'financial_type_id' => $this->_financialTypeId, | |
843 | 'receive_date' => '04/21/2015', | |
844 | 'receive_date_time' => '11:27PM', | |
845 | 'contact_id' => $this->_individualId, | |
846 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
847 | 'contribution_status_id' => 1, | |
848 | 'price_set_id' => 0, | |
849 | ), | |
850 | CRM_Core_Action::ADD | |
851 | ); | |
852 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
853 | array( | |
854 | 'contact_id' => $this->_individualId, | |
855 | 'return' => array('tax_amount', 'total_amount'), | |
856 | ) | |
857 | ); | |
858 | $this->assertEquals(110, $contribution['total_amount']); | |
859 | $this->assertEquals(10, $contribution['tax_amount']); | |
860 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); | |
861 | $this->callAPISuccessGetCount('FinancialItem', array(), 2); | |
862 | $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); | |
863 | $this->assertEquals(100, $lineItem['line_total']); | |
864 | $this->assertEquals(10, $lineItem['tax_amount']); | |
865 | } | |
866 | ||
1ec04220 PN |
867 | /** |
868 | * Test the submit function for FT without tax. | |
869 | */ | |
870 | public function testSubmitWithOutSaleTax() { | |
871 | $this->enableTaxAndInvoicing(); | |
872 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
873 | $form = new CRM_Contribute_Form_Contribution(); | |
874 | ||
875 | $form->testSubmit(array( | |
876 | 'total_amount' => 100, | |
877 | 'financial_type_id' => 3, | |
878 | 'receive_date' => '04/21/2015', | |
879 | 'receive_date_time' => '11:27PM', | |
880 | 'contact_id' => $this->_individualId, | |
881 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
882 | 'contribution_status_id' => 1, | |
883 | 'price_set_id' => 0, | |
884 | ), | |
885 | CRM_Core_Action::ADD | |
886 | ); | |
887 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
888 | array( | |
889 | 'contact_id' => $this->_individualId, | |
890 | 'return' => array('tax_amount', 'total_amount'), | |
891 | ) | |
892 | ); | |
893 | $this->assertEquals(100, $contribution['total_amount']); | |
894 | $this->assertEquals(NULL, $contribution['tax_amount']); | |
895 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); | |
896 | $this->callAPISuccessGetCount('FinancialItem', array(), 1); | |
897 | $lineItem = $this->callAPISuccessGetSingle( | |
898 | 'LineItem', | |
899 | array( | |
900 | 'contribution_id' => $contribution['id'], | |
901 | 'return' => array('line_total', 'tax_amount'), | |
902 | ) | |
903 | ); | |
904 | $this->assertEquals(100, $lineItem['line_total']); | |
905 | $this->assertTrue(empty($lineItem['tax_amount'])); | |
906 | } | |
907 | ||
f1662cbd | 908 | /** |
9308f1c2 | 909 | * Create a contribution & then edit it via backoffice form, checking tax with: default price_set |
f1662cbd | 910 | * |
911 | * @throws \Exception | |
912 | */ | |
335c41e7 | 913 | public function testReSubmitSaleTax() { |
335c41e7 K |
914 | $this->enableTaxAndInvoicing(); |
915 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
cf28d075 | 916 | list($form, $contribution) = $this->doInitialSubmit(); |
917 | $this->assertEquals(110, $contribution['total_amount']); | |
918 | $this->assertEquals(10, $contribution['tax_amount']); | |
919 | $this->assertEquals(110, $contribution['net_amount']); | |
335c41e7 | 920 | |
cf28d075 | 921 | $mut = new CiviMailUtils($this, TRUE); |
922 | // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: | |
335c41e7 | 923 | $form->testSubmit(array( |
cf28d075 | 924 | 'id' => $contribution['id'], |
925 | 'tax_amount' => $contribution['tax_amount'], | |
926 | 'financial_type_id' => $contribution['financial_type_id'], | |
927 | 'receive_date' => $contribution['receive_date'], | |
928 | 'payment_instrument_id' => $contribution['payment_instrument_id'], | |
335c41e7 | 929 | 'price_set_id' => 0, |
cf28d075 | 930 | 'check_number' => 12345, |
931 | 'contribution_status_id' => 1, | |
932 | 'is_email_receipt' => 1, | |
933 | 'from_email_address' => 'demo@example.com', | |
335c41e7 | 934 | ), |
cf28d075 | 935 | CRM_Core_Action::UPDATE |
335c41e7 K |
936 | ); |
937 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
938 | array( | |
939 | 'contribution_id' => 1, | |
940 | 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), | |
941 | ) | |
942 | ); | |
f1662cbd | 943 | $this->assertEquals(110, $contribution['total_amount']); |
944 | $this->assertEquals(10, $contribution['tax_amount']); | |
9308f1c2 | 945 | $this->assertEquals(110, $contribution['net_amount']); |
335c41e7 | 946 | |
cf28d075 | 947 | $strings = array( |
948 | 'Total Tax Amount : $ 10.00', | |
949 | 'Total Amount : $ 110.00', | |
950 | 'Date Received: April 21st, 2015', | |
951 | 'Paid By: Check', | |
952 | 'Check Number: 12345', | |
953 | ); | |
954 | ||
955 | $mut->checkMailLog($strings); | |
956 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 3); | |
957 | $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); | |
958 | $this->assertEquals(2, $items['count']); | |
959 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
960 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
961 | ||
962 | $this->assertEquals(100, $items['values'][0]['amount']); | |
963 | $this->assertEquals(10, $items['values'][1]['amount']); | |
964 | } | |
965 | ||
966 | /** | |
967 | * Create a contribution & then edit it via backoffice form, checking tax with: default price_set | |
968 | * | |
969 | * @throws \Exception | |
970 | */ | |
971 | public function testReSubmitSaleTaxAlteredAmount() { | |
972 | $this->enableTaxAndInvoicing(); | |
973 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
974 | list($form, $contribution) = $this->doInitialSubmit(); | |
975 | ||
f1662cbd | 976 | $mut = new CiviMailUtils($this, TRUE); |
9308f1c2 | 977 | // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: |
335c41e7 | 978 | $form->testSubmit(array( |
f1662cbd | 979 | 'id' => $contribution['id'], |
cf28d075 | 980 | 'total_amount' => 200, |
981 | 'tax_amount' => 20, | |
335c41e7 K |
982 | 'financial_type_id' => $contribution['financial_type_id'], |
983 | 'receive_date' => $contribution['receive_date'], | |
984 | 'payment_instrument_id' => $contribution['payment_instrument_id'], | |
985 | 'price_set_id' => 0, | |
986 | 'check_number' => 12345, | |
f1662cbd | 987 | 'contribution_status_id' => 1, |
988 | 'is_email_receipt' => 1, | |
989 | 'from_email_address' => 'demo@example.com', | |
335c41e7 K |
990 | ), |
991 | CRM_Core_Action::UPDATE | |
992 | ); | |
993 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
994 | array( | |
9308f1c2 K |
995 | 'contribution_id' => 1, |
996 | 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), | |
335c41e7 K |
997 | ) |
998 | ); | |
cf28d075 | 999 | $this->assertEquals(220, $contribution['total_amount']); |
1000 | $this->assertEquals(20, $contribution['tax_amount']); | |
1001 | $this->assertEquals(220, $contribution['net_amount']); | |
9308f1c2 | 1002 | |
f1662cbd | 1003 | $strings = array( |
cf28d075 | 1004 | 'Total Tax Amount : $ 20.00', |
1005 | 'Total Amount : $ 220.00', | |
f1662cbd | 1006 | 'Date Received: April 21st, 2015', |
1007 | 'Paid By: Check', | |
1008 | 'Check Number: 12345', | |
1009 | ); | |
335c41e7 | 1010 | |
f1662cbd | 1011 | $mut->checkMailLog($strings); |
cf28d075 | 1012 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 4); |
1013 | $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); | |
1014 | $this->assertEquals(4, $items['count']); | |
1015 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
1016 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
1017 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
1018 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
1019 | ||
1020 | $this->assertEquals(100, $items['values'][0]['amount']); | |
1021 | $this->assertEquals(10, $items['values'][1]['amount']); | |
7c63ab21 | 1022 | // @todo currently its $110 which is incorrect, the proper value should be $200 |
1023 | // $this->assertEquals(200, $items['values'][2]['amount']); | |
cf28d075 | 1024 | $this->assertEquals(20, $items['values'][3]['amount']); |
1025 | } | |
1026 | ||
1027 | /** | |
1028 | * Do the first contributions, in preparation for an edit-submit. | |
1029 | * | |
1030 | * @return array | |
1031 | * | |
1032 | * @throws \Exception | |
1033 | */ | |
1034 | protected function doInitialSubmit() { | |
1035 | $form = new CRM_Contribute_Form_Contribution(); | |
1036 | ||
1037 | $form->testSubmit(array( | |
1038 | 'total_amount' => 100, | |
1039 | 'financial_type_id' => $this->_financialTypeId, | |
1040 | 'receive_date' => '04/21/2015', | |
1041 | 'receive_date_time' => '11:27PM', | |
1042 | 'contact_id' => $this->_individualId, | |
1043 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
1044 | 'contribution_status_id' => 1, | |
1045 | 'price_set_id' => 0, | |
1046 | ), | |
1047 | CRM_Core_Action::ADD | |
1048 | ); | |
1049 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1050 | array( | |
1051 | 'contribution_id' => 1, | |
1052 | 'return' => array( | |
1053 | 'tax_amount', | |
1054 | 'total_amount', | |
1055 | 'net_amount', | |
1056 | 'financial_type_id', | |
1057 | 'receive_date', | |
1058 | 'payment_instrument_id', | |
1059 | ), | |
1060 | ) | |
1061 | ); | |
1062 | $this->assertEquals(110, $contribution['total_amount']); | |
1063 | $this->assertEquals(10, $contribution['tax_amount']); | |
1064 | $this->assertEquals(110, $contribution['net_amount']); | |
1065 | return array($form, $contribution); | |
335c41e7 K |
1066 | } |
1067 | ||
a55e39e9 | 1068 | /** |
1069 | * function to test card_type and pan truncation. | |
1070 | */ | |
1071 | public function testCardTypeAndPanTruncation() { | |
1072 | $form = new CRM_Contribute_Form_Contribution(); | |
1073 | $form->testSubmit( | |
1074 | array( | |
1075 | 'total_amount' => 100, | |
1076 | 'financial_type_id' => 3, | |
1077 | 'receive_date' => '04/21/2015', | |
1078 | 'receive_date_time' => '11:27PM', | |
1079 | 'contact_id' => $this->_individualId, | |
1080 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
1081 | 'contribution_status_id' => 1, | |
1082 | 'credit_card_type' => 'Visa', | |
1083 | 'pan_truncation' => 4567, | |
1084 | 'price_set_id' => 0, | |
1085 | ), | |
1086 | CRM_Core_Action::ADD | |
1087 | ); | |
1088 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1089 | array( | |
1090 | 'contact_id' => $this->_individualId, | |
1091 | 'return' => array('id'), | |
1092 | ) | |
1093 | ); | |
1094 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); | |
1095 | $financialTrxn = $this->callAPISuccessGetSingle( | |
1096 | 'FinancialTrxn', | |
1097 | array( | |
1098 | 'id' => $lastFinancialTrxnId['financialTrxnId'], | |
1099 | 'return' => array('card_type_id.label', 'pan_truncation'), | |
1100 | ) | |
1101 | ); | |
1102 | $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); | |
1103 | $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567); | |
1104 | } | |
1105 | ||
1106 | /** | |
1107 | * function to test card_type and pan truncation. | |
1108 | */ | |
1109 | public function testCardTypeAndPanTruncationLiveMode() { | |
1110 | $visaID = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', 'Visa'); | |
1111 | $form = new CRM_Contribute_Form_Contribution(); | |
1112 | $form->_mode = 'Live'; | |
a55e39e9 | 1113 | $form->testSubmit( |
1114 | array( | |
1115 | 'total_amount' => 50, | |
1116 | 'financial_type_id' => 1, | |
1117 | 'receive_date' => '04/21/2015', | |
1118 | 'receive_date_time' => '11:27PM', | |
1119 | 'contact_id' => $this->_individualId, | |
1120 | 'credit_card_number' => 4444333322221111, | |
1121 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
1122 | 'cvv2' => 123, | |
1123 | 'credit_card_exp_date' => array( | |
1124 | 'M' => 9, | |
1125 | 'Y' => date('Y', strtotime('+5 years')), | |
1126 | ), | |
1127 | 'credit_card_type' => 'Visa', | |
1128 | 'billing_first_name' => 'Junko', | |
1129 | 'billing_middle_name' => '', | |
1130 | 'billing_last_name' => 'Adams', | |
1131 | 'billing_street_address-5' => '790L Lincoln St S', | |
1132 | 'billing_city-5' => 'Maryknoll', | |
1133 | 'billing_state_province_id-5' => 1031, | |
1134 | 'billing_postal_code-5' => 10545, | |
1135 | 'billing_country_id-5' => 1228, | |
1136 | 'frequency_interval' => 1, | |
1137 | 'frequency_unit' => 'month', | |
1138 | 'installments' => '', | |
1139 | 'hidden_AdditionalDetail' => 1, | |
1140 | 'hidden_Premium' => 1, | |
1141 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
1142 | 'receipt_date' => '', | |
1143 | 'receipt_date_time' => '', | |
1144 | 'payment_processor_id' => $this->paymentProcessorID, | |
1145 | 'currency' => 'USD', | |
1146 | 'source' => 'bob sled race', | |
1147 | ), | |
1148 | CRM_Core_Action::ADD | |
1149 | ); | |
1150 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); | |
1151 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); | |
1152 | $financialTrxn = $this->callAPISuccessGetSingle( | |
1153 | 'FinancialTrxn', | |
1154 | array( | |
1155 | 'id' => $lastFinancialTrxnId['financialTrxnId'], | |
1156 | 'return' => array('card_type_id', 'pan_truncation'), | |
1157 | ) | |
1158 | ); | |
016569ee | 1159 | $this->assertEquals($visaID, $financialTrxn['card_type_id']); |
1160 | $this->assertEquals(1111, $financialTrxn['pan_truncation']); | |
a55e39e9 | 1161 | } |
1162 | ||
2dcbf765 | 1163 | } |