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('Completed', $contribution['contribution_status']);
1583 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
1584 $mut->checkMailLog(array(
1585 'Receipt - Contribution',
1586 'Please print this confirmation for your records.',
1592 * Test completing a transaction via the API.
1594 * Note that we are creating a logged in user because email goes out from
1597 public function testCompleteTransactionFeeAmount() {
1598 $this->createLoggedInUser();
1599 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1600 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1601 $this->callAPISuccess('contribution', 'completetransaction', array(
1602 'id' => $contribution['id'],
1603 'fee_amount' => '.56',
1604 'trxn_id' => '7778888',
1606 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1));
1607 $this->assertEquals('Completed', $contribution['contribution_status']);
1608 $this->assertEquals('7778888', $contribution['trxn_id']);
1609 $this->assertEquals('.56', $contribution['fee_amount']);
1610 $this->assertEquals('99.44', $contribution['net_amount']);
1614 * Test repeat contribution successfully creates line items.
1616 public function testRepeatTransaction() {
1617 $originalContribution = $this->setUpRepeatTransaction();
1619 $this->callAPISuccess('contribution', 'repeattransaction', array(
1620 'original_contribution_id' => $originalContribution['id'],
1621 'contribution_status_id' => 'Completed',
1622 'trxn_id' => uniqid(),
1624 $lineItemParams = array(
1625 'entity_id' => $originalContribution['id'],
1633 'financial_type_id',
1634 'deductible_amount',
1635 'price_field_value_id',
1639 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1640 'entity_id' => $originalContribution['id'],
1642 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1643 'entity_id' => $originalContribution['id'] +
1,
1645 unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
1646 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1647 $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
1649 $this->quickCleanUpFinancialEntities();
1653 * Test repeat contribution successfully creates line items.
1655 public function testRepeatTransactionIsTest() {
1656 $this->_params
['is_test'] = 1;
1657 $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1));
1659 $this->callAPISuccess('contribution', 'repeattransaction', array(
1660 'original_contribution_id' => $originalContribution['id'],
1661 'contribution_status_id' => 'Completed',
1662 'trxn_id' => uniqid(),
1664 $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2);
1668 * Test repeat contribution accepts recur_id instead of original_contribution_id.
1670 public function testRepeatTransactionAcceptRecurID() {
1671 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1672 'contact_id' => $this->_individualId
,
1673 'installments' => '12',
1674 'frequency_interval' => '1',
1676 'contribution_status_id' => 1,
1677 'start_date' => '2012-01-01 00:00:00',
1678 'currency' => 'USD',
1679 'frequency_unit' => 'month',
1680 'payment_processor_id' => $this->paymentProcessorID
,
1682 $this->callAPISuccess('contribution', 'create', array_merge(
1684 array('contribution_recur_id' => $contributionRecur['id']))
1687 $this->callAPISuccess('contribution', 'repeattransaction', array(
1688 'contribution_recur_id' => $contributionRecur['id'],
1689 'contribution_status_id' => 'Completed',
1690 'trxn_id' => uniqid(),
1693 $this->quickCleanUpFinancialEntities();
1697 * CRM-16397 test appropriate action if total amount has changed for single line items.
1699 public function testRepeatTransactionAlteredAmount() {
1700 $paymentProcessorID = $this->paymentProcessorCreate();
1701 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1702 'contact_id' => $this->_individualId
,
1703 'installments' => '12',
1704 'frequency_interval' => '1',
1706 'contribution_status_id' => 1,
1707 'start_date' => '2012-01-01 00:00:00',
1708 'currency' => 'USD',
1709 'frequency_unit' => 'month',
1710 'payment_processor_id' => $paymentProcessorID,
1712 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1715 'contribution_recur_id' => $contributionRecur['id'],
1719 $this->callAPISuccess('contribution', 'repeattransaction', array(
1720 'original_contribution_id' => $originalContribution['id'],
1721 'contribution_status_id' => 'Completed',
1722 'trxn_id' => uniqid(),
1723 'total_amount' => '400',
1726 $lineItemParams = array(
1727 'entity_id' => $originalContribution['id'],
1735 'financial_type_id',
1736 'deductible_amount',
1737 'price_field_value_id',
1741 $this->callAPISuccessGetSingle('contribution', array(
1742 'total_amount' => 400,
1744 'net_amount' => 350,
1746 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1747 'entity_id' => $originalContribution['id'],
1749 $expectedLineItem = array_merge(
1750 $lineItem1['values'][0], array(
1751 'line_total' => '400.00',
1752 'unit_price' => '400.00',
1756 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1757 'entity_id' => $originalContribution['id'] +
1,
1759 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1760 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1761 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1765 * CRM-17718 test appropriate action if financial type has changed for single line items.
1767 public function testRepeatTransactionPassedInFinancialType() {
1768 $originalContribution = $this->setUpRecurringContribution();
1770 $this->callAPISuccess('contribution', 'repeattransaction', array(
1771 'original_contribution_id' => $originalContribution['id'],
1772 'contribution_status_id' => 'Completed',
1773 'trxn_id' => uniqid(),
1774 'financial_type_id' => 2,
1776 $lineItemParams = array(
1777 'entity_id' => $originalContribution['id'],
1785 'financial_type_id',
1786 'deductible_amount',
1787 'price_field_value_id',
1792 $this->callAPISuccessGetSingle('contribution', array(
1793 'total_amount' => 100,
1794 'financial_type_id' => 2,
1796 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1797 'entity_id' => $originalContribution['id'],
1799 $expectedLineItem = array_merge(
1800 $lineItem1['values'][0], array(
1801 'line_total' => '100.00',
1802 'unit_price' => '100.00',
1803 'financial_type_id' => 2,
1807 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1808 'entity_id' => $originalContribution['id'] +
1,
1810 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1811 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1812 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1816 * CRM-17718 test appropriate action if financial type has changed for single line items.
1818 public function testRepeatTransactionUpdatedFinancialType() {
1819 $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2));
1821 $this->callAPISuccess('contribution', 'repeattransaction', array(
1822 'contribution_recur_id' => $originalContribution['id'],
1823 'contribution_status_id' => 'Completed',
1824 'trxn_id' => uniqid(),
1826 $lineItemParams = array(
1827 'entity_id' => $originalContribution['id'],
1835 'financial_type_id',
1836 'deductible_amount',
1837 'price_field_value_id',
1842 $this->callAPISuccessGetSingle('contribution', array(
1843 'total_amount' => 100,
1844 'financial_type_id' => 2,
1846 $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1847 'entity_id' => $originalContribution['id'],
1849 $expectedLineItem = array_merge(
1850 $lineItem1['values'][0], array(
1851 'line_total' => '100.00',
1852 'unit_price' => '100.00',
1853 'financial_type_id' => 2,
1857 $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
1858 'entity_id' => $originalContribution['id'] +
1,
1860 unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
1861 unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
1862 $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
1866 * CRM-16397 test appropriate action if campaign has been passed in.
1868 public function testRepeatTransactionPassedInCampaign() {
1869 $paymentProcessorID = $this->paymentProcessorCreate();
1870 $campaignID = $this->campaignCreate();
1871 $campaignID2 = $this->campaignCreate();
1872 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1873 'contact_id' => $this->_individualId
,
1874 'installments' => '12',
1875 'frequency_interval' => '1',
1877 'contribution_status_id' => 1,
1878 'start_date' => '2012-01-01 00:00:00',
1879 'currency' => 'USD',
1880 'frequency_unit' => 'month',
1881 'payment_processor_id' => $paymentProcessorID,
1883 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1886 'contribution_recur_id' => $contributionRecur['id'],
1887 'campaign_id' => $campaignID,
1891 $this->callAPISuccess('contribution', 'repeattransaction', array(
1892 'original_contribution_id' => $originalContribution['id'],
1893 'contribution_status_id' => 'Completed',
1894 'trxn_id' => uniqid(),
1895 'campaign_id' => $campaignID2,
1898 $this->callAPISuccessGetSingle('contribution', array(
1899 'total_amount' => 100,
1900 'campaign_id' => $campaignID2,
1905 * CRM-17718 campaign stored on contribution recur gets priority.
1907 * This reflects the fact we permit people to update them.
1909 public function testRepeatTransactionUpdatedCampaign() {
1910 $paymentProcessorID = $this->paymentProcessorCreate();
1911 $campaignID = $this->campaignCreate();
1912 $campaignID2 = $this->campaignCreate();
1913 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1914 'contact_id' => $this->_individualId
,
1915 'installments' => '12',
1916 'frequency_interval' => '1',
1918 'contribution_status_id' => 1,
1919 'start_date' => '2012-01-01 00:00:00',
1920 'currency' => 'USD',
1921 'frequency_unit' => 'month',
1922 'payment_processor_id' => $paymentProcessorID,
1923 'campaign_id' => $campaignID,
1925 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
1928 'contribution_recur_id' => $contributionRecur['id'],
1929 'campaign_id' => $campaignID2,
1933 $this->callAPISuccess('contribution', 'repeattransaction', array(
1934 'original_contribution_id' => $originalContribution['id'],
1935 'contribution_status_id' => 'Completed',
1936 'trxn_id' => uniqid(),
1939 $this->callAPISuccessGetSingle('contribution', array(
1940 'total_amount' => 100,
1941 'campaign_id' => $campaignID,
1946 * Test completing a transaction does not 'mess' with net amount (CRM-15960).
1948 public function testCompleteTransactionNetAmountOK() {
1949 $this->createLoggedInUser();
1950 $params = array_merge($this->_params
, array('contribution_status_id' => 2));
1951 unset($params['net_amount']);
1952 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1953 $this->callAPISuccess('contribution', 'completetransaction', array(
1954 'id' => $contribution['id'],
1956 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
1957 $this->assertEquals('Completed', $contribution['contribution_status']);
1958 $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
1962 * CRM-14151 - Test completing a transaction via the API.
1964 public function testCompleteTransactionWithReceiptDateSet() {
1965 $mut = new CiviMailUtils($this, TRUE);
1966 $this->createLoggedInUser();
1967 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
1968 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1969 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d')));
1970 $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
1971 $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
1972 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date'])));
1973 $mut->checkMailLog(array(
1974 'Receipt - Contribution',
1975 'Please print this confirmation for your records.',
1981 * Test completing first transaction in a recurring series.
1983 * The status should be set to 'in progress' and the next scheduled payment date calculated.
1985 public function testCompleteTransactionSetStatusToInProgress() {
1986 $paymentProcessorID = $this->paymentProcessorCreate();
1987 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
1988 'contact_id' => $this->_individualId
,
1989 'installments' => '12',
1990 'frequency_interval' => '1',
1992 'contribution_status_id' => 'Pending',
1993 'start_date' => '2012-01-01 00:00:00',
1994 'currency' => 'USD',
1995 'frequency_unit' => 'month',
1996 'payment_processor_id' => $paymentProcessorID,
1998 $contribution = $this->callAPISuccess('contribution', 'create', array_merge(
2001 'contribution_recur_id' => $contributionRecur['id'],
2002 'contribution_status_id' => 'Pending',
2005 $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $contribution));
2006 $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array(
2007 'id' => $contributionRecur['id'],
2008 'return' => array('next_sched_contribution_date', 'contribution_status_id'),
2010 $this->assertEquals(5, $contributionRecur['contribution_status_id']);
2011 $this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']);
2015 * Test completing a transaction with an event via the API.
2017 * Note that we are creating a logged in user because email goes out from
2020 public function testCompleteTransactionWithParticipantRecord() {
2021 $mut = new CiviMailUtils($this, TRUE);
2022 $mut->clearMessages();
2023 $this->createLoggedInUser();
2024 $contributionID = $this->createPendingParticipantContribution();
2025 $this->callAPISuccess('contribution', 'completetransaction', array(
2026 'id' => $contributionID,
2029 $participantStatus = $this->callAPISuccessGetValue('participant', array(
2030 'id' => $this->_ids
['participant'],
2031 'return' => 'participant_status_id',
2033 $this->assertEquals(1, $participantStatus);
2034 $mut->checkMailLog(array(
2035 'Annual CiviCRM meet',
2037 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.',
2043 * Test membership is renewed when transaction completed.
2045 public function testCompleteTransactionMembershipPriceSet() {
2046 $this->createPriceSetWithPage('membership');
2047 $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
2051 $this->setUpPendingContribution($this->_ids
['price_field_value'][0]);
2052 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2053 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
2054 'membership_id' => $this->_ids
['membership'],
2056 $this->assertEquals(1, $logs['count']);
2057 $this->assertEquals($stateOfGrace, $membership['status_id']);
2058 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
2059 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2060 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']);
2061 $this->callAPISuccessGetSingle('LineItem', array(
2062 'entity_id' => $this->_ids
['membership'],
2063 'entity_table' => 'civicrm_membership',
2065 $logs = $this->callAPISuccess('MembershipLog', 'get', array(
2066 'membership_id' => $this->_ids
['membership'],
2068 $this->assertEquals(2, $logs['count']);
2069 $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']);
2070 $this->cleanUpAfterPriceSets();
2074 * Test membership is renewed when transaction completed.
2076 public function testCompleteTransactionMembershipPriceSetTwoTerms() {
2077 $this->createPriceSetWithPage('membership');
2078 $this->setUpPendingContribution($this->_ids
['price_field_value'][1]);
2079 $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids
['contribution']));
2080 $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids
['membership']));
2081 $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']);
2082 $this->cleanUpAfterPriceSets();
2085 public function cleanUpAfterPriceSets() {
2086 $this->quickCleanUpFinancialEntities();
2087 $this->contactDelete($this->_ids
['contact']);
2092 * Create price set with contribution test for test setup.
2094 * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
2095 * on parent class at some point (fn is not in 4.4).
2098 * @param array $params
2100 public function createPriceSetWithPage($entity, $params = array()) {
2101 $membershipTypeID = $this->membershipTypeCreate();
2102 $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array(
2103 'title' => "Test Contribution Page",
2104 'financial_type_id' => 1,
2105 'currency' => 'NZD',
2106 'goal_amount' => 50,
2107 'is_pay_later' => 1,
2108 'is_monetary' => TRUE,
2109 'is_email_receipt' => FALSE,
2111 $priceSet = $this->callAPISuccess('price_set', 'create', array(
2112 'is_quick_config' => 0,
2113 'extends' => 'CiviMember',
2114 'financial_type_id' => 1,
2115 'title' => 'my Page',
2117 $priceSetID = $priceSet['id'];
2119 CRM_Price_BAO_PriceSet
::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
2120 $priceField = $this->callAPISuccess('price_field', 'create', array(
2121 'price_set_id' => $priceSetID,
2122 'label' => 'Goat Breed',
2123 'html_type' => 'Radio',
2125 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
2126 'price_set_id' => $priceSetID,
2127 'price_field_id' => $priceField['id'],
2128 'label' => 'Long Haired Goat',
2130 'financial_type_id' => 'Donation',
2131 'membership_type_id' => $membershipTypeID,
2132 'membership_num_terms' => 1,
2135 $this->_ids
['price_field_value'] = array($priceFieldValue['id']);
2136 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
2137 'price_set_id' => $priceSetID,
2138 'price_field_id' => $priceField['id'],
2139 'label' => 'Shoe-eating Goat',
2141 'financial_type_id' => 'Donation',
2142 'membership_type_id' => $membershipTypeID,
2143 'membership_num_terms' => 2,
2146 $this->_ids
['price_field_value'][] = $priceFieldValue['id'];
2147 $this->_ids
['price_set'] = $priceSetID;
2148 $this->_ids
['contribution_page'] = $contributionPageResult['id'];
2149 $this->_ids
['price_field'] = array($priceField['id']);
2151 $this->_ids
['membership_type'] = $membershipTypeID;
2155 * Set up a pending transaction with a specific price field id.
2157 * @param int $priceFieldValueID
2159 public function setUpPendingContribution($priceFieldValueID) {
2160 $contactID = $this->individualCreate();
2161 $membership = $this->callAPISuccess('membership', 'create', array(
2162 'contact_id' => $contactID,
2163 'membership_type_id' => $this->_ids
['membership_type'],
2164 'start_date' => 'yesterday - 1 year',
2165 'end_date' => 'yesterday',
2166 'join_date' => 'yesterday - 1 year',
2168 $contribution = $this->callAPISuccess('contribution', 'create', array(
2170 'contact_id' => $contactID,
2171 'receive_date' => date('Ymd'),
2172 'total_amount' => 100.00,
2173 'financial_type_id' => 1,
2174 'payment_instrument_id' => 'Credit Card',
2175 'non_deductible_amount' => 10.00,
2176 'trxn_id' => 'jdhfi88',
2177 'invoice_id' => 'djfhiewuyr',
2179 'contribution_status_id' => 2,
2180 'contribution_page_id' => $this->_ids
['contribution_page'],
2181 'api.membership_payment.create' => array('membership_id' => $membership['id']),
2184 $this->callAPISuccess('line_item', 'create', array(
2185 'entity_id' => $contribution['id'],
2186 'entity_table' => 'civicrm_contribution',
2187 'contribution_id' => $contribution['id'],
2188 'price_field_id' => $this->_ids
['price_field'][0],
2192 'financial_type_id' => 1,
2193 'price_field_value_id' => $priceFieldValueID,
2195 $this->_ids
['contact'] = $contactID;
2196 $this->_ids
['contribution'] = $contribution['id'];
2197 $this->_ids
['membership'] = $membership['id'];
2201 * Test sending a mail via the API.
2203 public function testSendMail() {
2204 $mut = new CiviMailUtils($this, TRUE);
2205 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
2206 $this->callAPISuccess('contribution', 'sendconfirmation', array(
2207 'id' => $contribution['id'],
2208 'receipt_from_email' => 'api@civicrm.org',
2211 $mut->checkMailLog(array(
2213 'Contribution Information',
2214 'Please print this confirmation for your records',
2223 * Test sending a mail via the API.
2225 public function testSendMailEvent() {
2226 $mut = new CiviMailUtils($this, TRUE);
2227 $contribution = $this->callAPISuccess('contribution', 'create', $this->_params
);
2228 $event = $this->eventCreate(array(
2229 'is_email_confirm' => 1,
2230 'confirm_from_email' => 'test@civicrm.org',
2232 $this->_eventID
= $event['id'];
2233 $participantParams = array(
2234 'contact_id' => $this->_individualId
,
2235 'event_id' => $this->_eventID
,
2238 // to ensure it matches later on
2239 'register_date' => '2007-07-21 00:00:00',
2240 'source' => 'Online Event Registration: API Testing',
2243 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
2244 $this->callAPISuccess('participant_payment', 'create', array(
2245 'participant_id' => $participant['id'],
2246 'contribution_id' => $contribution['id'],
2248 $this->callAPISuccess('contribution', 'sendconfirmation', array(
2249 'id' => $contribution['id'],
2250 'receipt_from_email' => 'api@civicrm.org',
2254 $mut->checkMailLog(array(
2255 'Annual CiviCRM meet',
2257 'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
2264 * This function does a GET & compares the result against the $params.
2266 * Use as a double check on Creates.
2268 * @param array $params
2270 * @param bool $delete
2272 public function contributionGetnCheck($params, $id, $delete = TRUE) {
2274 $contribution = $this->callAPISuccess('Contribution', 'Get', array(
2280 $this->callAPISuccess('contribution', 'delete', array('id' => $id));
2282 $this->assertAPISuccess($contribution, 0);
2283 $values = $contribution['values'][$contribution['id']];
2284 $params['receive_date'] = date('Y-m-d H:i:s', strtotime($params['receive_date']));
2285 // this is not returned in id format
2286 unset($params['payment_instrument_id']);
2287 $params['contribution_source'] = $params['source'];
2288 unset($params['source']);
2289 foreach ($params as $key => $value) {
2290 $this->assertEquals($value, $values[$key], $key . " value: $value doesn't match " . print_r($values, TRUE));
2295 * Create a pending contribution & linked pending participant record (along with an event).
2297 public function createPendingParticipantContribution() {
2298 $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
2299 $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6));
2300 $this->_ids
['participant'] = $participantID;
2301 $params = array_merge($this->_params
, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
2302 $contribution = $this->callAPISuccess('contribution', 'create', $params);
2303 $this->callAPISuccess('participant_payment', 'create', array(
2304 'contribution_id' => $contribution['id'],
2305 'participant_id' => $participantID,
2307 $this->callAPISuccess('line_item', 'get', array(
2308 'entity_id' => $contribution['id'],
2309 'entity_table' => 'civicrm_contribution',
2310 'api.line_item.create' => array(
2311 'entity_id' => $participantID,
2312 'entity_table' => 'civicrm_participant',
2315 return $contribution['id'];
2319 * Get financial transaction amount.
2321 * @param int $contId
2323 * @return null|string
2325 public function _getFinancialTrxnAmount($contId) {
2327 SUM( ft.total_amount ) AS total
2328 FROM civicrm_financial_trxn AS ft
2329 LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
2330 WHERE ceft.entity_table = 'civicrm_contribution'
2331 AND ceft.entity_id = {$contId}";
2333 $result = CRM_Core_DAO
::singleValueQuery($query);
2338 * @param int $contId
2340 * @return null|string
2342 public function _getFinancialItemAmount($contId) {
2343 $lineItem = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
2346 FROM civicrm_financial_item
2347 WHERE entity_table = 'civicrm_line_item'
2348 AND entity_id = {$lineItem}";
2349 $result = CRM_Core_DAO
::singleValueQuery($query);
2354 * @param int $contId
2357 public function _checkFinancialItem($contId, $context) {
2358 if ($context != 'paylater') {
2360 'entity_id' => $contId,
2361 'entity_table' => 'civicrm_contribution',
2363 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($params, TRUE));
2364 $entityParams = array(
2365 'financial_trxn_id' => $trxn['financial_trxn_id'],
2366 'entity_table' => 'civicrm_financial_item',
2368 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2370 'id' => $entityTrxn['entity_id'],
2373 if ($context == 'paylater') {
2374 $lineItems = CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution');
2375 foreach ($lineItems as $key => $item) {
2377 'entity_id' => $key,
2378 'entity_table' => 'civicrm_line_item',
2380 $compareParams = array('status_id' => 1);
2381 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2384 elseif ($context == 'refund') {
2385 $compareParams = array(
2387 'financial_account_id' => 1,
2391 elseif ($context == 'cancelPending') {
2392 $compareParams = array(
2394 'financial_account_id' => 1,
2398 elseif ($context == 'changeFinancial') {
2399 $lineKey = key(CRM_Price_BAO_LineItem
::getLineItems($contId, 'contribution'));
2401 'entity_id' => $lineKey,
2404 $compareParams = array(
2405 'financial_account_id' => 1,
2407 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2409 'financial_account_id' => 3,
2410 'entity_id' => $lineKey,
2412 $compareParams = array(
2416 if ($context != 'paylater') {
2417 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
2422 * Check financial transaction.
2424 * @todo break this down into sensible functions - most calls to it only use a few lines out of the big if.
2426 * @param array $contribution
2427 * @param string $context
2428 * @param int $instrumentId
2429 * @param array $extraParams
2431 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) {
2432 $trxnParams = array(
2433 'entity_id' => $contribution['id'],
2434 'entity_table' => 'civicrm_contribution',
2436 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($trxnParams, TRUE));
2438 'id' => $trxn['financial_trxn_id'],
2440 if ($context == 'payLater') {
2441 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
2442 $compareParams = array(
2444 'from_financial_account_id' => CRM_Contribute_PseudoConstant
::financialAccountType($contribution['financial_type_id'], $relationTypeId),
2447 elseif ($context == 'refund') {
2448 $compareParams = array(
2449 'to_financial_account_id' => 6,
2450 'total_amount' => -100,
2452 'trxn_date' => '2015-01-01 09:00:00',
2453 'trxn_id' => 'the refund',
2456 elseif ($context == 'cancelPending') {
2457 $compareParams = array(
2458 'to_financial_account_id' => 7,
2459 'total_amount' => -100,
2463 elseif ($context == 'changeFinancial' ||
$context == 'paymentInstrument') {
2464 $entityParams = array(
2465 'entity_id' => $contribution['id'],
2466 'entity_table' => 'civicrm_contribution',
2469 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2470 $trxnParams1 = array(
2471 'id' => $trxn['financial_trxn_id'],
2473 $compareParams = array(
2474 'total_amount' => -100,
2477 if ($context == 'paymentInstrument') {
2478 $compareParams +
= array(
2479 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount(4),
2480 'payment_instrument_id' => 4,
2484 $compareParams['to_financial_account_id'] = 12;
2486 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams));
2487 $compareParams['total_amount'] = 100;
2488 if ($context == 'paymentInstrument') {
2489 $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount($instrumentId);
2490 $compareParams['payment_instrument_id'] = $instrumentId;
2493 $compareParams['to_financial_account_id'] = 12;
2497 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams));
2503 public function _addPaymentInstrument() {
2504 $gId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name');
2505 $optionParams = array(
2506 'option_group_id' => $gId,
2507 'label' => 'Test Card',
2508 'name' => 'Test Card',
2513 $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams);
2514 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
2515 $financialParams = array(
2516 'entity_table' => 'civicrm_option_value',
2517 'entity_id' => $optionValue['id'],
2518 'account_relationship' => $relationTypeId,
2519 'financial_account_id' => 7,
2521 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, CRM_Core_DAO
::$_nullArray);
2522 $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']);
2523 return $optionValue['values'][$optionValue['id']]['value'];
2527 * @param array $params
2530 public function _checkFinancialRecords($params, $context) {
2531 $entityParams = array(
2532 'entity_id' => $params['id'],
2533 'entity_table' => 'civicrm_contribution',
2535 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
2536 $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
2537 if ($context == 'pending') {
2538 $trxn = CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams);
2539 $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
2542 $trxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2543 $trxnParams = array(
2544 'id' => $trxn['financial_trxn_id'],
2546 if ($context != 'online' && $context != 'payLater') {
2547 $compareParams = array(
2548 'to_financial_account_id' => 6,
2549 'total_amount' => 100,
2553 if ($context == 'feeAmount') {
2554 $compareParams['fee_amount'] = 50;
2556 elseif ($context == 'online') {
2557 $compareParams = array(
2558 'to_financial_account_id' => 12,
2559 'total_amount' => 100,
2563 elseif ($context == 'payLater') {
2564 $compareParams = array(
2565 'to_financial_account_id' => 7,
2566 'total_amount' => 100,
2570 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2571 $entityParams = array(
2572 'financial_trxn_id' => $trxn['financial_trxn_id'],
2573 'entity_table' => 'civicrm_financial_item',
2575 $entityTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($entityParams));
2576 $fitemParams = array(
2577 'id' => $entityTrxn['entity_id'],
2579 $compareParams = array(
2582 'financial_account_id' => 1,
2584 if ($context == 'payLater') {
2585 $compareParams = array(
2588 'financial_account_id' => 1,
2591 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2592 if ($context == 'feeAmount') {
2594 'entity_id' => $params['id'],
2595 'entity_table' => 'civicrm_contribution',
2597 $maxTrxn = current(CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($maxParams, TRUE));
2598 $trxnParams = array(
2599 'id' => $maxTrxn['financial_trxn_id'],
2601 $compareParams = array(
2602 'to_financial_account_id' => 5,
2603 'from_financial_account_id' => 6,
2604 'total_amount' => 50,
2607 $trxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($params['id'], 'DESC');
2608 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
2609 $fitemParams = array(
2610 'entity_id' => $trxnId['financialTrxnId'],
2611 'entity_table' => 'civicrm_financial_trxn',
2613 $compareParams = array(
2616 'financial_account_id' => 5,
2618 $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
2623 * Set up the basic recurring contribution for tests.
2625 * @param array $generalParams
2626 * Parameters that can be merged into the recurring AND the contribution.
2628 * @param array $recurParams
2629 * Parameters to merge into the recur only.
2633 protected function setUpRecurringContribution($generalParams = array(), $recurParams = array()) {
2634 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
2635 'contact_id' => $this->_individualId
,
2636 'installments' => '12',
2637 'frequency_interval' => '1',
2639 'contribution_status_id' => 1,
2640 'start_date' => '2012-01-01 00:00:00',
2641 'currency' => 'USD',
2642 'frequency_unit' => 'month',
2643 'payment_processor_id' => $this->paymentProcessorID
,
2644 ), $generalParams, $recurParams));
2645 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
2648 'contribution_recur_id' => $contributionRecur['id'],
2651 return $originalContribution;
2655 * Set up a repeat transaction.
2657 * @param array $recurParams
2661 protected function setUpRepeatTransaction($recurParams = array()) {
2662 $paymentProcessorID = $this->paymentProcessorCreate();
2663 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
2664 'contact_id' => $this->_individualId
,
2665 'installments' => '12',
2666 'frequency_interval' => '1',
2668 'contribution_status_id' => 1,
2669 'start_date' => '2012-01-01 00:00:00',
2670 'currency' => 'USD',
2671 'frequency_unit' => 'month',
2672 'payment_processor_id' => $paymentProcessorID,
2674 $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
2676 array('contribution_recur_id' => $contributionRecur['id']))
2678 return $originalContribution;