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() { | |
c85f1674 | 188 | $mut = new CiviMailUtils($this, TRUE); |
247ce80d | 189 | $mut->clearMessages(); |
f8453bef | 190 | $form = new CRM_Contribute_Form_Contribution(); |
191 | $paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0)); | |
192 | $form->_mode = 'Live'; | |
16f3bd02 | 193 | $error = FALSE; |
f8453bef | 194 | try { |
195 | $form->testSubmit(array( | |
196 | 'total_amount' => 50, | |
197 | 'financial_type_id' => 1, | |
198 | 'receive_date' => '04/21/2015', | |
199 | 'receive_date_time' => '11:27PM', | |
200 | 'contact_id' => $this->_individualId, | |
f8453bef | 201 | 'contribution_status_id' => 1, |
202 | 'credit_card_number' => 4444333322221111, | |
203 | 'cvv2' => 123, | |
204 | 'credit_card_exp_date' => array( | |
205 | 'M' => 9, | |
206 | 'Y' => 2025, | |
207 | ), | |
208 | 'credit_card_type' => 'Visa', | |
209 | 'billing_first_name' => 'Junko', | |
210 | 'billing_middle_name' => '', | |
211 | 'billing_last_name' => 'Adams', | |
212 | 'billing_street_address-5' => '790L Lincoln St S', | |
213 | 'billing_city-5' => 'Maryknoll', | |
214 | 'billing_state_province_id-5' => 1031, | |
215 | 'billing_postal_code-5' => 10545, | |
216 | 'billing_country_id-5' => 1228, | |
217 | 'frequency_interval' => 1, | |
218 | 'frequency_unit' => 'month', | |
219 | 'installments' => '', | |
220 | 'hidden_AdditionalDetail' => 1, | |
221 | 'hidden_Premium' => 1, | |
222 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
c85f1674 | 223 | 'is_email_receipt' => TRUE, |
f8453bef | 224 | 'receipt_date' => '', |
225 | 'receipt_date_time' => '', | |
226 | 'payment_processor_id' => $paymentProcessorID, | |
227 | 'currency' => 'USD', | |
dc0ca56c | 228 | 'source' => 'bob sled race', |
f8453bef | 229 | ), CRM_Core_Action::ADD); |
230 | } | |
231 | catch (Civi\Payment\Exception\PaymentProcessorException $e) { | |
16f3bd02 | 232 | $error = TRUE; |
f8453bef | 233 | } |
632196ea | 234 | |
f8453bef | 235 | $this->callAPISuccessGetCount('Contribution', array( |
236 | 'contact_id' => $this->_individualId, | |
5e67c92d | 237 | 'contribution_status_id' => $error ? 'Failed' : 'Completed', |
16f3bd02 | 238 | 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( |
239 | 'return' => 'payment_instrument_id', | |
240 | 'id' => $paymentProcessorID, | |
241 | )), | |
f8453bef | 242 | ), 1); |
dc0ca56c | 243 | $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); |
48e27df7 | 244 | $this->assertTrue(empty($contact['source'])); |
c85f1674 SL |
245 | if (!$error) { |
246 | $msgs = $mut->getAllMessages(); | |
247 | $this->assertEquals(1, count($msgs)); | |
248 | } | |
247ce80d | 249 | $mut->clearMessages(); |
c85f1674 | 250 | $mut->stop(); |
f8453bef | 251 | } |
252 | ||
bcf19fd7 SL |
253 | /** |
254 | * Test the submit function on the contribution page | |
255 | */ | |
256 | public function testSubmitCreditCardWithEmailReceipt() { | |
257 | $mut = new CiviMailUtils($this, TRUE); | |
247ce80d | 258 | $mut->clearMessages(); |
bcf19fd7 SL |
259 | $form = new CRM_Contribute_Form_Contribution(); |
260 | $form->_mode = 'Live'; | |
261 | $error = FALSE; | |
262 | try { | |
263 | $form->testSubmit(array( | |
264 | 'total_amount' => 50, | |
265 | 'financial_type_id' => 1, | |
266 | 'receive_date' => '04/21/2015', | |
267 | 'receive_date_time' => '11:27PM', | |
268 | 'contact_id' => $this->_individualId, | |
269 | 'contribution_status_id' => 1, | |
270 | 'credit_card_number' => 4444333322221111, | |
271 | 'cvv2' => 123, | |
272 | 'credit_card_exp_date' => array( | |
273 | 'M' => 9, | |
274 | 'Y' => 2025, | |
275 | ), | |
276 | 'credit_card_type' => 'Visa', | |
277 | 'billing_first_name' => 'Junko', | |
278 | 'billing_middle_name' => '', | |
279 | 'billing_last_name' => 'Adams', | |
280 | 'billing_street_address-5' => '790L Lincoln St S', | |
281 | 'billing_city-5' => 'Maryknoll', | |
282 | 'billing_state_province_id-5' => 1031, | |
283 | 'billing_postal_code-5' => 10545, | |
284 | 'billing_country_id-5' => 1228, | |
285 | 'frequency_interval' => 1, | |
286 | 'frequency_unit' => 'month', | |
287 | 'installments' => '', | |
288 | 'hidden_AdditionalDetail' => 1, | |
289 | 'hidden_Premium' => 1, | |
290 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
291 | 'is_email_receipt' => TRUE, | |
292 | 'receipt_date' => '', | |
293 | 'receipt_date_time' => '', | |
294 | 'payment_processor_id' => $this->paymentProcessorID, | |
295 | 'currency' => 'USD', | |
296 | 'source' => 'bob sled race', | |
297 | ), CRM_Core_Action::ADD); | |
298 | } | |
299 | catch (Civi\Payment\Exception\PaymentProcessorException $e) { | |
300 | $error = TRUE; | |
301 | } | |
302 | $this->callAPISuccessGetCount('Contribution', array( | |
303 | 'contact_id' => $this->_individualId, | |
304 | 'contribution_status_id' => $error ? 'Failed' : 'Completed', | |
305 | 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( | |
306 | 'return' => 'payment_instrument_id', | |
307 | 'id' => $this->paymentProcessorID, | |
308 | )), | |
309 | ), 1); | |
310 | $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); | |
311 | $this->assertTrue(empty($contact['source'])); | |
312 | $msgs = $mut->getAllMessages(); | |
313 | $this->assertEquals(1, count($msgs)); | |
314 | $mut->stop(); | |
315 | } | |
316 | ||
317 | ||
8188f8ec SL |
318 | /** |
319 | * Test the submit function on the contribution page. | |
320 | */ | |
321 | public function testSubmitCreditCardNoReceipt() { | |
322 | $mut = new CiviMailUtils($this, TRUE); | |
aaf44e0b | 323 | $mut->clearMessages(); |
8188f8ec | 324 | $form = new CRM_Contribute_Form_Contribution(); |
8188f8ec SL |
325 | $form->_mode = 'Live'; |
326 | $error = FALSE; | |
327 | try { | |
328 | $form->testSubmit(array( | |
329 | 'total_amount' => 60, | |
330 | 'financial_type_id' => 1, | |
331 | 'receive_date' => '04/21/2015', | |
332 | 'receive_date_time' => '11:27PM', | |
333 | 'contact_id' => $this->_individualId, | |
334 | 'contribution_status_id' => 1, | |
335 | 'credit_card_number' => 4444333322221111, | |
336 | 'cvv2' => 123, | |
337 | 'credit_card_exp_date' => array( | |
338 | 'M' => 9, | |
339 | 'Y' => 2025, | |
340 | ), | |
341 | 'credit_card_type' => 'Visa', | |
342 | 'billing_first_name' => 'Junko', | |
343 | 'billing_middle_name' => '', | |
344 | 'billing_last_name' => 'Adams', | |
345 | 'billing_street_address-5' => '790L Lincoln St S', | |
346 | 'billing_city-5' => 'Maryknoll', | |
347 | 'billing_state_province_id-5' => 1031, | |
348 | 'billing_postal_code-5' => 10545, | |
349 | 'billing_country_id-5' => 1228, | |
350 | 'frequency_interval' => 1, | |
351 | 'frequency_unit' => 'month', | |
352 | 'installments' => '', | |
353 | 'hidden_AdditionalDetail' => 1, | |
354 | 'hidden_Premium' => 1, | |
355 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
aaf44e0b | 356 | 'is_email_receipt' => FALSE, |
8188f8ec SL |
357 | 'receipt_date' => '', |
358 | 'receipt_date_time' => '', | |
bcf19fd7 | 359 | 'payment_processor_id' => $this->paymentProcessorID, |
8188f8ec SL |
360 | 'currency' => 'USD', |
361 | 'source' => 'bob sled race', | |
362 | ), CRM_Core_Action::ADD); | |
363 | } | |
364 | catch (Civi\Payment\Exception\PaymentProcessorException $e) { | |
365 | $error = TRUE; | |
366 | } | |
367 | ||
368 | $this->callAPISuccessGetCount('Contribution', array( | |
369 | 'contact_id' => $this->_individualId, | |
370 | 'contribution_status_id' => $error ? 'Failed' : 'Completed', | |
371 | 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( | |
372 | 'return' => 'payment_instrument_id', | |
bcf19fd7 | 373 | 'id' => $this->paymentProcessorID, |
8188f8ec SL |
374 | )), |
375 | ), 1); | |
376 | $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId)); | |
377 | $this->assertTrue(empty($contact['source'])); | |
378 | $mut->assertMailLogEmpty(); | |
379 | $mut->stop(); | |
380 | } | |
381 | ||
22e39333 | 382 | /** |
383 | * Test the submit function on the contribution page. | |
384 | */ | |
385 | public function testSubmitCreditCardFee() { | |
386 | $form = new CRM_Contribute_Form_Contribution(); | |
22e39333 | 387 | $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08)); |
388 | $form->_mode = 'Live'; | |
389 | $form->testSubmit(array( | |
390 | 'total_amount' => 50, | |
391 | 'financial_type_id' => 1, | |
392 | 'receive_date' => '04/21/2015', | |
393 | 'receive_date_time' => '11:27PM', | |
394 | 'contact_id' => $this->_individualId, | |
395 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
396 | 'contribution_status_id' => 1, | |
397 | 'credit_card_number' => 4444333322221111, | |
398 | 'cvv2' => 123, | |
399 | 'credit_card_exp_date' => array( | |
400 | 'M' => 9, | |
401 | 'Y' => 2025, | |
402 | ), | |
403 | 'credit_card_type' => 'Visa', | |
404 | 'billing_first_name' => 'Junko', | |
405 | 'billing_middle_name' => '', | |
406 | 'billing_last_name' => 'Adams', | |
407 | 'billing_street_address-5' => '790L Lincoln St S', | |
408 | 'billing_city-5' => 'Maryknoll', | |
409 | 'billing_state_province_id-5' => 1031, | |
410 | 'billing_postal_code-5' => 10545, | |
411 | 'billing_country_id-5' => 1228, | |
412 | 'frequency_interval' => 1, | |
413 | 'frequency_unit' => 'month', | |
414 | 'installments' => '', | |
415 | 'hidden_AdditionalDetail' => 1, | |
416 | 'hidden_Premium' => 1, | |
417 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
418 | 'receipt_date' => '', | |
419 | 'receipt_date_time' => '', | |
420 | 'payment_processor_id' => $this->paymentProcessorID, | |
421 | 'currency' => 'USD', | |
422 | 'source' => '', | |
423 | ), CRM_Core_Action::ADD); | |
424 | ||
425 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
426 | 'contact_id' => $this->_individualId, | |
427 | 'contribution_status_id' => 'Completed', | |
428 | )); | |
429 | $this->assertEquals('50', $contribution['total_amount']); | |
430 | $this->assertEquals(.08, $contribution['fee_amount']); | |
431 | $this->assertEquals(49.92, $contribution['net_amount']); | |
432 | $this->assertEquals('tx', $contribution['trxn_id']); | |
2b308818 | 433 | $this->assertEmpty($contribution['amount_level']); |
22e39333 | 434 | } |
435 | ||
11829025 JMW |
436 | /** |
437 | * Test a fully deductible contribution submitted by credit card (CRM-16669). | |
438 | */ | |
439 | public function testSubmitCreditCardFullyDeductible() { | |
440 | $form = new CRM_Contribute_Form_Contribution(); | |
441 | $form->_mode = 'Live'; | |
442 | $form->testSubmit(array( | |
443 | 'total_amount' => 50, | |
444 | 'financial_type_id' => 1, | |
445 | 'receive_date' => '04/21/2015', | |
446 | 'receive_date_time' => '11:27PM', | |
447 | 'contact_id' => $this->_individualId, | |
448 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
449 | 'contribution_status_id' => 1, | |
450 | 'credit_card_number' => 4444333322221111, | |
451 | 'cvv2' => 123, | |
452 | 'credit_card_exp_date' => array( | |
453 | 'M' => 9, | |
454 | 'Y' => 2025, | |
455 | ), | |
456 | 'credit_card_type' => 'Visa', | |
457 | 'billing_first_name' => 'Junko', | |
458 | 'billing_middle_name' => '', | |
459 | 'billing_last_name' => 'Adams', | |
460 | 'billing_street_address-5' => '790L Lincoln St S', | |
461 | 'billing_city-5' => 'Maryknoll', | |
462 | 'billing_state_province_id-5' => 1031, | |
463 | 'billing_postal_code-5' => 10545, | |
464 | 'billing_country_id-5' => 1228, | |
465 | 'frequency_interval' => 1, | |
466 | 'frequency_unit' => 'month', | |
467 | 'installments' => '', | |
468 | 'hidden_AdditionalDetail' => 1, | |
469 | 'hidden_Premium' => 1, | |
470 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
471 | 'receipt_date' => '', | |
472 | 'receipt_date_time' => '', | |
473 | 'payment_processor_id' => $this->paymentProcessorID, | |
474 | 'currency' => 'USD', | |
475 | 'source' => '', | |
476 | ), CRM_Core_Action::ADD); | |
477 | ||
478 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
479 | 'contact_id' => $this->_individualId, | |
480 | 'contribution_status_id' => 'Completed', | |
481 | )); | |
482 | $this->assertEquals('50', $contribution['total_amount']); | |
483 | $this->assertEquals(0, $contribution['non_deductible_amount']); | |
484 | } | |
485 | ||
7126b55c | 486 | /** |
7758bd2b EM |
487 | * Test the submit function with an invalid payment. |
488 | * | |
489 | * We expect the contribution to be created but left pending. The payment has failed. | |
490 | * | |
491 | * Test covers CRM-16417 change to keep failed transactions. | |
492 | * | |
493 | * We are left with | |
494 | * - 1 Contribution with status = Pending | |
495 | * - 1 Line item | |
496 | * - 1 civicrm_financial_item. This is linked to the line item and has a status of 3 | |
7126b55c | 497 | */ |
7758bd2b | 498 | public function testSubmitCreditCardInvalid() { |
7126b55c | 499 | $form = new CRM_Contribute_Form_Contribution(); |
7758bd2b EM |
500 | $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1)); |
501 | try { | |
502 | $form->testSubmit(array( | |
503 | 'total_amount' => 50, | |
504 | 'financial_type_id' => 1, | |
505 | 'receive_date' => '04/21/2015', | |
506 | 'receive_date_time' => '11:27PM', | |
507 | 'contact_id' => $this->_individualId, | |
508 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 509 | 'payment_processor_id' => $this->paymentProcessorID, |
7758bd2b EM |
510 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), |
511 | 'credit_card_number' => '411111111111111', | |
512 | ), CRM_Core_Action::ADD, | |
739a8336 | 513 | 'live' |
514 | ); | |
7758bd2b EM |
515 | } |
516 | catch (\Civi\Payment\Exception\PaymentProcessorException $e) { | |
40f5ec68 EM |
517 | $this->callAPISuccessGetCount('Contribution', array( |
518 | 'contact_id' => $this->_individualId, | |
382c5680 | 519 | 'contribution_status_id' => 'Failed', |
40f5ec68 | 520 | ), 1); |
7758bd2b EM |
521 | $lineItem = $this->callAPISuccessGetSingle('line_item', array()); |
522 | $this->assertEquals('50.00', $lineItem['unit_price']); | |
523 | $this->assertEquals('50.00', $lineItem['line_total']); | |
524 | $this->assertEquals(1, $lineItem['qty']); | |
525 | $this->assertEquals(1, $lineItem['financial_type_id']); | |
526 | $financialItem = $this->callAPISuccessGetSingle('financial_item', array( | |
527 | 'civicrm_line_item' => $lineItem['id'], | |
528 | 'entity_id' => $lineItem['id'], | |
529 | )); | |
530 | $this->assertEquals('50.00', $financialItem['amount']); | |
531 | $this->assertEquals(3, $financialItem['status_id']); | |
532 | return; | |
533 | } | |
534 | $this->fail('An expected exception has not been raised.'); | |
7126b55c EM |
535 | } |
536 | ||
739a8336 | 537 | /** |
538 | * Test the submit function creates a billing address if provided. | |
539 | */ | |
540 | public function testSubmitCreditCardWithBillingAddress() { | |
541 | $form = new CRM_Contribute_Form_Contribution(); | |
542 | $form->testSubmit(array( | |
543 | 'total_amount' => 50, | |
544 | 'financial_type_id' => 1, | |
545 | 'receive_date' => '04/21/2015', | |
546 | 'receive_date_time' => '11:27PM', | |
547 | 'contact_id' => $this->_individualId, | |
548 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 549 | 'payment_processor_id' => $this->paymentProcessorID, |
739a8336 | 550 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), |
551 | 'credit_card_number' => '411111111111111', | |
552 | 'billing_city-5' => 'Vancouver', | |
553 | ), CRM_Core_Action::ADD, | |
554 | 'live' | |
555 | ); | |
556 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); | |
557 | $this->assertNotEmpty($contribution['address_id']); | |
989a6bb8 | 558 | // CRM-18490 : There is a unwanted test leakage due to below getsingle Api as it only fails in Jenkin |
559 | // for now we are only fetching address on based on Address ID (removed filter location_type_id and city) | |
739a8336 | 560 | $this->callAPISuccessGetSingle('Address', array( |
739a8336 | 561 | 'id' => $contribution['address_id'], |
562 | )); | |
3d4e6ffa | 563 | } |
739a8336 | 564 | |
3d4e6ffa JP |
565 | /** |
566 | * CRM-20745: Test the submit function correctly sets the | |
567 | * receive date for recurring contribution. | |
568 | */ | |
569 | public function testSubmitCreditCardWithRecur() { | |
570 | $form = new CRM_Contribute_Form_Contribution(); | |
571 | $receiveDate = date('m/d/Y', strtotime('+1 month')); | |
572 | $form->testSubmit(array( | |
573 | 'total_amount' => 50, | |
574 | 'financial_type_id' => 1, | |
575 | 'is_recur' => 1, | |
576 | 'frequency_interval' => 2, | |
577 | 'frequency_unit' => 'month', | |
578 | 'installments' => 2, | |
579 | 'receive_date' => $receiveDate, | |
580 | 'receive_date_time' => '11:27PM', | |
581 | 'contact_id' => $this->_individualId, | |
582 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
583 | 'payment_processor_id' => $this->paymentProcessorID, | |
584 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), | |
585 | 'credit_card_number' => '411111111111111', | |
586 | 'billing_city-5' => 'Vancouver', | |
587 | ), CRM_Core_Action::ADD, | |
588 | 'live' | |
589 | ); | |
590 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'receive_date')); | |
591 | $this->assertEquals(date("m/d/Y", strtotime($contribution['receive_date'])), $receiveDate); | |
739a8336 | 592 | } |
593 | ||
594 | /** | |
595 | * Test the submit function does not create a billing address if no details provided. | |
596 | */ | |
597 | public function testSubmitCreditCardWithNoBillingAddress() { | |
598 | $form = new CRM_Contribute_Form_Contribution(); | |
599 | $form->testSubmit(array( | |
600 | 'total_amount' => 50, | |
601 | 'financial_type_id' => 1, | |
602 | 'receive_date' => '04/21/2015', | |
603 | 'receive_date_time' => '11:27PM', | |
604 | 'contact_id' => $this->_individualId, | |
605 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
22e39333 | 606 | 'payment_processor_id' => $this->paymentProcessorID, |
739a8336 | 607 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), |
608 | 'credit_card_number' => '411111111111111', | |
609 | ), CRM_Core_Action::ADD, | |
610 | 'live' | |
611 | ); | |
612 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); | |
613 | $this->assertEmpty($contribution['address_id']); | |
614 | $this->callAPISuccessGetCount('Address', array( | |
615 | 'city' => 'Vancouver', | |
616 | 'location_type_id' => 5, | |
617 | ), 0); | |
739a8336 | 618 | } |
619 | ||
a084385f EM |
620 | /** |
621 | * Test the submit function on the contribution page. | |
622 | */ | |
623 | public function testSubmitEmailReceipt() { | |
624 | $form = new CRM_Contribute_Form_Contribution(); | |
a084385f EM |
625 | $mut = new CiviMailUtils($this, TRUE); |
626 | $form->testSubmit(array( | |
627 | 'total_amount' => 50, | |
628 | 'financial_type_id' => 1, | |
629 | 'receive_date' => '04/21/2015', | |
630 | 'receive_date_time' => '11:27PM', | |
631 | 'contact_id' => $this->_individualId, | |
632 | 'is_email_receipt' => TRUE, | |
633 | 'from_email_address' => 'test@test.com', | |
5e27919e | 634 | 'contribution_status_id' => 1, |
31760f81 | 635 | ), CRM_Core_Action::ADD); |
a084385f EM |
636 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); |
637 | $mut->checkMailLog(array( | |
638 | '<p>Please print this receipt for your records.</p>', | |
639 | ) | |
640 | ); | |
641 | $mut->stop(); | |
642 | } | |
df729ab1 | 643 | |
0335c5f1 | 644 | /** |
645 | * Ensure that price field are shown during pay later/pending Contribution | |
646 | */ | |
647 | public function testEmailReceiptOnPayLater() { | |
648 | $donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name'); | |
649 | $paramsSet = array( | |
650 | 'title' => 'Price Set' . substr(sha1(rand()), 0, 4), | |
651 | 'is_active' => TRUE, | |
652 | 'financial_type_id' => $donationFT, | |
653 | 'extends' => 2, | |
654 | ); | |
655 | $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); | |
656 | ||
657 | $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); | |
658 | $priceSetId = $priceset->id; | |
659 | ||
660 | //Checking for priceset added in the table. | |
661 | $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', | |
662 | 'id', $paramsSet['title'], 'Check DB for created priceset' | |
663 | ); | |
664 | $paramsField = array( | |
665 | 'label' => 'Price Field', | |
666 | 'name' => CRM_Utils_String::titleToVar('Price Field'), | |
667 | 'html_type' => 'CheckBox', | |
668 | 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), | |
669 | 'option_value' => array('1' => 100, '2' => 200), | |
670 | 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), | |
671 | 'option_weight' => array('1' => 1, '2' => 2), | |
672 | 'option_amount' => array('1' => 100, '2' => 200), | |
673 | 'is_display_amounts' => 1, | |
674 | 'weight' => 1, | |
675 | 'options_per_line' => 1, | |
676 | 'is_active' => array('1' => 1, '2' => 1), | |
677 | 'price_set_id' => $priceset->id, | |
678 | 'is_enter_qty' => 1, | |
679 | 'financial_type_id' => $donationFT, | |
680 | ); | |
681 | $priceField = CRM_Price_BAO_PriceField::create($paramsField); | |
682 | $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); | |
683 | ||
684 | $params = array( | |
685 | 'total_amount' => 100, | |
686 | 'financial_type_id' => $donationFT, | |
687 | 'receive_date' => '04/21/2015', | |
688 | 'receive_date_time' => '11:27PM', | |
689 | 'contact_id' => $this->_individualId, | |
690 | 'is_email_receipt' => TRUE, | |
691 | 'from_email_address' => 'test@test.com', | |
692 | 'price_set_id' => $priceSetId, | |
f527e012 | 693 | 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), |
0335c5f1 | 694 | ); |
695 | ||
696 | foreach ($priceFieldValue['values'] as $id => $price) { | |
697 | if ($price['amount'] == 100) { | |
698 | $params['price_' . $priceField->id] = array($id => 1); | |
699 | } | |
700 | } | |
701 | $form = new CRM_Contribute_Form_Contribution(); | |
702 | $mut = new CiviMailUtils($this, TRUE); | |
703 | $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); | |
704 | $form->testSubmit($params, CRM_Core_Action::ADD); | |
705 | ||
706 | $mut->checkMailLog(array( | |
707 | 'Financial Type: Donation | |
708 | --------------------------------------------------------- | |
709 | Item Qty Each Total | |
710 | ---------------------------------------------------------- | |
711 | Price Field - Price Field 1 1 $ 100.00 $ 100.00 | |
712 | ', | |
713 | ) | |
714 | ); | |
715 | $mut->stop(); | |
716 | } | |
717 | ||
31760f81 EM |
718 | /** |
719 | * Test that a contribution is assigned against a pledge. | |
720 | */ | |
721 | public function testUpdatePledge() { | |
722 | $pledge = $this->callAPISuccess('pledge', 'create', array( | |
723 | 'contact_id' => $this->_individualId, | |
724 | 'pledge_create_date' => date('Ymd'), | |
725 | 'start_date' => date('Ymd'), | |
726 | 'amount' => 100.00, | |
727 | 'pledge_status_id' => '2', | |
728 | 'pledge_financial_type_id' => '1', | |
729 | 'pledge_original_installment_amount' => 20, | |
730 | 'frequency_interval' => 5, | |
731 | 'frequency_unit' => 'year', | |
732 | 'frequency_day' => 15, | |
733 | 'installments' => 2, | |
734 | 'sequential' => 1, | |
735 | )); | |
736 | $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array( | |
737 | 'pledge_id' => $pledge['id'], | |
738 | 'options' => array('limit' => 1), | |
739 | 'return' => 'id', | |
740 | )); | |
741 | $form = new CRM_Contribute_Form_Contribution(); | |
742 | $form->testSubmit(array( | |
743 | 'total_amount' => 50, | |
744 | 'financial_type_id' => 1, | |
745 | 'receive_date' => '04/21/2015', | |
746 | 'receive_date_time' => '11:27PM', | |
747 | 'contact_id' => $this->_individualId, | |
748 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
749 | 'pledge_payment_id' => $pledgePaymentID, | |
5e27919e | 750 | 'contribution_status_id' => 1, |
31760f81 EM |
751 | ), CRM_Core_Action::ADD); |
752 | $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID)); | |
753 | $this->assertNotEmpty($pledgePayment['contribution_id']); | |
754 | $this->assertEquals($pledgePayment['actual_amount'], 50); | |
755 | $this->assertEquals(1, $pledgePayment['status_id']); | |
756 | } | |
ef353929 | 757 | |
3e6a1f4a EM |
758 | /** |
759 | * Test functions involving premiums. | |
760 | */ | |
761 | public function testPremiumUpdate() { | |
762 | $form = new CRM_Contribute_Form_Contribution(); | |
43bf07d6 | 763 | $mut = new CiviMailUtils($this, TRUE); |
3e6a1f4a EM |
764 | $form->testSubmit(array( |
765 | 'total_amount' => 50, | |
766 | 'financial_type_id' => 1, | |
767 | 'receive_date' => '04/21/2015', | |
768 | 'receive_date_time' => '11:27PM', | |
769 | 'contact_id' => $this->_individualId, | |
770 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
771 | 'contribution_status_id' => 1, | |
772 | 'product_name' => array($this->products[0]['id'], 1), | |
773 | 'fulfilled_date' => '', | |
43bf07d6 EM |
774 | 'is_email_receipt' => TRUE, |
775 | 'from_email_address' => 'test@test.com', | |
3e6a1f4a EM |
776 | ), CRM_Core_Action::ADD); |
777 | $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); | |
778 | $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); | |
43bf07d6 EM |
779 | $mut->checkMailLog(array( |
780 | 'Premium Information', | |
781 | 'Smurf', | |
782 | 'clumsy smurf', | |
783 | )); | |
784 | $mut->stop(); | |
3e6a1f4a EM |
785 | } |
786 | ||
39f47c0d EM |
787 | /** |
788 | * Test functions involving premiums. | |
789 | */ | |
790 | public function testPremiumUpdateCreditCard() { | |
791 | $form = new CRM_Contribute_Form_Contribution(); | |
792 | $mut = new CiviMailUtils($this, TRUE); | |
793 | $form->testSubmit(array( | |
794 | 'total_amount' => 50, | |
795 | 'financial_type_id' => 1, | |
796 | 'receive_date' => '04/21/2015', | |
797 | 'receive_date_time' => '11:27PM', | |
798 | 'contact_id' => $this->_individualId, | |
799 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
800 | 'contribution_status_id' => 1, | |
801 | 'product_name' => array($this->products[0]['id'], 1), | |
802 | 'fulfilled_date' => '', | |
803 | 'is_email_receipt' => TRUE, | |
804 | 'from_email_address' => 'test@test.com', | |
22e39333 | 805 | 'payment_processor_id' => $this->paymentProcessorID, |
7758bd2b | 806 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026), |
39f47c0d EM |
807 | 'credit_card_number' => '411111111111111', |
808 | ), CRM_Core_Action::ADD, | |
809 | 'live'); | |
810 | $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); | |
811 | $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); | |
812 | $mut->checkMailLog(array( | |
813 | 'Premium Information', | |
814 | 'Smurf', | |
815 | 'clumsy smurf', | |
816 | )); | |
817 | $mut->stop(); | |
818 | } | |
819 | ||
945f423d EM |
820 | /** |
821 | * Test the submit function on the contribution page. | |
822 | */ | |
823 | public function testSubmitWithNote() { | |
824 | $form = new CRM_Contribute_Form_Contribution(); | |
825 | $form->testSubmit(array( | |
826 | 'total_amount' => 50, | |
827 | 'financial_type_id' => 1, | |
828 | 'receive_date' => '04/21/2015', | |
829 | 'receive_date_time' => '11:27PM', | |
830 | 'contact_id' => $this->_individualId, | |
831 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
832 | 'contribution_status_id' => 1, | |
833 | 'note' => 'Super cool and interesting stuff', | |
834 | ), | |
835 | CRM_Core_Action::ADD); | |
836 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
837 | $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); | |
838 | $this->assertEquals($note['note'], 'Super cool and interesting stuff'); | |
839 | } | |
840 | ||
841 | /** | |
842 | * Test the submit function on the contribution page. | |
843 | */ | |
844 | public function testSubmitWithNoteCreditCard() { | |
845 | $form = new CRM_Contribute_Form_Contribution(); | |
846 | ||
847 | $form->testSubmit(array( | |
848 | 'total_amount' => 50, | |
849 | 'financial_type_id' => 1, | |
850 | 'receive_date' => '04/21/2015', | |
851 | 'receive_date_time' => '11:27PM', | |
852 | 'contact_id' => $this->_individualId, | |
853 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
854 | 'contribution_status_id' => 1, | |
855 | 'note' => 'Super cool and interesting stuff', | |
1ea0b4ac | 856 | ) + $this->getCreditCardParams(), |
945f423d EM |
857 | CRM_Core_Action::ADD); |
858 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
859 | $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); | |
860 | $this->assertEquals($note['note'], 'Super cool and interesting stuff'); | |
861 | } | |
862 | ||
fa18b745 | 863 | /** |
71a3f5f9 | 864 | * Test that if a negative contribution is entered it does not get reset to $0. |
865 | * | |
866 | * Note that this fails locally for me & I believe there may be an issue for some sites | |
867 | * with negative numbers. Grep for CRM-16460 to find the places I think that might | |
868 | * be affected if you hit this. | |
fa18b745 K |
869 | */ |
870 | public function testEnterNegativeContribution() { | |
871 | $form = new CRM_Contribute_Form_Contribution(); | |
872 | $form->testSubmit(array( | |
873 | 'total_amount' => -5, | |
874 | 'financial_type_id' => 1, | |
875 | 'receive_date' => '04/24/2016', | |
876 | 'receive_date_time' => '11:27PM', | |
877 | 'contact_id' => $this->_individualId, | |
878 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
879 | 'contribution_status_id' => 1, | |
880 | ), | |
881 | CRM_Core_Action::ADD); | |
882 | $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); | |
883 | ||
884 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
885 | 'contact_id' => $this->_individualId, | |
886 | )); | |
887 | $this->assertEquals(-5, $contribution['total_amount']); | |
888 | } | |
889 | ||
55e55e84 | 890 | /** |
891 | * Test the submit function on the contribution page. | |
892 | */ | |
893 | public function testSubmitUpdate() { | |
894 | $form = new CRM_Contribute_Form_Contribution(); | |
895 | ||
896 | $form->testSubmit(array( | |
897 | 'total_amount' => 50, | |
898 | 'financial_type_id' => 1, | |
899 | 'receive_date' => '04/21/2015', | |
900 | 'receive_date_time' => '11:27PM', | |
901 | 'contact_id' => $this->_individualId, | |
902 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
903 | 'contribution_status_id' => 1, | |
904 | 'price_set_id' => 0, | |
905 | ), | |
906 | CRM_Core_Action::ADD); | |
907 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); | |
908 | $form->testSubmit(array( | |
909 | 'total_amount' => 45, | |
910 | 'net_amount' => 45, | |
911 | 'financial_type_id' => 1, | |
912 | 'receive_date' => '04/21/2015', | |
913 | 'receive_date_time' => '11:27PM', | |
914 | 'contact_id' => $this->_individualId, | |
915 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
916 | 'contribution_status_id' => 1, | |
917 | 'price_set_id' => 0, | |
918 | 'id' => $contribution['id'], | |
919 | ), | |
920 | CRM_Core_Action::UPDATE); | |
da77cbbd EM |
921 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); |
922 | $this->assertEquals(45, (int) $contribution['total_amount']); | |
923 | ||
55e55e84 | 924 | $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE)); |
925 | $this->assertEquals(2, $financialTransactions['count']); | |
926 | $this->assertEquals(50, $financialTransactions['values'][0]['total_amount']); | |
a4ed7706 EM |
927 | $this->assertEquals(-5, $financialTransactions['values'][1]['total_amount']); |
928 | $this->assertEquals(-5, $financialTransactions['values'][1]['net_amount']); | |
55e55e84 | 929 | $lineItem = $this->callAPISuccessGetSingle('LineItem', array()); |
930 | $this->assertEquals(45, $lineItem['line_total']); | |
931 | } | |
932 | ||
945f423d EM |
933 | /** |
934 | * Get parameters for credit card submit calls. | |
935 | * | |
936 | * @return array | |
937 | * Credit card specific parameters. | |
938 | */ | |
1ea0b4ac | 939 | protected function getCreditCardParams() { |
945f423d | 940 | return array( |
22e39333 | 941 | 'payment_processor_id' => $this->paymentProcessorID, |
945f423d EM |
942 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), |
943 | 'credit_card_number' => '411111111111111', | |
944 | ); | |
945 | } | |
945f423d | 946 | |
9beed6cf PN |
947 | /** |
948 | * Test the submit function that completes the partially paid payment using Credit Card | |
949 | */ | |
950 | public function testPartialPaymentWithCreditCard() { | |
951 | // create a partially paid contribution by using back-office form | |
952 | $form = new CRM_Contribute_Form_Contribution(); | |
953 | $form->testSubmit( | |
954 | array( | |
955 | 'total_amount' => 50, | |
956 | 'financial_type_id' => 1, | |
957 | 'receive_date' => '04/21/2015', | |
958 | 'receive_date_time' => '11:27PM', | |
959 | 'contact_id' => $this->_individualId, | |
960 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
961 | 'check_number' => substr(sha1(rand()), 0, 7), | |
962 | 'billing_city-5' => 'Vancouver', | |
963 | 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'), | |
964 | ), CRM_Core_Action::ADD | |
965 | ); | |
966 | ||
967 | $contribution = $this->callAPISuccessGetSingle('Contribution', array()); | |
968 | $this->assertNotEmpty($contribution); | |
969 | $this->assertEquals('Partially paid', $contribution['contribution_status']); | |
970 | // pay additional amount by using Credit Card | |
971 | $form = new CRM_Contribute_Form_AdditionalPayment(); | |
972 | $form->testSubmit(array( | |
973 | 'contribution_id' => $contribution['id'], | |
974 | 'contact_id' => $this->_individualId, | |
975 | 'total_amount' => 50, | |
976 | 'currency' => 'USD', | |
977 | 'financial_type_id' => 1, | |
978 | 'receive_date' => '04/21/2015', | |
979 | 'receive_date_time' => '11:27PM', | |
980 | 'contact_id' => $this->_individualId, | |
981 | 'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments), | |
982 | 'payment_processor_id' => $this->paymentProcessorID, | |
983 | 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), | |
984 | 'credit_card_number' => '411111111111111', | |
985 | 'cvv2' => 234, | |
986 | 'credit_card_type' => 'Visa', | |
987 | 'billing_city-5' => 'Vancouver', | |
988 | 'billing_state_province_id-5' => 1059, | |
989 | 'billing_postal_code-5' => 1321312, | |
990 | 'billing_country_id-5' => 1228, | |
991 | 'trxn_date' => '2017-04-11 13:05:11', | |
992 | ), 'live'); | |
993 | $contribution = $this->callAPISuccessGetSingle('Contribution', array()); | |
994 | $this->assertNotEmpty($contribution); | |
995 | $this->assertEquals('Completed', $contribution['contribution_status']); | |
996 | } | |
997 | ||
7a1f3919 PN |
998 | /** |
999 | * Test the submit function for FT with tax. | |
1000 | */ | |
1001 | public function testSubmitSaleTax() { | |
1002 | $this->enableTaxAndInvoicing(); | |
1003 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
1004 | $form = new CRM_Contribute_Form_Contribution(); | |
1005 | ||
1006 | $form->testSubmit(array( | |
1007 | 'total_amount' => 100, | |
1008 | 'financial_type_id' => $this->_financialTypeId, | |
1009 | 'receive_date' => '04/21/2015', | |
1010 | 'receive_date_time' => '11:27PM', | |
1011 | 'contact_id' => $this->_individualId, | |
1012 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
1013 | 'contribution_status_id' => 1, | |
1014 | 'price_set_id' => 0, | |
1015 | ), | |
1016 | CRM_Core_Action::ADD | |
1017 | ); | |
1018 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1019 | array( | |
1020 | 'contact_id' => $this->_individualId, | |
1021 | 'return' => array('tax_amount', 'total_amount'), | |
1022 | ) | |
1023 | ); | |
1024 | $this->assertEquals(110, $contribution['total_amount']); | |
1025 | $this->assertEquals(10, $contribution['tax_amount']); | |
1026 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); | |
1027 | $this->callAPISuccessGetCount('FinancialItem', array(), 2); | |
1028 | $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); | |
1029 | $this->assertEquals(100, $lineItem['line_total']); | |
1030 | $this->assertEquals(10, $lineItem['tax_amount']); | |
1031 | } | |
1032 | ||
1ec04220 PN |
1033 | /** |
1034 | * Test the submit function for FT without tax. | |
1035 | */ | |
1036 | public function testSubmitWithOutSaleTax() { | |
1037 | $this->enableTaxAndInvoicing(); | |
1038 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
1039 | $form = new CRM_Contribute_Form_Contribution(); | |
1040 | ||
1041 | $form->testSubmit(array( | |
1042 | 'total_amount' => 100, | |
1043 | 'financial_type_id' => 3, | |
1044 | 'receive_date' => '04/21/2015', | |
1045 | 'receive_date_time' => '11:27PM', | |
1046 | 'contact_id' => $this->_individualId, | |
1047 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
1048 | 'contribution_status_id' => 1, | |
1049 | 'price_set_id' => 0, | |
1050 | ), | |
1051 | CRM_Core_Action::ADD | |
1052 | ); | |
1053 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1054 | array( | |
1055 | 'contact_id' => $this->_individualId, | |
1056 | 'return' => array('tax_amount', 'total_amount'), | |
1057 | ) | |
1058 | ); | |
1059 | $this->assertEquals(100, $contribution['total_amount']); | |
1060 | $this->assertEquals(NULL, $contribution['tax_amount']); | |
1061 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); | |
1062 | $this->callAPISuccessGetCount('FinancialItem', array(), 1); | |
1063 | $lineItem = $this->callAPISuccessGetSingle( | |
1064 | 'LineItem', | |
1065 | array( | |
1066 | 'contribution_id' => $contribution['id'], | |
1067 | 'return' => array('line_total', 'tax_amount'), | |
1068 | ) | |
1069 | ); | |
1070 | $this->assertEquals(100, $lineItem['line_total']); | |
1071 | $this->assertTrue(empty($lineItem['tax_amount'])); | |
1072 | } | |
1073 | ||
f1662cbd | 1074 | /** |
9308f1c2 | 1075 | * Create a contribution & then edit it via backoffice form, checking tax with: default price_set |
f1662cbd | 1076 | * |
1077 | * @throws \Exception | |
1078 | */ | |
335c41e7 | 1079 | public function testReSubmitSaleTax() { |
335c41e7 K |
1080 | $this->enableTaxAndInvoicing(); |
1081 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
cf28d075 | 1082 | list($form, $contribution) = $this->doInitialSubmit(); |
1083 | $this->assertEquals(110, $contribution['total_amount']); | |
1084 | $this->assertEquals(10, $contribution['tax_amount']); | |
1085 | $this->assertEquals(110, $contribution['net_amount']); | |
335c41e7 | 1086 | |
cf28d075 | 1087 | $mut = new CiviMailUtils($this, TRUE); |
1088 | // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: | |
335c41e7 | 1089 | $form->testSubmit(array( |
cf28d075 | 1090 | 'id' => $contribution['id'], |
1091 | 'tax_amount' => $contribution['tax_amount'], | |
1092 | 'financial_type_id' => $contribution['financial_type_id'], | |
1093 | 'receive_date' => $contribution['receive_date'], | |
1094 | 'payment_instrument_id' => $contribution['payment_instrument_id'], | |
335c41e7 | 1095 | 'price_set_id' => 0, |
cf28d075 | 1096 | 'check_number' => 12345, |
1097 | 'contribution_status_id' => 1, | |
1098 | 'is_email_receipt' => 1, | |
1099 | 'from_email_address' => 'demo@example.com', | |
335c41e7 | 1100 | ), |
cf28d075 | 1101 | CRM_Core_Action::UPDATE |
335c41e7 K |
1102 | ); |
1103 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1104 | array( | |
1105 | 'contribution_id' => 1, | |
1106 | 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), | |
1107 | ) | |
1108 | ); | |
f1662cbd | 1109 | $this->assertEquals(110, $contribution['total_amount']); |
1110 | $this->assertEquals(10, $contribution['tax_amount']); | |
9308f1c2 | 1111 | $this->assertEquals(110, $contribution['net_amount']); |
335c41e7 | 1112 | |
cf28d075 | 1113 | $strings = array( |
1114 | 'Total Tax Amount : $ 10.00', | |
1115 | 'Total Amount : $ 110.00', | |
1116 | 'Date Received: April 21st, 2015', | |
1117 | 'Paid By: Check', | |
1118 | 'Check Number: 12345', | |
1119 | ); | |
1120 | ||
1121 | $mut->checkMailLog($strings); | |
1122 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 3); | |
1123 | $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); | |
1124 | $this->assertEquals(2, $items['count']); | |
1125 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
1126 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
1127 | ||
1128 | $this->assertEquals(100, $items['values'][0]['amount']); | |
1129 | $this->assertEquals(10, $items['values'][1]['amount']); | |
1130 | } | |
1131 | ||
1132 | /** | |
1133 | * Create a contribution & then edit it via backoffice form, checking tax with: default price_set | |
1134 | * | |
1135 | * @throws \Exception | |
1136 | */ | |
1137 | public function testReSubmitSaleTaxAlteredAmount() { | |
1138 | $this->enableTaxAndInvoicing(); | |
1139 | $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); | |
1140 | list($form, $contribution) = $this->doInitialSubmit(); | |
1141 | ||
f1662cbd | 1142 | $mut = new CiviMailUtils($this, TRUE); |
9308f1c2 | 1143 | // Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same: |
335c41e7 | 1144 | $form->testSubmit(array( |
f1662cbd | 1145 | 'id' => $contribution['id'], |
cf28d075 | 1146 | 'total_amount' => 200, |
1147 | 'tax_amount' => 20, | |
335c41e7 K |
1148 | 'financial_type_id' => $contribution['financial_type_id'], |
1149 | 'receive_date' => $contribution['receive_date'], | |
1150 | 'payment_instrument_id' => $contribution['payment_instrument_id'], | |
1151 | 'price_set_id' => 0, | |
1152 | 'check_number' => 12345, | |
f1662cbd | 1153 | 'contribution_status_id' => 1, |
1154 | 'is_email_receipt' => 1, | |
1155 | 'from_email_address' => 'demo@example.com', | |
335c41e7 K |
1156 | ), |
1157 | CRM_Core_Action::UPDATE | |
1158 | ); | |
1159 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1160 | array( | |
9308f1c2 K |
1161 | 'contribution_id' => 1, |
1162 | 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'), | |
335c41e7 K |
1163 | ) |
1164 | ); | |
cf28d075 | 1165 | $this->assertEquals(220, $contribution['total_amount']); |
1166 | $this->assertEquals(20, $contribution['tax_amount']); | |
1167 | $this->assertEquals(220, $contribution['net_amount']); | |
9308f1c2 | 1168 | |
f1662cbd | 1169 | $strings = array( |
cf28d075 | 1170 | 'Total Tax Amount : $ 20.00', |
1171 | 'Total Amount : $ 220.00', | |
f1662cbd | 1172 | 'Date Received: April 21st, 2015', |
1173 | 'Paid By: Check', | |
1174 | 'Check Number: 12345', | |
1175 | ); | |
335c41e7 | 1176 | |
f1662cbd | 1177 | $mut->checkMailLog($strings); |
cf28d075 | 1178 | $this->callAPISuccessGetCount('FinancialTrxn', array(), 4); |
1179 | $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1)); | |
1180 | $this->assertEquals(4, $items['count']); | |
1181 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
1182 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
1183 | $this->assertEquals('Contribution Amount', $items['values'][0]['description']); | |
1184 | $this->assertEquals('Sales Tax', $items['values'][1]['description']); | |
1185 | ||
1186 | $this->assertEquals(100, $items['values'][0]['amount']); | |
1187 | $this->assertEquals(10, $items['values'][1]['amount']); | |
7c63ab21 | 1188 | // @todo currently its $110 which is incorrect, the proper value should be $200 |
1189 | // $this->assertEquals(200, $items['values'][2]['amount']); | |
cf28d075 | 1190 | $this->assertEquals(20, $items['values'][3]['amount']); |
1191 | } | |
1192 | ||
1193 | /** | |
1194 | * Do the first contributions, in preparation for an edit-submit. | |
1195 | * | |
1196 | * @return array | |
1197 | * | |
1198 | * @throws \Exception | |
1199 | */ | |
1200 | protected function doInitialSubmit() { | |
1201 | $form = new CRM_Contribute_Form_Contribution(); | |
1202 | ||
1203 | $form->testSubmit(array( | |
1204 | 'total_amount' => 100, | |
1205 | 'financial_type_id' => $this->_financialTypeId, | |
1206 | 'receive_date' => '04/21/2015', | |
1207 | 'receive_date_time' => '11:27PM', | |
1208 | 'contact_id' => $this->_individualId, | |
1209 | 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), | |
1210 | 'contribution_status_id' => 1, | |
1211 | 'price_set_id' => 0, | |
1212 | ), | |
1213 | CRM_Core_Action::ADD | |
1214 | ); | |
1215 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1216 | array( | |
1217 | 'contribution_id' => 1, | |
1218 | 'return' => array( | |
1219 | 'tax_amount', | |
1220 | 'total_amount', | |
1221 | 'net_amount', | |
1222 | 'financial_type_id', | |
1223 | 'receive_date', | |
1224 | 'payment_instrument_id', | |
1225 | ), | |
1226 | ) | |
1227 | ); | |
1228 | $this->assertEquals(110, $contribution['total_amount']); | |
1229 | $this->assertEquals(10, $contribution['tax_amount']); | |
1230 | $this->assertEquals(110, $contribution['net_amount']); | |
1231 | return array($form, $contribution); | |
335c41e7 K |
1232 | } |
1233 | ||
a55e39e9 | 1234 | /** |
1235 | * function to test card_type and pan truncation. | |
1236 | */ | |
1237 | public function testCardTypeAndPanTruncation() { | |
1238 | $form = new CRM_Contribute_Form_Contribution(); | |
1239 | $form->testSubmit( | |
1240 | array( | |
1241 | 'total_amount' => 100, | |
1242 | 'financial_type_id' => 3, | |
1243 | 'receive_date' => '04/21/2015', | |
1244 | 'receive_date_time' => '11:27PM', | |
1245 | 'contact_id' => $this->_individualId, | |
1246 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
1247 | 'contribution_status_id' => 1, | |
1248 | 'credit_card_type' => 'Visa', | |
1249 | 'pan_truncation' => 4567, | |
1250 | 'price_set_id' => 0, | |
1251 | ), | |
1252 | CRM_Core_Action::ADD | |
1253 | ); | |
1254 | $contribution = $this->callAPISuccessGetSingle('Contribution', | |
1255 | array( | |
1256 | 'contact_id' => $this->_individualId, | |
1257 | 'return' => array('id'), | |
1258 | ) | |
1259 | ); | |
1260 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); | |
1261 | $financialTrxn = $this->callAPISuccessGetSingle( | |
1262 | 'FinancialTrxn', | |
1263 | array( | |
1264 | 'id' => $lastFinancialTrxnId['financialTrxnId'], | |
1265 | 'return' => array('card_type_id.label', 'pan_truncation'), | |
1266 | ) | |
1267 | ); | |
1268 | $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); | |
1269 | $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567); | |
1270 | } | |
1271 | ||
1272 | /** | |
1273 | * function to test card_type and pan truncation. | |
1274 | */ | |
1275 | public function testCardTypeAndPanTruncationLiveMode() { | |
1276 | $visaID = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', 'Visa'); | |
1277 | $form = new CRM_Contribute_Form_Contribution(); | |
1278 | $form->_mode = 'Live'; | |
a55e39e9 | 1279 | $form->testSubmit( |
1280 | array( | |
1281 | 'total_amount' => 50, | |
1282 | 'financial_type_id' => 1, | |
1283 | 'receive_date' => '04/21/2015', | |
1284 | 'receive_date_time' => '11:27PM', | |
1285 | 'contact_id' => $this->_individualId, | |
1286 | 'credit_card_number' => 4444333322221111, | |
1287 | 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), | |
1288 | 'cvv2' => 123, | |
1289 | 'credit_card_exp_date' => array( | |
1290 | 'M' => 9, | |
1291 | 'Y' => date('Y', strtotime('+5 years')), | |
1292 | ), | |
1293 | 'credit_card_type' => 'Visa', | |
1294 | 'billing_first_name' => 'Junko', | |
1295 | 'billing_middle_name' => '', | |
1296 | 'billing_last_name' => 'Adams', | |
1297 | 'billing_street_address-5' => '790L Lincoln St S', | |
1298 | 'billing_city-5' => 'Maryknoll', | |
1299 | 'billing_state_province_id-5' => 1031, | |
1300 | 'billing_postal_code-5' => 10545, | |
1301 | 'billing_country_id-5' => 1228, | |
1302 | 'frequency_interval' => 1, | |
1303 | 'frequency_unit' => 'month', | |
1304 | 'installments' => '', | |
1305 | 'hidden_AdditionalDetail' => 1, | |
1306 | 'hidden_Premium' => 1, | |
1307 | 'from_email_address' => '"civi45" <civi45@civicrm.com>', | |
1308 | 'receipt_date' => '', | |
1309 | 'receipt_date_time' => '', | |
1310 | 'payment_processor_id' => $this->paymentProcessorID, | |
1311 | 'currency' => 'USD', | |
1312 | 'source' => 'bob sled race', | |
1313 | ), | |
1314 | CRM_Core_Action::ADD | |
1315 | ); | |
1316 | $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId)); | |
1317 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); | |
1318 | $financialTrxn = $this->callAPISuccessGetSingle( | |
1319 | 'FinancialTrxn', | |
1320 | array( | |
1321 | 'id' => $lastFinancialTrxnId['financialTrxnId'], | |
1322 | 'return' => array('card_type_id', 'pan_truncation'), | |
1323 | ) | |
1324 | ); | |
016569ee | 1325 | $this->assertEquals($visaID, $financialTrxn['card_type_id']); |
1326 | $this->assertEquals(1111, $financialTrxn['pan_truncation']); | |
a55e39e9 | 1327 | } |
1328 | ||
2dcbf765 | 1329 | } |