3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 require_once 'CiviTest/CiviMailUtils.php';
33 * Test APIv3 civicrm_contribute_* functions
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contribution
38 class api_v3_ContributionTest
extends CiviUnitTestCase
{
41 * Assume empty database with just civicrm_data.
43 protected $_individualId;
44 protected $_contribution;
45 protected $_financialTypeId = 1;
46 protected $_apiversion;
47 protected $_entity = 'Contribution';
50 protected $_ids = array();
51 protected $_pageParams = array();
54 * Parameters to create payment processor.
58 protected $_processorParams = array();
61 * ID of created event.
70 public function setUp() {
73 $this->_apiversion
= 3;
74 $this->_individualId
= $this->individualCreate();
75 $paymentProcessor = $this->processorCreate();
76 $this->_params
= array(
77 'contact_id' => $this->_individualId
,
78 'receive_date' => '20120511',
79 'total_amount' => 100.00,
80 'financial_type_id' => $this->_financialTypeId
,
81 'non_deductible_amount' => 10.00,
83 'net_amount' => 95.00,
85 'contribution_status_id' => 1,
87 $this->_processorParams
= array(
90 'payment_processor_type_id' => 10,
91 'financial_account_id' => 12,
94 'url_site' => 'http://dummy.com',
95 'url_recur' => 'http://dummy.com',
98 $this->_pageParams
= array(
99 'title' => 'Test Contribution Page',
100 'financial_type_id' => 1,
102 'financial_account_id' => 1,
103 'payment_processor' => $paymentProcessor->id
,
105 'is_allow_other_amount' => 1,
107 'max_amount' => 1000,
112 * Clean up after each test.
114 public function tearDown() {
115 $this->quickCleanUpFinancialEntities();
121 public function testGetContribution() {
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,
131 'invoice_id' => 78910,
133 'contribution_status_id' => 1,
135 $this->_contribution
= $this->callAPISuccess('contribution', 'create', $p);
138 'contribution_id' => $this->_contribution
['id'],
141 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__
, __FILE__
);
142 $financialParams['id'] = $this->_financialTypeId
;
144 CRM_Financial_BAO_FinancialType
::retrieve($financialParams, $default);
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';
164 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
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,
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,
180 $this->assertEquals($contribution2['id'], $contribution);
182 $contribution = $this->callAPISuccess('contribution', 'get', array(
183 'id' => $this->_contribution
['id'],
185 $this->assertEquals(1, $contribution['count']);
187 // Test get by contact id works.
188 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId
));
190 $this->assertEquals(2, $contribution['count']);
191 $this->callAPISuccess('Contribution', 'Delete', array(
192 'id' => $this->_contribution
['id'],
194 $this->callAPISuccess('Contribution', 'Delete', array(
195 'id' => $contribution2['id'],
200 * We need to ensure previous tested behaviour still works as part of the api contract.
202 public function testGetContributionLegacyBehaviour() {
204 'contact_id' => $this->_individualId
,
205 'receive_date' => '2010-01-20',
206 'total_amount' => 100.00,
207 'contribution_type_id' => $this->_financialTypeId
,
208 'non_deductible_amount' => 10.00,
209 'fee_amount' => 5.00,
210 'net_amount' => 95.00,
212 'invoice_id' => 78910,
214 'contribution_status_id' => 1,
216 $this->_contribution
= $this->callAPISuccess('contribution', 'create', $p);
219 'contribution_id' => $this->_contribution
['id'],
221 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__
, __FILE__
);
222 $financialParams['id'] = $this->_financialTypeId
;
224 CRM_Financial_BAO_FinancialType
::retrieve($financialParams, $default);
226 $this->assertEquals(1, $contribution['count']);
227 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
228 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->_financialTypeId
);
229 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_type_id'], $this->_financialTypeId
);
230 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
231 $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00);
232 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00);
233 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00);
234 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456);
235 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
236 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
237 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
239 // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id).
240 $p['trxn_id'] = '3847';
241 $p['invoice_id'] = '3847';
243 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
245 // now we have 2 - test getcount
246 $contribution = $this->callAPISuccess('contribution', 'getcount', array());
247 $this->assertEquals(2, $contribution);
248 //test id only format
249 $contribution = $this->callAPISuccess('contribution', 'get', array(
250 'id' => $this->_contribution
['id'],
251 'format.only_id' => 1,
253 $this->assertEquals($this->_contribution
['id'], $contribution, print_r($contribution, TRUE));
254 //test id only format
255 $contribution = $this->callAPISuccess('contribution', 'get', array(
256 'id' => $contribution2['id'],
257 'format.only_id' => 1,
259 $this->assertEquals($contribution2['id'], $contribution);
260 $contribution = $this->callAPISuccess('contribution', 'get', array(
261 'id' => $this->_contribution
['id'],
264 $this->assertEquals(1, $contribution['count']);
265 // $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ;
266 //test get by contact id works
267 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId
));
269 $this->assertEquals(2, $contribution['count']);
270 $this->callAPISuccess('Contribution', 'Delete', array(
271 'id' => $this->_contribution
['id'],
273 $this->callAPISuccess('Contribution', 'Delete', array(
274 'id' => $contribution2['id'],
279 * Create an contribution_id=FALSE and financial_type_id=Donation.
281 public function testCreateEmptyContributionIDUseDonation() {
283 'contribution_id' => FALSE,
286 'check_permissions' => FALSE,
287 'financial_type_id' => 'Donation',
289 $this->callAPISuccess('contribution', 'create', $params);
293 * Check with complete array + custom field.
295 * Note that the test is written on purpose without any
296 * variables specific to participant so it can be replicated into other entities
297 * and / or moved to the automated test suite
299 public function testCreateWithCustom() {
300 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
302 $params = $this->_params
;
303 $params['custom_' . $ids['custom_field_id']] = "custom string";
305 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
306 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
307 $check = $this->callAPISuccess($this->_entity
, 'get', array(
308 'return.custom_' . $ids['custom_field_id'] => 1,
309 'id' => $result['id'],
311 $this->customFieldDelete($ids['custom_field_id']);
312 $this->customGroupDelete($ids['custom_group_id']);
313 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
317 * Check with complete array + custom field.
319 * Note that the test is written on purpose without any
320 * variables specific to participant so it can be replicated into other entities
321 * and / or moved to the automated test suite
323 public function testCreateGetFieldsWithCustom() {
324 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
325 $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, 'ContactTest.php');
326 $result = $this->callAPISuccess('Contribution', 'getfields', array());
327 $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']);
328 $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']);
329 $this->customFieldDelete($ids['custom_field_id']);
330 $this->customGroupDelete($ids['custom_group_id']);
331 $this->customFieldDelete($idsContact['custom_field_id']);
332 $this->customGroupDelete($idsContact['custom_group_id']);
335 public function testCreateContributionNoLineItems() {
338 'contact_id' => $this->_individualId
,
339 'receive_date' => '20120511',
340 'total_amount' => 100.00,
341 'financial_type_id' => $this->_financialTypeId
,
342 'payment_instrument_id' => 1,
343 'non_deductible_amount' => 10.00,
344 'fee_amount' => 50.00,
345 'net_amount' => 90.00,
347 'invoice_id' => 67890,
349 'contribution_status_id' => 1,
353 $contribution = $this->callAPISuccess('contribution', 'create', $params);
354 $lineItems = $this->callAPISuccess('line_item', 'get', array(
355 'entity_id' => $contribution['id'],
356 'entity_table' => 'civicrm_contribution',
359 $this->assertEquals(0, $lineItems['count']);
363 * Test checks that passing in line items suppresses the create mechanism.
365 public function testCreateContributionChainedLineItems() {
367 'contact_id' => $this->_individualId
,
368 'receive_date' => '20120511',
369 'total_amount' => 100.00,
370 'financial_type_id' => $this->_financialTypeId
,
371 'payment_instrument_id' => 1,
372 'non_deductible_amount' => 10.00,
373 'fee_amount' => 50.00,
374 'net_amount' => 90.00,
376 'invoice_id' => 67890,
378 'contribution_status_id' => 1,
380 'api.line_item.create' => array(
382 'price_field_id' => 1,
384 'line_total' => '20',
385 'unit_price' => '10',
388 'price_field_id' => 1,
390 'line_total' => '80',
391 'unit_price' => '80',
396 $description = "Create Contribution with Nested Line Items.";
397 $subfile = "CreateWithNestedLineItems";
398 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
400 $lineItems = $this->callAPISuccess('line_item', 'get', array(
401 'entity_id' => $contribution['id'],
402 'contribution_id' => $contribution['id'],
403 'entity_table' => 'civicrm_contribution',
406 $this->assertEquals(2, $lineItems['count']);
409 public function testCreateContributionOffline() {
411 'contact_id' => $this->_individualId
,
412 'receive_date' => '20120511',
413 'total_amount' => 100.00,
414 'financial_type_id' => 1,
416 'invoice_id' => 67890,
418 'contribution_status_id' => 1,
421 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
422 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
423 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
424 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
425 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
426 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
427 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
428 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
429 $lineItems = $this->callAPISuccess('line_item', 'get', array(
430 'entity_id' => $contribution['id'],
431 'contribution_id' => $contribution['id'],
432 'entity_table' => 'civicrm_contribution',
435 $this->assertEquals(1, $lineItems['count']);
436 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
437 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
438 $this->_checkFinancialRecords($contribution, 'offline');
439 $this->contributionGetnCheck($params, $contribution['id']);
443 * Test create with valid payment instrument.
445 public function testCreateContributionWithPaymentInstrument() {
446 $params = $this->_params +
array('payment_instrument' => 'EFT');
447 $contribution = $this->callAPISuccess('contribution', 'create', $params);
448 $contribution = $this->callAPISuccess('contribution', 'get', array(
450 'id' => $contribution['id'],
452 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
453 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
455 $this->callAPISuccess('contribution', 'create', array(
456 'id' => $contribution['id'],
457 'payment_instrument' => 'Credit Card',
459 $contribution = $this->callAPISuccess('contribution', 'get', array(
461 'id' => $contribution['id'],
463 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
464 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
467 public function testGetContributionByPaymentInstrument() {
468 $params = $this->_params +
array('payment_instrument' => 'EFT');
469 $params2 = $this->_params +
array('payment_instrument' => 'Cash');
470 $this->callAPISuccess('contribution', 'create', $params);
471 $this->callAPISuccess('contribution', 'create', $params2);
472 $contribution = $this->callAPISuccess('contribution', 'get', array(
474 'contribution_payment_instrument' => 'Cash',
476 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
477 $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
478 $this->assertEquals(1, $contribution['count']);
479 $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument' => 'Cash'));
480 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
481 $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
482 $this->assertEquals(1, $contribution['count']);
483 $contribution = $this->callAPISuccess('contribution', 'get', array(
485 'payment_instrument_id' => 5,
487 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
488 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
489 $this->assertEquals(1, $contribution['count']);
490 $contribution = $this->callAPISuccess('contribution', 'get', array(
492 'payment_instrument' => 'EFT',
494 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
495 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
496 $this->assertEquals(1, $contribution['count']);
497 $contribution = $this->callAPISuccess('contribution', 'create', array(
498 'id' => $contribution['id'],
499 'payment_instrument' => 'Credit Card',
501 $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id']));
502 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
503 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
504 $this->assertEquals(1, $contribution['count']);
508 * Create test with unique field name on source.
510 public function testCreateContributionSource() {
513 'contact_id' => $this->_individualId
,
514 'receive_date' => date('Ymd'),
515 'total_amount' => 100.00,
516 'financial_type_id' => $this->_financialTypeId
,
517 'payment_instrument_id' => 1,
518 'non_deductible_amount' => 10.00,
519 'fee_amount' => 50.00,
520 'net_amount' => 90.00,
522 'invoice_id' => 67890,
523 'contribution_source' => 'SSF',
524 'contribution_status_id' => 1,
527 $contribution = $this->callAPISuccess('contribution', 'create', $params);
528 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
529 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
533 * Create test with unique field name on source.
535 public function testCreateDefaultNow() {
537 $params = $this->_params
;
538 unset($params['receive_date']);
540 $contribution = $this->callAPISuccess('contribution', 'create', $params);
541 $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
542 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
546 * Create test with unique field name on source.
548 public function testCreateContributionSourceInvalidContact() {
552 'receive_date' => date('Ymd'),
553 'total_amount' => 100.00,
554 'financial_type_id' => $this->_financialTypeId
,
555 'payment_instrument_id' => 1,
556 'non_deductible_amount' => 10.00,
557 'fee_amount' => 50.00,
558 'net_amount' => 90.00,
560 'invoice_id' => 67890,
561 'contribution_source' => 'SSF',
562 'contribution_status_id' => 1,
565 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
568 public function testCreateContributionSourceInvalidContContact() {
571 'contribution_contact_id' => 999,
572 'receive_date' => date('Ymd'),
573 'total_amount' => 100.00,
574 'financial_type_id' => $this->_financialTypeId
,
575 'payment_instrument_id' => 1,
576 'non_deductible_amount' => 10.00,
577 'fee_amount' => 50.00,
578 'net_amount' => 90.00,
580 'invoice_id' => 67890,
581 'contribution_source' => 'SSF',
582 'contribution_status_id' => 1,
585 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
589 * Test note created correctly.
591 public function testCreateContributionWithNote() {
592 $description = "Demonstrates creating contribution with Note Entity.";
593 $subfile = "ContributionCreateWithNote";
595 'contact_id' => $this->_individualId
,
596 'receive_date' => '2012-01-01',
597 'total_amount' => 100.00,
598 'financial_type_id' => $this->_financialTypeId
,
599 'payment_instrument_id' => 1,
600 'non_deductible_amount' => 10.00,
601 'fee_amount' => 50.00,
602 'net_amount' => 90.00,
604 'invoice_id' => 67890,
606 'contribution_status_id' => 1,
607 'note' => 'my contribution note',
610 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
611 $result = $this->callAPISuccess('note', 'get', array(
612 'entity_table' => 'civicrm_contribution',
613 'entity_id' => $contribution['id'],
616 $this->assertEquals('my contribution note', $result['values'][0]['note']);
617 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
620 public function testCreateContributionWithNoteUniqueNameAliases() {
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,
631 'invoice_id' => 67890,
633 'contribution_status_id' => 1,
634 'contribution_note' => 'my contribution note',
637 $contribution = $this->callAPISuccess('contribution', 'create', $params);
638 $result = $this->callAPISuccess('note', 'get', array(
639 'entity_table' => 'civicrm_contribution',
640 'entity_id' => $contribution['id'],
643 $this->assertEquals('my contribution note', $result['values'][0]['note']);
644 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
648 * This is the test for creating soft credits.
650 public function testCreateContributionWithSoftCredit() {
651 $description = "Demonstrates creating contribution with SoftCredit.";
652 $subfile = "ContributionCreateWithSoftCredit";
653 $contact2 = $this->callAPISuccess('Contact', 'create', array(
654 'display_name' => 'superman',
655 'contact_type' => 'Individual',
658 'contact_id' => $contact2['id'],
660 'soft_credit_type_id' => 3,
663 $params = $this->_params +
array('soft_credit' => array(1 => $softParams));
664 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
665 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
667 $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']);
668 $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']);
669 $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']);
671 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
672 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
675 public function testCreateContributionWithSoftCreditDefaults() {
676 $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type.";
677 $subfile = "ContributionCreateWithSoftCreditDefaults";
678 $contact2 = $this->callAPISuccess('Contact', 'create', array(
679 'display_name' => 'superman',
680 'contact_type' => 'Individual',
682 $params = $this->_params +
array(
683 'soft_credit_to' => $contact2['id'],
685 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
686 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
688 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
689 // Default soft credit amount = contribution.total_amount
690 $this->assertEquals($this->_params
['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
691 $this->assertEquals(CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
693 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
694 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
697 public function testCreateContributionWithHonoreeContact() {
698 $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.";
699 $subfile = "ContributionCreateWithHonoreeContact";
700 $contact2 = $this->callAPISuccess('Contact', 'create', array(
701 'display_name' => 'superman',
702 'contact_type' => 'Individual',
704 $params = $this->_params +
array(
705 'honor_contact_id' => $contact2['id'],
707 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
708 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
710 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
711 // Default soft credit amount = contribution.total_amount
712 // Legacy mode in create api (honor_contact_id param) uses the standard "In Honor of" soft credit type
713 $this->assertEquals($this->_params
['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
714 $this->assertEquals(CRM_Core_OptionGroup
::getValue('soft_credit_type', 'in_honor_of', 'name'), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
716 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
717 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
721 * Test using example code.
723 public function testContributionCreateExample() {
724 //make sure at least on page exists since there is a truncate in tear down
725 $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
726 require_once 'api/v3/examples/Contribution/Create.php';
727 $result = contribution_create_example();
729 $expectedResult = contribution_create_expectedresult();
730 $this->checkArrayEquals($expectedResult, $result);
731 $this->contributionDelete($id);
735 * Function tests that additional financial records are created when fee amount is recorded.
737 public function testCreateContributionWithFee() {
739 'contact_id' => $this->_individualId
,
740 'receive_date' => '20120511',
741 'total_amount' => 100.00,
743 'financial_type_id' => 1,
745 'invoice_id' => 67890,
747 'contribution_status_id' => 1,
750 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
751 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
752 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
753 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 50.00);
754 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 50.00);
755 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
756 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
757 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
758 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
759 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
761 $lineItems = $this->callAPISuccess('line_item', 'get', array(
763 'entity_id' => $contribution['id'],
764 'entity_table' => 'civicrm_contribution',
767 $this->assertEquals(1, $lineItems['count']);
768 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
769 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
770 $lineItems = $this->callAPISuccess('line_item', 'get', array(
772 'entity_id' => $contribution['id'],
773 'contribution_id' => $contribution['id'],
774 'entity_table' => 'civicrm_contribution',
777 $this->assertEquals(1, $lineItems['count']);
778 $this->_checkFinancialRecords($contribution, 'feeAmount');
783 * Function tests that additional financial records are created when online contribution is created.
785 public function testCreateContributionOnline() {
786 CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
787 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
788 $this->assertAPISuccess($contributionPage);
790 'contact_id' => $this->_individualId
,
791 'receive_date' => '20120511',
792 'total_amount' => 100.00,
793 'financial_type_id' => 1,
794 'contribution_page_id' => $contributionPage['id'],
795 'payment_processor' => 1,
797 'invoice_id' => 67890,
799 'contribution_status_id' => 1,
803 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
804 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
805 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
806 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
807 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
808 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
809 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
810 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
811 $this->_checkFinancialRecords($contribution, 'online');
815 * Check handling of financial type.
817 * In the interests of removing financial type / contribution type checks from
818 * legacy format function lets test that the api is doing this for us
820 public function testCreateInvalidFinancialType() {
821 $params = $this->_params
;
822 $params['financial_type_id'] = 99999;
823 $this->callAPIFailure($this->_entity
, 'create', $params, "'99999' is not a valid option for field financial_type_id");
827 * Check handling of financial type.
829 * In the interests of removing financial type / contribution type checks from
830 * legacy format function lets test that the api is doing this for us
832 public function testValidNamedFinancialType() {
833 $params = $this->_params
;
834 $params['financial_type_id'] = 'Donation';
835 $this->callAPISuccess($this->_entity
, 'create', $params);
839 * Tests that additional financial records are created.
841 * Checks when online contribution with pay later option is created
843 public function testCreateContributionPayLaterOnline() {
844 CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
845 $this->_pageParams
['is_pay_later'] = 1;
846 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
847 $this->assertAPISuccess($contributionPage);
849 'contact_id' => $this->_individualId
,
850 'receive_date' => '20120511',
851 'total_amount' => 100.00,
852 'financial_type_id' => 1,
853 'contribution_page_id' => $contributionPage['id'],
856 'invoice_id' => 67890,
858 'contribution_status_id' => 2,
862 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
863 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
864 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
865 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
866 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
867 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
868 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
869 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
870 $this->_checkFinancialRecords($contribution, 'payLater');
874 * Function tests that additional financial records are created for online contribution with pending option.
876 public function testCreateContributionPendingOnline() {
877 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
878 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
879 $this->assertAPISuccess($contributionPage);
881 'contact_id' => $this->_individualId
,
882 'receive_date' => '20120511',
883 'total_amount' => 100.00,
884 'financial_type_id' => 1,
885 'contribution_page_id' => $contributionPage['id'],
887 'invoice_id' => 67890,
889 'contribution_status_id' => 2,
892 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
893 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
894 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
895 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
896 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
897 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
898 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
899 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
900 $this->_checkFinancialRecords($contribution, 'pending');
904 * Test that BAO defaults work.
906 public function testCreateBAODefaults() {
907 unset($this->_params
['contribution_source_id'], $this->_params
['payment_instrument_id']);
908 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
909 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
910 'id' => $contribution['id'],
911 'api.contribution.delete' => 1,
913 $this->assertEquals(1, $contribution['contribution_status_id']);
914 $this->assertEquals('Check', $contribution['payment_instrument']);
918 * Function tests that line items, financial records are updated when contribution amount is changed.
920 public function testCreateUpdateContributionChangeTotal() {
921 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
922 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
924 'entity_id' => $contribution['id'],
925 'entity_table' => 'civicrm_contribution',
927 'return' => 'line_total',
929 $this->assertEquals('100.00', $lineItems);
930 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
931 // Financial trxn SUM = 100 + 5 (fee)
932 $this->assertEquals('105.00', $trxnAmount);
935 'id' => $contribution['id'],
936 'total_amount' => '125',
938 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
940 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
942 'entity_id' => $contribution['id'],
943 'entity_table' => 'civicrm_contribution',
945 'return' => 'line_total',
948 $this->assertEquals('125.00', $lineItems);
949 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
951 // Financial trxn SUM = 125 + 5 (fee).
952 $this->assertEquals('130.00', $trxnAmount);
953 $this->assertEquals('125.00', $this->_getFinancialItemAmount($contribution['id']));
957 * Function tests that line items, financial records are updated when pay later contribution is received.
959 public function testCreateUpdateContributionPayLater() {
960 $contribParams = array(
961 'contact_id' => $this->_individualId
,
962 'receive_date' => '2012-01-01',
963 'total_amount' => 100.00,
964 'financial_type_id' => $this->_financialTypeId
,
965 'payment_instrument_id' => 1,
966 'contribution_status_id' => 2,
970 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
972 $newParams = array_merge($contribParams, array(
973 'id' => $contribution['id'],
974 'contribution_status_id' => 1,
977 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
978 $contribution = $contribution['values'][$contribution['id']];
979 $this->assertEquals($contribution['contribution_status_id'], '1');
980 $this->_checkFinancialItem($contribution['id'], 'paylater');
981 $this->_checkFinancialTrxn($contribution, 'payLater');
985 * Function tests that financial records are updated when Payment Instrument is changed.
987 public function testCreateUpdateContributionPaymentInstrument() {
988 $instrumentId = $this->_addPaymentInstrument();
989 $contribParams = array(
990 'contact_id' => $this->_individualId
,
991 'total_amount' => 100.00,
992 'financial_type_id' => $this->_financialTypeId
,
993 'payment_instrument_id' => 4,
994 'contribution_status_id' => 1,
997 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
999 $newParams = array_merge($contribParams, array(
1000 'id' => $contribution['id'],
1001 'payment_instrument_id' => $instrumentId,
1004 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1005 $this->assertAPISuccess($contribution);
1006 $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId);
1010 * Function tests that financial records are added when Contribution is Refunded.
1012 public function testCreateUpdateContributionRefund() {
1013 $contribParams = array(
1014 'contact_id' => $this->_individualId
,
1015 'receive_date' => '2012-01-01',
1016 'total_amount' => 100.00,
1017 'financial_type_id' => $this->_financialTypeId
,
1018 'payment_instrument_id' => 4,
1019 'contribution_status_id' => 1,
1022 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1023 $newParams = array_merge($contribParams, array(
1024 'id' => $contribution['id'],
1025 'contribution_status_id' => 7,
1029 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1030 $this->_checkFinancialTrxn($contribution, 'refund');
1031 $this->_checkFinancialItem($contribution['id'], 'refund');
1035 * Function tests invalid contribution status change.
1037 public function testCreateUpdateContributionInValidStatusChange() {
1038 $contribParams = array(
1040 'receive_date' => '2012-01-01',
1041 'total_amount' => 100.00,
1042 'financial_type_id' => 1,
1043 'payment_instrument_id' => 1,
1044 'contribution_status_id' => 1,
1046 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1047 $newParams = array_merge($contribParams, array(
1048 'id' => $contribution['id'],
1049 'contribution_status_id' => 2,
1052 $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.'));
1057 * Function tests that financial records are added when Pending Contribution is Canceled.
1059 public function testCreateUpdateContributionCancelPending() {
1060 $contribParams = array(
1061 'contact_id' => $this->_individualId
,
1062 'receive_date' => '2012-01-01',
1063 'total_amount' => 100.00,
1064 'financial_type_id' => $this->_financialTypeId
,
1065 'payment_instrument_id' => 1,
1066 'contribution_status_id' => 2,
1067 'is_pay_later' => 1,
1070 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1071 $newParams = array_merge($contribParams, array(
1072 'id' => $contribution['id'],
1073 'contribution_status_id' => 3,
1076 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1077 $this->_checkFinancialTrxn($contribution, 'cancelPending');
1078 $this->_checkFinancialItem($contribution['id'], 'cancelPending');
1082 * Function tests that financial records are added when Financial Type is Changed.
1084 public function testCreateUpdateContributionChangeFinancialType() {
1085 $contribParams = array(
1086 'contact_id' => $this->_individualId
,
1087 'receive_date' => '2012-01-01',
1088 'total_amount' => 100.00,
1089 'financial_type_id' => 1,
1090 'payment_instrument_id' => 1,
1091 'contribution_status_id' => 1,
1094 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1095 $newParams = array_merge($contribParams, array(
1096 'id' => $contribution['id'],
1097 'financial_type_id' => 3,
1100 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1101 $this->_checkFinancialTrxn($contribution, 'changeFinancial');
1102 $this->_checkFinancialItem($contribution['id'], 'changeFinancial');
1106 * Test that update does not change status id CRM-15105.
1108 public function testCreateUpdateWithoutChangingPendingStatus() {
1109 $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params
, array('contribution_status_id' => 2)));
1110 $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source'));
1111 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1112 'id' => $contribution['id'],
1113 'api.contribution.delete' => 1,
1115 $this->assertEquals(2, $contribution['contribution_status_id']);
1119 * Test Updating a Contribution.
1121 * CHANGE: we require the API to do an incremental update
1123 public function testCreateUpdateContribution() {
1125 $contributionID = $this->contributionCreate($this->_individualId
, $this->_financialTypeId
, 'idofsh', 212355);
1126 $old_params = array(
1127 'contribution_id' => $contributionID,
1130 $original = $this->callAPISuccess('contribution', 'get', $old_params);
1131 // Make sure it came back.
1132 $this->assertAPISuccess($original);
1133 $this->assertEquals($original['id'], $contributionID);
1134 //set up list of old params, verify
1136 //This should not be required on update:
1137 $old_contact_id = $original['values'][$contributionID]['contact_id'];
1138 $old_payment_instrument = $original['values'][$contributionID]['instrument_id'];
1139 $old_fee_amount = $original['values'][$contributionID]['fee_amount'];
1140 $old_source = $original['values'][$contributionID]['contribution_source'];
1142 $old_trxn_id = $original['values'][$contributionID]['trxn_id'];
1143 $old_invoice_id = $original['values'][$contributionID]['invoice_id'];
1145 //check against values in CiviUnitTestCase::createContribution()
1146 $this->assertEquals($old_contact_id, $this->_individualId
);
1147 $this->assertEquals($old_fee_amount, 5.00);
1148 $this->assertEquals($old_source, 'SSF');
1149 $this->assertEquals($old_trxn_id, 212355);
1150 $this->assertEquals($old_invoice_id, 'idofsh');
1152 'id' => $contributionID,
1153 'contact_id' => $this->_individualId
,
1154 'total_amount' => 110.00,
1155 'financial_type_id' => $this->_financialTypeId
,
1156 'non_deductible_amount' => 10.00,
1157 'net_amount' => 100.00,
1158 'contribution_status_id' => 1,
1159 'note' => 'Donating for Nobel Cause',
1163 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1165 $new_params = array(
1166 'contribution_id' => $contribution['id'],
1169 $contribution = $this->callAPISuccess('contribution', 'get', $new_params);
1171 $this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId
);
1172 $this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00);
1173 $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId
);
1174 $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument);
1175 $this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00);
1176 $this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount);
1177 $this->assertEquals($contribution['values'][$contributionID]['net_amount'], 100.00);
1178 $this->assertEquals($contribution['values'][$contributionID]['trxn_id'], $old_trxn_id);
1179 $this->assertEquals($contribution['values'][$contributionID]['invoice_id'], $old_invoice_id);
1180 $this->assertEquals($contribution['values'][$contributionID]['contribution_source'], $old_source);
1181 $this->assertEquals($contribution['values'][$contributionID]['contribution_status'], 'Completed');
1183 'contribution_id' => $contributionID,
1186 $result = $this->callAPISuccess('contribution', 'delete', $params);
1187 $this->assertAPISuccess($result);
1190 ///////////////// civicrm_contribution_delete methods
1193 * Attempt (but fail) to delete a contribution without parameters.
1195 public function testDeleteEmptyParamsContribution() {
1197 $this->callAPIFailure('contribution', 'delete', $params);
1200 public function testDeleteParamsNotArrayContribution() {
1201 $params = 'contribution_id= 1';
1202 $contribution = $this->callAPIFailure('contribution', 'delete', $params);
1203 $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array');
1206 public function testDeleteWrongParamContribution() {
1208 'contribution_source' => 'SSF',
1211 $this->callAPIFailure('contribution', 'delete', $params);
1214 public function testDeleteContribution() {
1216 $contributionID = $this->contributionCreate($this->_individualId
, $this->_financialTypeId
, 'dfsdf', 12389);
1218 'id' => $contributionID,
1220 $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__
, __FILE__
);
1224 * Test civicrm_contribution_search with empty params.
1226 * All available contributions expected.
1228 public function testSearchEmptyParams() {
1232 'contact_id' => $this->_individualId
,
1233 'receive_date' => date('Ymd'),
1234 'total_amount' => 100.00,
1235 'financial_type_id' => $this->_financialTypeId
,
1236 'non_deductible_amount' => 10.00,
1237 'fee_amount' => 5.00,
1238 'net_amount' => 95.00,
1240 'invoice_id' => 78910,
1242 'contribution_status_id' => 1,
1245 $contribution = $this->callAPISuccess('contribution', 'create', $p);
1247 $result = $this->callAPISuccess('contribution', 'get', $params);
1248 // We're taking the first element.
1249 $res = $result['values'][$contribution['id']];
1251 $this->assertEquals($p['contact_id'], $res['contact_id']);
1252 $this->assertEquals($p['total_amount'], $res['total_amount']);
1253 $this->assertEquals($p['financial_type_id'], $res['financial_type_id']);
1254 $this->assertEquals($p['net_amount'], $res['net_amount']);
1255 $this->assertEquals($p['non_deductible_amount'], $res['non_deductible_amount']);
1256 $this->assertEquals($p['fee_amount'], $res['fee_amount']);
1257 $this->assertEquals($p['trxn_id'], $res['trxn_id']);
1258 $this->assertEquals($p['invoice_id'], $res['invoice_id']);
1259 $this->assertEquals($p['source'], $res['contribution_source']);
1260 // contribution_status_id = 1 => Completed
1261 $this->assertEquals('Completed', $res['contribution_status']);
1263 $this->contributionDelete($contribution['id']);
1267 * Test civicrm_contribution_search. Success expected.
1269 public function testSearch() {
1271 'contact_id' => $this->_individualId
,
1272 'receive_date' => date('Ymd'),
1273 'total_amount' => 100.00,
1274 'financial_type_id' => $this->_financialTypeId
,
1275 'non_deductible_amount' => 10.00,
1276 'contribution_status_id' => 1,
1279 $contribution1 = $this->callAPISuccess('contribution', 'create', $p1);
1282 'contact_id' => $this->_individualId
,
1283 'receive_date' => date('Ymd'),
1284 'total_amount' => 200.00,
1285 'financial_type_id' => $this->_financialTypeId
,
1286 'non_deductible_amount' => 20.00,
1287 'trxn_id' => 5454565,
1288 'invoice_id' => 1212124,
1289 'fee_amount' => 50.00,
1290 'net_amount' => 60.00,
1291 'contribution_status_id' => 2,
1294 $contribution2 = $this->callAPISuccess('contribution', 'create', $p2);
1297 'contribution_id' => $contribution2['id'],
1300 $result = $this->callAPISuccess('contribution', 'get', $params);
1301 $res = $result['values'][$contribution2['id']];
1303 $this->assertEquals($p2['contact_id'], $res['contact_id']);
1304 $this->assertEquals($p2['total_amount'], $res['total_amount']);
1305 $this->assertEquals($p2['financial_type_id'], $res['financial_type_id']);
1306 $this->assertEquals($p2['net_amount'], $res['net_amount']);
1307 $this->assertEquals($p2['non_deductible_amount'], $res['non_deductible_amount']);
1308 $this->assertEquals($p2['fee_amount'], $res['fee_amount']);
1309 $this->assertEquals($p2['trxn_id'], $res['trxn_id']);
1310 $this->assertEquals($p2['invoice_id'], $res['invoice_id']);
1311 // contribution_status_id = 2 => Pending
1312 $this->assertEquals('Pending', $res['contribution_status']);
1314 $this->contributionDelete($contribution1['id']);
1315 $this->contributionDelete($contribution2['id']);
1319 * Test completing a transaction via the API.
1321 * Note that we are creating a logged in user because email goes out from
1324 public function testCompleteTransaction() {
1325 $mut = new CiviMailUtils($this, TRUE);
1326 $this->createLoggedInUser();
1327 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1328 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1329 $this->callAPISuccess('contribution', 'completetransaction', array(
1330 'id' => $contribution['id'],
1332 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1333 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1334 $mut->checkMailLog(array(
1335 'Receipt - Contribution',
1336 'Please print this confirmation for your records.',
1342 * Test repeat contribution successfully creates line items.
1344 public function testRepeatTransaction() {
1345 $paymentProcessorID = $this->paymentProcessorCreate();
1346 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1347 'contact_id' => $this->_individualId
,
1348 'installments' => '12',
1349 'frequency_interval' => '1',
1351 'contribution_status_id' => 1,
1352 'start_date' => '2012-01-01 00:00:00',
1353 'currency' => 'USD',
1354 'frequency_unit' => 'month',
1355 'payment_processor_id' => $paymentProcessorID,
1357 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1359 array('contribution_recur_id' => $contributionRecur['id']))
1362 $this->callAPISuccess('contribution', 'repeattransaction', array(
1363 'original_contribution_id' => $originalContribution['id'],
1364 'contribution_status_id' => 'Completed',
1365 'trxn_id' => uniqid(),
1367 $lineItemParams = array(
1368 'entity_id' => $originalContribution['id'],
1376 'financial_type_id',
1377 'deductible_amount',
1378 'price_field_value_id',
1382 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1383 'entity_id' => $originalContribution['id'],
1385 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1386 'entity_id' => $originalContribution['id'] +
1,
1388 unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
1389 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1390 $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
1392 $this->quickCleanUpFinancialEntities();
1396 * Test completing a transaction does not 'mess' with net amount (CRM-15960).
1398 public function testCompleteTransactionNetAmountOK() {
1399 $this->createLoggedInUser();
1400 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1401 unset($params['net_amount']);
1402 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1403 $this->callAPISuccess('contribution', 'completetransaction', array(
1404 'id' => $contribution['id'],
1406 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
1407 $this->assertEquals('Completed', $contribution['contribution_status']);
1408 $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
1412 * CRM-14151 - Test completing a transaction via the API.
1414 public function testCompleteTransactionWithReceiptDateSet() {
1415 $mut = new CiviMailUtils($this, TRUE);
1416 $this->createLoggedInUser();
1417 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
1418 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1419 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id']));
1420 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1421 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1422 $mut->checkMailLog(array(
1423 'Receipt - Contribution',
1424 'Please print this confirmation for your records.',
1430 * Test completing a transaction with an event via the API.
1432 * Note that we are creating a logged in user because email goes out from
1435 public function testCompleteTransactionWithParticipantRecord() {
1436 $mut = new CiviMailUtils($this, TRUE);
1437 $mut->clearMessages();
1438 $this->createLoggedInUser();
1439 $contributionID = $this->createPendingParticipantContribution();
1440 $this->callAPISuccess('contribution', 'completetransaction', array(
1441 'id' => $contributionID,
1444 $participantStatus = $this->callAPISuccessGetValue('participant', array(
1445 'id' => $this->_ids
['participant'],
1446 'return' => 'participant_status_id',
1448 $this->assertEquals(1, $participantStatus);
1449 $mut->checkMailLog(array(
1450 'Annual CiviCRM meet',
1452 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.',
1458 * Test membership is renewed when transaction completed.
1460 public function testCompleteTransactionMembershipPriceSet() {
1461 $this->createPriceSetWithPage('membership');
1462 $this->setUpPendingContribution($this->_ids
['price_field_value'][0]);
1463 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
1464 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
1465 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']);
1466 $this->cleanUpAfterPriceSets();
1470 * Test membership is renewed when transaction completed.
1472 public function testCompleteTransactionMembershipPriceSetTwoTerms() {
1473 $this->createPriceSetWithPage('membership');
1474 $this->setUpPendingContribution($this->_ids
['price_field_value'][1]);
1475 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
1476 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
1477 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']);
1478 $this->cleanUpAfterPriceSets();
1481 public function cleanUpAfterPriceSets() {
1482 $this->quickCleanUpFinancialEntities();
1483 $this->contactDelete($this->_ids
['contact']);
1484 $this->callAPISuccess('price_set', 'delete', array('id' => $this->_ids
['price_set']));
1489 * Create price set with contribution test for test setup.
1491 * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
1492 * on parent class at some point (fn is not in 4.4).
1495 * @param array $params
1497 public function createPriceSetWithPage($entity, $params = array()) {
1498 $membershipTypeID = $this->membershipTypeCreate();
1499 $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array(
1500 'title' => "Test Contribution Page",
1501 'financial_type_id' => 1,
1502 'currency' => 'NZD',
1503 'goal_amount' => 50,
1504 'is_pay_later' => 1,
1505 'is_monetary' => TRUE,
1506 'is_email_receipt' => FALSE,
1508 $priceSet = $this->callAPISuccess('price_set', 'create', array(
1509 'is_quick_config' => 0,
1510 'extends' => 'CiviMember',
1511 'financial_type_id' => 1,
1512 'title' => 'my Page',
1514 $priceSetID = $priceSet['id'];
1516 CRM_Price_BAO_PriceSet
::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
1517 $priceField = $this->callAPISuccess('price_field', 'create', array(
1518 'price_set_id' => $priceSetID,
1519 'label' => 'Goat Breed',
1520 'html_type' => 'Radio',
1522 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1523 'price_set_id' => $priceSetID,
1524 'price_field_id' => $priceField['id'],
1525 'label' => 'Long Haired Goat',
1527 'membership_type_id' => $membershipTypeID,
1528 'membership_num_terms' => 1,
1531 $this->_ids
['price_field_value'] = array($priceFieldValue['id']);
1532 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1533 'price_set_id' => $priceSetID,
1534 'price_field_id' => $priceField['id'],
1535 'label' => 'Shoe-eating Goat',
1537 'membership_type_id' => $membershipTypeID,
1538 'membership_num_terms' => 2,
1541 $this->_ids
['price_field_value'][] = $priceFieldValue['id'];
1542 $this->_ids
['price_set'] = $priceSetID;
1543 $this->_ids
['contribution_page'] = $contributionPageResult['id'];
1544 $this->_ids
['price_field'] = array($priceField['id']);
1546 $this->_ids
['membership_type'] = $membershipTypeID;
1550 * Set up a pending transaction with a specific price field id.
1552 * @param int $priceFieldValueID
1554 public function setUpPendingContribution($priceFieldValueID) {
1555 $contactID = $this->individualCreate();
1556 $membership = $this->callAPISuccess('membership', 'create', array(
1557 'contact_id' => $contactID,
1558 'membership_type_id' => $this->_ids
['membership_type'],
1559 'start_date' => 'yesterday - 1 year',
1560 'end_date' => 'yesterday',
1562 $contribution = $this->callAPISuccess('contribution', 'create', array(
1564 'contact_id' => $contactID,
1565 'receive_date' => date('Ymd'),
1566 'total_amount' => 100.00,
1567 'financial_type_id' => 1,
1568 'payment_instrument_id' => 'Credit Card',
1569 'non_deductible_amount' => 10.00,
1570 'trxn_id' => 'jdhfi88',
1571 'invoice_id' => 'djfhiewuyr',
1573 'contribution_status_id' => 2,
1574 'contribution_page_id' => $this->_ids
['contribution_page'],
1575 'api.membership_payment.create' => array('membership_id' => $membership['id']),
1578 $this->callAPISuccess('line_item', 'create', array(
1579 'entity_id' => $contribution['id'],
1580 'entity_table' => 'civicrm_contribution',
1581 'contribution_id' => $contribution['id'],
1582 'price_field_id' => $this->_ids
['price_field'][0],
1586 'financial_type_id' => 1,
1587 'price_field_value_id' => $priceFieldValueID,
1589 $this->_ids
['contact'] = $contactID;
1590 $this->_ids
['contribution'] = $contribution['id'];
1591 $this->_ids
['membership'] = $membership['id'];
1595 * Test sending a mail via the API.
1597 public function testSendMail() {
1598 $mut = new CiviMailUtils($this, TRUE);
1599 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
1600 $this->callAPISuccess('contribution', 'sendconfirmation', array(
1601 'id' => $contribution['id'],
1602 'receipt_from_email' => 'api@civicrm.org',
1605 $mut->checkMailLog(array(
1607 'Contribution Information',
1608 'Please print this confirmation for your records',
1617 * Test sending a mail via the API.
1619 public function testSendMailEvent() {
1620 $mut = new CiviMailUtils($this, TRUE);
1621 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
1622 $event = $this->eventCreate(array(
1623 'is_email_confirm' => 1,
1624 'confirm_from_email' => 'test@civicrm.org',
1626 $this->_eventID
= $event['id'];
1627 $participantParams = array(
1628 'contact_id' => $this->_individualId
,
1629 'event_id' => $this->_eventID
,
1632 // to ensure it matches later on
1633 'register_date' => '2007-07-21 00:00:00',
1634 'source' => 'Online Event Registration: API Testing',
1637 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
1638 $this->callAPISuccess('participant_payment', 'create', array(
1639 'participant_id' => $participant['id'],
1640 'contribution_id' => $contribution['id'],
1642 $this->callAPISuccess('contribution', 'sendconfirmation', array(
1643 'id' => $contribution['id'],
1644 'receipt_from_email' => 'api@civicrm.org',
1648 $mut->checkMailLog(array(
1649 'Annual CiviCRM meet',
1651 'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
1658 * This function does a GET & compares the result against the $params.
1660 * Use as a double check on Creates.
1662 * @param array $params
1664 * @param bool int $delete
1666 public function contributionGetnCheck($params, $id, $delete = TRUE) {
1668 $contribution = $this->callAPISuccess('Contribution', 'Get', array(
1674 $this->callAPISuccess('contribution', 'delete', array('id' => $id));
1676 $this->assertAPISuccess($contribution, 0);
1677 $values = $contribution['values'][$contribution['id']];
1678 $params['receive_date'] = date('Y-m-d H:i:s', strtotime($params['receive_date']));
1679 // this is not returned in id format
1680 unset($params['payment_instrument_id']);
1681 $params['contribution_source'] = $params['source'];
1682 unset($params['source']);
1683 foreach ($params as $key => $value) {
1684 $this->assertEquals($value, $values[$key], $key . " value: $value doesn't match " . print_r($values, TRUE));
1689 * Create a pending contribution & linked pending participant record (along with an event).
1691 public function createPendingParticipantContribution() {
1692 $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
1693 $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6));
1694 $this->_ids
['participant'] = $participantID;
1695 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
1696 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1697 $this->callAPISuccess('participant_payment', 'create', array(
1698 'contribution_id' => $contribution['id'],
1699 'participant_id' => $participantID,
1701 $this->callAPISuccess('line_item', 'get', array(
1702 'entity_id' => $contribution['id'],
1703 'entity_table' => 'civicrm_contribution',
1704 'api.line_item.create' => array(
1705 'entity_id' => $participantID,
1706 'entity_table' => 'civicrm_participant',
1709 return $contribution['id'];
1713 * Get financial transaction amount.
1715 * @param int $contId
1717 * @return null|string
1719 public function _getFinancialTrxnAmount($contId) {
1721 SUM( ft.total_amount ) AS total
1722 FROM civicrm_financial_trxn AS ft
1723 LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
1724 WHERE ceft.entity_table = 'civicrm_contribution'
1725 AND ceft.entity_id = {$contId}";
1727 $result = CRM_Core_DAO
::singleValueQuery($query);
1732 * @param int $contId
1734 * @return null|string
1736 public function _getFinancialItemAmount($contId) {
1737 $lineItem = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
1740 FROM civicrm_financial_item
1741 WHERE entity_table = 'civicrm_line_item'
1742 AND entity_id = {$lineItem}";
1743 $result = CRM_Core_DAO
::singleValueQuery($query);
1748 * @param int $contId
1751 public function _checkFinancialItem($contId, $context) {
1752 if ($context != 'paylater') {
1754 'entity_id' => $contId,
1755 'entity_table' => 'civicrm_contribution',
1757 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($params, TRUE));
1758 $entityParams = array(
1759 'financial_trxn_id' => $trxn['financial_trxn_id'],
1760 'entity_table' => 'civicrm_financial_item',
1762 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
1764 'id' => $entityTrxn['entity_id'],
1767 if ($context == 'paylater') {
1768 $lineItems = CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution');
1769 foreach ($lineItems as $key => $item) {
1771 'entity_id' => $key,
1772 'entity_table' => 'civicrm_line_item',
1774 $compareParams = array('status_id' => 1);
1775 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
1778 elseif ($context == 'refund') {
1779 $compareParams = array(
1781 'financial_account_id' => 1,
1785 elseif ($context == 'cancelPending') {
1786 $compareParams = array(
1788 'financial_account_id' => 1,
1792 elseif ($context == 'changeFinancial') {
1793 $lineKey = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
1795 'entity_id' => $lineKey,
1798 $compareParams = array(
1799 'financial_account_id' => 1,
1801 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
1803 'financial_account_id' => 3,
1804 'entity_id' => $lineKey,
1806 $compareParams = array(
1810 if ($context != 'paylater') {
1811 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
1816 * @param $contribution
1818 * @param int $instrumentId
1820 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL) {
1821 $trxnParams = array(
1822 'entity_id' => $contribution['id'],
1823 'entity_table' => 'civicrm_contribution',
1825 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($trxnParams, TRUE));
1827 'id' => $trxn['financial_trxn_id'],
1829 if ($context == 'payLater') {
1830 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
1831 $compareParams = array(
1833 'from_financial_account_id' => CRM_Contribute_PseudoConstant
::financialAccountType($contribution['financial_type_id'], $relationTypeId),
1836 elseif ($context == 'refund') {
1837 $compareParams = array(
1838 'to_financial_account_id' => 6,
1839 'total_amount' => -100,
1843 elseif ($context == 'cancelPending') {
1844 $compareParams = array(
1845 'from_financial_account_id' => 7,
1846 'total_amount' => -100,
1850 elseif ($context == 'changeFinancial' ||
$context == 'paymentInstrument') {
1851 $entityParams = array(
1852 'entity_id' => $contribution['id'],
1853 'entity_table' => 'civicrm_contribution',
1856 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
1857 $trxnParams1 = array(
1858 'id' => $trxn['financial_trxn_id'],
1860 $compareParams = array(
1861 'total_amount' => -100,
1864 if ($context == 'paymentInstrument') {
1865 $compareParams +
= array(
1866 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount(4),
1867 'payment_instrument_id' => 4,
1871 $compareParams['to_financial_account_id'] = 12;
1873 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, $compareParams);
1874 $compareParams['total_amount'] = 100;
1875 if ($context == 'paymentInstrument') {
1876 $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount($instrumentId);
1877 $compareParams['payment_instrument_id'] = $instrumentId;
1880 $compareParams['to_financial_account_id'] = 12;
1884 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, $compareParams);
1890 public function _addPaymentInstrument() {
1891 $gId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name');
1892 $optionParams = array(
1893 'option_group_id' => $gId,
1894 'label' => 'Test Card',
1895 'name' => 'Test Card',
1900 $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams);
1901 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
1902 $financialParams = array(
1903 'entity_table' => 'civicrm_option_value',
1904 'entity_id' => $optionValue['id'],
1905 'account_relationship' => $relationTypeId,
1906 'financial_account_id' => 7,
1908 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, CRM_Core_DAO
::$_nullArray);
1909 $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']);
1910 return $optionValue['values'][$optionValue['id']]['value'];
1914 * @param array $params
1917 public function _checkFinancialRecords($params, $context) {
1918 $entityParams = array(
1919 'entity_id' => $params['id'],
1920 'entity_table' => 'civicrm_contribution',
1922 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
1923 $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
1924 if ($context == 'pending') {
1925 $trxn = CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams);
1926 $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
1929 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
1930 $trxnParams = array(
1931 'id' => $trxn['financial_trxn_id'],
1933 if ($context != 'online' && $context != 'payLater') {
1934 $compareParams = array(
1935 'to_financial_account_id' => 6,
1936 'total_amount' => 100,
1940 if ($context == 'feeAmount') {
1941 $compareParams['fee_amount'] = 50;
1943 elseif ($context == 'online') {
1944 $compareParams = array(
1945 'to_financial_account_id' => 12,
1946 'total_amount' => 100,
1950 elseif ($context == 'payLater') {
1951 $compareParams = array(
1952 'to_financial_account_id' => 7,
1953 'total_amount' => 100,
1957 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
1958 $entityParams = array(
1959 'financial_trxn_id' => $trxn['financial_trxn_id'],
1960 'entity_table' => 'civicrm_financial_item',
1962 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
1963 $fitemParams = array(
1964 'id' => $entityTrxn['entity_id'],
1966 $compareParams = array(
1969 'financial_account_id' => 1,
1971 if ($context == 'payLater') {
1972 $compareParams = array(
1975 'financial_account_id' => 1,
1978 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
1979 if ($context == 'feeAmount') {
1981 'entity_id' => $params['id'],
1982 'entity_table' => 'civicrm_contribution',
1984 $maxTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($maxParams, TRUE));
1985 $trxnParams = array(
1986 'id' => $maxTrxn['financial_trxn_id'],
1988 $compareParams = array(
1989 'to_financial_account_id' => 5,
1990 'from_financial_account_id' => 6,
1991 'total_amount' => 50,
1994 $trxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($params['id'], 'DESC');
1995 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
1996 $fitemParams = array(
1997 'entity_id' => $trxnId['financialTrxnId'],
1998 'entity_table' => 'civicrm_financial_trxn',
2000 $compareParams = array(
2003 'financial_account_id' => 5,
2005 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);