Merge pull request #16774 from mattwire/settingssmtpfreezeoutboundoption
[civicrm-core.git] / tests / phpunit / CRM / Core / Payment / BaseIPNTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Core_Payment_BaseIPNTest
14 * @group headless
15 */
16 class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
17
18 protected $_financialTypeId;
19 protected $_contributionParams;
20 protected $_contactId;
21 protected $_contributionId;
22 protected $_participantId;
23 protected $_pledgeId;
24 protected $_eventId;
25 protected $_processorId;
26 protected $_contributionRecurParams;
27 protected $_paymentProcessor;
28
29 /**
30 * Parameters to create a membership.
31 *
32 * @var array
33 */
34 protected $_membershipParams = [];
35
36 /**
37 * IPN instance.
38 *
39 * @var CRM_Core_Payment_BaseIPN
40 */
41 protected $IPN;
42 protected $_recurId;
43 protected $_membershipId;
44 protected $input;
45 protected $ids;
46 protected $objects;
47
48 /**
49 * @var int
50 */
51 protected $_membershipTypeID;
52
53 /**
54 * @var int
55 */
56 protected $_membershipStatusID;
57 public $DBResetRequired = FALSE;
58
59 /**
60 * Setup function.
61 */
62 public function setUp() {
63 parent::setUp();
64 $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(['is_test' => 0]);
65 $this->input = $this->ids = $this->objects = [];
66 $this->IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->input);
67
68 $this->_contactId = $this->individualCreate();
69 $this->ids['contact'] = $this->_contactId;
70 $this->_financialTypeId = 1;
71
72 $this->_contributionParams = [
73 'contact_id' => $this->_contactId,
74 'financial_type_id' => $this->_financialTypeId,
75 'receive_date' => date('Ymd'),
76 'total_amount' => 150.00,
77 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
78 'currency' => 'USD',
79 'contribution_recur_id' => $this->_recurId,
80 'contribution_status_id' => 2,
81 ];
82 $contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams);
83 $this->_contributionId = $contribution['id'];
84
85 $contribution = new CRM_Contribute_BAO_Contribution();
86 $contribution->id = $this->_contributionId;
87 $contribution->find(TRUE);
88 $this->objects['contribution'] = $contribution;
89 }
90
91 /**
92 * Tear down after class.
93 */
94 public function tearDown() {
95 $this->quickCleanUpFinancialEntities();
96 CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
97 CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
98 }
99
100 /**
101 * Test the LoadObjects function with recurring membership data.
102 */
103 public function testLoadMembershipObjects() {
104 $this->_setUpMembershipObjects();
105 $this->_setUpRecurringContribution();
106 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
107 $this->assertFalse(empty($this->objects['membership']));
108 $this->assertArrayHasKey($this->_membershipTypeID, $this->objects['membership']);
109 $this->assertTrue(is_a($this->objects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
110 $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
111 $this->assertFalse(empty($this->objects['contributionRecur']));
112 $this->assertFalse(empty($this->objects['paymentProcessor']));
113 }
114
115 /**
116 * Test the LoadObjects function with recurring membership data.
117 */
118 public function testLoadMembershipObjectsNoLeakage() {
119 $this->_setUpMembershipObjects();
120 $this->_setUpRecurringContribution();
121 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
122 $this->assertEquals('Anthony', $this->objects['contact']->first_name);
123
124 $this->ids['contact'] = $this->_contactId = $this->individualCreate([
125 'first_name' => 'Donald',
126 'last_name' => 'Duck',
127 'email' => 'the-don@duckville.com',
128 ]);
129 $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc']));
130 $this->_contributionId = $contribution['id'];
131 $this->_setUpMembershipObjects();
132 $this->input['invoiceID'] = 'abc';
133 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
134 $this->assertEquals('Donald', $this->objects['contact']->first_name);
135 }
136
137 /**
138 * Test the LoadObjects function with recurring membership data.
139 */
140 public function testLoadMembershipObjectsLoadAll() {
141 $this->_setUpMembershipObjects();
142 $this->_setUpRecurringContribution();
143 unset($this->ids['membership']);
144 $contribution = new CRM_Contribute_BAO_Contribution();
145 $contribution->id = $this->_contributionId;
146 $contribution->find(TRUE);
147 $contribution->loadRelatedObjects($this->input, $this->ids, TRUE);
148 $this->assertFalse(empty($contribution->_relatedObjects['membership']));
149 $this->assertArrayHasKey($this->_membershipTypeID, $contribution->_relatedObjects['membership']);
150 $this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
151 $this->assertTrue(is_a($contribution->_relatedObjects['financialType'], 'CRM_Financial_BAO_FinancialType'));
152 $this->assertFalse(empty($contribution->_relatedObjects['contributionRecur']));
153 $this->assertFalse(empty($contribution->_relatedObjects['paymentProcessor']));
154 }
155
156 /**
157 * Test the LoadObjects function with recurring membership data.
158 */
159 public function testsendMailMembershipObjects() {
160 $this->_setUpMembershipObjects();
161 $values = [];
162 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
163 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
164 $this->assertTrue(is_array($msg), "Message returned as an array in line");
165 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
166 $this->assertContains('Membership Type: General', $msg['body']);
167 }
168
169 /**
170 * Test the LoadObjects function data does not leak.
171 *
172 * If more than one iteration takes place the variables should not leak.
173 */
174 public function testSendMailMembershipObjectsNoLeakage() {
175 $this->_setUpMembershipObjects();
176 $values = [];
177 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
178 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
179 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
180 $this->assertContains('Membership Type: General', $msg['body']);
181
182 $this->ids['contact'] = $this->_contactId = $this->individualCreate(['prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com']);
183 $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc']));
184 $this->_contributionId = $contribution['id'];
185
186 $this->_membershipTypeID = $this->membershipTypeCreate(['name' => 'Fowl']);
187 $this->_setUpMembershipObjects();
188 $this->input['invoiceID'] = 'abc';
189 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
190 $this->assertEquals('Donald', $this->objects['contact']->first_name);
191 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
192 $this->assertEquals('Dr. Donald Duck II', $msg['to']);
193 $this->assertContains('Membership Type: Fowl', $msg['body']);
194 }
195
196 /**
197 * Test the LoadObjects function with recurring membership data.
198 */
199 public function testsendMailMembershipWithoutLoadObjects() {
200 $this->_setUpMembershipObjects();
201 $values = [];
202 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
203 $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
204 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
205 $this->assertContains('Membership Type: General', $msg['body']);
206 }
207
208 /**
209 * Test that loadObjects works with participant values.
210 */
211 public function testLoadParticipantObjects() {
212 $this->_setUpParticipantObjects();
213 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
214 $this->assertFalse(empty($this->objects['participant']));
215 $this->assertTrue(is_a($this->objects['participant'], 'CRM_Event_BAO_Participant'));
216 $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
217 $this->assertFalse(empty($this->objects['event']));
218 $this->assertTrue(is_a($this->objects['event'], 'CRM_Event_BAO_Event'));
219 $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
220 $this->assertFalse(empty($this->objects['event']->id));
221 }
222
223 /**
224 * Test the LoadObjects function with a participant.
225 */
226 public function testComposeMailParticipant() {
227 $this->_setUpParticipantObjects();
228 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
229 $values = [];
230 $this->assertFalse(empty($this->objects['event']));
231 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
232 $this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']);
233 $this->assertContains('Annual CiviCRM meet', $msg['html']);
234 }
235
236 /**
237 */
238 public function testComposeMailParticipantObjects() {
239 $this->_setUpParticipantObjects();
240 $values = [];
241 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
242 $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
243 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
244 $this->assertContains('Thank you for your registration', $msg['body']);
245 }
246
247 /**
248 * Test the LoadObjects function with recurring membership data.
249 */
250 public function testsendMailParticipantObjectsCheckLog() {
251 $this->_setUpParticipantObjects();
252 $values = [];
253 $mut = new CiviMailUtils($this, TRUE);
254 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
255 $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
256 $mut->checkMailLog([
257 'Thank you for your registration',
258 'Annual CiviCRM meet',
259 'Mr. Anthony Anderson II',
260 ]);
261 $mut->stop();
262 }
263
264 /**
265 * Test the LoadObjects function with recurring membership data.
266 */
267 public function testsendMailParticipantObjectsNoMail() {
268 $this->_setUpParticipantObjects();
269 $event = new CRM_Event_BAO_Event();
270 $event->id = $this->_eventId;
271 $event->is_email_confirm = FALSE;
272 $event->save();
273 $values = [];
274 $tablesToTruncate = [
275 'civicrm_mailing_spool',
276 ];
277 $this->quickCleanup($tablesToTruncate, FALSE);
278 $mut = new CiviMailUtils($this, TRUE);
279 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
280 $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
281 $mut->assertMailLogEmpty('no mail should have been send as event set to no confirm');
282 $mut->stop();
283 }
284
285 /**
286 * Test that loadObjects works with participant values.
287 */
288 public function testLoadPledgeObjects() {
289 $this->_setUpPledgeObjects();
290 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
291 $this->assertFalse(empty($this->objects['pledge_payment'][0]));
292 $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
293 $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
294 $this->assertTrue(is_a($this->objects['pledge_payment'][0], 'CRM_Pledge_BAO_PledgePayment'));
295 $this->assertFalse(empty($this->objects['pledge_payment'][0]->id));
296 $this->assertEquals($this->_financialTypeId, $this->objects['financialType']->id);
297 $this->assertEquals($this->_processorId, $this->objects['paymentProcessor']['id']);
298 $this->assertEquals($this->_contributionId, $this->objects['contribution']->id);
299 $this->assertEquals($this->_contactId, $this->objects['contact']->id);
300 $this->assertEquals($this->_pledgeId, $this->objects['pledge_payment'][0]->pledge_id);
301 }
302
303 /**
304 * Test that loadObjects works with participant values.
305 */
306 public function testLoadPledgeObjectsInvalidPledgeID() {
307 $this->_setUpPledgeObjects();
308 $this->ids['pledge_payment'][0] = 0;
309 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
310 $this->assertArrayHasKey('error_message', $result);
311 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
312 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
313 $this->ids['pledge_payment'][0] = NULL;
314 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
315 $this->assertArrayHasKey('error_message', $result);
316 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
317 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
318 $this->ids['pledge_payment'][0] = '';
319 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
320 $this->assertArrayHasKey('error_message', $result);
321 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
322 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
323
324 $this->ids['pledge_payment'][0] = 999;
325 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, ['return_error' => 1]);
326 $this->assertArrayHasKey('error_message', $result);
327 $this->assertEquals('Could not find pledge payment record: 999', $result['error_message']);
328 }
329
330 /**
331 * Test the LoadObjects function with a pledge.
332 */
333 public function testsendMailPledge() {
334 $this->_setUpPledgeObjects();
335 $values = [];
336 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL);
337 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
338 $this->assertContains('Contribution Information', $msg['html']);
339 }
340
341 /**
342 * Test that an error is returned if required set & no contribution page.
343 */
344 public function testRequiredWithoutProcessorID() {
345 $this->_setUpPledgeObjects();
346 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
347 $this->assertArrayHasKey('error_message', $result);
348 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
349 // error is only returned if $required set to True
350 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]);
351 $this->assertFalse(is_array($result));
352 //check that error is not returned if error checking not set
353 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]);
354 $this->assertFalse(is_array($result));
355 }
356
357 /**
358 * Test that an error is not if required set & no processor ID
359 */
360 public function testRequiredWithContributionPage() {
361 $this->_setUpContributionObjects(TRUE);
362 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
363 $this->assertEquals(1, $result['is_error']);
364 ;
365 }
366
367 /**
368 * Test that if part of $input the payment processor loads OK.
369 *
370 * It's preferable to pass it in as it cannot be correctly calculated.
371 */
372 public function testPaymentProcessorLoadsAsParam() {
373 $this->_setUpContributionObjects();
374 $this->input = array_merge($this->input, ['payment_processor_id' => $this->_processorId]);
375 $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]));
376 }
377
378 /**
379 * Test that an error is returned if required set & contribution page exists
380 */
381 public function testRequiredWithContributionPageError() {
382 $this->_setUpContributionObjects();
383 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
384 $this->assertArrayHasKey('error_message', $result);
385 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
386 // error is only returned if $required set to True
387 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]);
388 $this->assertFalse(is_array($result));
389 //check that error is not returned if error checking not set
390 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]);
391 $this->assertFalse(is_array($result));
392 }
393
394 public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
395 $this->_setUpParticipantObjects('Pending from incomplete transaction');
396 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
397 $additionalParticipantId = $this->participantCreate([
398 'event_id' => $this->_eventId,
399 'registered_by_id' => $this->_participantId,
400 'status_id' => 'Pending from incomplete transaction',
401 ]);
402
403 $transaction = new CRM_Core_Transaction();
404 $this->IPN->cancelled($this->objects, $transaction);
405
406 $cancelledParticipantsCount = civicrm_api3('Participant', 'get', [
407 'sequential' => 1,
408 'id' => ['IN' => [$this->_participantId, $additionalParticipantId]],
409 'status_id' => 'Cancelled',
410 ])['count'];
411 $this->assertEquals(2, $cancelledParticipantsCount);
412
413 $cancelledActivatesCount = civicrm_api3('Activity', 'get', [
414 'sequential' => 1,
415 'activity_type_id' => 'Event Registration',
416 'subject' => ['LIKE' => '%Cancelled%'],
417 'source_record_id' => ['IN' => [$this->_participantId, $additionalParticipantId]],
418 ]);
419
420 $this->assertEquals(2, $cancelledActivatesCount['count']);
421 }
422
423 public function testThatFailedEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
424 $this->_setUpParticipantObjects('Pending from incomplete transaction');
425 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
426 $additionalParticipantId = $this->participantCreate([
427 'event_id' => $this->_eventId,
428 'registered_by_id' => $this->_participantId,
429 'status_id' => 'Pending from incomplete transaction',
430 ]);
431
432 $transaction = new CRM_Core_Transaction();
433 $this->IPN->failed($this->objects, $transaction);
434
435 $cancelledParticipantsCount = civicrm_api3('Participant', 'get', [
436 'sequential' => 1,
437 'id' => ['IN' => [$this->_participantId, $additionalParticipantId]],
438 'status_id' => 'Cancelled',
439 ])['count'];
440 $this->assertEquals(2, $cancelledParticipantsCount);
441
442 $cancelledActivatesCount = civicrm_api3('Activity', 'get', [
443 'sequential' => 1,
444 'activity_type_id' => 'Event Registration',
445 'subject' => ['LIKE' => '%Cancelled%'],
446 'source_record_id' => ['IN' => [$this->_participantId, $additionalParticipantId]],
447 ]);
448
449 $this->assertEquals(2, $cancelledActivatesCount['count']);
450 }
451
452 /**
453 * Prepare for contribution Test - involving only contribution objects
454 *
455 * @param bool $contributionPage
456 */
457 public function _setUpContributionObjects($contributionPage = FALSE) {
458
459 $contribution = new CRM_Contribute_BAO_Contribution();
460 $contribution->id = $this->_contributionId;
461 $contribution->find(TRUE);
462 $contributionPageID = NULL;
463
464 if (!empty($contributionPage)) {
465 $dao = new CRM_Core_DAO();
466 $contribution_page = $dao->createTestObject('CRM_Contribute_DAO_ContributionPage');
467 $contribution_page->payment_processor = 1;
468 $contribution_page->save();
469 $contribution->contribution_page_id = $contributionPageID = $contribution_page->id;
470 //for unknown reasons trying to do a find & save on a contribution with a receive_date set
471 // doesn't work. This seems of minimal relevance to this test so ignoring
472 // note that in tests it worked sometimes & not others - dependent on which other tests run.
473 // running all CRM_Core tests caused failure as did just the single failing test. But running
474 // just this class succeeds - because it actually doesn't do a mysql update on the following save
475 // (unknown reason)
476 unset($contribution->receive_date);
477 $contribution->save();
478 }
479
480 $this->objects['contribution'] = $contribution;
481 $this->input = [
482 'component' => 'contribute',
483 'contribution_page_id' => $contributionPageID,
484 'total_amount' => 110.00,
485 'invoiceID' => "c8acb91e080ad7777a2adc119c192885",
486 'contactID' => $this->_contactId,
487 'contributionID' => $this->objects['contribution']->id,
488 ];
489 }
490
491 /**
492 * Prepare for membership test.
493 */
494 public function _setUpMembershipObjects() {
495 try {
496 if (!$this->_membershipTypeID) {
497 $this->_membershipTypeID = $this->membershipTypeCreate();
498 }
499 if (!$this->_membershipStatusID) {
500 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
501 }
502 }
503 catch (Exception$e) {
504 echo $e->getMessage();
505 }
506 CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE);
507 CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
508 $this->_membershipParams = [
509 'contact_id' => $this->_contactId,
510 'membership_type_id' => $this->_membershipTypeID,
511 'join_date' => '2009-01-21',
512 'start_date' => '2009-01-21',
513 'end_date' => '2009-12-21',
514 'source' => 'Payment',
515 'is_override' => 1,
516 'status_id' => $this->_membershipStatusID,
517 'version' => 3,
518 ];
519
520 $membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams);
521 if ($this->objects['contribution']->id != $this->_contributionId) {
522 $contribution = new CRM_Contribute_BAO_Contribution();
523 $contribution->id = $this->_contributionId;
524 $contribution->find(TRUE);
525 $this->objects = ['contribution' => $contribution];
526 }
527 $this->_membershipId = $membership['id'];
528 //we'll create membership payment here because to make setup more re-usable
529 $this->callAPISuccess('membership_payment', 'create', [
530 'contribution_id' => $this->_contributionId,
531 'membership_id' => $this->_membershipId,
532 ]);
533
534 $this->input = [
535 'component' => 'contribute',
536 'total_amount' => 150.00,
537 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
538 'contactID' => $this->_contactId,
539 'contributionID' => $this->_contributionId,
540 'membershipID' => $this->_membershipId,
541 ];
542
543 $this->ids['membership'] = $this->_membershipId;
544 }
545
546 public function _setUpRecurringContribution() {
547 $this->_contributionRecurParams = [
548 'contact_id' => $this->_contactId,
549 'amount' => 150.00,
550 'currency' => 'USD',
551 'frequency_unit' => 'week',
552 'frequency_interval' => 1,
553 'installments' => 2,
554 'start_date' => date('Ymd'),
555 'create_date' => date('Ymd'),
556 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
557 'contribution_status_id' => 2,
558 'financial_type_id' => $this->_financialTypeId,
559 'version' => 3,
560 'payment_processor_id' => $this->_processorId,
561 ];
562 $this->_recurId = $this->callAPISuccess('contribution_recur', 'create', $this->_contributionRecurParams);
563 $this->_recurId = $this->_recurId['id'];
564 $this->input['contributionRecurId'] = $this->_recurId;
565 $this->ids['contributionRecur'] = $this->_recurId;
566 }
567
568 /**
569 * Set up participant requirements for test.
570 *
571 * @param string $participantStatus
572 * The participant to create status
573 */
574 public function _setUpParticipantObjects($participantStatus = 'Attended') {
575 $event = $this->eventCreate(['is_email_confirm' => 1]);
576
577 $this->_eventId = $event['id'];
578 $this->_participantId = $this->participantCreate([
579 'event_id' => $this->_eventId,
580 'contact_id' => $this->_contactId,
581 'status_id' => $participantStatus,
582 ]);
583
584 $this->callAPISuccess('participant_payment', 'create', [
585 'contribution_id' => $this->_contributionId,
586 'participant_id' => $this->_participantId,
587 ]);
588
589 $contribution = new CRM_Contribute_BAO_Contribution();
590 $contribution->id = $this->_contributionId;
591 $contribution->find();
592 $this->objects['contribution'] = $contribution;
593 $this->input = [
594 'component' => 'event',
595 'total_amount' => 150.00,
596 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
597 'contactID' => $this->_contactId,
598 'contributionID' => $contribution->id,
599 'participantID' => $this->_participantId,
600 ];
601
602 $this->ids['participant'] = $this->_participantId;
603 $this->ids['event'] = $this->_eventId;
604 }
605
606 /**
607 * Set up participant requirements for test.
608 */
609 public function _setUpPledgeObjects() {
610 $this->_pledgeId = $this->pledgeCreate(['contact_id' => $this->_contactId]);
611 //we'll create membership payment here because to make setup more re-usable
612 $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', [
613 'version' => 3,
614 'pledge_id' => $this->_pledgeId,
615 'contribution_id' => $this->_contributionId,
616 'status_id' => 1,
617 'actual_amount' => 50,
618 ]);
619
620 $this->input = [
621 'component' => 'contribute',
622 'total_amount' => 150.00,
623 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
624 'contactID' => $this->_contactId,
625 'contributionID' => $this->_contributionId,
626 'pledgeID' => $this->_pledgeId,
627 ];
628
629 $this->ids['pledge_payment'][] = $pledgePayment['id'];
630 }
631
632 }