3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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_PaymentTest
extends CiviUnitTestCase
{
37 protected $_individualId;
39 protected $_financialTypeId = 1;
41 protected $_apiversion;
48 public function setUp() {
51 $this->_apiversion
= 3;
52 $this->_individualId
= $this->individualCreate();
53 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= [];
57 * Clean up after each test.
61 public function tearDown() {
62 $this->quickCleanUpFinancialEntities();
63 $this->quickCleanup(['civicrm_uf_match']);
64 unset(CRM_Core_Config
::singleton()->userPermissionClass
->permissions
);
69 * Test Get Payment api.
71 public function testGetPayment() {
73 'contact_id' => $this->_individualId
,
74 'receive_date' => '2010-01-20',
75 'total_amount' => 100.00,
76 'financial_type_id' => $this->_financialTypeId
,
78 'contribution_status_id' => 1,
80 $contribution = $this->callAPISuccess('contribution', 'create', $p);
83 'contribution_id' => $contribution['id'],
84 'check_permissions' => TRUE,
86 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM', 'administer CiviCRM'];
87 $payment = $this->callAPIFailure('payment', 'get', $params, 'API permission check failed for Payment/get call; insufficient permission: require access CiviCRM and access CiviContribute');
89 array_push(CRM_Core_Config
::singleton()->userPermissionClass
->permissions
, 'access CiviContribute');
90 $payment = $this->callAPISuccess('payment', 'get', $params);
92 $payment = $this->callAPIAndDocument('payment', 'get', $params, __FUNCTION__
, __FILE__
);
93 $this->assertEquals(1, $payment['count']);
96 $contribution['id'] => [
97 'total_amount' => 100,
99 'trxn_date' => '2010-01-20 00:00:00',
100 'contribution_id' => $contribution['id'],
104 $this->checkPaymentResult($payment, $expectedResult);
105 $this->callAPISuccess('Contribution', 'Delete', [
106 'id' => $contribution['id'],
111 * Test email receipt for partial payment.
113 public function testPaymentEmailReceipt() {
114 $mut = new CiviMailUtils($this);
115 list($lineItems, $contribution) = $this->createParticipantWithContribution();
116 $event = $this->callAPISuccess('Event', 'get', []);
117 $this->addLocationToEvent($event['id']);
119 'contribution_id' => $contribution['id'],
120 'total_amount' => 50,
121 'check_number' => '345',
122 'trxn_date' => '2018-08-13 17:57:56',
124 $payment = $this->callAPISuccess('payment', 'create', $params);
125 $this->checkPaymentResult($payment, [
127 'from_financial_account_id' => 7,
128 'to_financial_account_id' => 6,
129 'total_amount' => 50,
135 $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
136 $mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet']);
139 'Total Fees: $ 300.00',
140 'This Payment Amount: $ 50.00',
141 //150 was paid in the 1st payment.
142 'Balance Owed: $ 100.00',
143 'Event Information and Location',
146 'Transaction Date: August 13th, 2018 5:57 PM',
151 $mut->clearMessages();
155 * Test email receipt for partial payment.
157 * @throws \CRM_Core_Exception
159 public function testPaymentEmailReceiptFullyPaid() {
160 $mut = new CiviMailUtils($this);
161 list($lineItems, $contribution) = $this->createParticipantWithContribution();
164 'contribution_id' => $contribution['id'],
165 'total_amount' => 150,
167 $payment = $this->callAPISuccess('payment', 'create', $params);
169 $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
170 $mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet', 'Registration Confirmation - Annual CiviCRM meet']);
173 'A payment has been received.',
174 'Total Fees: $ 300.00',
175 'This Payment Amount: $ 150.00',
176 'Balance Owed: $ 0.00',
177 'Thank you for completing payment.',
180 $mut->clearMessages();
184 * Test email receipt for partial payment.
186 * @dataProvider getThousandSeparators
188 * @param string $thousandSeparator
190 public function testRefundEmailReceipt($thousandSeparator) {
191 $this->setCurrencySeparators($thousandSeparator);
192 $decimalSeparator = ($thousandSeparator === ',' ?
'.' : ',');
193 $mut = new CiviMailUtils($this);
194 list($lineItems, $contribution) = $this->createParticipantWithContribution();
195 $this->callAPISuccess('payment', 'create', [
196 'contribution_id' => $contribution['id'],
197 'total_amount' => 50,
198 'check_number' => '345',
199 'trxn_date' => '2018-08-13 17:57:56',
202 $payment = $this->callAPISuccess('payment', 'create', [
203 'contribution_id' => $contribution['id'],
204 'total_amount' => -30,
205 'trxn_date' => '2018-11-13 12:01:56',
206 'sequential' => TRUE,
210 'from_financial_account_id' => 7,
211 'to_financial_account_id' => 6,
212 'total_amount' => -30,
213 'status_id' => CRM_Core_PseudoConstant
::getKey('CRM_Core_BAO_FinancialTrxn', 'status_id', 'Refunded'),
216 foreach ($expected as $key => $value) {
217 $this->assertEquals($expected[$key], $payment[$key], 'mismatch on key ' . $key);
220 $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
221 $mut->assertSubjects(['Refund Notification - Annual CiviCRM meet']);
224 'A refund has been issued based on changes in your registration selections.',
225 'Total Fees: $ 300' . $decimalSeparator . '00',
226 'Refund Amount: $ -30' . $decimalSeparator . '00',
227 'Event Information and Location',
229 'Transaction Date: November 13th, 2018 12:01 PM',
230 'You Paid: $ 170' . $decimalSeparator . '00',
233 $mut->clearMessages();
237 * Test create payment api with no line item in params
239 public function testCreatePaymentNoLineItems() {
240 list($lineItems, $contribution) = $this->createParticipantWithContribution();
242 //Create partial payment
244 'contribution_id' => $contribution['id'],
245 'total_amount' => 50,
247 $payment = $this->callAPIAndDocument('payment', 'create', $params, __FUNCTION__
, __FILE__
);
250 'from_financial_account_id' => 7,
251 'to_financial_account_id' => 6,
252 'total_amount' => 50,
257 $this->checkPaymentResult($payment, $expectedResult);
259 // Check entity financial trxn created properly
261 'entity_id' => $contribution['id'],
262 'entity_table' => 'civicrm_contribution',
263 'financial_trxn_id' => $payment['id'],
266 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
268 $this->assertEquals($eft['values'][$eft['id']]['amount'], 50);
271 'entity_table' => 'civicrm_financial_item',
272 'financial_trxn_id' => $payment['id'],
274 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
275 $amounts = [33.33, 16.67];
276 foreach ($eft['values'] as $value) {
277 $this->assertEquals($value['amount'], array_pop($amounts));
280 // Now create payment to complete total amount of contribution
282 'contribution_id' => $contribution['id'],
283 'total_amount' => 100,
285 $payment = $this->callAPISuccess('payment', 'create', $params);
288 'from_financial_account_id' => 7,
289 'to_financial_account_id' => 6,
290 'total_amount' => 100,
295 $this->checkPaymentResult($payment, $expectedResult);
297 'entity_table' => 'civicrm_financial_item',
298 'financial_trxn_id' => $payment['id'],
300 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
301 $amounts = [66.67, 33.33];
302 foreach ($eft['values'] as $value) {
303 $this->assertEquals($value['amount'], array_pop($amounts));
305 // Check contribution for completed status
306 $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
308 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
309 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 300.00);
310 $paymentParticipant = [
311 'contribution_id' => $contribution['id'],
313 $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
314 $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
315 $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Registered');
316 $this->callAPISuccess('Contribution', 'Delete', [
317 'id' => $contribution['id'],
322 * Function to assert db values
324 public function checkPaymentResult($payment, $expectedResult) {
325 foreach ($expectedResult[$payment['id']] as $key => $value) {
326 $this->assertEquals($payment['values'][$payment['id']][$key], $value, 'mismatch on ' . $key);
331 * Test create payment api with line item in params
333 public function testCreatePaymentLineItems() {
334 list($lineItems, $contribution) = $this->createParticipantWithContribution();
335 $lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $contribution['id']]);
337 //Create partial payment by passing line item array is params
339 'contribution_id' => $contribution['id'],
340 'total_amount' => 50,
343 foreach ($lineItems['values'] as $id => $ignore) {
344 $params['line_item'][] = [$id => array_pop($amounts)];
346 $payment = $this->callAPIAndDocument('payment', 'create', $params, __FUNCTION__
, __FILE__
, 'Payment with line item', 'CreatePaymentWithLineItems');
349 'from_financial_account_id' => 7,
350 'to_financial_account_id' => 6,
351 'total_amount' => 50,
356 $this->checkPaymentResult($payment, $expectedResult);
358 // Check entity financial trxn created properly
360 'entity_id' => $contribution['id'],
361 'entity_table' => 'civicrm_contribution',
362 'financial_trxn_id' => $payment['id'],
365 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
367 $this->assertEquals($eft['values'][$eft['id']]['amount'], 50);
370 'entity_table' => 'civicrm_financial_item',
371 'financial_trxn_id' => $payment['id'],
373 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
375 foreach ($eft['values'] as $value) {
376 $this->assertEquals($value['amount'], array_pop($amounts));
379 // Now create payment to complete total amount of contribution
381 'contribution_id' => $contribution['id'],
382 'total_amount' => 100,
385 foreach ($lineItems['values'] as $id => $ignore) {
386 $params['line_item'][] = [$id => array_pop($amounts)];
388 $payment = $this->callAPISuccess('payment', 'create', $params);
391 'from_financial_account_id' => 7,
392 'to_financial_account_id' => 6,
393 'total_amount' => 100,
398 $this->checkPaymentResult($payment, $expectedResult);
400 'entity_table' => 'civicrm_financial_item',
401 'financial_trxn_id' => $payment['id'],
403 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
405 foreach ($eft['values'] as $value) {
406 $this->assertEquals($value['amount'], array_pop($amounts));
408 // Check contribution for completed status
409 $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
411 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
412 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 300.00);
413 $paymentParticipant = [
414 'contribution_id' => $contribution['id'],
416 $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
417 $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
418 $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Registered');
419 $this->callAPISuccess('Contribution', 'Delete', [
420 'id' => $contribution['id'],
425 * Test cancel payment api
427 public function testCancelPayment() {
428 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['administer CiviCRM', 'access CiviContribute'];
429 list($lineItems, $contribution) = $this->createParticipantWithContribution();
432 'contribution_id' => $contribution['id'],
435 $payment = $this->callAPISuccess('payment', 'get', $params);
436 $this->assertEquals(1, $payment['count']);
439 'id' => $payment['id'],
440 'check_permissions' => TRUE,
442 $payment = $this->callAPIFailure('payment', 'cancel', $cancelParams, 'API permission check failed for Payment/cancel call; insufficient permission: require access CiviCRM and access CiviContribute and edit contributions');
444 array_push(CRM_Core_Config
::singleton()->userPermissionClass
->permissions
, 'access CiviCRM', 'edit contributions');
446 $this->callAPIAndDocument('payment', 'cancel', $cancelParams, __FUNCTION__
, __FILE__
);
448 $payment = $this->callAPISuccess('payment', 'get', $params);
449 $this->assertEquals(2, $payment['count']);
450 $amounts = [-150.00, 150.00];
451 foreach ($payment['values'] as $value) {
452 $this->assertEquals($value['total_amount'], array_pop($amounts), 'Mismatch total amount');
455 $this->callAPISuccess('Contribution', 'Delete', [
456 'id' => $contribution['id'],
461 * Test delete payment api
463 public function testDeletePayment() {
464 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['administer CiviCRM', 'access CiviContribute'];
465 list($lineItems, $contribution) = $this->createParticipantWithContribution();
468 'contribution_id' => $contribution['id'],
471 $payment = $this->callAPISuccess('payment', 'get', $params);
472 $this->assertEquals(1, $payment['count']);
475 'id' => $payment['id'],
476 'check_permissions' => TRUE,
478 $payment = $this->callAPIFailure('payment', 'delete', $deleteParams, 'API permission check failed for Payment/delete call; insufficient permission: require access CiviCRM and access CiviContribute and delete in CiviContribute');
480 array_push(CRM_Core_Config
::singleton()->userPermissionClass
->permissions
, 'access CiviCRM', 'delete in CiviContribute');
481 $this->callAPIAndDocument('payment', 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
483 $payment = $this->callAPISuccess('payment', 'get', $params);
484 $this->assertEquals(0, $payment['count']);
486 $this->callAPISuccess('Contribution', 'Delete', [
487 'id' => $contribution['id'],
492 * Test update payment api.
494 * 1) create a contribution for $300 with a partial payment of $150
495 * - this results in 2 financial transactions. The accounts receivable transaction is linked
496 * via entity_financial_trxns to the 2 line items. The $150 payment is not linked to the line items
497 * so the line items are fully allocated even though they are only half paid.
499 * 2) add a payment of $50 -
500 * This payment transaction IS linked to the line items so $350 of the $300 in line items is allocated
503 * 3) update that payment to be $100
504 * This results in a negative and a positive payment ($50 & $100) - the negative payment results in
505 * financial_items but the positive payment does not.
507 * The final result is we have
508 * - 1 partly paid contribution of $300
509 * - payment financial_trxns totalling $250
510 * - 1 Accounts receivable financial_trxn totalling $300
511 * - 2 financial items totalling $300 linked to the Accounts receivable financial_trxn
512 * - 6 entries in the civicrm_entity_financial_trxn linked to line items - totalling $450.
513 * - 5 entries in the civicrm_entity_financial_trxn linked to contributions - totalling $550.
515 public function testUpdatePayment() {
516 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['administer CiviCRM', 'access CiviContribute', 'edit contributions'];
517 list($lineItems, $contribution) = $this->createParticipantWithContribution();
519 //Create partial payment by passing line item array is params
521 'contribution_id' => $contribution['id'],
522 'total_amount' => 50,
525 $payment = $this->callAPISuccess('payment', 'create', $params);
528 'from_financial_account_id' => 7,
529 'to_financial_account_id' => 6,
530 'total_amount' => 50,
535 $this->checkPaymentResult($payment, $expectedResult);
538 'entity_table' => 'civicrm_financial_item',
539 'financial_trxn_id' => $payment['id'],
541 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
542 $amounts = [33.33, 16.67];
543 foreach ($eft['values'] as $value) {
544 $this->assertEquals($value['amount'], array_pop($amounts));
547 // update the amount for payment
549 'contribution_id' => $contribution['id'],
550 'total_amount' => 100,
551 'id' => $payment['id'],
552 'check_permissions' => TRUE,
554 // @todo - move this permissions test to it's own test - it just confuses here.
555 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['administer CiviCRM', 'access CiviContribute'];
556 $this->callAPIFailure('payment', 'create', $params, 'API permission check failed for Payment/create call; insufficient permission: require access CiviCRM and access CiviContribute and edit contributions');
558 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['administer CiviCRM', 'access CiviContribute', 'access CiviCRM', 'edit contributions'];
559 $payment = $this->callAPIAndDocument('payment', 'create', $params, __FUNCTION__
, __FILE__
, 'Update Payment', 'UpdatePayment');
561 // Check for proportional cancelled payment against lineitems.
563 'entity_table' => 'civicrm_financial_item',
564 'financial_trxn_id' => $payment['id'] - 1,
567 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $minParams);
568 $amounts = [-33.33, -16.67];
570 foreach ($eft['values'] as $value) {
571 $this->assertEquals($value['amount'], array_pop($amounts));
574 // Check for proportional updated payment against lineitems.
576 'entity_table' => 'civicrm_financial_item',
577 'financial_trxn_id' => $payment['id'],
579 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
580 $amounts = [66.67, 33.33];
581 foreach ($eft['values'] as $value) {
582 $this->assertEquals($value['amount'], array_pop($amounts));
584 $items = $this->callAPISuccess('FinancialItem', 'get', [])['values'];
585 $this->assertCount(2, $items);
587 foreach ($items as $item) {
588 $this->assertEquals('civicrm_line_item', $item['entity_table']);
589 $itemSum +
= $item['amount'];
591 $this->assertEquals(300, $itemSum);
594 'contribution_id' => $contribution['id'],
596 $payment = $this->callAPISuccess('payment', 'get', $params);
597 $amounts = [100.00, -50.00, 50.00, 150.00];
598 foreach ($payment['values'] as $value) {
599 $amount = array_pop($amounts);
600 $this->assertEquals($value['total_amount'], $amount, 'Mismatch total amount');
602 // Check entity financial trxn created properly
604 'entity_id' => $contribution['id'],
605 'entity_table' => 'civicrm_contribution',
606 'financial_trxn_id' => $value['id'],
608 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
609 $this->assertEquals($eft['values'][$eft['id']]['amount'], $amount);
612 $this->callAPISuccess('Contribution', 'Delete', [
613 'id' => $contribution['id'],
618 * Test create payment api for paylater contribution
620 public function testCreatePaymentPayLater() {
621 $this->createLoggedInUser();
622 $contributionParams = [
623 'total_amount' => 100,
625 'contact_id' => $this->_individualId
,
626 'financial_type_id' => 1,
627 'contribution_status_id' => 2,
630 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
631 //add payment for pay later transaction
633 'contribution_id' => $contribution['id'],
634 'total_amount' => 100,
636 $payment = $this->callAPISuccess('Payment', 'create', $params);
639 'from_financial_account_id' => 7,
640 'to_financial_account_id' => 6,
641 'total_amount' => 100,
646 $this->checkPaymentResult($payment, $expectedResult);
647 // Check entity financial trxn created properly
649 'entity_id' => $contribution['id'],
650 'entity_table' => 'civicrm_contribution',
651 'financial_trxn_id' => $payment['id'],
653 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
654 $this->assertEquals($eft['values'][$eft['id']]['amount'], 100);
656 'entity_table' => 'civicrm_financial_item',
657 'financial_trxn_id' => $payment['id'],
659 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
660 $this->assertEquals($eft['values'][$eft['id']]['amount'], 100);
661 // Check contribution for completed status
662 $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
663 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
664 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
665 $this->callAPISuccess('Contribution', 'Delete', [
666 'id' => $contribution['id'],
671 * Test create payment api for pay later contribution with partial payment.
675 public function testCreatePaymentPayLaterPartialPayment() {
676 $this->createLoggedInUser();
677 $contributionParams = [
678 'total_amount' => 100,
680 'contact_id' => $this->_individualId
,
681 'financial_type_id' => 1,
682 'contribution_status_id' => 2,
685 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
686 //Create partial payment
688 'contribution_id' => $contribution['id'],
689 'total_amount' => 60,
691 $payment = $this->callAPISuccess('Payment', 'create', $params);
694 'total_amount' => 60,
699 $this->checkPaymentResult($payment, $expectedResult);
700 // Check entity financial trxn created properly
702 'entity_id' => $contribution['id'],
703 'entity_table' => 'civicrm_contribution',
704 'financial_trxn_id' => $payment['id'],
706 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
707 $this->assertEquals($eft['values'][$eft['id']]['amount'], 60);
709 'entity_table' => 'civicrm_financial_item',
710 'financial_trxn_id' => $payment['id'],
712 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
713 $this->assertEquals($eft['values'][$eft['id']]['amount'], 60);
714 $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
715 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Partially paid');
716 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
717 //Create full payment
719 'contribution_id' => $contribution['id'],
720 'total_amount' => 40,
722 // Rename the 'completed' status label first to check that we are not using the labels!
723 $this->callAPISuccess('OptionValue', 'get', ['name' => 'Completed', 'option_group_id' => 'contribution_status', 'api.OptionValue.create' => ['label' => 'Unicorn']]);
724 $payment = $this->callAPISuccess('Payment', 'create', $params);
727 'from_financial_account_id' => 7,
728 'to_financial_account_id' => 6,
729 'total_amount' => 40,
734 $this->checkPaymentResult($payment, $expectedResult);
735 // Check entity financial trxn created properly
737 'entity_id' => $contribution['id'],
738 'entity_table' => 'civicrm_contribution',
739 'financial_trxn_id' => $payment['id'],
741 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
742 $this->assertEquals($eft['values'][$eft['id']]['amount'], 40);
744 'entity_table' => 'civicrm_financial_item',
745 'financial_trxn_id' => $payment['id'],
747 $eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
748 $this->assertEquals($eft['values'][$eft['id']]['amount'], 40);
749 // Check contribution for completed status
750 $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
751 $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Unicorn');
752 $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
753 $this->callAPISuccess('Contribution', 'Delete', [
754 'id' => $contribution['id'],
756 $this->callAPISuccess('OptionValue', 'get', ['name' => 'Completed', 'option_group_id' => 'contribution_status', 'api.OptionValue.create' => ['label' => 'Completed']]);
757 $this->callAPISuccessGetCount('Activity', ['target_contact_id' => $this->_individualId
, 'activity_type_id' => 'Payment'], 2);
761 * Add a location to our event.
763 * @param int $eventID
765 protected function addLocationToEvent($eventID) {
767 'name' => 'event place',
768 'street_address' => 'streety street',
769 'location_type_id' => 1,
772 // api requires contact_id - perhaps incorrectly but use add to get past that.
773 $address = CRM_Core_BAO_Address
::add($addressParams);
775 $location = $this->callAPISuccess('LocBlock', 'create', ['address_id' => $address->id
]);
776 $this->callAPISuccess('Event', 'create', [
778 'loc_block_id' => $location['id'],
779 'is_show_location' => TRUE,