Merge pull request #7522 from colemanw/case_api
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 require_once 'CiviTest/CiviMailUtils.php';
30
31
32 /**
33 * Test APIv3 civicrm_contribute_* functions
34 *
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contribution
37 */
38 class api_v3_ContributionTest extends CiviUnitTestCase {
39
40 /**
41 * Assume empty database with just civicrm_data.
42 */
43 protected $_individualId;
44 protected $_contribution;
45 protected $_financialTypeId = 1;
46 protected $_apiversion;
47 protected $_entity = 'Contribution';
48 public $debug = 0;
49 protected $_params;
50 protected $_ids = array();
51 protected $_pageParams = array();
52
53 /**
54 * Parameters to create payment processor.
55 *
56 * @var array
57 */
58 protected $_processorParams = array();
59
60 /**
61 * ID of created event.
62 *
63 * @var int
64 */
65 protected $_eventID;
66
67 /**
68 * Setup function.
69 */
70 public function setUp() {
71 parent::setUp();
72
73 $this->_apiversion = 3;
74 $this->_individualId = $this->individualCreate();
75 $this->_params = array(
76 'contact_id' => $this->_individualId,
77 'receive_date' => '20120511',
78 'total_amount' => 100.00,
79 'financial_type_id' => $this->_financialTypeId,
80 'non_deductible_amount' => 10.00,
81 'fee_amount' => 5.00,
82 'net_amount' => 95.00,
83 'source' => 'SSF',
84 'contribution_status_id' => 1,
85 );
86 $this->_processorParams = array(
87 'domain_id' => 1,
88 'name' => 'Dummy',
89 'payment_processor_type_id' => 10,
90 'financial_account_id' => 12,
91 'is_active' => 1,
92 'user_name' => '',
93 'url_site' => 'http://dummy.com',
94 'url_recur' => 'http://dummy.com',
95 'billing_mode' => 1,
96 );
97 $this->_pageParams = array(
98 'title' => 'Test Contribution Page',
99 'financial_type_id' => 1,
100 'currency' => 'USD',
101 'financial_account_id' => 1,
102 'payment_processor' => $this->processorCreate(),
103 'is_active' => 1,
104 'is_allow_other_amount' => 1,
105 'min_amount' => 10,
106 'max_amount' => 1000,
107 );
108 }
109
110 /**
111 * Clean up after each test.
112 */
113 public function tearDown() {
114 $this->quickCleanUpFinancialEntities();
115 $this->quickCleanup(array('civicrm_uf_match'));
116 }
117
118 /**
119 * Test Get.
120 */
121 public function testGetContribution() {
122 $p = array(
123 'contact_id' => $this->_individualId,
124 'receive_date' => '2010-01-20',
125 'total_amount' => 100.00,
126 'financial_type_id' => $this->_financialTypeId,
127 'non_deductible_amount' => 10.00,
128 'fee_amount' => 5.00,
129 'net_amount' => 95.00,
130 'trxn_id' => 23456,
131 'invoice_id' => 78910,
132 'source' => 'SSF',
133 'contribution_status_id' => 1,
134 );
135 $this->_contribution = $this->callAPISuccess('contribution', 'create', $p);
136
137 $params = array(
138 'contribution_id' => $this->_contribution['id'],
139 );
140
141 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__);
142 $financialParams['id'] = $this->_financialTypeId;
143 $default = NULL;
144 CRM_Financial_BAO_FinancialType::retrieve($financialParams, $default);
145
146 $this->assertEquals(1, $contribution['count']);
147 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
148 // Note there was an assertion converting financial_type_id to 'Donation' which wasn't working.
149 // Passing back a string rather than an id seems like an error/cruft.
150 // If it is to be introduced we should discuss.
151 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
152 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
153 $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00);
154 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00);
155 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00);
156 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456);
157 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
158 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
159 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
160 // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id).
161 $p['trxn_id'] = '3847';
162 $p['invoice_id'] = '3847';
163
164 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
165
166 // Now we have 2 - test getcount.
167 $contribution = $this->callAPISuccess('contribution', 'getcount', array());
168 $this->assertEquals(2, $contribution);
169 // Test id only format.
170 $contribution = $this->callAPISuccess('contribution', 'get', array(
171 'id' => $this->_contribution['id'],
172 'format.only_id' => 1,
173 ));
174 $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE));
175 // Test id only format.
176 $contribution = $this->callAPISuccess('contribution', 'get', array(
177 'id' => $contribution2['id'],
178 'format.only_id' => 1,
179 ));
180 $this->assertEquals($contribution2['id'], $contribution);
181 // Test id as field.
182 $contribution = $this->callAPISuccess('contribution', 'get', array(
183 'id' => $this->_contribution['id'],
184 ));
185 $this->assertEquals(1, $contribution['count']);
186
187 // Test get by contact id works.
188 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId));
189
190 $this->assertEquals(2, $contribution['count']);
191 $this->callAPISuccess('Contribution', 'Delete', array(
192 'id' => $this->_contribution['id'],
193 ));
194 $this->callAPISuccess('Contribution', 'Delete', array(
195 'id' => $contribution2['id'],
196 ));
197 }
198
199 /**
200 * Test that test contributions can be retrieved.
201 */
202 public function testGetTestContribution() {
203 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('is_test' => 1)));
204 $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1));
205 }
206
207 /**
208 * We need to ensure previous tested behaviour still works as part of the api contract.
209 */
210 public function testGetContributionLegacyBehaviour() {
211 $p = array(
212 'contact_id' => $this->_individualId,
213 'receive_date' => '2010-01-20',
214 'total_amount' => 100.00,
215 'contribution_type_id' => $this->_financialTypeId,
216 'non_deductible_amount' => 10.00,
217 'fee_amount' => 5.00,
218 'net_amount' => 95.00,
219 'trxn_id' => 23456,
220 'invoice_id' => 78910,
221 'source' => 'SSF',
222 'contribution_status_id' => 1,
223 );
224 $this->_contribution = $this->callAPISuccess('Contribution', 'create', $p);
225
226 $params = array(
227 'contribution_id' => $this->_contribution['id'],
228 );
229 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__);
230 $financialParams['id'] = $this->_financialTypeId;
231 $default = NULL;
232 CRM_Financial_BAO_FinancialType::retrieve($financialParams, $default);
233
234 $this->assertEquals(1, $contribution['count']);
235 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
236 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->_financialTypeId);
237 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_type_id'], $this->_financialTypeId);
238 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
239 $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00);
240 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00);
241 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00);
242 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456);
243 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
244 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
245 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
246
247 // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id).
248 $p['trxn_id'] = '3847';
249 $p['invoice_id'] = '3847';
250
251 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
252
253 // now we have 2 - test getcount
254 $contribution = $this->callAPISuccess('contribution', 'getcount', array());
255 $this->assertEquals(2, $contribution);
256 //test id only format
257 $contribution = $this->callAPISuccess('contribution', 'get', array(
258 'id' => $this->_contribution['id'],
259 'format.only_id' => 1,
260 ));
261 $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE));
262 //test id only format
263 $contribution = $this->callAPISuccess('contribution', 'get', array(
264 'id' => $contribution2['id'],
265 'format.only_id' => 1,
266 ));
267 $this->assertEquals($contribution2['id'], $contribution);
268 $contribution = $this->callAPISuccess('contribution', 'get', array(
269 'id' => $this->_contribution['id'],
270 ));
271 //test id as field
272 $this->assertEquals(1, $contribution['count']);
273 // $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ;
274 //test get by contact id works
275 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId));
276
277 $this->assertEquals(2, $contribution['count']);
278 $this->callAPISuccess('Contribution', 'Delete', array(
279 'id' => $this->_contribution['id'],
280 ));
281 $this->callAPISuccess('Contribution', 'Delete', array(
282 'id' => $contribution2['id'],
283 ));
284 }
285
286 /**
287 * Create an contribution_id=FALSE and financial_type_id=Donation.
288 */
289 public function testCreateEmptyContributionIDUseDonation() {
290 $params = array(
291 'contribution_id' => FALSE,
292 'contact_id' => 1,
293 'total_amount' => 1,
294 'check_permissions' => FALSE,
295 'financial_type_id' => 'Donation',
296 );
297 $this->callAPISuccess('contribution', 'create', $params);
298 }
299
300 /**
301 * Check with complete array + custom field.
302 *
303 * Note that the test is written on purpose without any
304 * variables specific to participant so it can be replicated into other entities
305 * and / or moved to the automated test suite
306 */
307 public function testCreateWithCustom() {
308 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
309
310 $params = $this->_params;
311 $params['custom_' . $ids['custom_field_id']] = "custom string";
312
313 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
314 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
315 $check = $this->callAPISuccess($this->_entity, 'get', array(
316 'return.custom_' . $ids['custom_field_id'] => 1,
317 'id' => $result['id'],
318 ));
319 $this->customFieldDelete($ids['custom_field_id']);
320 $this->customGroupDelete($ids['custom_group_id']);
321 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
322 }
323
324 /**
325 * Check with complete array + custom field.
326 *
327 * Note that the test is written on purpose without any
328 * variables specific to participant so it can be replicated into other entities
329 * and / or moved to the automated test suite
330 */
331 public function testCreateGetFieldsWithCustom() {
332 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
333 $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php');
334 $result = $this->callAPISuccess('Contribution', 'getfields', array());
335 $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']);
336 $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']);
337 $this->customFieldDelete($ids['custom_field_id']);
338 $this->customGroupDelete($ids['custom_group_id']);
339 $this->customFieldDelete($idsContact['custom_field_id']);
340 $this->customGroupDelete($idsContact['custom_group_id']);
341 }
342
343 public function testCreateContributionNoLineItems() {
344
345 $params = array(
346 'contact_id' => $this->_individualId,
347 'receive_date' => '20120511',
348 'total_amount' => 100.00,
349 'financial_type_id' => $this->_financialTypeId,
350 'payment_instrument_id' => 1,
351 'non_deductible_amount' => 10.00,
352 'fee_amount' => 50.00,
353 'net_amount' => 90.00,
354 'trxn_id' => 12345,
355 'invoice_id' => 67890,
356 'source' => 'SSF',
357 'contribution_status_id' => 1,
358 'skipLineItem' => 1,
359 );
360
361 $contribution = $this->callAPISuccess('contribution', 'create', $params);
362 $lineItems = $this->callAPISuccess('line_item', 'get', array(
363 'entity_id' => $contribution['id'],
364 'entity_table' => 'civicrm_contribution',
365 'sequential' => 1,
366 ));
367 $this->assertEquals(0, $lineItems['count']);
368 }
369
370 /**
371 * Test checks that passing in line items suppresses the create mechanism.
372 */
373 public function testCreateContributionChainedLineItems() {
374 $params = array(
375 'contact_id' => $this->_individualId,
376 'receive_date' => '20120511',
377 'total_amount' => 100.00,
378 'financial_type_id' => $this->_financialTypeId,
379 'payment_instrument_id' => 1,
380 'non_deductible_amount' => 10.00,
381 'fee_amount' => 50.00,
382 'net_amount' => 90.00,
383 'trxn_id' => 12345,
384 'invoice_id' => 67890,
385 'source' => 'SSF',
386 'contribution_status_id' => 1,
387 'skipLineItem' => 1,
388 'api.line_item.create' => array(
389 array(
390 'price_field_id' => 1,
391 'qty' => 2,
392 'line_total' => '20',
393 'unit_price' => '10',
394 ),
395 array(
396 'price_field_id' => 1,
397 'qty' => 1,
398 'line_total' => '80',
399 'unit_price' => '80',
400 ),
401 ),
402 );
403
404 $description = "Create Contribution with Nested Line Items.";
405 $subfile = "CreateWithNestedLineItems";
406 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
407
408 $lineItems = $this->callAPISuccess('line_item', 'get', array(
409 'entity_id' => $contribution['id'],
410 'contribution_id' => $contribution['id'],
411 'entity_table' => 'civicrm_contribution',
412 'sequential' => 1,
413 ));
414 $this->assertEquals(2, $lineItems['count']);
415 }
416
417 public function testCreateContributionOffline() {
418 $params = array(
419 'contact_id' => $this->_individualId,
420 'receive_date' => '20120511',
421 'total_amount' => 100.00,
422 'financial_type_id' => 1,
423 'trxn_id' => 12345,
424 'invoice_id' => 67890,
425 'source' => 'SSF',
426 'contribution_status_id' => 1,
427 );
428
429 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
430 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
431 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
432 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
433 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
434 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
435 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
436 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
437 $lineItems = $this->callAPISuccess('line_item', 'get', array(
438 'entity_id' => $contribution['id'],
439 'contribution_id' => $contribution['id'],
440 'entity_table' => 'civicrm_contribution',
441 'sequential' => 1,
442 ));
443 $this->assertEquals(1, $lineItems['count']);
444 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
445 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
446 $this->_checkFinancialRecords($contribution, 'offline');
447 $this->contributionGetnCheck($params, $contribution['id']);
448 }
449
450 /**
451 * Test create with valid payment instrument.
452 */
453 public function testCreateContributionWithPaymentInstrument() {
454 $params = $this->_params + array('payment_instrument' => 'EFT');
455 $contribution = $this->callAPISuccess('contribution', 'create', $params);
456 $contribution = $this->callAPISuccess('contribution', 'get', array(
457 'sequential' => 1,
458 'id' => $contribution['id'],
459 ));
460 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
461 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
462
463 $this->callAPISuccess('contribution', 'create', array(
464 'id' => $contribution['id'],
465 'payment_instrument' => 'Credit Card',
466 ));
467 $contribution = $this->callAPISuccess('contribution', 'get', array(
468 'sequential' => 1,
469 'id' => $contribution['id'],
470 ));
471 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
472 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
473 }
474
475 public function testGetContributionByPaymentInstrument() {
476 $params = $this->_params + array('payment_instrument' => 'EFT');
477 $params2 = $this->_params + array('payment_instrument' => 'Cash');
478 $this->callAPISuccess('contribution', 'create', $params);
479 $this->callAPISuccess('contribution', 'create', $params2);
480 $contribution = $this->callAPISuccess('contribution', 'get', array(
481 'sequential' => 1,
482 'contribution_payment_instrument' => 'Cash',
483 ));
484 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
485 $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
486 $this->assertEquals(1, $contribution['count']);
487 $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument' => 'Cash'));
488 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
489 $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
490 $this->assertEquals(1, $contribution['count']);
491 $contribution = $this->callAPISuccess('contribution', 'get', array(
492 'sequential' => 1,
493 'payment_instrument_id' => 5,
494 ));
495 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
496 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
497 $this->assertEquals(1, $contribution['count']);
498 $contribution = $this->callAPISuccess('contribution', 'get', array(
499 'sequential' => 1,
500 'payment_instrument' => 'EFT',
501 ));
502 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
503 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
504 $this->assertEquals(1, $contribution['count']);
505 $contribution = $this->callAPISuccess('contribution', 'create', array(
506 'id' => $contribution['id'],
507 'payment_instrument' => 'Credit Card',
508 ));
509 $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id']));
510 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
511 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
512 $this->assertEquals(1, $contribution['count']);
513 }
514
515 /**
516 * CRM-16227 introduces invoice_id as a parameter.
517 */
518 public function testGetContributionByInvoice() {
519 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('invoice_id' => 'curly')));
520 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), array('invoice_id' => 'churlish'));
521 $this->callAPISuccessGetCount('Contribution', array(), 2);
522 $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => 'curly'));
523 // The following don't work. They are the format we are trying to introduce but although the form uses this format
524 // CRM_Contact_BAO_Query::convertFormValues puts them into the other format & the where only supports that.
525 // ideally the where clause would support this format (as it does on contact_BAO_Query) and those lines would
526 // come out of convertFormValues
527 // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('LIKE' => '%ish%')));
528 // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('NOT IN' => array('curly'))));
529 // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('LIKE' => '%ly%')), 2);
530 // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('IN' => array('curly', 'churlish'))),
531 // 2);
532 }
533
534 /**
535 * Create test with unique field name on source.
536 */
537 public function testCreateContributionSource() {
538
539 $params = array(
540 'contact_id' => $this->_individualId,
541 'receive_date' => date('Ymd'),
542 'total_amount' => 100.00,
543 'financial_type_id' => $this->_financialTypeId,
544 'payment_instrument_id' => 1,
545 'non_deductible_amount' => 10.00,
546 'fee_amount' => 50.00,
547 'net_amount' => 90.00,
548 'trxn_id' => 12345,
549 'invoice_id' => 67890,
550 'contribution_source' => 'SSF',
551 'contribution_status_id' => 1,
552 );
553
554 $contribution = $this->callAPISuccess('contribution', 'create', $params);
555 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
556 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
557 }
558
559 /**
560 * Create test with unique field name on source.
561 */
562 public function testCreateDefaultNow() {
563
564 $params = $this->_params;
565 unset($params['receive_date']);
566
567 $contribution = $this->callAPISuccess('contribution', 'create', $params);
568 $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
569 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
570 }
571
572 /**
573 * Create test with unique field name on source.
574 */
575 public function testCreateContributionSourceInvalidContact() {
576
577 $params = array(
578 'contact_id' => 999,
579 'receive_date' => date('Ymd'),
580 'total_amount' => 100.00,
581 'financial_type_id' => $this->_financialTypeId,
582 'payment_instrument_id' => 1,
583 'non_deductible_amount' => 10.00,
584 'fee_amount' => 50.00,
585 'net_amount' => 90.00,
586 'trxn_id' => 12345,
587 'invoice_id' => 67890,
588 'contribution_source' => 'SSF',
589 'contribution_status_id' => 1,
590 );
591
592 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
593 }
594
595 public function testCreateContributionSourceInvalidContContact() {
596
597 $params = array(
598 'contribution_contact_id' => 999,
599 'receive_date' => date('Ymd'),
600 'total_amount' => 100.00,
601 'financial_type_id' => $this->_financialTypeId,
602 'payment_instrument_id' => 1,
603 'non_deductible_amount' => 10.00,
604 'fee_amount' => 50.00,
605 'net_amount' => 90.00,
606 'trxn_id' => 12345,
607 'invoice_id' => 67890,
608 'contribution_source' => 'SSF',
609 'contribution_status_id' => 1,
610 );
611
612 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
613 }
614
615 /**
616 * Test note created correctly.
617 */
618 public function testCreateContributionWithNote() {
619 $description = "Demonstrates creating contribution with Note Entity.";
620 $subfile = "ContributionCreateWithNote";
621 $params = array(
622 'contact_id' => $this->_individualId,
623 'receive_date' => '2012-01-01',
624 'total_amount' => 100.00,
625 'financial_type_id' => $this->_financialTypeId,
626 'payment_instrument_id' => 1,
627 'non_deductible_amount' => 10.00,
628 'fee_amount' => 50.00,
629 'net_amount' => 90.00,
630 'trxn_id' => 12345,
631 'invoice_id' => 67890,
632 'source' => 'SSF',
633 'contribution_status_id' => 1,
634 'note' => 'my contribution note',
635 );
636
637 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
638 $result = $this->callAPISuccess('note', 'get', array(
639 'entity_table' => 'civicrm_contribution',
640 'entity_id' => $contribution['id'],
641 'sequential' => 1,
642 ));
643 $this->assertEquals('my contribution note', $result['values'][0]['note']);
644 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
645 }
646
647 public function testCreateContributionWithNoteUniqueNameAliases() {
648 $params = array(
649 'contact_id' => $this->_individualId,
650 'receive_date' => '2012-01-01',
651 'total_amount' => 100.00,
652 'financial_type_id' => $this->_financialTypeId,
653 'payment_instrument_id' => 1,
654 'non_deductible_amount' => 10.00,
655 'fee_amount' => 50.00,
656 'net_amount' => 90.00,
657 'trxn_id' => 12345,
658 'invoice_id' => 67890,
659 'source' => 'SSF',
660 'contribution_status_id' => 1,
661 'contribution_note' => 'my contribution note',
662 );
663
664 $contribution = $this->callAPISuccess('contribution', 'create', $params);
665 $result = $this->callAPISuccess('note', 'get', array(
666 'entity_table' => 'civicrm_contribution',
667 'entity_id' => $contribution['id'],
668 'sequential' => 1,
669 ));
670 $this->assertEquals('my contribution note', $result['values'][0]['note']);
671 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
672 }
673
674 /**
675 * This is the test for creating soft credits.
676 */
677 public function testCreateContributionWithSoftCredit() {
678 $description = "Demonstrates creating contribution with SoftCredit.";
679 $subfile = "ContributionCreateWithSoftCredit";
680 $contact2 = $this->callAPISuccess('Contact', 'create', array(
681 'display_name' => 'superman',
682 'contact_type' => 'Individual',
683 ));
684 $softParams = array(
685 'contact_id' => $contact2['id'],
686 'amount' => 50,
687 'soft_credit_type_id' => 3,
688 );
689
690 $params = $this->_params + array('soft_credit' => array(1 => $softParams));
691 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
692 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
693
694 $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']);
695 $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']);
696 $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']);
697
698 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
699 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
700 }
701
702 public function testCreateContributionWithSoftCreditDefaults() {
703 $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type.";
704 $subfile = "ContributionCreateWithSoftCreditDefaults";
705 $contact2 = $this->callAPISuccess('Contact', 'create', array(
706 'display_name' => 'superman',
707 'contact_type' => 'Individual',
708 ));
709 $params = $this->_params + array(
710 'soft_credit_to' => $contact2['id'],
711 );
712 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
713 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
714
715 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
716 // Default soft credit amount = contribution.total_amount
717 $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
718 $this->assertEquals(CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
719
720 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
721 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
722 }
723
724 public function testCreateContributionWithHonoreeContact() {
725 $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.";
726 $subfile = "ContributionCreateWithHonoreeContact";
727 $contact2 = $this->callAPISuccess('Contact', 'create', array(
728 'display_name' => 'superman',
729 'contact_type' => 'Individual',
730 ));
731 $params = $this->_params + array(
732 'honor_contact_id' => $contact2['id'],
733 );
734 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
735 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
736
737 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
738 // Default soft credit amount = contribution.total_amount
739 // Legacy mode in create api (honor_contact_id param) uses the standard "In Honor of" soft credit type
740 $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
741 $this->assertEquals(CRM_Core_OptionGroup::getValue('soft_credit_type', 'in_honor_of', 'name'), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
742
743 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
744 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
745 }
746
747 /**
748 * Test using example code.
749 */
750 public function testContributionCreateExample() {
751 //make sure at least on page exists since there is a truncate in tear down
752 $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
753 require_once 'api/v3/examples/Contribution/Create.php';
754 $result = contribution_create_example();
755 $id = $result['id'];
756 $expectedResult = contribution_create_expectedresult();
757 $this->checkArrayEquals($expectedResult, $result);
758 $this->contributionDelete($id);
759 }
760
761 /**
762 * Function tests that additional financial records are created when fee amount is recorded.
763 */
764 public function testCreateContributionWithFee() {
765 $params = array(
766 'contact_id' => $this->_individualId,
767 'receive_date' => '20120511',
768 'total_amount' => 100.00,
769 'fee_amount' => 50,
770 'financial_type_id' => 1,
771 'trxn_id' => 12345,
772 'invoice_id' => 67890,
773 'source' => 'SSF',
774 'contribution_status_id' => 1,
775 );
776
777 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
778 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
779 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
780 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 50.00);
781 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 50.00);
782 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
783 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
784 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
785 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
786 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
787
788 $lineItems = $this->callAPISuccess('line_item', 'get', array(
789
790 'entity_id' => $contribution['id'],
791 'entity_table' => 'civicrm_contribution',
792 'sequential' => 1,
793 ));
794 $this->assertEquals(1, $lineItems['count']);
795 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
796 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
797 $lineItems = $this->callAPISuccess('line_item', 'get', array(
798
799 'entity_id' => $contribution['id'],
800 'contribution_id' => $contribution['id'],
801 'entity_table' => 'civicrm_contribution',
802 'sequential' => 1,
803 ));
804 $this->assertEquals(1, $lineItems['count']);
805 $this->_checkFinancialRecords($contribution, 'feeAmount');
806 }
807
808
809 /**
810 * Function tests that additional financial records are created when online contribution is created.
811 */
812 public function testCreateContributionOnline() {
813 CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
814 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
815 $this->assertAPISuccess($contributionPage);
816 $params = array(
817 'contact_id' => $this->_individualId,
818 'receive_date' => '20120511',
819 'total_amount' => 100.00,
820 'financial_type_id' => 1,
821 'contribution_page_id' => $contributionPage['id'],
822 'payment_processor' => 1,
823 'trxn_id' => 12345,
824 'invoice_id' => 67890,
825 'source' => 'SSF',
826 'contribution_status_id' => 1,
827
828 );
829
830 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
831 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
832 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
833 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
834 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
835 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
836 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
837 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
838 $this->_checkFinancialRecords($contribution, 'online');
839 }
840
841 /**
842 * Check handling of financial type.
843 *
844 * In the interests of removing financial type / contribution type checks from
845 * legacy format function lets test that the api is doing this for us
846 */
847 public function testCreateInvalidFinancialType() {
848 $params = $this->_params;
849 $params['financial_type_id'] = 99999;
850 $this->callAPIFailure($this->_entity, 'create', $params, "'99999' is not a valid option for field financial_type_id");
851 }
852
853 /**
854 * Check handling of financial type.
855 *
856 * In the interests of removing financial type / contribution type checks from
857 * legacy format function lets test that the api is doing this for us
858 */
859 public function testValidNamedFinancialType() {
860 $params = $this->_params;
861 $params['financial_type_id'] = 'Donation';
862 $this->callAPISuccess($this->_entity, 'create', $params);
863 }
864
865 /**
866 * Tests that additional financial records are created.
867 *
868 * Checks when online contribution with pay later option is created
869 */
870 public function testCreateContributionPayLaterOnline() {
871 CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
872 $this->_pageParams['is_pay_later'] = 1;
873 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
874 $this->assertAPISuccess($contributionPage);
875 $params = array(
876 'contact_id' => $this->_individualId,
877 'receive_date' => '20120511',
878 'total_amount' => 100.00,
879 'financial_type_id' => 1,
880 'contribution_page_id' => $contributionPage['id'],
881 'trxn_id' => 12345,
882 'is_pay_later' => 1,
883 'invoice_id' => 67890,
884 'source' => 'SSF',
885 'contribution_status_id' => 2,
886
887 );
888
889 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
890 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
891 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
892 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
893 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
894 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
895 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
896 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
897 $this->_checkFinancialRecords($contribution, 'payLater');
898 }
899
900 /**
901 * Function tests that additional financial records are created for online contribution with pending option.
902 */
903 public function testCreateContributionPendingOnline() {
904 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
905 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
906 $this->assertAPISuccess($contributionPage);
907 $params = array(
908 'contact_id' => $this->_individualId,
909 'receive_date' => '20120511',
910 'total_amount' => 100.00,
911 'financial_type_id' => 1,
912 'contribution_page_id' => $contributionPage['id'],
913 'trxn_id' => 12345,
914 'invoice_id' => 67890,
915 'source' => 'SSF',
916 'contribution_status_id' => 2,
917 );
918
919 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
920 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
921 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
922 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
923 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
924 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
925 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
926 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
927 $this->_checkFinancialRecords($contribution, 'pending');
928 }
929
930 /**
931 * Test that BAO defaults work.
932 */
933 public function testCreateBAODefaults() {
934 unset($this->_params['contribution_source_id'], $this->_params['payment_instrument_id']);
935 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
936 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
937 'id' => $contribution['id'],
938 'api.contribution.delete' => 1,
939 ));
940 $this->assertEquals(1, $contribution['contribution_status_id']);
941 $this->assertEquals('Check', $contribution['payment_instrument']);
942 }
943
944 /**
945 * Function tests that line items, financial records are updated when contribution amount is changed.
946 */
947 public function testCreateUpdateContributionChangeTotal() {
948 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
949 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
950
951 'entity_id' => $contribution['id'],
952 'entity_table' => 'civicrm_contribution',
953 'sequential' => 1,
954 'return' => 'line_total',
955 ));
956 $this->assertEquals('100.00', $lineItems);
957 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
958 // Financial trxn SUM = 100 + 5 (fee)
959 $this->assertEquals('105.00', $trxnAmount);
960 $newParams = array(
961
962 'id' => $contribution['id'],
963 'total_amount' => '125',
964 );
965 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
966
967 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
968
969 'entity_id' => $contribution['id'],
970 'entity_table' => 'civicrm_contribution',
971 'sequential' => 1,
972 'return' => 'line_total',
973 ));
974
975 $this->assertEquals('125.00', $lineItems);
976 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
977
978 // Financial trxn SUM = 125 + 5 (fee).
979 $this->assertEquals('130.00', $trxnAmount);
980 $this->assertEquals('125.00', $this->_getFinancialItemAmount($contribution['id']));
981 }
982
983 /**
984 * Function tests that line items, financial records are updated when pay later contribution is received.
985 */
986 public function testCreateUpdateContributionPayLater() {
987 $contribParams = array(
988 'contact_id' => $this->_individualId,
989 'receive_date' => '2012-01-01',
990 'total_amount' => 100.00,
991 'financial_type_id' => $this->_financialTypeId,
992 'payment_instrument_id' => 1,
993 'contribution_status_id' => 2,
994 'is_pay_later' => 1,
995
996 );
997 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
998
999 $newParams = array_merge($contribParams, array(
1000 'id' => $contribution['id'],
1001 'contribution_status_id' => 1,
1002 )
1003 );
1004 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1005 $contribution = $contribution['values'][$contribution['id']];
1006 $this->assertEquals($contribution['contribution_status_id'], '1');
1007 $this->_checkFinancialItem($contribution['id'], 'paylater');
1008 $this->_checkFinancialTrxn($contribution, 'payLater');
1009 }
1010
1011 /**
1012 * Function tests that financial records are updated when Payment Instrument is changed.
1013 */
1014 public function testCreateUpdateContributionPaymentInstrument() {
1015 $instrumentId = $this->_addPaymentInstrument();
1016 $contribParams = array(
1017 'contact_id' => $this->_individualId,
1018 'total_amount' => 100.00,
1019 'financial_type_id' => $this->_financialTypeId,
1020 'payment_instrument_id' => 4,
1021 'contribution_status_id' => 1,
1022
1023 );
1024 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1025
1026 $newParams = array_merge($contribParams, array(
1027 'id' => $contribution['id'],
1028 'payment_instrument_id' => $instrumentId,
1029 )
1030 );
1031 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1032 $this->assertAPISuccess($contribution);
1033 $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId);
1034 }
1035
1036 /**
1037 * Function tests that financial records are added when Contribution is Refunded.
1038 */
1039 public function testCreateUpdateContributionRefund() {
1040 $contributionParams = array(
1041 'contact_id' => $this->_individualId,
1042 'receive_date' => '2012-01-01',
1043 'total_amount' => 100.00,
1044 'financial_type_id' => $this->_financialTypeId,
1045 'payment_instrument_id' => 4,
1046 'contribution_status_id' => 1,
1047 'trxn_id' => 'original_payment',
1048 );
1049 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1050 $newParams = array_merge($contributionParams, array(
1051 'id' => $contribution['id'],
1052 'contribution_status_id' => 'Refunded',
1053 'cancel_date' => '2015-01-01 09:00',
1054 'refund_trxn_id' => 'the refund',
1055 )
1056 );
1057
1058 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1059 $this->_checkFinancialTrxn($contribution, 'refund');
1060 $this->_checkFinancialItem($contribution['id'], 'refund');
1061 $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', array(
1062 'id' => $contribution['id'],
1063 'return' => 'trxn_id',
1064 )));
1065 }
1066
1067 /**
1068 * Function tests that trxn_id is set when passed in.
1069 *
1070 * Here we ensure that the civicrm_financial_trxn.trxn_id & the civicrm_contribution.trxn_id are set
1071 * when trxn_id is passed in.
1072 */
1073 public function testCreateUpdateContributionRefundTrxnIDPassedIn() {
1074 $contributionParams = array(
1075 'contact_id' => $this->_individualId,
1076 'receive_date' => '2012-01-01',
1077 'total_amount' => 100.00,
1078 'financial_type_id' => $this->_financialTypeId,
1079 'payment_instrument_id' => 4,
1080 'contribution_status_id' => 1,
1081 'trxn_id' => 'original_payment',
1082 );
1083 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1084 $newParams = array_merge($contributionParams, array(
1085 'id' => $contribution['id'],
1086 'contribution_status_id' => 'Refunded',
1087 'cancel_date' => '2015-01-01 09:00',
1088 'trxn_id' => 'the refund',
1089 )
1090 );
1091
1092 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1093 $this->_checkFinancialTrxn($contribution, 'refund');
1094 $this->_checkFinancialItem($contribution['id'], 'refund');
1095 $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', array(
1096 'id' => $contribution['id'],
1097 'return' => 'trxn_id',
1098 )));
1099 }
1100
1101 /**
1102 * Function tests that trxn_id is set when passed in.
1103 *
1104 * Here we ensure that the civicrm_contribution.trxn_id is set
1105 * when trxn_id is passed in but if refund_trxn_id is different then that
1106 * is kept for the refund transaction.
1107 */
1108 public function testCreateUpdateContributionRefundRefundAndTrxnIDPassedIn() {
1109 $contributionParams = array(
1110 'contact_id' => $this->_individualId,
1111 'receive_date' => '2012-01-01',
1112 'total_amount' => 100.00,
1113 'financial_type_id' => $this->_financialTypeId,
1114 'payment_instrument_id' => 4,
1115 'contribution_status_id' => 1,
1116 'trxn_id' => 'original_payment',
1117 );
1118 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1119 $newParams = array_merge($contributionParams, array(
1120 'id' => $contribution['id'],
1121 'contribution_status_id' => 'Refunded',
1122 'cancel_date' => '2015-01-01 09:00',
1123 'trxn_id' => 'cont id',
1124 'refund_trxn_id' => 'the refund',
1125 )
1126 );
1127
1128 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1129 $this->_checkFinancialTrxn($contribution, 'refund');
1130 $this->_checkFinancialItem($contribution['id'], 'refund');
1131 $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
1132 'id' => $contribution['id'],
1133 'return' => 'trxn_id',
1134 )));
1135 }
1136
1137 /**
1138 * Function tests that refund_trxn_id is set when passed in empty.
1139 *
1140 * Here we ensure that the civicrm_contribution.trxn_id is set
1141 * when trxn_id is passed in but if refund_trxn_id isset but empty then that
1142 * is kept for the refund transaction.
1143 */
1144 public function testCreateUpdateContributionRefundRefundNullTrxnIDPassedIn() {
1145 $contributionParams = array(
1146 'contact_id' => $this->_individualId,
1147 'receive_date' => '2012-01-01',
1148 'total_amount' => 100.00,
1149 'financial_type_id' => $this->_financialTypeId,
1150 'payment_instrument_id' => 4,
1151 'contribution_status_id' => 1,
1152 'trxn_id' => 'original_payment',
1153 );
1154 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1155 $newParams = array_merge($contributionParams, array(
1156 'id' => $contribution['id'],
1157 'contribution_status_id' => 'Refunded',
1158 'cancel_date' => '2015-01-01 09:00',
1159 'trxn_id' => 'cont id',
1160 'refund_trxn_id' => '',
1161 )
1162 );
1163
1164 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1165 $this->_checkFinancialTrxn($contribution, 'refund', NULL, array('trxn_id' => NULL));
1166 $this->_checkFinancialItem($contribution['id'], 'refund');
1167 $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
1168 'id' => $contribution['id'],
1169 'return' => 'trxn_id',
1170 )));
1171 }
1172
1173 /**
1174 * Function tests invalid contribution status change.
1175 */
1176 public function testCreateUpdateContributionInValidStatusChange() {
1177 $contribParams = array(
1178 'contact_id' => 1,
1179 'receive_date' => '2012-01-01',
1180 'total_amount' => 100.00,
1181 'financial_type_id' => 1,
1182 'payment_instrument_id' => 1,
1183 'contribution_status_id' => 1,
1184 );
1185 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1186 $newParams = array_merge($contribParams, array(
1187 'id' => $contribution['id'],
1188 'contribution_status_id' => 2,
1189 )
1190 );
1191 $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.'));
1192
1193 }
1194
1195 /**
1196 * Function tests that financial records are added when Pending Contribution is Canceled.
1197 */
1198 public function testCreateUpdateContributionCancelPending() {
1199 $contribParams = array(
1200 'contact_id' => $this->_individualId,
1201 'receive_date' => '2012-01-01',
1202 'total_amount' => 100.00,
1203 'financial_type_id' => $this->_financialTypeId,
1204 'payment_instrument_id' => 1,
1205 'contribution_status_id' => 2,
1206 'is_pay_later' => 1,
1207
1208 );
1209 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1210 $newParams = array_merge($contribParams, array(
1211 'id' => $contribution['id'],
1212 'contribution_status_id' => 3,
1213 )
1214 );
1215 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1216 $this->_checkFinancialTrxn($contribution, 'cancelPending');
1217 $this->_checkFinancialItem($contribution['id'], 'cancelPending');
1218 }
1219
1220 /**
1221 * Function tests that financial records are added when Financial Type is Changed.
1222 */
1223 public function testCreateUpdateContributionChangeFinancialType() {
1224 $contribParams = array(
1225 'contact_id' => $this->_individualId,
1226 'receive_date' => '2012-01-01',
1227 'total_amount' => 100.00,
1228 'financial_type_id' => 1,
1229 'payment_instrument_id' => 1,
1230 'contribution_status_id' => 1,
1231
1232 );
1233 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1234 $newParams = array_merge($contribParams, array(
1235 'id' => $contribution['id'],
1236 'financial_type_id' => 3,
1237 )
1238 );
1239 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1240 $this->_checkFinancialTrxn($contribution, 'changeFinancial');
1241 $this->_checkFinancialItem($contribution['id'], 'changeFinancial');
1242 }
1243
1244 /**
1245 * Test that update does not change status id CRM-15105.
1246 */
1247 public function testCreateUpdateWithoutChangingPendingStatus() {
1248 $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2)));
1249 $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source'));
1250 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1251 'id' => $contribution['id'],
1252 'api.contribution.delete' => 1,
1253 ));
1254 $this->assertEquals(2, $contribution['contribution_status_id']);
1255 }
1256
1257 /**
1258 * Test Updating a Contribution.
1259 *
1260 * CHANGE: we require the API to do an incremental update
1261 */
1262 public function testCreateUpdateContribution() {
1263
1264 $contributionID = $this->contributionCreate(array(
1265 'contact_id' => $this->_individualId,
1266 'trxn_id' => 212355,
1267 'financial_type_id' => $this->_financialTypeId,
1268 'invoice_id' => 'old_invoice',
1269 ));
1270 $old_params = array(
1271 'contribution_id' => $contributionID,
1272 );
1273 $original = $this->callAPISuccess('contribution', 'get', $old_params);
1274 $this->assertEquals($original['id'], $contributionID);
1275 //set up list of old params, verify
1276
1277 //This should not be required on update:
1278 $old_contact_id = $original['values'][$contributionID]['contact_id'];
1279 $old_payment_instrument = $original['values'][$contributionID]['instrument_id'];
1280 $old_fee_amount = $original['values'][$contributionID]['fee_amount'];
1281 $old_source = $original['values'][$contributionID]['contribution_source'];
1282
1283 $old_trxn_id = $original['values'][$contributionID]['trxn_id'];
1284 $old_invoice_id = $original['values'][$contributionID]['invoice_id'];
1285
1286 //check against values in CiviUnitTestCase::createContribution()
1287 $this->assertEquals($old_contact_id, $this->_individualId);
1288 $this->assertEquals($old_fee_amount, 5.00);
1289 $this->assertEquals($old_source, 'SSF');
1290 $this->assertEquals($old_trxn_id, 212355);
1291 $this->assertEquals($old_invoice_id, 'old_invoice');
1292 $params = array(
1293 'id' => $contributionID,
1294 'contact_id' => $this->_individualId,
1295 'total_amount' => 110.00,
1296 'financial_type_id' => $this->_financialTypeId,
1297 'non_deductible_amount' => 10.00,
1298 'net_amount' => 100.00,
1299 'contribution_status_id' => 1,
1300 'note' => 'Donating for Nobel Cause',
1301
1302 );
1303
1304 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1305
1306 $new_params = array(
1307 'contribution_id' => $contribution['id'],
1308
1309 );
1310 $contribution = $this->callAPISuccess('contribution', 'get', $new_params);
1311
1312 $this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId);
1313 $this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00);
1314 $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId);
1315 $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument);
1316 $this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00);
1317 $this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount);
1318 $this->assertEquals($contribution['values'][$contributionID]['net_amount'], 100.00);
1319 $this->assertEquals($contribution['values'][$contributionID]['trxn_id'], $old_trxn_id);
1320 $this->assertEquals($contribution['values'][$contributionID]['invoice_id'], $old_invoice_id);
1321 $this->assertEquals($contribution['values'][$contributionID]['contribution_source'], $old_source);
1322 $this->assertEquals($contribution['values'][$contributionID]['contribution_status'], 'Completed');
1323 $params = array(
1324 'contribution_id' => $contributionID,
1325
1326 );
1327 $result = $this->callAPISuccess('contribution', 'delete', $params);
1328 $this->assertAPISuccess($result);
1329 }
1330
1331 ///////////////// civicrm_contribution_delete methods
1332
1333 /**
1334 * Attempt (but fail) to delete a contribution without parameters.
1335 */
1336 public function testDeleteEmptyParamsContribution() {
1337 $params = array();
1338 $this->callAPIFailure('contribution', 'delete', $params);
1339 }
1340
1341 public function testDeleteParamsNotArrayContribution() {
1342 $params = 'contribution_id= 1';
1343 $contribution = $this->callAPIFailure('contribution', 'delete', $params);
1344 $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array');
1345 }
1346
1347 public function testDeleteWrongParamContribution() {
1348 $params = array(
1349 'contribution_source' => 'SSF',
1350
1351 );
1352 $this->callAPIFailure('contribution', 'delete', $params);
1353 }
1354
1355 public function testDeleteContribution() {
1356 $contributionID = $this->contributionCreate(array(
1357 'contact_id' => $this->_individualId,
1358 'financial_type_id' => $this->_financialTypeId,
1359 ));
1360 $params = array(
1361 'id' => $contributionID,
1362 );
1363 $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__, __FILE__);
1364 }
1365
1366 /**
1367 * Test civicrm_contribution_search with empty params.
1368 *
1369 * All available contributions expected.
1370 */
1371 public function testSearchEmptyParams() {
1372 $params = array();
1373
1374 $p = array(
1375 'contact_id' => $this->_individualId,
1376 'receive_date' => date('Ymd'),
1377 'total_amount' => 100.00,
1378 'financial_type_id' => $this->_financialTypeId,
1379 'non_deductible_amount' => 10.00,
1380 'fee_amount' => 5.00,
1381 'net_amount' => 95.00,
1382 'trxn_id' => 23456,
1383 'invoice_id' => 78910,
1384 'source' => 'SSF',
1385 'contribution_status_id' => 1,
1386
1387 );
1388 $contribution = $this->callAPISuccess('contribution', 'create', $p);
1389
1390 $result = $this->callAPISuccess('contribution', 'get', $params);
1391 // We're taking the first element.
1392 $res = $result['values'][$contribution['id']];
1393
1394 $this->assertEquals($p['contact_id'], $res['contact_id']);
1395 $this->assertEquals($p['total_amount'], $res['total_amount']);
1396 $this->assertEquals($p['financial_type_id'], $res['financial_type_id']);
1397 $this->assertEquals($p['net_amount'], $res['net_amount']);
1398 $this->assertEquals($p['non_deductible_amount'], $res['non_deductible_amount']);
1399 $this->assertEquals($p['fee_amount'], $res['fee_amount']);
1400 $this->assertEquals($p['trxn_id'], $res['trxn_id']);
1401 $this->assertEquals($p['invoice_id'], $res['invoice_id']);
1402 $this->assertEquals($p['source'], $res['contribution_source']);
1403 // contribution_status_id = 1 => Completed
1404 $this->assertEquals('Completed', $res['contribution_status']);
1405
1406 $this->contributionDelete($contribution['id']);
1407 }
1408
1409 /**
1410 * Test civicrm_contribution_search. Success expected.
1411 */
1412 public function testSearch() {
1413 $p1 = array(
1414 'contact_id' => $this->_individualId,
1415 'receive_date' => date('Ymd'),
1416 'total_amount' => 100.00,
1417 'financial_type_id' => $this->_financialTypeId,
1418 'non_deductible_amount' => 10.00,
1419 'contribution_status_id' => 1,
1420
1421 );
1422 $contribution1 = $this->callAPISuccess('contribution', 'create', $p1);
1423
1424 $p2 = array(
1425 'contact_id' => $this->_individualId,
1426 'receive_date' => date('Ymd'),
1427 'total_amount' => 200.00,
1428 'financial_type_id' => $this->_financialTypeId,
1429 'non_deductible_amount' => 20.00,
1430 'trxn_id' => 5454565,
1431 'invoice_id' => 1212124,
1432 'fee_amount' => 50.00,
1433 'net_amount' => 60.00,
1434 'contribution_status_id' => 2,
1435
1436 );
1437 $contribution2 = $this->callAPISuccess('contribution', 'create', $p2);
1438
1439 $params = array(
1440 'contribution_id' => $contribution2['id'],
1441
1442 );
1443 $result = $this->callAPISuccess('contribution', 'get', $params);
1444 $res = $result['values'][$contribution2['id']];
1445
1446 $this->assertEquals($p2['contact_id'], $res['contact_id']);
1447 $this->assertEquals($p2['total_amount'], $res['total_amount']);
1448 $this->assertEquals($p2['financial_type_id'], $res['financial_type_id']);
1449 $this->assertEquals($p2['net_amount'], $res['net_amount']);
1450 $this->assertEquals($p2['non_deductible_amount'], $res['non_deductible_amount']);
1451 $this->assertEquals($p2['fee_amount'], $res['fee_amount']);
1452 $this->assertEquals($p2['trxn_id'], $res['trxn_id']);
1453 $this->assertEquals($p2['invoice_id'], $res['invoice_id']);
1454 // contribution_status_id = 2 => Pending
1455 $this->assertEquals('Pending', $res['contribution_status']);
1456
1457 $this->contributionDelete($contribution1['id']);
1458 $this->contributionDelete($contribution2['id']);
1459 }
1460
1461 /**
1462 * Test completing a transaction via the API.
1463 *
1464 * Note that we are creating a logged in user because email goes out from
1465 * that person
1466 */
1467 public function testCompleteTransaction() {
1468 $mut = new CiviMailUtils($this, TRUE);
1469 $this->createLoggedInUser();
1470 $params = array_merge($this->_params, array('contribution_status_id' => 2));
1471 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1472 $this->callAPISuccess('contribution', 'completetransaction', array(
1473 'id' => $contribution['id'],
1474 ));
1475 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1476 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1477 $mut->checkMailLog(array(
1478 'Receipt - Contribution',
1479 'Please print this confirmation for your records.',
1480 ));
1481 $mut->stop();
1482 }
1483
1484 /**
1485 * Test completing a transaction via the API.
1486 *
1487 * Note that we are creating a logged in user because email goes out from
1488 * that person
1489 */
1490 public function testCompleteTransactionFeeAmount() {
1491 $this->createLoggedInUser();
1492 $params = array_merge($this->_params, array('contribution_status_id' => 2));
1493 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1494 $this->callAPISuccess('contribution', 'completetransaction', array(
1495 'id' => $contribution['id'],
1496 'fee_amount' => '.56',
1497 'trxn_id' => '7778888',
1498 ));
1499 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1));
1500 $this->assertEquals('Completed', $contribution['contribution_status']);
1501 $this->assertEquals('7778888', $contribution['trxn_id']);
1502 $this->assertEquals('.56', $contribution['fee_amount']);
1503 $this->assertEquals('99.44', $contribution['net_amount']);
1504 }
1505
1506 /**
1507 * Test repeat contribution successfully creates line items.
1508 */
1509 public function testRepeatTransaction() {
1510 $paymentProcessorID = $this->paymentProcessorCreate();
1511 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1512 'contact_id' => $this->_individualId,
1513 'installments' => '12',
1514 'frequency_interval' => '1',
1515 'amount' => '500',
1516 'contribution_status_id' => 1,
1517 'start_date' => '2012-01-01 00:00:00',
1518 'currency' => 'USD',
1519 'frequency_unit' => 'month',
1520 'payment_processor_id' => $paymentProcessorID,
1521 ));
1522 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1523 $this->_params,
1524 array('contribution_recur_id' => $contributionRecur['id']))
1525 );
1526
1527 $this->callAPISuccess('contribution', 'repeattransaction', array(
1528 'original_contribution_id' => $originalContribution['id'],
1529 'contribution_status_id' => 'Completed',
1530 'trxn_id' => uniqid(),
1531 ));
1532 $lineItemParams = array(
1533 'entity_id' => $originalContribution['id'],
1534 'sequential' => 1,
1535 'return' => array(
1536 'entity_table',
1537 'qty',
1538 'unit_price',
1539 'line_total',
1540 'label',
1541 'financial_type_id',
1542 'deductible_amount',
1543 'price_field_value_id',
1544 'price_field_id',
1545 ),
1546 );
1547 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1548 'entity_id' => $originalContribution['id'],
1549 )));
1550 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1551 'entity_id' => $originalContribution['id'] + 1,
1552 )));
1553 unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
1554 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1555 $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
1556
1557 $this->quickCleanUpFinancialEntities();
1558 }
1559
1560 /**
1561 * CRM-16397 test appropriate action if total amount has changed for single line items.
1562 */
1563 public function testRepeatTransactionAlteredAmount() {
1564 $paymentProcessorID = $this->paymentProcessorCreate();
1565 $campaignID = $this->campaignCreate();
1566 $campaignID2 = $this->campaignCreate();
1567 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1568 'contact_id' => $this->_individualId,
1569 'installments' => '12',
1570 'frequency_interval' => '1',
1571 'amount' => '500',
1572 'contribution_status_id' => 1,
1573 'start_date' => '2012-01-01 00:00:00',
1574 'currency' => 'USD',
1575 'frequency_unit' => 'month',
1576 'payment_processor_id' => $paymentProcessorID,
1577 ));
1578 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1579 $this->_params,
1580 array(
1581 'contribution_recur_id' => $contributionRecur['id'],
1582 'campaign_id' => $campaignID,
1583 ))
1584 );
1585
1586 $this->callAPISuccess('contribution', 'repeattransaction', array(
1587 'original_contribution_id' => $originalContribution['id'],
1588 'contribution_status_id' => 'Completed',
1589 'trxn_id' => uniqid(),
1590 'total_amount' => '400',
1591 'fee_amount' => 50,
1592 'campaign_id' => $campaignID2,
1593 ));
1594 $lineItemParams = array(
1595 'entity_id' => $originalContribution['id'],
1596 'sequential' => 1,
1597 'return' => array(
1598 'entity_table',
1599 'qty',
1600 'unit_price',
1601 'line_total',
1602 'label',
1603 'financial_type_id',
1604 'deductible_amount',
1605 'price_field_value_id',
1606 'price_field_id',
1607 ),
1608 );
1609 $this->callAPISuccessGetSingle('contribution', array(
1610 'total_amount' => 400,
1611 'campaign_id' => $campaignID2,
1612 'fee_amount' => 50,
1613 'net_amount' => 350,
1614 ));
1615 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1616 'entity_id' => $originalContribution['id'],
1617 )));
1618 $expectedLineItem = array_merge(
1619 $lineItem1['values'][0], array(
1620 'line_total' => '400.00',
1621 'unit_price' => '400.00',
1622 )
1623 );
1624
1625 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1626 'entity_id' => $originalContribution['id'] + 1,
1627 )));
1628 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1629 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1630 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1631
1632 $this->quickCleanUpFinancialEntities();
1633 }
1634
1635 /**
1636 * Test completing a transaction does not 'mess' with net amount (CRM-15960).
1637 */
1638 public function testCompleteTransactionNetAmountOK() {
1639 $this->createLoggedInUser();
1640 $params = array_merge($this->_params, array('contribution_status_id' => 2));
1641 unset($params['net_amount']);
1642 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1643 $this->callAPISuccess('contribution', 'completetransaction', array(
1644 'id' => $contribution['id'],
1645 ));
1646 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
1647 $this->assertEquals('Completed', $contribution['contribution_status']);
1648 $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
1649 }
1650
1651 /**
1652 * CRM-14151 - Test completing a transaction via the API.
1653 */
1654 public function testCompleteTransactionWithReceiptDateSet() {
1655 $mut = new CiviMailUtils($this, TRUE);
1656 $this->createLoggedInUser();
1657 $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
1658 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1659 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d')));
1660 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1661 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1662 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date'])));
1663 $mut->checkMailLog(array(
1664 'Receipt - Contribution',
1665 'Please print this confirmation for your records.',
1666 ));
1667 $mut->stop();
1668 }
1669
1670 /**
1671 * Test completing first transaction in a recurring series.
1672 *
1673 * The status should be set to 'in progress' and the next scheduled payment date calculated.
1674 */
1675 public function testCompleteTransactionSetStatusToInProgress() {
1676 $paymentProcessorID = $this->paymentProcessorCreate();
1677 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1678 'contact_id' => $this->_individualId,
1679 'installments' => '12',
1680 'frequency_interval' => '1',
1681 'amount' => '500',
1682 'contribution_status_id' => 'Pending',
1683 'start_date' => '2012-01-01 00:00:00',
1684 'currency' => 'USD',
1685 'frequency_unit' => 'month',
1686 'payment_processor_id' => $paymentProcessorID,
1687 ));
1688 $contribution = $this->callAPISuccess('contribution', 'create', array_merge(
1689 $this->_params,
1690 array(
1691 'contribution_recur_id' => $contributionRecur['id'],
1692 'contribution_status_id' => 'Pending',
1693 ))
1694 );
1695 $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $contribution));
1696 $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array(
1697 'id' => $contributionRecur['id'],
1698 'return' => array('next_sched_contribution_date', 'contribution_status_id'),
1699 ));
1700 $this->assertEquals(5, $contributionRecur['contribution_status_id']);
1701 $this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']);
1702 }
1703
1704 /**
1705 * Test completing a transaction with an event via the API.
1706 *
1707 * Note that we are creating a logged in user because email goes out from
1708 * that person
1709 */
1710 public function testCompleteTransactionWithParticipantRecord() {
1711 $mut = new CiviMailUtils($this, TRUE);
1712 $mut->clearMessages();
1713 $this->createLoggedInUser();
1714 $contributionID = $this->createPendingParticipantContribution();
1715 $this->callAPISuccess('contribution', 'completetransaction', array(
1716 'id' => $contributionID,
1717 )
1718 );
1719 $participantStatus = $this->callAPISuccessGetValue('participant', array(
1720 'id' => $this->_ids['participant'],
1721 'return' => 'participant_status_id',
1722 ));
1723 $this->assertEquals(1, $participantStatus);
1724 $mut->checkMailLog(array(
1725 'Annual CiviCRM meet',
1726 'Event',
1727 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.',
1728 ));
1729 $mut->stop();
1730 }
1731
1732 /**
1733 * Test membership is renewed when transaction completed.
1734 */
1735 public function testCompleteTransactionMembershipPriceSet() {
1736 $this->createPriceSetWithPage('membership');
1737 $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
1738 'name' => 'Grace',
1739 'return' => 'id')
1740 );
1741 $this->setUpPendingContribution($this->_ids['price_field_value'][0]);
1742 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
1743 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
1744 'membership_id' => $this->_ids['membership'],
1745 ));
1746 $this->assertEquals(1, $logs['count']);
1747 $this->assertEquals($stateOfGrace, $membership['status_id']);
1748 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution']));
1749 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
1750 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']);
1751 $this->callAPISuccessGetSingle('LineItem', array(
1752 'entity_id' => $this->_ids['membership'],
1753 'entity_table' => 'civicrm_membership',
1754 ));
1755 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
1756 'membership_id' => $this->_ids['membership'],
1757 ));
1758 $this->assertEquals(2, $logs['count']);
1759 $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']);
1760 $this->cleanUpAfterPriceSets();
1761 }
1762
1763 /**
1764 * Test membership is renewed when transaction completed.
1765 */
1766 public function testCompleteTransactionMembershipPriceSetTwoTerms() {
1767 $this->createPriceSetWithPage('membership');
1768 $this->setUpPendingContribution($this->_ids['price_field_value'][1]);
1769 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution']));
1770 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
1771 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']);
1772 $this->cleanUpAfterPriceSets();
1773 }
1774
1775 public function cleanUpAfterPriceSets() {
1776 $this->quickCleanUpFinancialEntities();
1777 $this->contactDelete($this->_ids['contact']);
1778 }
1779
1780
1781 /**
1782 * Create price set with contribution test for test setup.
1783 *
1784 * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
1785 * on parent class at some point (fn is not in 4.4).
1786 *
1787 * @param $entity
1788 * @param array $params
1789 */
1790 public function createPriceSetWithPage($entity, $params = array()) {
1791 $membershipTypeID = $this->membershipTypeCreate();
1792 $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array(
1793 'title' => "Test Contribution Page",
1794 'financial_type_id' => 1,
1795 'currency' => 'NZD',
1796 'goal_amount' => 50,
1797 'is_pay_later' => 1,
1798 'is_monetary' => TRUE,
1799 'is_email_receipt' => FALSE,
1800 ));
1801 $priceSet = $this->callAPISuccess('price_set', 'create', array(
1802 'is_quick_config' => 0,
1803 'extends' => 'CiviMember',
1804 'financial_type_id' => 1,
1805 'title' => 'my Page',
1806 ));
1807 $priceSetID = $priceSet['id'];
1808
1809 CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
1810 $priceField = $this->callAPISuccess('price_field', 'create', array(
1811 'price_set_id' => $priceSetID,
1812 'label' => 'Goat Breed',
1813 'html_type' => 'Radio',
1814 ));
1815 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1816 'price_set_id' => $priceSetID,
1817 'price_field_id' => $priceField['id'],
1818 'label' => 'Long Haired Goat',
1819 'amount' => 20,
1820 'financial_type_id' => 'Donation',
1821 'membership_type_id' => $membershipTypeID,
1822 'membership_num_terms' => 1,
1823 )
1824 );
1825 $this->_ids['price_field_value'] = array($priceFieldValue['id']);
1826 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1827 'price_set_id' => $priceSetID,
1828 'price_field_id' => $priceField['id'],
1829 'label' => 'Shoe-eating Goat',
1830 'amount' => 10,
1831 'financial_type_id' => 'Donation',
1832 'membership_type_id' => $membershipTypeID,
1833 'membership_num_terms' => 2,
1834 )
1835 );
1836 $this->_ids['price_field_value'][] = $priceFieldValue['id'];
1837 $this->_ids['price_set'] = $priceSetID;
1838 $this->_ids['contribution_page'] = $contributionPageResult['id'];
1839 $this->_ids['price_field'] = array($priceField['id']);
1840
1841 $this->_ids['membership_type'] = $membershipTypeID;
1842 }
1843
1844 /**
1845 * Set up a pending transaction with a specific price field id.
1846 *
1847 * @param int $priceFieldValueID
1848 */
1849 public function setUpPendingContribution($priceFieldValueID) {
1850 $contactID = $this->individualCreate();
1851 $membership = $this->callAPISuccess('membership', 'create', array(
1852 'contact_id' => $contactID,
1853 'membership_type_id' => $this->_ids['membership_type'],
1854 'start_date' => 'yesterday - 1 year',
1855 'end_date' => 'yesterday',
1856 'join_date' => 'yesterday - 1 year',
1857 ));
1858 $contribution = $this->callAPISuccess('contribution', 'create', array(
1859 'domain_id' => 1,
1860 'contact_id' => $contactID,
1861 'receive_date' => date('Ymd'),
1862 'total_amount' => 100.00,
1863 'financial_type_id' => 1,
1864 'payment_instrument_id' => 'Credit Card',
1865 'non_deductible_amount' => 10.00,
1866 'trxn_id' => 'jdhfi88',
1867 'invoice_id' => 'djfhiewuyr',
1868 'source' => 'SSF',
1869 'contribution_status_id' => 2,
1870 'contribution_page_id' => $this->_ids['contribution_page'],
1871 'api.membership_payment.create' => array('membership_id' => $membership['id']),
1872 ));
1873
1874 $this->callAPISuccess('line_item', 'create', array(
1875 'entity_id' => $contribution['id'],
1876 'entity_table' => 'civicrm_contribution',
1877 'contribution_id' => $contribution['id'],
1878 'price_field_id' => $this->_ids['price_field'][0],
1879 'qty' => 1,
1880 'unit_price' => 20,
1881 'line_total' => 20,
1882 'financial_type_id' => 1,
1883 'price_field_value_id' => $priceFieldValueID,
1884 ));
1885 $this->_ids['contact'] = $contactID;
1886 $this->_ids['contribution'] = $contribution['id'];
1887 $this->_ids['membership'] = $membership['id'];
1888 }
1889
1890 /**
1891 * Test sending a mail via the API.
1892 */
1893 public function testSendMail() {
1894 $mut = new CiviMailUtils($this, TRUE);
1895 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
1896 $this->callAPISuccess('contribution', 'sendconfirmation', array(
1897 'id' => $contribution['id'],
1898 'receipt_from_email' => 'api@civicrm.org',
1899 )
1900 );
1901 $mut->checkMailLog(array(
1902 '$ 100.00',
1903 'Contribution Information',
1904 'Please print this confirmation for your records',
1905 ), array(
1906 'Event',
1907 )
1908 );
1909 $mut->stop();
1910 }
1911
1912 /**
1913 * Test sending a mail via the API.
1914 */
1915 public function testSendMailEvent() {
1916 $mut = new CiviMailUtils($this, TRUE);
1917 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
1918 $event = $this->eventCreate(array(
1919 'is_email_confirm' => 1,
1920 'confirm_from_email' => 'test@civicrm.org',
1921 ));
1922 $this->_eventID = $event['id'];
1923 $participantParams = array(
1924 'contact_id' => $this->_individualId,
1925 'event_id' => $this->_eventID,
1926 'status_id' => 1,
1927 'role_id' => 1,
1928 // to ensure it matches later on
1929 'register_date' => '2007-07-21 00:00:00',
1930 'source' => 'Online Event Registration: API Testing',
1931
1932 );
1933 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
1934 $this->callAPISuccess('participant_payment', 'create', array(
1935 'participant_id' => $participant['id'],
1936 'contribution_id' => $contribution['id'],
1937 ));
1938 $this->callAPISuccess('contribution', 'sendconfirmation', array(
1939 'id' => $contribution['id'],
1940 'receipt_from_email' => 'api@civicrm.org',
1941 )
1942 );
1943
1944 $mut->checkMailLog(array(
1945 'Annual CiviCRM meet',
1946 'Event',
1947 'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
1948 ), array()
1949 );
1950 $mut->stop();
1951 }
1952
1953 /**
1954 * This function does a GET & compares the result against the $params.
1955 *
1956 * Use as a double check on Creates.
1957 *
1958 * @param array $params
1959 * @param int $id
1960 * @param bool $delete
1961 */
1962 public function contributionGetnCheck($params, $id, $delete = TRUE) {
1963
1964 $contribution = $this->callAPISuccess('Contribution', 'Get', array(
1965 'id' => $id,
1966
1967 ));
1968
1969 if ($delete) {
1970 $this->callAPISuccess('contribution', 'delete', array('id' => $id));
1971 }
1972 $this->assertAPISuccess($contribution, 0);
1973 $values = $contribution['values'][$contribution['id']];
1974 $params['receive_date'] = date('Y-m-d H:i:s', strtotime($params['receive_date']));
1975 // this is not returned in id format
1976 unset($params['payment_instrument_id']);
1977 $params['contribution_source'] = $params['source'];
1978 unset($params['source']);
1979 foreach ($params as $key => $value) {
1980 $this->assertEquals($value, $values[$key], $key . " value: $value doesn't match " . print_r($values, TRUE));
1981 }
1982 }
1983
1984 /**
1985 * Create a pending contribution & linked pending participant record (along with an event).
1986 */
1987 public function createPendingParticipantContribution() {
1988 $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
1989 $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6));
1990 $this->_ids['participant'] = $participantID;
1991 $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
1992 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1993 $this->callAPISuccess('participant_payment', 'create', array(
1994 'contribution_id' => $contribution['id'],
1995 'participant_id' => $participantID,
1996 ));
1997 $this->callAPISuccess('line_item', 'get', array(
1998 'entity_id' => $contribution['id'],
1999 'entity_table' => 'civicrm_contribution',
2000 'api.line_item.create' => array(
2001 'entity_id' => $participantID,
2002 'entity_table' => 'civicrm_participant',
2003 ),
2004 ));
2005 return $contribution['id'];
2006 }
2007
2008 /**
2009 * Get financial transaction amount.
2010 *
2011 * @param int $contId
2012 *
2013 * @return null|string
2014 */
2015 public function _getFinancialTrxnAmount($contId) {
2016 $query = "SELECT
2017 SUM( ft.total_amount ) AS total
2018 FROM civicrm_financial_trxn AS ft
2019 LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
2020 WHERE ceft.entity_table = 'civicrm_contribution'
2021 AND ceft.entity_id = {$contId}";
2022
2023 $result = CRM_Core_DAO::singleValueQuery($query);
2024 return $result;
2025 }
2026
2027 /**
2028 * @param int $contId
2029 *
2030 * @return null|string
2031 */
2032 public function _getFinancialItemAmount($contId) {
2033 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
2034 $query = "SELECT
2035 SUM(amount)
2036 FROM civicrm_financial_item
2037 WHERE entity_table = 'civicrm_line_item'
2038 AND entity_id = {$lineItem}";
2039 $result = CRM_Core_DAO::singleValueQuery($query);
2040 return $result;
2041 }
2042
2043 /**
2044 * @param int $contId
2045 * @param $context
2046 */
2047 public function _checkFinancialItem($contId, $context) {
2048 if ($context != 'paylater') {
2049 $params = array(
2050 'entity_id' => $contId,
2051 'entity_table' => 'civicrm_contribution',
2052 );
2053 $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params, TRUE));
2054 $entityParams = array(
2055 'financial_trxn_id' => $trxn['financial_trxn_id'],
2056 'entity_table' => 'civicrm_financial_item',
2057 );
2058 $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
2059 $params = array(
2060 'id' => $entityTrxn['entity_id'],
2061 );
2062 }
2063 if ($context == 'paylater') {
2064 $lineItems = CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution');
2065 foreach ($lineItems as $key => $item) {
2066 $params = array(
2067 'entity_id' => $key,
2068 'entity_table' => 'civicrm_line_item',
2069 );
2070 $compareParams = array('status_id' => 1);
2071 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2072 }
2073 }
2074 elseif ($context == 'refund') {
2075 $compareParams = array(
2076 'status_id' => 1,
2077 'financial_account_id' => 1,
2078 'amount' => -100,
2079 );
2080 }
2081 elseif ($context == 'cancelPending') {
2082 $compareParams = array(
2083 'status_id' => 3,
2084 'financial_account_id' => 1,
2085 'amount' => -100,
2086 );
2087 }
2088 elseif ($context == 'changeFinancial') {
2089 $lineKey = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
2090 $params = array(
2091 'entity_id' => $lineKey,
2092 'amount' => -100,
2093 );
2094 $compareParams = array(
2095 'financial_account_id' => 1,
2096 );
2097 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2098 $params = array(
2099 'financial_account_id' => 3,
2100 'entity_id' => $lineKey,
2101 );
2102 $compareParams = array(
2103 'amount' => 100,
2104 );
2105 }
2106 if ($context != 'paylater') {
2107 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2108 }
2109 }
2110
2111 /**
2112 * @param array $contribution
2113 * @param string $context
2114 * @param int $instrumentId
2115 */
2116 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) {
2117 $trxnParams = array(
2118 'entity_id' => $contribution['id'],
2119 'entity_table' => 'civicrm_contribution',
2120 );
2121 $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, TRUE));
2122 $params = array(
2123 'id' => $trxn['financial_trxn_id'],
2124 );
2125 if ($context == 'payLater') {
2126 $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
2127 $compareParams = array(
2128 'status_id' => 1,
2129 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId),
2130 );
2131 }
2132 elseif ($context == 'refund') {
2133 $compareParams = array(
2134 'to_financial_account_id' => 6,
2135 'total_amount' => -100,
2136 'status_id' => 7,
2137 'trxn_date' => '2015-01-01 09:00:00',
2138 'trxn_id' => 'the refund',
2139 );
2140 }
2141 elseif ($context == 'cancelPending') {
2142 $compareParams = array(
2143 'to_financial_account_id' => 7,
2144 'total_amount' => -100,
2145 'status_id' => 3,
2146 );
2147 }
2148 elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') {
2149 $entityParams = array(
2150 'entity_id' => $contribution['id'],
2151 'entity_table' => 'civicrm_contribution',
2152 'amount' => -100,
2153 );
2154 $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
2155 $trxnParams1 = array(
2156 'id' => $trxn['financial_trxn_id'],
2157 );
2158 $compareParams = array(
2159 'total_amount' => -100,
2160 'status_id' => 1,
2161 );
2162 if ($context == 'paymentInstrument') {
2163 $compareParams += array(
2164 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4),
2165 'payment_instrument_id' => 4,
2166 );
2167 }
2168 else {
2169 $compareParams['to_financial_account_id'] = 12;
2170 }
2171 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams));
2172 $compareParams['total_amount'] = 100;
2173 if ($context == 'paymentInstrument') {
2174 $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId);
2175 $compareParams['payment_instrument_id'] = $instrumentId;
2176 }
2177 else {
2178 $compareParams['to_financial_account_id'] = 12;
2179 }
2180 }
2181
2182 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams));
2183 }
2184
2185 /**
2186 * @return mixed
2187 */
2188 public function _addPaymentInstrument() {
2189 $gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name');
2190 $optionParams = array(
2191 'option_group_id' => $gId,
2192 'label' => 'Test Card',
2193 'name' => 'Test Card',
2194 'value' => '6',
2195 'weight' => '6',
2196 'is_active' => 1,
2197 );
2198 $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams);
2199 $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
2200 $financialParams = array(
2201 'entity_table' => 'civicrm_option_value',
2202 'entity_id' => $optionValue['id'],
2203 'account_relationship' => $relationTypeId,
2204 'financial_account_id' => 7,
2205 );
2206 CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, CRM_Core_DAO::$_nullArray);
2207 $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']);
2208 return $optionValue['values'][$optionValue['id']]['value'];
2209 }
2210
2211 /**
2212 * @param array $params
2213 * @param $context
2214 */
2215 public function _checkFinancialRecords($params, $context) {
2216 $entityParams = array(
2217 'entity_id' => $params['id'],
2218 'entity_table' => 'civicrm_contribution',
2219 );
2220 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
2221 $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
2222 if ($context == 'pending') {
2223 $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
2224 $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
2225 return;
2226 }
2227 $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
2228 $trxnParams = array(
2229 'id' => $trxn['financial_trxn_id'],
2230 );
2231 if ($context != 'online' && $context != 'payLater') {
2232 $compareParams = array(
2233 'to_financial_account_id' => 6,
2234 'total_amount' => 100,
2235 'status_id' => 1,
2236 );
2237 }
2238 if ($context == 'feeAmount') {
2239 $compareParams['fee_amount'] = 50;
2240 }
2241 elseif ($context == 'online') {
2242 $compareParams = array(
2243 'to_financial_account_id' => 12,
2244 'total_amount' => 100,
2245 'status_id' => 1,
2246 );
2247 }
2248 elseif ($context == 'payLater') {
2249 $compareParams = array(
2250 'to_financial_account_id' => 7,
2251 'total_amount' => 100,
2252 'status_id' => 2,
2253 );
2254 }
2255 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2256 $entityParams = array(
2257 'financial_trxn_id' => $trxn['financial_trxn_id'],
2258 'entity_table' => 'civicrm_financial_item',
2259 );
2260 $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
2261 $fitemParams = array(
2262 'id' => $entityTrxn['entity_id'],
2263 );
2264 $compareParams = array(
2265 'amount' => 100,
2266 'status_id' => 1,
2267 'financial_account_id' => 1,
2268 );
2269 if ($context == 'payLater') {
2270 $compareParams = array(
2271 'amount' => 100,
2272 'status_id' => 3,
2273 'financial_account_id' => 1,
2274 );
2275 }
2276 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2277 if ($context == 'feeAmount') {
2278 $maxParams = array(
2279 'entity_id' => $params['id'],
2280 'entity_table' => 'civicrm_contribution',
2281 );
2282 $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
2283 $trxnParams = array(
2284 'id' => $maxTrxn['financial_trxn_id'],
2285 );
2286 $compareParams = array(
2287 'to_financial_account_id' => 5,
2288 'from_financial_account_id' => 6,
2289 'total_amount' => 50,
2290 'status_id' => 1,
2291 );
2292 $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
2293 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2294 $fitemParams = array(
2295 'entity_id' => $trxnId['financialTrxnId'],
2296 'entity_table' => 'civicrm_financial_trxn',
2297 );
2298 $compareParams = array(
2299 'amount' => 50,
2300 'status_id' => 1,
2301 'financial_account_id' => 5,
2302 );
2303 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2304 }
2305 }
2306
2307 }