3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_contribute_* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
35 class api_v3_ContributionTest
extends CiviUnitTestCase
{
38 * Assume empty database with just civicrm_data.
40 protected $_individualId;
41 protected $_contribution;
42 protected $_financialTypeId = 1;
43 protected $_apiversion;
44 protected $_entity = 'Contribution';
47 protected $_ids = array();
48 protected $_pageParams = array();
50 * Payment processor ID (dummy processor).
54 protected $paymentProcessorID;
57 * Parameters to create payment processor.
61 protected $_processorParams = array();
64 * ID of created event.
73 public function setUp() {
76 $this->_apiversion
= 3;
77 $this->_individualId
= $this->individualCreate();
78 $this->_params
= array(
79 'contact_id' => $this->_individualId
,
80 'receive_date' => '20120511',
81 'total_amount' => 100.00,
82 'financial_type_id' => $this->_financialTypeId
,
83 'non_deductible_amount' => 10.00,
85 'net_amount' => 95.00,
87 'contribution_status_id' => 1,
89 $this->_processorParams
= array(
92 'payment_processor_type_id' => CRM_Core_PseudoConstant
::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'),
93 'financial_account_id' => 12,
96 'url_site' => 'http://dummy.com',
97 'url_recur' => 'http://dummy.com',
100 $this->paymentProcessorID
= $this->processorCreate();
101 $this->_pageParams
= array(
102 'title' => 'Test Contribution Page',
103 'financial_type_id' => 1,
105 'financial_account_id' => 1,
106 'payment_processor' => $this->paymentProcessorID
,
108 'is_allow_other_amount' => 1,
110 'max_amount' => 1000,
115 * Clean up after each test.
117 public function tearDown() {
118 $this->quickCleanUpFinancialEntities();
119 $this->quickCleanup(array('civicrm_uf_match'));
125 public function testGetContribution() {
127 'contact_id' => $this->_individualId
,
128 'receive_date' => '2010-01-20',
129 'total_amount' => 100.00,
130 'financial_type_id' => $this->_financialTypeId
,
131 'non_deductible_amount' => 10.00,
132 'fee_amount' => 5.00,
133 'net_amount' => 95.00,
135 'invoice_id' => 78910,
137 'contribution_status_id' => 1,
139 $this->_contribution
= $this->callAPISuccess('contribution', 'create', $p);
142 'contribution_id' => $this->_contribution
['id'],
145 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__
, __FILE__
);
146 $financialParams['id'] = $this->_financialTypeId
;
148 CRM_Financial_BAO_FinancialType
::retrieve($financialParams, $default);
150 $this->assertEquals(1, $contribution['count']);
151 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
152 // Note there was an assertion converting financial_type_id to 'Donation' which wasn't working.
153 // Passing back a string rather than an id seems like an error/cruft.
154 // If it is to be introduced we should discuss.
155 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
156 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
157 $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00);
158 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00);
159 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00);
160 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456);
161 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
162 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
163 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
164 // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id).
165 $p['trxn_id'] = '3847';
166 $p['invoice_id'] = '3847';
168 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
170 // Now we have 2 - test getcount.
171 $contribution = $this->callAPISuccess('contribution', 'getcount', array());
172 $this->assertEquals(2, $contribution);
173 // Test id only format.
174 $contribution = $this->callAPISuccess('contribution', 'get', array(
175 'id' => $this->_contribution
['id'],
176 'format.only_id' => 1,
178 $this->assertEquals($this->_contribution
['id'], $contribution, print_r($contribution, TRUE));
179 // Test id only format.
180 $contribution = $this->callAPISuccess('contribution', 'get', array(
181 'id' => $contribution2['id'],
182 'format.only_id' => 1,
184 $this->assertEquals($contribution2['id'], $contribution);
186 $contribution = $this->callAPISuccess('contribution', 'get', array(
187 'id' => $this->_contribution
['id'],
189 $this->assertEquals(1, $contribution['count']);
191 // Test get by contact id works.
192 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId
));
194 $this->assertEquals(2, $contribution['count']);
195 $this->callAPISuccess('Contribution', 'Delete', array(
196 'id' => $this->_contribution
['id'],
198 $this->callAPISuccess('Contribution', 'Delete', array(
199 'id' => $contribution2['id'],
204 * Test that test contributions can be retrieved.
206 public function testGetTestContribution() {
207 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params
, array('is_test' => 1)));
208 $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1));
212 * We need to ensure previous tested behaviour still works as part of the api contract.
214 public function testGetContributionLegacyBehaviour() {
216 'contact_id' => $this->_individualId
,
217 'receive_date' => '2010-01-20',
218 'total_amount' => 100.00,
219 'contribution_type_id' => $this->_financialTypeId
,
220 'non_deductible_amount' => 10.00,
221 'fee_amount' => 5.00,
222 'net_amount' => 95.00,
224 'invoice_id' => 78910,
226 'contribution_status_id' => 1,
228 $this->_contribution
= $this->callAPISuccess('Contribution', 'create', $p);
231 'contribution_id' => $this->_contribution
['id'],
233 $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__
, __FILE__
);
234 $financialParams['id'] = $this->_financialTypeId
;
236 CRM_Financial_BAO_FinancialType
::retrieve($financialParams, $default);
238 $this->assertEquals(1, $contribution['count']);
239 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
240 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->_financialTypeId
);
241 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_type_id'], $this->_financialTypeId
);
242 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
243 $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00);
244 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00);
245 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00);
246 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456);
247 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
248 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
249 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
251 // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id).
252 $p['trxn_id'] = '3847';
253 $p['invoice_id'] = '3847';
255 $contribution2 = $this->callAPISuccess('contribution', 'create', $p);
257 // now we have 2 - test getcount
258 $contribution = $this->callAPISuccess('contribution', 'getcount', array());
259 $this->assertEquals(2, $contribution);
260 //test id only format
261 $contribution = $this->callAPISuccess('contribution', 'get', array(
262 'id' => $this->_contribution
['id'],
263 'format.only_id' => 1,
265 $this->assertEquals($this->_contribution
['id'], $contribution, print_r($contribution, TRUE));
266 //test id only format
267 $contribution = $this->callAPISuccess('contribution', 'get', array(
268 'id' => $contribution2['id'],
269 'format.only_id' => 1,
271 $this->assertEquals($contribution2['id'], $contribution);
272 $contribution = $this->callAPISuccess('contribution', 'get', array(
273 'id' => $this->_contribution
['id'],
276 $this->assertEquals(1, $contribution['count']);
277 // $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ;
278 //test get by contact id works
279 $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId
));
281 $this->assertEquals(2, $contribution['count']);
282 $this->callAPISuccess('Contribution', 'Delete', array(
283 'id' => $this->_contribution
['id'],
285 $this->callAPISuccess('Contribution', 'Delete', array(
286 'id' => $contribution2['id'],
291 * Create an contribution_id=FALSE and financial_type_id=Donation.
293 public function testCreateEmptyContributionIDUseDonation() {
295 'contribution_id' => FALSE,
298 'check_permissions' => FALSE,
299 'financial_type_id' => 'Donation',
301 $this->callAPISuccess('contribution', 'create', $params);
305 * Check with complete array + custom field.
307 * Note that the test is written on purpose without any
308 * variables specific to participant so it can be replicated into other entities
309 * and / or moved to the automated test suite
311 public function testCreateWithCustom() {
312 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
314 $params = $this->_params
;
315 $params['custom_' . $ids['custom_field_id']] = "custom string";
317 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
318 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
319 $check = $this->callAPISuccess($this->_entity
, 'get', array(
320 'return.custom_' . $ids['custom_field_id'] => 1,
321 'id' => $result['id'],
323 $this->customFieldDelete($ids['custom_field_id']);
324 $this->customGroupDelete($ids['custom_group_id']);
325 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
329 * Check with complete array + custom field.
331 * Note that the test is written on purpose without any
332 * variables specific to participant so it can be replicated into other entities
333 * and / or moved to the automated test suite
335 public function testCreateGetFieldsWithCustom() {
336 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
337 $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, 'ContactTest.php');
338 $result = $this->callAPISuccess('Contribution', 'getfields', array());
339 $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']);
340 $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']);
341 $this->customFieldDelete($ids['custom_field_id']);
342 $this->customGroupDelete($ids['custom_group_id']);
343 $this->customFieldDelete($idsContact['custom_field_id']);
344 $this->customGroupDelete($idsContact['custom_group_id']);
347 public function testCreateContributionNoLineItems() {
350 'contact_id' => $this->_individualId
,
351 'receive_date' => '20120511',
352 'total_amount' => 100.00,
353 'financial_type_id' => $this->_financialTypeId
,
354 'payment_instrument_id' => 1,
355 'non_deductible_amount' => 10.00,
356 'fee_amount' => 50.00,
357 'net_amount' => 90.00,
359 'invoice_id' => 67890,
361 'contribution_status_id' => 1,
365 $contribution = $this->callAPISuccess('contribution', 'create', $params);
366 $lineItems = $this->callAPISuccess('line_item', 'get', array(
367 'entity_id' => $contribution['id'],
368 'entity_table' => 'civicrm_contribution',
371 $this->assertEquals(0, $lineItems['count']);
375 * Test checks that passing in line items suppresses the create mechanism.
377 public function testCreateContributionChainedLineItems() {
379 'contact_id' => $this->_individualId
,
380 'receive_date' => '20120511',
381 'total_amount' => 100.00,
382 'financial_type_id' => $this->_financialTypeId
,
383 'payment_instrument_id' => 1,
384 'non_deductible_amount' => 10.00,
385 'fee_amount' => 50.00,
386 'net_amount' => 90.00,
388 'invoice_id' => 67890,
390 'contribution_status_id' => 1,
392 'api.line_item.create' => array(
394 'price_field_id' => 1,
396 'line_total' => '20',
397 'unit_price' => '10',
400 'price_field_id' => 1,
402 'line_total' => '80',
403 'unit_price' => '80',
408 $description = "Create Contribution with Nested Line Items.";
409 $subfile = "CreateWithNestedLineItems";
410 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
412 $lineItems = $this->callAPISuccess('line_item', 'get', array(
413 'entity_id' => $contribution['id'],
414 'contribution_id' => $contribution['id'],
415 'entity_table' => 'civicrm_contribution',
418 $this->assertEquals(2, $lineItems['count']);
421 public function testCreateContributionOffline() {
423 'contact_id' => $this->_individualId
,
424 'receive_date' => '20120511',
425 'total_amount' => 100.00,
426 'financial_type_id' => 1,
428 'invoice_id' => 67890,
430 'contribution_status_id' => 1,
433 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
434 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
435 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
436 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
437 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
438 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
439 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
440 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
441 $lineItems = $this->callAPISuccess('line_item', 'get', array(
442 'entity_id' => $contribution['id'],
443 'contribution_id' => $contribution['id'],
444 'entity_table' => 'civicrm_contribution',
447 $this->assertEquals(1, $lineItems['count']);
448 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
449 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
450 $this->_checkFinancialRecords($contribution, 'offline');
451 $this->contributionGetnCheck($params, $contribution['id']);
455 * Test create with valid payment instrument.
457 public function testCreateContributionWithPaymentInstrument() {
458 $params = $this->_params +
array('payment_instrument' => 'EFT');
459 $contribution = $this->callAPISuccess('contribution', 'create', $params);
460 $contribution = $this->callAPISuccess('contribution', 'get', array(
462 'id' => $contribution['id'],
464 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
465 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
467 $this->callAPISuccess('contribution', 'create', array(
468 'id' => $contribution['id'],
469 'payment_instrument' => 'Credit Card',
471 $contribution = $this->callAPISuccess('contribution', 'get', array(
473 'id' => $contribution['id'],
475 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
476 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
479 public function testGetContributionByPaymentInstrument() {
480 $params = $this->_params +
array('payment_instrument' => 'EFT');
481 $params2 = $this->_params +
array('payment_instrument' => 'Cash');
482 $this->callAPISuccess('contribution', 'create', $params);
483 $this->callAPISuccess('contribution', 'create', $params2);
484 $contribution = $this->callAPISuccess('contribution', 'get', array(
486 'contribution_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('sequential' => 1, 'payment_instrument' => 'Cash'));
492 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
493 $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
494 $this->assertEquals(1, $contribution['count']);
495 $contribution = $this->callAPISuccess('contribution', 'get', array(
497 'payment_instrument_id' => 5,
499 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
500 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
501 $this->assertEquals(1, $contribution['count']);
502 $contribution = $this->callAPISuccess('contribution', 'get', array(
504 'payment_instrument' => 'EFT',
506 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
507 $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
508 $this->assertEquals(1, $contribution['count']);
509 $contribution = $this->callAPISuccess('contribution', 'create', array(
510 'id' => $contribution['id'],
511 'payment_instrument' => 'Credit Card',
513 $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id']));
514 $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
515 $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
516 $this->assertEquals(1, $contribution['count']);
520 * CRM-16227 introduces invoice_id as a parameter.
522 public function testGetContributionByInvoice() {
523 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params
, array('invoice_id' => 'curly')));
524 $this->callAPISuccess('Contribution', 'create', array_merge($this->_params
), array('invoice_id' => 'churlish'));
525 $this->callAPISuccessGetCount('Contribution', array(), 2);
526 $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => 'curly'));
527 // The following don't work. They are the format we are trying to introduce but although the form uses this format
528 // CRM_Contact_BAO_Query::convertFormValues puts them into the other format & the where only supports that.
529 // ideally the where clause would support this format (as it does on contact_BAO_Query) and those lines would
530 // come out of convertFormValues
531 // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('LIKE' => '%ish%')));
532 // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('NOT IN' => array('curly'))));
533 // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('LIKE' => '%ly%')), 2);
534 // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('IN' => array('curly', 'churlish'))),
539 * Create test with unique field name on source.
541 public function testCreateContributionSource() {
544 'contact_id' => $this->_individualId
,
545 'receive_date' => date('Ymd'),
546 'total_amount' => 100.00,
547 'financial_type_id' => $this->_financialTypeId
,
548 'payment_instrument_id' => 1,
549 'non_deductible_amount' => 10.00,
550 'fee_amount' => 50.00,
551 'net_amount' => 90.00,
553 'invoice_id' => 67890,
554 'contribution_source' => 'SSF',
555 'contribution_status_id' => 1,
558 $contribution = $this->callAPISuccess('contribution', 'create', $params);
559 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
560 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
564 * Create test with unique field name on source.
566 public function testCreateDefaultNow() {
568 $params = $this->_params
;
569 unset($params['receive_date']);
571 $contribution = $this->callAPISuccess('contribution', 'create', $params);
572 $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
573 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
577 * Create test with unique field name on source.
579 public function testCreateContributionSourceInvalidContact() {
583 'receive_date' => date('Ymd'),
584 'total_amount' => 100.00,
585 'financial_type_id' => $this->_financialTypeId
,
586 'payment_instrument_id' => 1,
587 'non_deductible_amount' => 10.00,
588 'fee_amount' => 50.00,
589 'net_amount' => 90.00,
591 'invoice_id' => 67890,
592 'contribution_source' => 'SSF',
593 'contribution_status_id' => 1,
596 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
599 public function testCreateContributionSourceInvalidContContact() {
602 'contribution_contact_id' => 999,
603 'receive_date' => date('Ymd'),
604 'total_amount' => 100.00,
605 'financial_type_id' => $this->_financialTypeId
,
606 'payment_instrument_id' => 1,
607 'non_deductible_amount' => 10.00,
608 'fee_amount' => 50.00,
609 'net_amount' => 90.00,
611 'invoice_id' => 67890,
612 'contribution_source' => 'SSF',
613 'contribution_status_id' => 1,
616 $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
620 * Test note created correctly.
622 public function testCreateContributionWithNote() {
623 $description = "Demonstrates creating contribution with Note Entity.";
624 $subfile = "ContributionCreateWithNote";
626 'contact_id' => $this->_individualId
,
627 'receive_date' => '2012-01-01',
628 'total_amount' => 100.00,
629 'financial_type_id' => $this->_financialTypeId
,
630 'payment_instrument_id' => 1,
631 'non_deductible_amount' => 10.00,
632 'fee_amount' => 50.00,
633 'net_amount' => 90.00,
635 'invoice_id' => 67890,
637 'contribution_status_id' => 1,
638 'note' => 'my contribution note',
641 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
642 $result = $this->callAPISuccess('note', 'get', array(
643 'entity_table' => 'civicrm_contribution',
644 'entity_id' => $contribution['id'],
647 $this->assertEquals('my contribution note', $result['values'][0]['note']);
648 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
651 public function testCreateContributionWithNoteUniqueNameAliases() {
653 'contact_id' => $this->_individualId
,
654 'receive_date' => '2012-01-01',
655 'total_amount' => 100.00,
656 'financial_type_id' => $this->_financialTypeId
,
657 'payment_instrument_id' => 1,
658 'non_deductible_amount' => 10.00,
659 'fee_amount' => 50.00,
660 'net_amount' => 90.00,
662 'invoice_id' => 67890,
664 'contribution_status_id' => 1,
665 'contribution_note' => 'my contribution note',
668 $contribution = $this->callAPISuccess('contribution', 'create', $params);
669 $result = $this->callAPISuccess('note', 'get', array(
670 'entity_table' => 'civicrm_contribution',
671 'entity_id' => $contribution['id'],
674 $this->assertEquals('my contribution note', $result['values'][0]['note']);
675 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
679 * This is the test for creating soft credits.
681 public function testCreateContributionWithSoftCredit() {
682 $description = "Demonstrates creating contribution with SoftCredit.";
683 $subfile = "ContributionCreateWithSoftCredit";
684 $contact2 = $this->callAPISuccess('Contact', 'create', array(
685 'display_name' => 'superman',
686 'contact_type' => 'Individual',
689 'contact_id' => $contact2['id'],
691 'soft_credit_type_id' => 3,
694 $params = $this->_params +
array('soft_credit' => array(1 => $softParams));
695 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
696 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
698 $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']);
699 $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']);
700 $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']);
702 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
703 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
706 public function testCreateContributionWithSoftCreditDefaults() {
707 $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type.";
708 $subfile = "ContributionCreateWithSoftCreditDefaults";
709 $contact2 = $this->callAPISuccess('Contact', 'create', array(
710 'display_name' => 'superman',
711 'contact_type' => 'Individual',
713 $params = $this->_params +
array(
714 'soft_credit_to' => $contact2['id'],
716 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
717 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
719 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
720 // Default soft credit amount = contribution.total_amount
721 $this->assertEquals($this->_params
['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
722 $this->assertEquals(CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
724 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
725 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
728 public function testCreateContributionWithHonoreeContact() {
729 $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.";
730 $subfile = "ContributionCreateWithHonoreeContact";
731 $contact2 = $this->callAPISuccess('Contact', 'create', array(
732 'display_name' => 'superman',
733 'contact_type' => 'Individual',
735 $params = $this->_params +
array(
736 'honor_contact_id' => $contact2['id'],
738 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
739 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
741 $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
742 // Default soft credit amount = contribution.total_amount
743 // Legacy mode in create api (honor_contact_id param) uses the standard "In Honor of" soft credit type
744 $this->assertEquals($this->_params
['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
745 $this->assertEquals(CRM_Core_OptionGroup
::getValue('soft_credit_type', 'in_honor_of', 'name'), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
747 $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
748 $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
752 * Test using example code.
754 public function testContributionCreateExample() {
755 //make sure at least on page exists since there is a truncate in tear down
756 $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
757 require_once 'api/v3/examples/Contribution/Create.php';
758 $result = contribution_create_example();
760 $expectedResult = contribution_create_expectedresult();
761 $this->checkArrayEquals($expectedResult, $result);
762 $this->contributionDelete($id);
766 * Function tests that additional financial records are created when fee amount is recorded.
768 public function testCreateContributionWithFee() {
770 'contact_id' => $this->_individualId
,
771 'receive_date' => '20120511',
772 'total_amount' => 100.00,
774 'financial_type_id' => 1,
776 'invoice_id' => 67890,
778 'contribution_status_id' => 1,
781 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
782 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
783 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
784 $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 50.00);
785 $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 50.00);
786 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
787 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
788 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
789 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
790 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
792 $lineItems = $this->callAPISuccess('line_item', 'get', array(
794 'entity_id' => $contribution['id'],
795 'entity_table' => 'civicrm_contribution',
798 $this->assertEquals(1, $lineItems['count']);
799 $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
800 $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
801 $lineItems = $this->callAPISuccess('line_item', 'get', array(
803 'entity_id' => $contribution['id'],
804 'contribution_id' => $contribution['id'],
805 'entity_table' => 'civicrm_contribution',
808 $this->assertEquals(1, $lineItems['count']);
809 $this->_checkFinancialRecords($contribution, 'feeAmount');
814 * Function tests that additional financial records are created when online contribution is created.
816 public function testCreateContributionOnline() {
817 CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
818 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
819 $this->assertAPISuccess($contributionPage);
821 'contact_id' => $this->_individualId
,
822 'receive_date' => '20120511',
823 'total_amount' => 100.00,
824 'financial_type_id' => 1,
825 'contribution_page_id' => $contributionPage['id'],
826 'payment_processor' => 1,
828 'invoice_id' => 67890,
830 'contribution_status_id' => 1,
834 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
835 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
836 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
837 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
838 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
839 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
840 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
841 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
842 $this->_checkFinancialRecords($contribution, 'online');
846 * Check handling of financial type.
848 * In the interests of removing financial type / contribution type checks from
849 * legacy format function lets test that the api is doing this for us
851 public function testCreateInvalidFinancialType() {
852 $params = $this->_params
;
853 $params['financial_type_id'] = 99999;
854 $this->callAPIFailure($this->_entity
, 'create', $params, "'99999' is not a valid option for field financial_type_id");
858 * Check handling of financial type.
860 * In the interests of removing financial type / contribution type checks from
861 * legacy format function lets test that the api is doing this for us
863 public function testValidNamedFinancialType() {
864 $params = $this->_params
;
865 $params['financial_type_id'] = 'Donation';
866 $this->callAPISuccess($this->_entity
, 'create', $params);
870 * Tests that additional financial records are created.
872 * Checks when online contribution with pay later option is created
874 public function testCreateContributionPayLaterOnline() {
875 CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
876 $this->_pageParams
['is_pay_later'] = 1;
877 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
878 $this->assertAPISuccess($contributionPage);
880 'contact_id' => $this->_individualId
,
881 'receive_date' => '20120511',
882 'total_amount' => 100.00,
883 'financial_type_id' => 1,
884 'contribution_page_id' => $contributionPage['id'],
887 'invoice_id' => 67890,
889 'contribution_status_id' => 2,
893 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
894 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
895 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
896 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
897 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
898 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
899 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
900 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
901 $this->_checkFinancialRecords($contribution, 'payLater');
905 * Function tests that additional financial records are created for online contribution with pending option.
907 public function testCreateContributionPendingOnline() {
908 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::create($this->_processorParams
);
909 $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams
);
910 $this->assertAPISuccess($contributionPage);
912 'contact_id' => $this->_individualId
,
913 'receive_date' => '20120511',
914 'total_amount' => 100.00,
915 'financial_type_id' => 1,
916 'contribution_page_id' => $contributionPage['id'],
918 'invoice_id' => 67890,
920 'contribution_status_id' => 2,
923 $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__
, __FILE__
);
924 $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId
);
925 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
926 $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1);
927 $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
928 $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
929 $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
930 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
931 $this->_checkFinancialRecords($contribution, 'pending');
935 * Test that BAO defaults work.
937 public function testCreateBAODefaults() {
938 unset($this->_params
['contribution_source_id'], $this->_params
['payment_instrument_id']);
939 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
940 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
941 'id' => $contribution['id'],
942 'api.contribution.delete' => 1,
944 $this->assertEquals(1, $contribution['contribution_status_id']);
945 $this->assertEquals('Check', $contribution['payment_instrument']);
949 * Function tests that line items, financial records are updated when contribution amount is changed.
951 public function testCreateUpdateContributionChangeTotal() {
952 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
953 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
955 'entity_id' => $contribution['id'],
956 'entity_table' => 'civicrm_contribution',
958 'return' => 'line_total',
960 $this->assertEquals('100.00', $lineItems);
961 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
962 // Financial trxn SUM = 100 + 5 (fee)
963 $this->assertEquals('105.00', $trxnAmount);
966 'id' => $contribution['id'],
967 'total_amount' => '125',
969 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
971 $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
973 'entity_id' => $contribution['id'],
974 'entity_table' => 'civicrm_contribution',
976 'return' => 'line_total',
979 $this->assertEquals('125.00', $lineItems);
980 $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
982 // Financial trxn SUM = 125 + 5 (fee).
983 $this->assertEquals('130.00', $trxnAmount);
984 $this->assertEquals('125.00', $this->_getFinancialItemAmount($contribution['id']));
988 * Function tests that line items, financial records are updated when pay later contribution is received.
990 public function testCreateUpdateContributionPayLater() {
991 $contribParams = array(
992 'contact_id' => $this->_individualId
,
993 'receive_date' => '2012-01-01',
994 'total_amount' => 100.00,
995 'financial_type_id' => $this->_financialTypeId
,
996 'payment_instrument_id' => 1,
997 'contribution_status_id' => 2,
1001 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1003 $newParams = array_merge($contribParams, array(
1004 'id' => $contribution['id'],
1005 'contribution_status_id' => 1,
1008 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1009 $contribution = $contribution['values'][$contribution['id']];
1010 $this->assertEquals($contribution['contribution_status_id'], '1');
1011 $this->_checkFinancialItem($contribution['id'], 'paylater');
1012 $this->_checkFinancialTrxn($contribution, 'payLater');
1016 * Function tests that financial records are updated when Payment Instrument is changed.
1018 public function testCreateUpdateContributionPaymentInstrument() {
1019 $instrumentId = $this->_addPaymentInstrument();
1020 $contribParams = array(
1021 'contact_id' => $this->_individualId
,
1022 'total_amount' => 100.00,
1023 'financial_type_id' => $this->_financialTypeId
,
1024 'payment_instrument_id' => 4,
1025 'contribution_status_id' => 1,
1028 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1030 $newParams = array_merge($contribParams, array(
1031 'id' => $contribution['id'],
1032 'payment_instrument_id' => $instrumentId,
1035 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1036 $this->assertAPISuccess($contribution);
1037 $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId);
1041 * Function tests that financial records are added when Contribution is Refunded.
1043 public function testCreateUpdateContributionRefund() {
1044 $contributionParams = array(
1045 'contact_id' => $this->_individualId
,
1046 'receive_date' => '2012-01-01',
1047 'total_amount' => 100.00,
1048 'financial_type_id' => $this->_financialTypeId
,
1049 'payment_instrument_id' => 4,
1050 'contribution_status_id' => 1,
1051 'trxn_id' => 'original_payment',
1053 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1054 $newParams = array_merge($contributionParams, array(
1055 'id' => $contribution['id'],
1056 'contribution_status_id' => 'Refunded',
1057 'cancel_date' => '2015-01-01 09:00',
1058 'refund_trxn_id' => 'the refund',
1062 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1063 $this->_checkFinancialTrxn($contribution, 'refund');
1064 $this->_checkFinancialItem($contribution['id'], 'refund');
1065 $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', array(
1066 'id' => $contribution['id'],
1067 'return' => 'trxn_id',
1072 * Refund a contribution for a financial type with a contra account.
1074 * CRM-17951 the contra account is a financial account with a relationship to a
1075 * financial type. It is not always configured but should be reflected
1076 * in the financial_trxn & financial_item table if it is.
1078 public function testCreateUpdateChargebackContributionDefaultAccount() {
1079 $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params
);
1080 $this->callAPISuccess('Contribution', 'create', array(
1081 'id' => $contribution['id'],
1082 'contribution_status_id' => 'Chargeback',
1084 $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback'));
1086 $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
1087 'contribution_id' => $contribution['id'],
1088 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
1090 $this->assertEquals(1, $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
1091 $this->callAPISuccessGetSingle('FinancialTrxn', array(
1092 'total_amount' => -100,
1093 'status_id' => 'Chargeback',
1094 'to_financial_account_id' => 6,
1099 * Refund a contribution for a financial type with a contra account.
1101 * CRM-17951 the contra account is a financial account with a relationship to a
1102 * financial type. It is not always configured but should be reflected
1103 * in the financial_trxn & financial_item table if it is.
1105 public function testCreateUpdateChargebackContributionCustomAccount() {
1106 $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array(
1107 'name' => 'Chargeback Account',
1108 'is_active' => TRUE,
1111 $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array(
1112 'entity_id' => $this->_financialTypeId
,
1113 'entity_table' => 'civicrm_financial_type',
1114 'account_relationship' => 'Chargeback Account is',
1115 'financial_account_id' => 'Chargeback Account',
1118 $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params
);
1119 $this->callAPISuccess('Contribution', 'create', array(
1120 'id' => $contribution['id'],
1121 'contribution_status_id' => 'Chargeback',
1123 $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback'));
1125 $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
1126 'contribution_id' => $contribution['id'],
1127 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
1129 $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
1131 $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id']));
1132 $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id']));
1133 $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id']));
1137 * Refund a contribution for a financial type with a contra account.
1139 * CRM-17951 the contra account is a financial account with a relationship to a
1140 * financial type. It is not always configured but should be reflected
1141 * in the financial_trxn & financial_item table if it is.
1143 public function testCreateUpdateRefundContributionConfiguredContraAccount() {
1144 $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array(
1145 'name' => 'Refund Account',
1146 'is_active' => TRUE,
1149 $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array(
1150 'entity_id' => $this->_financialTypeId
,
1151 'entity_table' => 'civicrm_financial_type',
1152 'account_relationship' => 'Credit/Contra Revenue Account is',
1153 'financial_account_id' => 'Refund Account',
1156 $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params
);
1157 $this->callAPISuccess('Contribution', 'create', array(
1158 'id' => $contribution['id'],
1159 'contribution_status_id' => 'Refunded',
1162 $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
1163 'contribution_id' => $contribution['id'],
1164 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
1166 $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
1168 $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id']));
1169 $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id']));
1170 $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id']));
1174 * Function tests that trxn_id is set when passed in.
1176 * Here we ensure that the civicrm_financial_trxn.trxn_id & the civicrm_contribution.trxn_id are set
1177 * when trxn_id is passed in.
1179 public function testCreateUpdateContributionRefundTrxnIDPassedIn() {
1180 $contributionParams = array(
1181 'contact_id' => $this->_individualId
,
1182 'receive_date' => '2012-01-01',
1183 'total_amount' => 100.00,
1184 'financial_type_id' => $this->_financialTypeId
,
1185 'payment_instrument_id' => 4,
1186 'contribution_status_id' => 1,
1187 'trxn_id' => 'original_payment',
1189 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1190 $newParams = array_merge($contributionParams, array(
1191 'id' => $contribution['id'],
1192 'contribution_status_id' => 'Refunded',
1193 'cancel_date' => '2015-01-01 09:00',
1194 'trxn_id' => 'the refund',
1198 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1199 $this->_checkFinancialTrxn($contribution, 'refund');
1200 $this->_checkFinancialItem($contribution['id'], 'refund');
1201 $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', array(
1202 'id' => $contribution['id'],
1203 'return' => 'trxn_id',
1208 * Function tests that trxn_id is set when passed in.
1210 * Here we ensure that the civicrm_contribution.trxn_id is set
1211 * when trxn_id is passed in but if refund_trxn_id is different then that
1212 * is kept for the refund transaction.
1214 public function testCreateUpdateContributionRefundRefundAndTrxnIDPassedIn() {
1215 $contributionParams = array(
1216 'contact_id' => $this->_individualId
,
1217 'receive_date' => '2012-01-01',
1218 'total_amount' => 100.00,
1219 'financial_type_id' => $this->_financialTypeId
,
1220 'payment_instrument_id' => 4,
1221 'contribution_status_id' => 1,
1222 'trxn_id' => 'original_payment',
1224 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1225 $newParams = array_merge($contributionParams, array(
1226 'id' => $contribution['id'],
1227 'contribution_status_id' => 'Refunded',
1228 'cancel_date' => '2015-01-01 09:00',
1229 'trxn_id' => 'cont id',
1230 'refund_trxn_id' => 'the refund',
1234 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1235 $this->_checkFinancialTrxn($contribution, 'refund');
1236 $this->_checkFinancialItem($contribution['id'], 'refund');
1237 $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
1238 'id' => $contribution['id'],
1239 'return' => 'trxn_id',
1244 * Function tests that refund_trxn_id is set when passed in empty.
1246 * Here we ensure that the civicrm_contribution.trxn_id is set
1247 * when trxn_id is passed in but if refund_trxn_id isset but empty then that
1248 * is kept for the refund transaction.
1250 public function testCreateUpdateContributionRefundRefundNullTrxnIDPassedIn() {
1251 $contributionParams = array(
1252 'contact_id' => $this->_individualId
,
1253 'receive_date' => '2012-01-01',
1254 'total_amount' => 100.00,
1255 'financial_type_id' => $this->_financialTypeId
,
1256 'payment_instrument_id' => 4,
1257 'contribution_status_id' => 1,
1258 'trxn_id' => 'original_payment',
1260 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
1261 $newParams = array_merge($contributionParams, array(
1262 'id' => $contribution['id'],
1263 'contribution_status_id' => 'Refunded',
1264 'cancel_date' => '2015-01-01 09:00',
1265 'trxn_id' => 'cont id',
1266 'refund_trxn_id' => '',
1270 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1271 $this->_checkFinancialTrxn($contribution, 'refund', NULL, array('trxn_id' => NULL));
1272 $this->_checkFinancialItem($contribution['id'], 'refund');
1273 $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
1274 'id' => $contribution['id'],
1275 'return' => 'trxn_id',
1280 * Function tests invalid contribution status change.
1282 public function testCreateUpdateContributionInValidStatusChange() {
1283 $contribParams = array(
1285 'receive_date' => '2012-01-01',
1286 'total_amount' => 100.00,
1287 'financial_type_id' => 1,
1288 'payment_instrument_id' => 1,
1289 'contribution_status_id' => 1,
1291 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1292 $newParams = array_merge($contribParams, array(
1293 'id' => $contribution['id'],
1294 'contribution_status_id' => 2,
1297 $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.'));
1302 * Function tests that financial records are added when Pending Contribution is Canceled.
1304 public function testCreateUpdateContributionCancelPending() {
1305 $contribParams = array(
1306 'contact_id' => $this->_individualId
,
1307 'receive_date' => '2012-01-01',
1308 'total_amount' => 100.00,
1309 'financial_type_id' => $this->_financialTypeId
,
1310 'payment_instrument_id' => 1,
1311 'contribution_status_id' => 2,
1312 'is_pay_later' => 1,
1315 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1316 $newParams = array_merge($contribParams, array(
1317 'id' => $contribution['id'],
1318 'contribution_status_id' => 3,
1321 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1322 $this->_checkFinancialTrxn($contribution, 'cancelPending');
1323 $this->_checkFinancialItem($contribution['id'], 'cancelPending');
1327 * Function tests that financial records are added when Financial Type is Changed.
1329 public function testCreateUpdateContributionChangeFinancialType() {
1330 $contribParams = array(
1331 'contact_id' => $this->_individualId
,
1332 'receive_date' => '2012-01-01',
1333 'total_amount' => 100.00,
1334 'financial_type_id' => 1,
1335 'payment_instrument_id' => 1,
1336 'contribution_status_id' => 1,
1339 $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
1340 $newParams = array_merge($contribParams, array(
1341 'id' => $contribution['id'],
1342 'financial_type_id' => 3,
1345 $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
1346 $this->_checkFinancialTrxn($contribution, 'changeFinancial');
1347 $this->_checkFinancialItem($contribution['id'], 'changeFinancial');
1351 * Test that update does not change status id CRM-15105.
1353 public function testCreateUpdateWithoutChangingPendingStatus() {
1354 $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params
, array('contribution_status_id' => 2)));
1355 $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source'));
1356 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1357 'id' => $contribution['id'],
1358 'api.contribution.delete' => 1,
1360 $this->assertEquals(2, $contribution['contribution_status_id']);
1364 * Test Updating a Contribution.
1366 * CHANGE: we require the API to do an incremental update
1368 public function testCreateUpdateContribution() {
1370 $contributionID = $this->contributionCreate(array(
1371 'contact_id' => $this->_individualId
,
1372 'trxn_id' => 212355,
1373 'financial_type_id' => $this->_financialTypeId
,
1374 'invoice_id' => 'old_invoice',
1376 $old_params = array(
1377 'contribution_id' => $contributionID,
1379 $original = $this->callAPISuccess('contribution', 'get', $old_params);
1380 $this->assertEquals($original['id'], $contributionID);
1381 //set up list of old params, verify
1383 //This should not be required on update:
1384 $old_contact_id = $original['values'][$contributionID]['contact_id'];
1385 $old_payment_instrument = $original['values'][$contributionID]['instrument_id'];
1386 $old_fee_amount = $original['values'][$contributionID]['fee_amount'];
1387 $old_source = $original['values'][$contributionID]['contribution_source'];
1389 $old_trxn_id = $original['values'][$contributionID]['trxn_id'];
1390 $old_invoice_id = $original['values'][$contributionID]['invoice_id'];
1392 //check against values in CiviUnitTestCase::createContribution()
1393 $this->assertEquals($old_contact_id, $this->_individualId
);
1394 $this->assertEquals($old_fee_amount, 5.00);
1395 $this->assertEquals($old_source, 'SSF');
1396 $this->assertEquals($old_trxn_id, 212355);
1397 $this->assertEquals($old_invoice_id, 'old_invoice');
1399 'id' => $contributionID,
1400 'contact_id' => $this->_individualId
,
1401 'total_amount' => 110.00,
1402 'financial_type_id' => $this->_financialTypeId
,
1403 'non_deductible_amount' => 10.00,
1404 'net_amount' => 100.00,
1405 'contribution_status_id' => 1,
1406 'note' => 'Donating for Nobel Cause',
1410 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1412 $new_params = array(
1413 'contribution_id' => $contribution['id'],
1416 $contribution = $this->callAPISuccess('contribution', 'get', $new_params);
1418 $this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId
);
1419 $this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00);
1420 $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId
);
1421 $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument);
1422 $this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00);
1423 $this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount);
1424 $this->assertEquals($contribution['values'][$contributionID]['net_amount'], 100.00);
1425 $this->assertEquals($contribution['values'][$contributionID]['trxn_id'], $old_trxn_id);
1426 $this->assertEquals($contribution['values'][$contributionID]['invoice_id'], $old_invoice_id);
1427 $this->assertEquals($contribution['values'][$contributionID]['contribution_source'], $old_source);
1428 $this->assertEquals($contribution['values'][$contributionID]['contribution_status'], 'Completed');
1430 'contribution_id' => $contributionID,
1433 $result = $this->callAPISuccess('contribution', 'delete', $params);
1434 $this->assertAPISuccess($result);
1437 ///////////////// civicrm_contribution_delete methods
1440 * Attempt (but fail) to delete a contribution without parameters.
1442 public function testDeleteEmptyParamsContribution() {
1444 $this->callAPIFailure('contribution', 'delete', $params);
1447 public function testDeleteParamsNotArrayContribution() {
1448 $params = 'contribution_id= 1';
1449 $contribution = $this->callAPIFailure('contribution', 'delete', $params);
1450 $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array');
1453 public function testDeleteWrongParamContribution() {
1455 'contribution_source' => 'SSF',
1458 $this->callAPIFailure('contribution', 'delete', $params);
1461 public function testDeleteContribution() {
1462 $contributionID = $this->contributionCreate(array(
1463 'contact_id' => $this->_individualId
,
1464 'financial_type_id' => $this->_financialTypeId
,
1467 'id' => $contributionID,
1469 $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__
, __FILE__
);
1473 * Test civicrm_contribution_search with empty params.
1475 * All available contributions expected.
1477 public function testSearchEmptyParams() {
1481 'contact_id' => $this->_individualId
,
1482 'receive_date' => date('Ymd'),
1483 'total_amount' => 100.00,
1484 'financial_type_id' => $this->_financialTypeId
,
1485 'non_deductible_amount' => 10.00,
1486 'fee_amount' => 5.00,
1487 'net_amount' => 95.00,
1489 'invoice_id' => 78910,
1491 'contribution_status_id' => 1,
1494 $contribution = $this->callAPISuccess('contribution', 'create', $p);
1496 $result = $this->callAPISuccess('contribution', 'get', $params);
1497 // We're taking the first element.
1498 $res = $result['values'][$contribution['id']];
1500 $this->assertEquals($p['contact_id'], $res['contact_id']);
1501 $this->assertEquals($p['total_amount'], $res['total_amount']);
1502 $this->assertEquals($p['financial_type_id'], $res['financial_type_id']);
1503 $this->assertEquals($p['net_amount'], $res['net_amount']);
1504 $this->assertEquals($p['non_deductible_amount'], $res['non_deductible_amount']);
1505 $this->assertEquals($p['fee_amount'], $res['fee_amount']);
1506 $this->assertEquals($p['trxn_id'], $res['trxn_id']);
1507 $this->assertEquals($p['invoice_id'], $res['invoice_id']);
1508 $this->assertEquals($p['source'], $res['contribution_source']);
1509 // contribution_status_id = 1 => Completed
1510 $this->assertEquals('Completed', $res['contribution_status']);
1512 $this->contributionDelete($contribution['id']);
1516 * Test civicrm_contribution_search. Success expected.
1518 public function testSearch() {
1520 'contact_id' => $this->_individualId
,
1521 'receive_date' => date('Ymd'),
1522 'total_amount' => 100.00,
1523 'financial_type_id' => $this->_financialTypeId
,
1524 'non_deductible_amount' => 10.00,
1525 'contribution_status_id' => 1,
1528 $contribution1 = $this->callAPISuccess('contribution', 'create', $p1);
1531 'contact_id' => $this->_individualId
,
1532 'receive_date' => date('Ymd'),
1533 'total_amount' => 200.00,
1534 'financial_type_id' => $this->_financialTypeId
,
1535 'non_deductible_amount' => 20.00,
1536 'trxn_id' => 5454565,
1537 'invoice_id' => 1212124,
1538 'fee_amount' => 50.00,
1539 'net_amount' => 60.00,
1540 'contribution_status_id' => 2,
1543 $contribution2 = $this->callAPISuccess('contribution', 'create', $p2);
1546 'contribution_id' => $contribution2['id'],
1549 $result = $this->callAPISuccess('contribution', 'get', $params);
1550 $res = $result['values'][$contribution2['id']];
1552 $this->assertEquals($p2['contact_id'], $res['contact_id']);
1553 $this->assertEquals($p2['total_amount'], $res['total_amount']);
1554 $this->assertEquals($p2['financial_type_id'], $res['financial_type_id']);
1555 $this->assertEquals($p2['net_amount'], $res['net_amount']);
1556 $this->assertEquals($p2['non_deductible_amount'], $res['non_deductible_amount']);
1557 $this->assertEquals($p2['fee_amount'], $res['fee_amount']);
1558 $this->assertEquals($p2['trxn_id'], $res['trxn_id']);
1559 $this->assertEquals($p2['invoice_id'], $res['invoice_id']);
1560 // contribution_status_id = 2 => Pending
1561 $this->assertEquals('Pending', $res['contribution_status']);
1563 $this->contributionDelete($contribution1['id']);
1564 $this->contributionDelete($contribution2['id']);
1568 * Test completing a transaction via the API.
1570 * Note that we are creating a logged in user because email goes out from
1573 public function testCompleteTransaction() {
1574 $mut = new CiviMailUtils($this, TRUE);
1575 $this->createLoggedInUser();
1576 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1577 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1578 $this->callAPISuccess('contribution', 'completetransaction', array(
1579 'id' => $contribution['id'],
1581 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
1582 $this->assertEquals('SSF', $contribution['contribution_source']);
1583 $this->assertEquals('Completed', $contribution['contribution_status']);
1584 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
1585 $mut->checkMailLog(array(
1586 'Receipt - Contribution',
1587 'Please print this confirmation for your records.',
1594 * Test completing a transaction via the API.
1596 * Note that we are creating a logged in user because email goes out from
1599 public function testCompleteTransactionFeeAmount() {
1600 $this->createLoggedInUser();
1601 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1602 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1603 $this->callAPISuccess('contribution', 'completetransaction', array(
1604 'id' => $contribution['id'],
1605 'fee_amount' => '.56',
1606 'trxn_id' => '7778888',
1608 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1));
1609 $this->assertEquals('Completed', $contribution['contribution_status']);
1610 $this->assertEquals('7778888', $contribution['trxn_id']);
1611 $this->assertEquals('.56', $contribution['fee_amount']);
1612 $this->assertEquals('99.44', $contribution['net_amount']);
1616 * Test repeat contribution successfully creates line items.
1618 public function testRepeatTransaction() {
1619 $originalContribution = $this->setUpRepeatTransaction();
1621 $this->callAPISuccess('contribution', 'repeattransaction', array(
1622 'original_contribution_id' => $originalContribution['id'],
1623 'contribution_status_id' => 'Completed',
1624 'trxn_id' => uniqid(),
1626 $lineItemParams = array(
1627 'entity_id' => $originalContribution['id'],
1635 'financial_type_id',
1636 'deductible_amount',
1637 'price_field_value_id',
1641 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1642 'entity_id' => $originalContribution['id'],
1644 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1645 'entity_id' => $originalContribution['id'] +
1,
1647 unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
1648 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1649 $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
1651 $this->quickCleanUpFinancialEntities();
1655 * Test repeat contribution successfully creates line items.
1657 public function testRepeatTransactionIsTest() {
1658 $this->_params
['is_test'] = 1;
1659 $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1));
1661 $this->callAPISuccess('contribution', 'repeattransaction', array(
1662 'original_contribution_id' => $originalContribution['id'],
1663 'contribution_status_id' => 'Completed',
1664 'trxn_id' => uniqid(),
1666 $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2);
1670 * Test repeat contribution passed in status.
1672 public function testRepeatTransactionPassedInStatus() {
1673 $originalContribution = $this->setUpRepeatTransaction();
1675 $this->callAPISuccess('contribution', 'repeattransaction', array(
1676 'original_contribution_id' => $originalContribution['id'],
1677 'contribution_status_id' => 'Pending',
1678 'trxn_id' => uniqid(),
1680 $this->callAPISuccessGetCount('Contribution', array('contribution_status_id' => 2), 1);
1684 * Test repeat contribution accepts recur_id instead of original_contribution_id.
1686 public function testRepeatTransactionAcceptRecurID() {
1687 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1688 'contact_id' => $this->_individualId
,
1689 'installments' => '12',
1690 'frequency_interval' => '1',
1692 'contribution_status_id' => 1,
1693 'start_date' => '2012-01-01 00:00:00',
1694 'currency' => 'USD',
1695 'frequency_unit' => 'month',
1696 'payment_processor_id' => $this->paymentProcessorID
,
1698 $this->callAPISuccess('contribution', 'create', array_merge(
1700 array('contribution_recur_id' => $contributionRecur['id']))
1703 $this->callAPISuccess('contribution', 'repeattransaction', array(
1704 'contribution_recur_id' => $contributionRecur['id'],
1705 'contribution_status_id' => 'Completed',
1706 'trxn_id' => uniqid(),
1709 $this->quickCleanUpFinancialEntities();
1713 * CRM-16397 test appropriate action if total amount has changed for single line items.
1715 public function testRepeatTransactionAlteredAmount() {
1716 $paymentProcessorID = $this->paymentProcessorCreate();
1717 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1718 'contact_id' => $this->_individualId
,
1719 'installments' => '12',
1720 'frequency_interval' => '1',
1722 'contribution_status_id' => 1,
1723 'start_date' => '2012-01-01 00:00:00',
1724 'currency' => 'USD',
1725 'frequency_unit' => 'month',
1726 'payment_processor_id' => $paymentProcessorID,
1728 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1731 'contribution_recur_id' => $contributionRecur['id'],
1735 $this->callAPISuccess('contribution', 'repeattransaction', array(
1736 'original_contribution_id' => $originalContribution['id'],
1737 'contribution_status_id' => 'Completed',
1738 'trxn_id' => uniqid(),
1739 'total_amount' => '400',
1742 $lineItemParams = array(
1743 'entity_id' => $originalContribution['id'],
1751 'financial_type_id',
1752 'deductible_amount',
1753 'price_field_value_id',
1757 $this->callAPISuccessGetSingle('contribution', array(
1758 'total_amount' => 400,
1760 'net_amount' => 350,
1762 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1763 'entity_id' => $originalContribution['id'],
1765 $expectedLineItem = array_merge(
1766 $lineItem1['values'][0], array(
1767 'line_total' => '400.00',
1768 'unit_price' => '400.00',
1772 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1773 'entity_id' => $originalContribution['id'] +
1,
1775 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1776 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1777 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1781 * CRM-17718 test appropriate action if financial type has changed for single line items.
1783 public function testRepeatTransactionPassedInFinancialType() {
1784 $originalContribution = $this->setUpRecurringContribution();
1786 $this->callAPISuccess('contribution', 'repeattransaction', array(
1787 'original_contribution_id' => $originalContribution['id'],
1788 'contribution_status_id' => 'Completed',
1789 'trxn_id' => uniqid(),
1790 'financial_type_id' => 2,
1792 $lineItemParams = array(
1793 'entity_id' => $originalContribution['id'],
1801 'financial_type_id',
1802 'deductible_amount',
1803 'price_field_value_id',
1808 $this->callAPISuccessGetSingle('contribution', array(
1809 'total_amount' => 100,
1810 'financial_type_id' => 2,
1812 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1813 'entity_id' => $originalContribution['id'],
1815 $expectedLineItem = array_merge(
1816 $lineItem1['values'][0], array(
1817 'line_total' => '100.00',
1818 'unit_price' => '100.00',
1819 'financial_type_id' => 2,
1823 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1824 'entity_id' => $originalContribution['id'] +
1,
1826 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1827 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1828 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1832 * CRM-17718 test appropriate action if financial type has changed for single line items.
1834 public function testRepeatTransactionUpdatedFinancialType() {
1835 $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2));
1837 $this->callAPISuccess('contribution', 'repeattransaction', array(
1838 'contribution_recur_id' => $originalContribution['id'],
1839 'contribution_status_id' => 'Completed',
1840 'trxn_id' => uniqid(),
1842 $lineItemParams = array(
1843 'entity_id' => $originalContribution['id'],
1851 'financial_type_id',
1852 'deductible_amount',
1853 'price_field_value_id',
1858 $this->callAPISuccessGetSingle('contribution', array(
1859 'total_amount' => 100,
1860 'financial_type_id' => 2,
1862 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1863 'entity_id' => $originalContribution['id'],
1865 $expectedLineItem = array_merge(
1866 $lineItem1['values'][0], array(
1867 'line_total' => '100.00',
1868 'unit_price' => '100.00',
1869 'financial_type_id' => 2,
1873 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1874 'entity_id' => $originalContribution['id'] +
1,
1876 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1877 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1878 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1882 * CRM-16397 test appropriate action if campaign has been passed in.
1884 public function testRepeatTransactionPassedInCampaign() {
1885 $paymentProcessorID = $this->paymentProcessorCreate();
1886 $campaignID = $this->campaignCreate();
1887 $campaignID2 = $this->campaignCreate();
1888 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1889 'contact_id' => $this->_individualId
,
1890 'installments' => '12',
1891 'frequency_interval' => '1',
1893 'contribution_status_id' => 1,
1894 'start_date' => '2012-01-01 00:00:00',
1895 'currency' => 'USD',
1896 'frequency_unit' => 'month',
1897 'payment_processor_id' => $paymentProcessorID,
1899 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1902 'contribution_recur_id' => $contributionRecur['id'],
1903 'campaign_id' => $campaignID,
1907 $this->callAPISuccess('contribution', 'repeattransaction', array(
1908 'original_contribution_id' => $originalContribution['id'],
1909 'contribution_status_id' => 'Completed',
1910 'trxn_id' => uniqid(),
1911 'campaign_id' => $campaignID2,
1914 $this->callAPISuccessGetSingle('contribution', array(
1915 'total_amount' => 100,
1916 'campaign_id' => $campaignID2,
1921 * CRM-17718 campaign stored on contribution recur gets priority.
1923 * This reflects the fact we permit people to update them.
1925 public function testRepeatTransactionUpdatedCampaign() {
1926 $paymentProcessorID = $this->paymentProcessorCreate();
1927 $campaignID = $this->campaignCreate();
1928 $campaignID2 = $this->campaignCreate();
1929 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1930 'contact_id' => $this->_individualId
,
1931 'installments' => '12',
1932 'frequency_interval' => '1',
1934 'contribution_status_id' => 1,
1935 'start_date' => '2012-01-01 00:00:00',
1936 'currency' => 'USD',
1937 'frequency_unit' => 'month',
1938 'payment_processor_id' => $paymentProcessorID,
1939 'campaign_id' => $campaignID,
1941 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1944 'contribution_recur_id' => $contributionRecur['id'],
1945 'campaign_id' => $campaignID2,
1949 $this->callAPISuccess('contribution', 'repeattransaction', array(
1950 'original_contribution_id' => $originalContribution['id'],
1951 'contribution_status_id' => 'Completed',
1952 'trxn_id' => uniqid(),
1955 $this->callAPISuccessGetSingle('contribution', array(
1956 'total_amount' => 100,
1957 'campaign_id' => $campaignID,
1962 * Test completing a transaction does not 'mess' with net amount (CRM-15960).
1964 public function testCompleteTransactionNetAmountOK() {
1965 $this->createLoggedInUser();
1966 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1967 unset($params['net_amount']);
1968 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1969 $this->callAPISuccess('contribution', 'completetransaction', array(
1970 'id' => $contribution['id'],
1972 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
1973 $this->assertEquals('Completed', $contribution['contribution_status']);
1974 $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
1978 * CRM-14151 - Test completing a transaction via the API.
1980 public function testCompleteTransactionWithReceiptDateSet() {
1981 $mut = new CiviMailUtils($this, TRUE);
1982 $this->createLoggedInUser();
1983 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
1984 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1985 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d')));
1986 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1987 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1988 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date'])));
1989 $mut->checkMailLog(array(
1990 'Receipt - Contribution',
1991 'Please print this confirmation for your records.',
1997 * Test completing first transaction in a recurring series.
1999 * The status should be set to 'in progress' and the next scheduled payment date calculated.
2001 public function testCompleteTransactionSetStatusToInProgress() {
2002 $paymentProcessorID = $this->paymentProcessorCreate();
2003 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
2004 'contact_id' => $this->_individualId
,
2005 'installments' => '12',
2006 'frequency_interval' => '1',
2008 'contribution_status_id' => 'Pending',
2009 'start_date' => '2012-01-01 00:00:00',
2010 'currency' => 'USD',
2011 'frequency_unit' => 'month',
2012 'payment_processor_id' => $paymentProcessorID,
2014 $contribution = $this->callAPISuccess('contribution', 'create', array_merge(
2017 'contribution_recur_id' => $contributionRecur['id'],
2018 'contribution_status_id' => 'Pending',
2021 $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $contribution));
2022 $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array(
2023 'id' => $contributionRecur['id'],
2024 'return' => array('next_sched_contribution_date', 'contribution_status_id'),
2026 $this->assertEquals(5, $contributionRecur['contribution_status_id']);
2027 $this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']);
2031 * Test completing a transaction with an event via the API.
2033 * Note that we are creating a logged in user because email goes out from
2036 public function testCompleteTransactionWithParticipantRecord() {
2037 $mut = new CiviMailUtils($this, TRUE);
2038 $mut->clearMessages();
2039 $this->createLoggedInUser();
2040 $contributionID = $this->createPendingParticipantContribution();
2041 $this->callAPISuccess('contribution', 'completetransaction', array(
2042 'id' => $contributionID,
2045 $participantStatus = $this->callAPISuccessGetValue('participant', array(
2046 'id' => $this->_ids
['participant'],
2047 'return' => 'participant_status_id',
2049 $this->assertEquals(1, $participantStatus);
2050 $mut->checkMailLog(array(
2051 'Annual CiviCRM meet',
2053 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.',
2059 * Test membership is renewed when transaction completed.
2061 public function testCompleteTransactionMembershipPriceSet() {
2062 $this->createPriceSetWithPage('membership');
2063 $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
2067 $this->setUpPendingContribution($this->_ids
['price_field_value'][0]);
2068 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2069 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
2070 'membership_id' => $this->_ids
['membership'],
2072 $this->assertEquals(1, $logs['count']);
2073 $this->assertEquals($stateOfGrace, $membership['status_id']);
2074 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
2075 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2076 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']);
2077 $this->callAPISuccessGetSingle('LineItem', array(
2078 'entity_id' => $this->_ids
['membership'],
2079 'entity_table' => 'civicrm_membership',
2081 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
2082 'membership_id' => $this->_ids
['membership'],
2084 $this->assertEquals(2, $logs['count']);
2085 $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']);
2086 $this->cleanUpAfterPriceSets();
2090 * Test membership is renewed when transaction completed.
2092 public function testCompleteTransactionMembershipPriceSetTwoTerms() {
2093 $this->createPriceSetWithPage('membership');
2094 $this->setUpPendingContribution($this->_ids
['price_field_value'][1]);
2095 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
2096 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2097 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']);
2098 $this->cleanUpAfterPriceSets();
2101 public function cleanUpAfterPriceSets() {
2102 $this->quickCleanUpFinancialEntities();
2103 $this->contactDelete($this->_ids
['contact']);
2108 * Create price set with contribution test for test setup.
2110 * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
2111 * on parent class at some point (fn is not in 4.4).
2114 * @param array $params
2116 public function createPriceSetWithPage($entity, $params = array()) {
2117 $membershipTypeID = $this->membershipTypeCreate();
2118 $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array(
2119 'title' => "Test Contribution Page",
2120 'financial_type_id' => 1,
2121 'currency' => 'NZD',
2122 'goal_amount' => 50,
2123 'is_pay_later' => 1,
2124 'is_monetary' => TRUE,
2125 'is_email_receipt' => FALSE,
2127 $priceSet = $this->callAPISuccess('price_set', 'create', array(
2128 'is_quick_config' => 0,
2129 'extends' => 'CiviMember',
2130 'financial_type_id' => 1,
2131 'title' => 'my Page',
2133 $priceSetID = $priceSet['id'];
2135 CRM_Price_BAO_PriceSet
::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
2136 $priceField = $this->callAPISuccess('price_field', 'create', array(
2137 'price_set_id' => $priceSetID,
2138 'label' => 'Goat Breed',
2139 'html_type' => 'Radio',
2141 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
2142 'price_set_id' => $priceSetID,
2143 'price_field_id' => $priceField['id'],
2144 'label' => 'Long Haired Goat',
2146 'financial_type_id' => 'Donation',
2147 'membership_type_id' => $membershipTypeID,
2148 'membership_num_terms' => 1,
2151 $this->_ids
['price_field_value'] = array($priceFieldValue['id']);
2152 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
2153 'price_set_id' => $priceSetID,
2154 'price_field_id' => $priceField['id'],
2155 'label' => 'Shoe-eating Goat',
2157 'financial_type_id' => 'Donation',
2158 'membership_type_id' => $membershipTypeID,
2159 'membership_num_terms' => 2,
2162 $this->_ids
['price_field_value'][] = $priceFieldValue['id'];
2163 $this->_ids
['price_set'] = $priceSetID;
2164 $this->_ids
['contribution_page'] = $contributionPageResult['id'];
2165 $this->_ids
['price_field'] = array($priceField['id']);
2167 $this->_ids
['membership_type'] = $membershipTypeID;
2171 * Set up a pending transaction with a specific price field id.
2173 * @param int $priceFieldValueID
2175 public function setUpPendingContribution($priceFieldValueID) {
2176 $contactID = $this->individualCreate();
2177 $membership = $this->callAPISuccess('membership', 'create', array(
2178 'contact_id' => $contactID,
2179 'membership_type_id' => $this->_ids
['membership_type'],
2180 'start_date' => 'yesterday - 1 year',
2181 'end_date' => 'yesterday',
2182 'join_date' => 'yesterday - 1 year',
2184 $contribution = $this->callAPISuccess('contribution', 'create', array(
2186 'contact_id' => $contactID,
2187 'receive_date' => date('Ymd'),
2188 'total_amount' => 100.00,
2189 'financial_type_id' => 1,
2190 'payment_instrument_id' => 'Credit Card',
2191 'non_deductible_amount' => 10.00,
2192 'trxn_id' => 'jdhfi88',
2193 'invoice_id' => 'djfhiewuyr',
2195 'contribution_status_id' => 2,
2196 'contribution_page_id' => $this->_ids
['contribution_page'],
2197 'api.membership_payment.create' => array('membership_id' => $membership['id']),
2200 $this->callAPISuccess('line_item', 'create', array(
2201 'entity_id' => $contribution['id'],
2202 'entity_table' => 'civicrm_contribution',
2203 'contribution_id' => $contribution['id'],
2204 'price_field_id' => $this->_ids
['price_field'][0],
2208 'financial_type_id' => 1,
2209 'price_field_value_id' => $priceFieldValueID,
2211 $this->_ids
['contact'] = $contactID;
2212 $this->_ids
['contribution'] = $contribution['id'];
2213 $this->_ids
['membership'] = $membership['id'];
2217 * Test sending a mail via the API.
2219 public function testSendMail() {
2220 $mut = new CiviMailUtils($this, TRUE);
2221 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
2222 $this->callAPISuccess('contribution', 'sendconfirmation', array(
2223 'id' => $contribution['id'],
2224 'receipt_from_email' => 'api@civicrm.org',
2227 $mut->checkMailLog(array(
2229 'Contribution Information',
2230 'Please print this confirmation for your records',
2239 * Test sending a mail via the API.
2241 public function testSendMailEvent() {
2242 $mut = new CiviMailUtils($this, TRUE);
2243 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
2244 $event = $this->eventCreate(array(
2245 'is_email_confirm' => 1,
2246 'confirm_from_email' => 'test@civicrm.org',
2248 $this->_eventID
= $event['id'];
2249 $participantParams = array(
2250 'contact_id' => $this->_individualId
,
2251 'event_id' => $this->_eventID
,
2254 // to ensure it matches later on
2255 'register_date' => '2007-07-21 00:00:00',
2256 'source' => 'Online Event Registration: API Testing',
2259 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
2260 $this->callAPISuccess('participant_payment', 'create', array(
2261 'participant_id' => $participant['id'],
2262 'contribution_id' => $contribution['id'],
2264 $this->callAPISuccess('contribution', 'sendconfirmation', array(
2265 'id' => $contribution['id'],
2266 'receipt_from_email' => 'api@civicrm.org',
2270 $mut->checkMailLog(array(
2271 'Annual CiviCRM meet',
2273 'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
2280 * This function does a GET & compares the result against the $params.
2282 * Use as a double check on Creates.
2284 * @param array $params
2286 * @param bool $delete
2288 public function contributionGetnCheck($params, $id, $delete = TRUE) {
2290 $contribution = $this->callAPISuccess('Contribution', 'Get', array(
2296 $this->callAPISuccess('contribution', 'delete', array('id' => $id));
2298 $this->assertAPISuccess($contribution, 0);
2299 $values = $contribution['values'][$contribution['id']];
2300 $params['receive_date'] = date('Y-m-d H:i:s', strtotime($params['receive_date']));
2301 // this is not returned in id format
2302 unset($params['payment_instrument_id']);
2303 $params['contribution_source'] = $params['source'];
2304 unset($params['source']);
2305 foreach ($params as $key => $value) {
2306 $this->assertEquals($value, $values[$key], $key . " value: $value doesn't match " . print_r($values, TRUE));
2311 * Create a pending contribution & linked pending participant record (along with an event).
2313 public function createPendingParticipantContribution() {
2314 $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
2315 $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6));
2316 $this->_ids
['participant'] = $participantID;
2317 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
2318 $contribution = $this->callAPISuccess('contribution', 'create', $params);
2319 $this->callAPISuccess('participant_payment', 'create', array(
2320 'contribution_id' => $contribution['id'],
2321 'participant_id' => $participantID,
2323 $this->callAPISuccess('line_item', 'get', array(
2324 'entity_id' => $contribution['id'],
2325 'entity_table' => 'civicrm_contribution',
2326 'api.line_item.create' => array(
2327 'entity_id' => $participantID,
2328 'entity_table' => 'civicrm_participant',
2331 return $contribution['id'];
2335 * Get financial transaction amount.
2337 * @param int $contId
2339 * @return null|string
2341 public function _getFinancialTrxnAmount($contId) {
2343 SUM( ft.total_amount ) AS total
2344 FROM civicrm_financial_trxn AS ft
2345 LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
2346 WHERE ceft.entity_table = 'civicrm_contribution'
2347 AND ceft.entity_id = {$contId}";
2349 $result = CRM_Core_DAO
::singleValueQuery($query);
2354 * @param int $contId
2356 * @return null|string
2358 public function _getFinancialItemAmount($contId) {
2359 $lineItem = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
2362 FROM civicrm_financial_item
2363 WHERE entity_table = 'civicrm_line_item'
2364 AND entity_id = {$lineItem}";
2365 $result = CRM_Core_DAO
::singleValueQuery($query);
2370 * @param int $contId
2373 public function _checkFinancialItem($contId, $context) {
2374 if ($context != 'paylater') {
2376 'entity_id' => $contId,
2377 'entity_table' => 'civicrm_contribution',
2379 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($params, TRUE));
2380 $entityParams = array(
2381 'financial_trxn_id' => $trxn['financial_trxn_id'],
2382 'entity_table' => 'civicrm_financial_item',
2384 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2386 'id' => $entityTrxn['entity_id'],
2389 if ($context == 'paylater') {
2390 $lineItems = CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution');
2391 foreach ($lineItems as $key => $item) {
2393 'entity_id' => $key,
2394 'entity_table' => 'civicrm_line_item',
2396 $compareParams = array('status_id' => 1);
2397 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2400 elseif ($context == 'refund') {
2401 $compareParams = array(
2403 'financial_account_id' => 1,
2407 elseif ($context == 'cancelPending') {
2408 $compareParams = array(
2410 'financial_account_id' => 1,
2414 elseif ($context == 'changeFinancial') {
2415 $lineKey = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
2417 'entity_id' => $lineKey,
2420 $compareParams = array(
2421 'financial_account_id' => 1,
2423 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2425 'financial_account_id' => 3,
2426 'entity_id' => $lineKey,
2428 $compareParams = array(
2432 if ($context != 'paylater') {
2433 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2438 * Check financial transaction.
2440 * @todo break this down into sensible functions - most calls to it only use a few lines out of the big if.
2442 * @param array $contribution
2443 * @param string $context
2444 * @param int $instrumentId
2445 * @param array $extraParams
2447 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) {
2448 $trxnParams = array(
2449 'entity_id' => $contribution['id'],
2450 'entity_table' => 'civicrm_contribution',
2452 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($trxnParams, TRUE));
2454 'id' => $trxn['financial_trxn_id'],
2456 if ($context == 'payLater') {
2457 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
2458 $compareParams = array(
2460 'from_financial_account_id' => CRM_Contribute_PseudoConstant
::financialAccountType($contribution['financial_type_id'], $relationTypeId),
2463 elseif ($context == 'refund') {
2464 $compareParams = array(
2465 'to_financial_account_id' => 6,
2466 'total_amount' => -100,
2468 'trxn_date' => '2015-01-01 09:00:00',
2469 'trxn_id' => 'the refund',
2472 elseif ($context == 'cancelPending') {
2473 $compareParams = array(
2474 'to_financial_account_id' => 7,
2475 'total_amount' => -100,
2479 elseif ($context == 'changeFinancial' ||
$context == 'paymentInstrument') {
2480 $entityParams = array(
2481 'entity_id' => $contribution['id'],
2482 'entity_table' => 'civicrm_contribution',
2485 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2486 $trxnParams1 = array(
2487 'id' => $trxn['financial_trxn_id'],
2489 $compareParams = array(
2490 'total_amount' => -100,
2493 if ($context == 'paymentInstrument') {
2494 $compareParams +
= array(
2495 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount(4),
2496 'payment_instrument_id' => 4,
2500 $compareParams['to_financial_account_id'] = 12;
2502 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams));
2503 $compareParams['total_amount'] = 100;
2504 if ($context == 'paymentInstrument') {
2505 $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount($instrumentId);
2506 $compareParams['payment_instrument_id'] = $instrumentId;
2509 $compareParams['to_financial_account_id'] = 12;
2513 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams));
2519 public function _addPaymentInstrument() {
2520 $gId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name');
2521 $optionParams = array(
2522 'option_group_id' => $gId,
2523 'label' => 'Test Card',
2524 'name' => 'Test Card',
2529 $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams);
2530 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
2531 $financialParams = array(
2532 'entity_table' => 'civicrm_option_value',
2533 'entity_id' => $optionValue['id'],
2534 'account_relationship' => $relationTypeId,
2535 'financial_account_id' => 7,
2537 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, CRM_Core_DAO
::$_nullArray);
2538 $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']);
2539 return $optionValue['values'][$optionValue['id']]['value'];
2543 * @param array $params
2546 public function _checkFinancialRecords($params, $context) {
2547 $entityParams = array(
2548 'entity_id' => $params['id'],
2549 'entity_table' => 'civicrm_contribution',
2551 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
2552 $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
2553 if ($context == 'pending') {
2554 $trxn = CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams);
2555 $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
2558 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2559 $trxnParams = array(
2560 'id' => $trxn['financial_trxn_id'],
2562 if ($context != 'online' && $context != 'payLater') {
2563 $compareParams = array(
2564 'to_financial_account_id' => 6,
2565 'total_amount' => 100,
2569 if ($context == 'feeAmount') {
2570 $compareParams['fee_amount'] = 50;
2572 elseif ($context == 'online') {
2573 $compareParams = array(
2574 'to_financial_account_id' => 12,
2575 'total_amount' => 100,
2579 elseif ($context == 'payLater') {
2580 $compareParams = array(
2581 'to_financial_account_id' => 7,
2582 'total_amount' => 100,
2586 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2587 $entityParams = array(
2588 'financial_trxn_id' => $trxn['financial_trxn_id'],
2589 'entity_table' => 'civicrm_financial_item',
2591 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2592 $fitemParams = array(
2593 'id' => $entityTrxn['entity_id'],
2595 $compareParams = array(
2598 'financial_account_id' => 1,
2600 if ($context == 'payLater') {
2601 $compareParams = array(
2604 'financial_account_id' => 1,
2607 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2608 if ($context == 'feeAmount') {
2610 'entity_id' => $params['id'],
2611 'entity_table' => 'civicrm_contribution',
2613 $maxTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($maxParams, TRUE));
2614 $trxnParams = array(
2615 'id' => $maxTrxn['financial_trxn_id'],
2617 $compareParams = array(
2618 'to_financial_account_id' => 5,
2619 'from_financial_account_id' => 6,
2620 'total_amount' => 50,
2623 $trxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($params['id'], 'DESC');
2624 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2625 $fitemParams = array(
2626 'entity_id' => $trxnId['financialTrxnId'],
2627 'entity_table' => 'civicrm_financial_trxn',
2629 $compareParams = array(
2632 'financial_account_id' => 5,
2634 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2639 * Set up the basic recurring contribution for tests.
2641 * @param array $generalParams
2642 * Parameters that can be merged into the recurring AND the contribution.
2644 * @param array $recurParams
2645 * Parameters to merge into the recur only.
2649 protected function setUpRecurringContribution($generalParams = array(), $recurParams = array()) {
2650 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
2651 'contact_id' => $this->_individualId
,
2652 'installments' => '12',
2653 'frequency_interval' => '1',
2655 'contribution_status_id' => 1,
2656 'start_date' => '2012-01-01 00:00:00',
2657 'currency' => 'USD',
2658 'frequency_unit' => 'month',
2659 'payment_processor_id' => $this->paymentProcessorID
,
2660 ), $generalParams, $recurParams));
2661 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
2664 'contribution_recur_id' => $contributionRecur['id'],
2667 return $originalContribution;
2671 * Set up a repeat transaction.
2673 * @param array $recurParams
2677 protected function setUpRepeatTransaction($recurParams = array()) {
2678 $paymentProcessorID = $this->paymentProcessorCreate();
2679 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
2680 'contact_id' => $this->_individualId
,
2681 'installments' => '12',
2682 'frequency_interval' => '1',
2684 'contribution_status_id' => 1,
2685 'start_date' => '2012-01-01 00:00:00',
2686 'currency' => 'USD',
2687 'frequency_unit' => 'month',
2688 'payment_processor_id' => $paymentProcessorID,
2690 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
2692 array('contribution_recur_id' => $contributionRecur['id']))
2694 return $originalContribution;