6e3c1b84a43e16e950aff9585245234517fbfd93
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionPageTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test APIv3 civicrm_contribute_recur* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
33 * @group headless
34 */
35 class api_v3_ContributionPageTest extends CiviUnitTestCase {
36 protected $_apiversion = 3;
37 protected $testAmount = 34567;
38 protected $params;
39 protected $id = 0;
40 protected $contactIds = array();
41 protected $_entity = 'contribution_page';
42 protected $contribution_result = NULL;
43 protected $_priceSetParams = array();
44 /**
45 * Payment processor details.
46 * @var array
47 */
48 protected $_paymentProcessor = array();
49
50 /**
51 * @var array
52 * - contribution_page
53 * - price_set
54 * - price_field
55 * - price_field_value
56 */
57 protected $_ids = array();
58
59
60 public $DBResetRequired = TRUE;
61
62 public function setUp() {
63 parent::setUp();
64 $this->contactIds[] = $this->individualCreate();
65 $this->params = array(
66 'title' => "Test Contribution Page",
67 'financial_type_id' => 1,
68 'currency' => 'NZD',
69 'goal_amount' => $this->testAmount,
70 'is_pay_later' => 1,
71 'is_monetary' => TRUE,
72 'is_email_receipt' => TRUE,
73 'receipt_from_email' => 'yourconscience@donate.com',
74 'receipt_from_name' => 'Ego Freud',
75 );
76
77 $this->_priceSetParams = array(
78 'is_quick_config' => 1,
79 'extends' => 'CiviContribute',
80 'financial_type_id' => 'Donation',
81 'title' => 'my Page',
82 );
83 }
84
85 public function tearDown() {
86 foreach ($this->contactIds as $id) {
87 $this->callAPISuccess('contact', 'delete', array('id' => $id));
88 }
89 $this->quickCleanUpFinancialEntities();
90 }
91
92 public function testCreateContributionPage() {
93 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
94 $this->assertEquals(1, $result['count']);
95 $this->assertNotNull($result['values'][$result['id']]['id']);
96 $this->getAndCheck($this->params, $result['id'], $this->_entity);
97 }
98
99 public function testGetBasicContributionPage() {
100 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
101 $this->id = $createResult['id'];
102 $getParams = array(
103 'currency' => 'NZD',
104 'financial_type_id' => 1,
105 );
106 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
107 $this->assertEquals(1, $getResult['count']);
108 }
109
110 public function testGetContributionPageByAmount() {
111 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
112 $this->id = $createResult['id'];
113 $getParams = array(
114 'amount' => '' . $this->testAmount, // 3456
115 'currency' => 'NZD',
116 'financial_type_id' => 1,
117 );
118 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
119 $this->assertEquals(1, $getResult['count']);
120 }
121
122 public function testDeleteContributionPage() {
123 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
124 $deleteParams = array('id' => $createResult['id']);
125 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
126 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
127 $this->assertEquals(0, $checkDeleted['count']);
128 }
129
130 public function testGetFieldsContributionPage() {
131 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
132 $this->assertEquals(12, $result['values']['start_date']['type']);
133 }
134
135
136 /**
137 * Test form submission with basic price set.
138 */
139 public function testSubmit() {
140 $this->setUpContributionPage();
141 $priceFieldID = reset($this->_ids['price_field']);
142 $priceFieldValueID = reset($this->_ids['price_field_value']);
143 $submitParams = array(
144 'price_' . $priceFieldID => $priceFieldValueID,
145 'id' => (int) $this->_ids['contribution_page'],
146 'amount' => 10,
147 );
148
149 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
150 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
151 //assert non-deductible amount
152 $this->assertEquals(5.00, $contribution['non_deductible_amount']);
153 }
154
155 /**
156 * Test form submission with billing first & last name where the contact does NOT
157 * otherwise have one.
158 */
159 public function testSubmitNewBillingNameData() {
160 $this->setUpContributionPage();
161 $contact = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com'));
162 $priceFieldID = reset($this->_ids['price_field']);
163 $priceFieldValueID = reset($this->_ids['price_field_value']);
164 $submitParams = array(
165 'price_' . $priceFieldID => $priceFieldValueID,
166 'id' => (int) $this->_ids['contribution_page'],
167 'amount' => 10,
168 'billing_first_name' => 'Wonder',
169 'billing_last_name' => 'Woman',
170 'contactID' => $contact['id'],
171 'email' => 'wonderwoman@amazon.com',
172 );
173
174 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
175 $contact = $this->callAPISuccess('Contact', 'get', array(
176 'id' => $contact['id'],
177 'return' => array(
178 'first_name',
179 'last_name',
180 'sort_name',
181 'display_name',
182 ),
183 ));
184 $this->assertEquals(array(
185 'first_name' => 'Wonder',
186 'last_name' => 'Woman',
187 'display_name' => 'Wonder Woman',
188 'sort_name' => 'Woman, Wonder',
189 'id' => $contact['id'],
190 'contact_id' => $contact['id'],
191 ), $contact['values'][$contact['id']]);
192
193 }
194
195 /**
196 * Test form submission with billing first & last name where the contact does
197 * otherwise have one and should not be overwritten.
198 */
199 public function testSubmitNewBillingNameDoNotOverwrite() {
200 $this->setUpContributionPage();
201 $contact = $this->callAPISuccess('Contact', 'create', array(
202 'contact_type' => 'Individual',
203 'email' => 'wonderwoman@amazon.com',
204 'first_name' => 'Super',
205 'last_name' => 'Boy',
206 ));
207 $priceFieldID = reset($this->_ids['price_field']);
208 $priceFieldValueID = reset($this->_ids['price_field_value']);
209 $submitParams = array(
210 'price_' . $priceFieldID => $priceFieldValueID,
211 'id' => (int) $this->_ids['contribution_page'],
212 'amount' => 10,
213 'billing_first_name' => 'Wonder',
214 'billing_last_name' => 'Woman',
215 'contactID' => $contact['id'],
216 'email' => 'wonderwoman@amazon.com',
217 );
218
219 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
220 $contact = $this->callAPISuccess('Contact', 'get', array(
221 'id' => $contact['id'],
222 'return' => array(
223 'first_name',
224 'last_name',
225 'sort_name',
226 'display_name',
227 ),
228 ));
229 $this->assertEquals(array(
230 'first_name' => 'Super',
231 'last_name' => 'Boy',
232 'display_name' => 'Super Boy',
233 'sort_name' => 'Boy, Super',
234 'id' => $contact['id'],
235 'contact_id' => $contact['id'],
236 ), $contact['values'][$contact['id']]);
237
238 }
239
240 /**
241 * Test process with instant payment when more than one configured for the page.
242 *
243 * CRM-16923
244 */
245 public function testSubmitRecurMultiProcessorInstantPayment() {
246 $this->setUpContributionPage();
247 $this->setupPaymentProcessor();
248 $paymentProcessor2ID = $this->paymentProcessorCreate(array(
249 'payment_processor_type_id' => 'Dummy',
250 'name' => 'processor 2',
251 'class_name' => 'Payment_Dummy',
252 'billing_mode' => 1,
253 ));
254 $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID);
255 $dummyPP->setDoDirectPaymentResult(array(
256 'payment_status_id' => 1,
257 'trxn_id' => 'create_first_success',
258 'fee_amount' => .85,
259 ));
260 $this->callAPISuccess('ContributionPage', 'create', array(
261 'id' => $this->_ids['contribution_page'],
262 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']),
263 ));
264
265 $priceFieldID = reset($this->_ids['price_field']);
266 $priceFieldValueID = reset($this->_ids['price_field_value']);
267 $submitParams = array(
268 'price_' . $priceFieldID => $priceFieldValueID,
269 'id' => (int) $this->_ids['contribution_page'],
270 'amount' => 10,
271 'is_recur' => 1,
272 'frequency_interval' => 1,
273 'frequency_unit' => 'month',
274 'payment_processor_id' => $paymentProcessor2ID,
275 );
276
277 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
278 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
279 'contribution_page_id' => $this->_ids['contribution_page'],
280 'contribution_status_id' => 1,
281 ));
282 $this->assertEquals('create_first_success', $contribution['trxn_id']);
283 $this->assertEquals(10, $contribution['total_amount']);
284 $this->assertEquals(.85, $contribution['fee_amount']);
285 $this->assertEquals(9.15, $contribution['net_amount']);
286 $this->_checkFinancialRecords(array(
287 'id' => $contribution['id'],
288 'total_amount' => $contribution['total_amount'],
289 ), 'online');
290 }
291
292 /**
293 * Test submit with a membership block in place.
294 */
295 public function testSubmitMembershipBlockNotSeparatePayment() {
296 $this->setUpMembershipContributionPage();
297 $submitParams = array(
298 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
299 'id' => (int) $this->_ids['contribution_page'],
300 'amount' => 10,
301 'billing_first_name' => 'Billy',
302 'billing_middle_name' => 'Goat',
303 'billing_last_name' => 'Gruff',
304 'selectMembership' => $this->_ids['membership_type'],
305
306 );
307
308 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
309 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
310 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
311 $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']));
312 }
313
314 /**
315 * Test submit with a membership block in place.
316 */
317 public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() {
318 $mut = new CiviMailUtils($this, TRUE);
319 $this->setUpMembershipContributionPage();
320 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
321
322 $submitParams = array(
323 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
324 'id' => (int) $this->_ids['contribution_page'],
325 'amount' => 10,
326 'billing_first_name' => 'Billy',
327 'billing_middle_name' => 'Goat',
328 'billing_last_name' => 'Gruff',
329 'selectMembership' => $this->_ids['membership_type'],
330 'email-Primary' => 'billy-goat@the-bridge.net',
331 'payment_processor_id' => $this->_paymentProcessor['id'],
332 'credit_card_number' => '4111111111111111',
333 'credit_card_type' => 'Visa',
334 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
335 'cvv2' => 123,
336 );
337
338 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
339 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
340 $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
341 $mut->checkMailLog(array(
342 'Membership Type: General',
343 ));
344 $mut->stop();
345 $mut->clearMessages();
346 }
347
348 /**
349 * Test submit with a membership block in place.
350 */
351 public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() {
352 $mut = new CiviMailUtils($this, TRUE);
353 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
354 $this->setUpMembershipContributionPage();
355 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
356
357 $submitParams = array(
358 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
359 'id' => (int) $this->_ids['contribution_page'],
360 'amount' => 0,
361 'billing_first_name' => 'Billy',
362 'billing_middle_name' => 'Goat',
363 'billing_last_name' => 'Gruffier',
364 'selectMembership' => $this->_ids['membership_type'],
365 'email-Primary' => 'billy-goat@the-new-bridge.net',
366 );
367
368 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
369 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
370 $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
371 $mut->checkMailLog(array(
372 'Membership Type: General',
373 'Gruffier',
374 ),
375 array(
376 'Amount',
377 )
378 );
379 $mut->stop();
380 $mut->clearMessages(999);
381 }
382
383 /**
384 * Test submit with a membership block in place.
385 */
386 public function testSubmitMembershipBlockIsSeparatePayment() {
387 $this->setUpMembershipContributionPage(TRUE);
388 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
389 $submitParams = array(
390 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
391 'id' => (int) $this->_ids['contribution_page'],
392 'amount' => 10,
393 'billing_first_name' => 'Billy',
394 'billing_middle_name' => 'Goat',
395 'billing_last_name' => 'Gruff',
396 'selectMembership' => $this->_ids['membership_type'],
397 );
398
399 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
400 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
401 $this->assertCount(2, $contributions['values']);
402 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
403 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
404 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
405 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
406 }
407
408 /**
409 * Test submit with a membership block in place.
410 */
411 public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() {
412 $mut = new CiviMailUtils($this, TRUE);
413 $this->setUpMembershipContributionPage(TRUE);
414 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
415
416 $submitParams = array(
417 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
418 'id' => (int) $this->_ids['contribution_page'],
419 'amount' => 10,
420 'billing_first_name' => 'Billy',
421 'billing_middle_name' => 'Goat',
422 'billing_last_name' => 'Gruff',
423 'selectMembership' => $this->_ids['membership_type'],
424 'email-Primary' => 'billy-goat@the-bridge.net',
425 'payment_processor_id' => $this->_paymentProcessor['id'],
426 'credit_card_number' => '4111111111111111',
427 'credit_card_type' => 'Visa',
428 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
429 'cvv2' => 123,
430 );
431
432 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
433 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
434 $this->assertCount(2, $contributions['values']);
435 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
436 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
437 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
438 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
439 $mut->checkAllMailLog(array(
440 '$ 2.00',
441 'Membership Fee',
442 ));
443 $mut->stop();
444 $mut->clearMessages(999);
445 }
446
447 /**
448 * Test submit with a membership block in place.
449 */
450 public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() {
451 $mut = new CiviMailUtils($this, TRUE);
452 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
453 $this->setUpMembershipContributionPage(TRUE);
454 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
455
456 $submitParams = array(
457 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
458 'id' => (int) $this->_ids['contribution_page'],
459 'amount' => 0,
460 'billing_first_name' => 'Billy',
461 'billing_middle_name' => 'Goat',
462 'billing_last_name' => 'Gruffalo',
463 'selectMembership' => $this->_ids['membership_type'],
464 'payment_processor_id' => 0,
465 'email-Primary' => 'gruffalo@the-bridge.net',
466 );
467
468 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
469 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
470 $this->assertCount(2, $contributions['values']);
471 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
472 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
473 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
474 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
475 $mut->checkMailLog(array(
476 'Gruffalo',
477 'General Membership: $ 0.00',
478 'Membership Fee',
479 ));
480 $mut->stop();
481 $mut->clearMessages();
482 }
483
484 /**
485 * Test submit with a membership block in place.
486 */
487 public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
488 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6)));
489 $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50));
490 $this->setUpMembershipContributionPage(TRUE);
491 $submitParams = array(
492 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1],
493 'id' => (int) $this->_ids['contribution_page'],
494 'amount' => 10,
495 'billing_first_name' => 'Billy',
496 'billing_middle_name' => 'Goat',
497 'billing_last_name' => 'Gruff',
498 'selectMembership' => $this->_ids['membership_type'][1],
499 );
500
501 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
502 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
503 $this->assertCount(2, $contributions['values']);
504 $ids = array_keys($contributions['values']);
505 $this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']);
506 $this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']);
507 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
508 $this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']);
509 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
510 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
511 }
512
513 /**
514 * Test submit with a membership block in place.
515 *
516 * We are expecting a separate payment for the membership vs the contribution.
517 */
518 public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() {
519 $this->setUpMembershipContributionPage(TRUE);
520 $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']);
521 $processor->setDoDirectPaymentResult(array('fee_amount' => .72));
522 $submitParams = array(
523 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
524 'id' => (int) $this->_ids['contribution_page'],
525 'amount' => 10,
526 'billing_first_name' => 'Billy',
527 'billing_middle_name' => 'Goat',
528 'billing_last_name' => 'Gruff',
529 'selectMembership' => $this->_ids['membership_type'],
530 'payment_processor_id' => $this->_paymentProcessor['id'],
531 'credit_card_number' => '4111111111111111',
532 'credit_card_type' => 'Visa',
533 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
534 'cvv2' => 123,
535 );
536
537 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
538 $contributions = $this->callAPISuccess('contribution', 'get', array(
539 'contribution_page_id' => $this->_ids['contribution_page'],
540 'contribution_status_id' => 1,
541 ));
542 $this->assertCount(2, $contributions['values']);
543 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
544 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
545 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
546 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
547 foreach ($contributions['values'] as $contribution) {
548 $this->assertEquals(.72, $contribution['fee_amount']);
549 $this->assertEquals($contribution['total_amount'] - .72, $contribution['net_amount']);
550 }
551 }
552
553 /**
554 * Test that when a transaction fails the pending contribution remains.
555 *
556 * An activity should also be created. CRM-16417.
557 */
558 public function testSubmitPaymentProcessorFailure() {
559 $this->setUpContributionPage();
560 $this->setupPaymentProcessor();
561 $this->createLoggedInUser();
562 $priceFieldID = reset($this->_ids['price_field']);
563 $priceFieldValueID = reset($this->_ids['price_field_value']);
564 $submitParams = array(
565 'price_' . $priceFieldID => $priceFieldValueID,
566 'id' => (int) $this->_ids['contribution_page'],
567 'amount' => 10,
568 'payment_processor_id' => 1,
569 'credit_card_number' => '4111111111111111',
570 'credit_card_type' => 'Visa',
571 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008),
572 'cvv2' => 123,
573 );
574
575 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
576 $contribution = $this->callAPISuccessGetSingle('contribution', array(
577 'contribution_page_id' => $this->_ids['contribution_page'],
578 'contribution_status_id' => 2,
579 ));
580
581 $this->callAPISuccessGetSingle('activity', array(
582 'source_record_id' => $contribution['id'],
583 'activity_type_id' => 'Failed Payment',
584 ));
585
586 }
587
588 /**
589 * Test submit recurring membership with immediate confirmation (IATS style).
590 *
591 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
592 * processor (IATS style - denoted by returning trxn_id)
593 * - the first creates a new membership, completed contribution, in progress recurring. Check these
594 * - create another - end date should be extended
595 */
596 public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment() {
597 $this->params['is_recur'] = 1;
598 $this->params['recur_frequency_unit'] = 'month';
599 $this->setUpMembershipContributionPage();
600 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
601 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
602
603 $submitParams = array(
604 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
605 'id' => (int) $this->_ids['contribution_page'],
606 'amount' => 10,
607 'billing_first_name' => 'Billy',
608 'billing_middle_name' => 'Goat',
609 'billing_last_name' => 'Gruff',
610 'email' => 'billy@goat.gruff',
611 'selectMembership' => $this->_ids['membership_type'],
612 'payment_processor_id' => 1,
613 'credit_card_number' => '4111111111111111',
614 'credit_card_type' => 'Visa',
615 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
616 'cvv2' => 123,
617 'is_recur' => 1,
618 'frequency_interval' => 1,
619 'frequency_unit' => 'month',
620 );
621
622 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
623 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
624 'contribution_page_id' => $this->_ids['contribution_page'],
625 'contribution_status_id' => 1,
626 ));
627
628 $this->assertEquals('create_first_success', $contribution['trxn_id']);
629 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
630 $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
631 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
632 $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
633 $this->assertEquals(1, $membership['status_id']);
634 $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
635
636 $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id']));
637 //renew it with processor setting completed - should extend membership
638 $submitParams['contact_id'] = $contribution['contact_id'];
639 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
640 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
641 $this->callAPISuccess('contribution', 'getsingle', array(
642 'id' => array('NOT IN' => array($contribution['id'])),
643 'contribution_page_id' => $this->_ids['contribution_page'],
644 'contribution_status_id' => 1,
645 ));
646 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
647 $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']);
648 $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
649 $this->assertEquals(5, $recurringContribution['contribution_status_id']);
650 }
651
652 /**
653 * Test submit recurring membership with immediate confirmation (IATS style).
654 *
655 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
656 * processor (IATS style - denoted by returning trxn_id)
657 * - the first creates a new membership, completed contribution, in progress recurring. Check these
658 * - create another - end date should be extended
659 */
660 public function testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePaymentRecurInstantPayment() {
661
662 $this->setUpMembershipContributionPage(TRUE);
663 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
664 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
665
666 $submitParams = array(
667 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
668 'id' => (int) $this->_ids['contribution_page'],
669 'amount' => 10,
670 'billing_first_name' => 'Billy',
671 'billing_middle_name' => 'Goat',
672 'billing_last_name' => 'Gruff',
673 'email' => 'billy@goat.gruff',
674 'selectMembership' => $this->_ids['membership_type'],
675 'payment_processor_id' => 1,
676 'credit_card_number' => '4111111111111111',
677 'credit_card_type' => 'Visa',
678 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
679 'cvv2' => 123,
680 'is_recur' => 1,
681 'auto_renew' => TRUE,
682 'frequency_interval' => 1,
683 'frequency_unit' => 'month',
684 );
685
686 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
687 $contribution = $this->callAPISuccess('contribution', 'get', array(
688 'contribution_page_id' => $this->_ids['contribution_page'],
689 'contribution_status_id' => 1,
690 ));
691
692 $this->assertEquals(2, $contribution['count']);
693 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
694 $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
695 $this->assertNotEmpty($contribution['values'][$membershipPayment['contribution_id']]['contribution_recur_id']);
696 $this->callAPISuccess('contribution_recur', 'getsingle', array());
697 }
698
699 /**
700 * Test submit recurring membership with delayed confirmation (Authorize.net style)
701 * - we process 2 membership transactions against with a recurring contribution against a contribution page with a delayed
702 * processor (Authorize.net style - denoted by NOT returning trxn_id)
703 * - the first creates a pending membership, pending contribution, penging recurring. Check these
704 * - complete the transaction
705 * - create another - end date should NOT be extended
706 */
707 public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() {
708 $this->params['is_recur'] = 1;
709 $this->params['recur_frequency_unit'] = 'month';
710 $this->setUpMembershipContributionPage();
711 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
712 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
713 $this->membershipTypeCreate(array('name' => 'Student'));
714
715 // Add a contribution & a couple of memberships so the id will not be 1 & will differ from membership id.
716 // This saves us from 'accidental success'.
717 $this->contributionCreate(array('contact_id' => $this->contactIds[0]));
718 $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
719 $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student'));
720
721 $submitParams = array(
722 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
723 'id' => (int) $this->_ids['contribution_page'],
724 'amount' => 10,
725 'billing_first_name' => 'Billy',
726 'billing_middle_name' => 'Goat',
727 'billing_last_name' => 'Gruff',
728 'email' => 'billy@goat.gruff',
729 'selectMembership' => $this->_ids['membership_type'],
730 'payment_processor_id' => 1,
731 'credit_card_number' => '4111111111111111',
732 'credit_card_type' => 'Visa',
733 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
734 'cvv2' => 123,
735 'is_recur' => 1,
736 'frequency_interval' => 1,
737 'frequency_unit' => 'month',
738 );
739
740 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
741 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
742 'contribution_page_id' => $this->_ids['contribution_page'],
743 'contribution_status_id' => 2,
744 ));
745
746 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
747 $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
748 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
749 $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
750 $this->assertEquals(5, $membership['status_id']);
751
752 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
753 $this->assertEquals('civicrm_membership', $line['entity_table']);
754 $this->assertEquals($membership['id'], $line['entity_id']);
755
756 $this->callAPISuccess('contribution', 'completetransaction', array(
757 'id' => $contribution['id'],
758 'trxn_id' => 'ipn_called',
759 'payment_processor_id' => $this->_paymentProcessor['id'],
760 ));
761 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
762 $this->assertEquals('civicrm_membership', $line['entity_table']);
763 $this->assertEquals($membership['id'], $line['entity_id']);
764
765 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
766 //renew it with processor setting completed - should extend membership
767 $submitParams = array_merge($submitParams, array(
768 'contact_id' => $contribution['contact_id'],
769 'is_recur' => 1,
770 'frequency_interval' => 1,
771 'frequency_unit' => 'month',
772 )
773 );
774
775 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
776 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
777 $newContribution = $this->callAPISuccess('contribution', 'getsingle', array(
778 'id' => array(
779 'NOT IN' => array($contribution['id']),
780 ),
781 'contribution_page_id' => $this->_ids['contribution_page'],
782 'contribution_status_id' => 2,
783 )
784 );
785 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $newContribution['id']));
786 $this->assertEquals('civicrm_membership', $line['entity_table']);
787 $this->assertEquals($membership['id'], $line['entity_id']);
788
789 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
790 //no renewal as the date hasn't changed
791 $this->assertEquals($membership['end_date'], $renewedMembership['end_date']);
792 $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id']));
793 $this->assertEquals(2, $recurringContribution['contribution_status_id']);
794 }
795
796 /**
797 * Set up membership contribution page.
798 * @param bool $isSeparatePayment
799 */
800 public function setUpMembershipContributionPage($isSeparatePayment = FALSE) {
801 $this->setUpMembershipBlockPriceSet();
802 $this->setupPaymentProcessor();
803 $this->setUpContributionPage();
804
805 $this->callAPISuccess('membership_block', 'create', array(
806 'entity_id' => $this->_ids['contribution_page'],
807 'entity_table' => 'civicrm_contribution_page',
808 'is_required' => TRUE,
809 'is_active' => TRUE,
810 'is_separate_payment' => $isSeparatePayment,
811 'membership_type_default' => $this->_ids['membership_type'],
812 ));
813 }
814
815 /**
816 * Set up pledge block.
817 */
818 public function setUpPledgeBlock() {
819 $params = array(
820 'entity_table' => 'civicrm_contribution_page',
821 'entity_id' => $this->_ids['contribution_page'],
822 'pledge_frequency_unit' => 'week',
823 'is_pledge_interval' => 0,
824 'pledge_start_date' => json_encode(array('calendar_date' => date('Ymd', strtotime("+1 month")))),
825 );
826 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
827 $this->_ids['pledge_block_id'] = $pledgeBlock->id;
828 }
829
830 /**
831 * The default data set does not include a complete default membership price set - not quite sure why.
832 *
833 * This function ensures it exists & populates $this->_ids with it's data
834 */
835 public function setUpMembershipBlockPriceSet() {
836 $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array(
837 'name' => 'default_membership_type_amount',
838 'return' => 'id',
839 ));
840 if (empty($this->_ids['membership_type'])) {
841 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
842 }
843 $priceField = $this->callAPISuccess('price_field', 'create', array(
844 'price_set_id' => reset($this->_ids['price_set']),
845 'name' => 'membership_amount',
846 'label' => 'Membership Amount',
847 'html_type' => 'Radio',
848 'sequential' => 1,
849 ));
850 $this->_ids['price_field'][] = $priceField['id'];
851
852 foreach ($this->_ids['membership_type'] as $membershipTypeID) {
853 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
854 'name' => 'membership_amount',
855 'label' => 'Membership Amount',
856 'amount' => 1,
857 'financial_type_id' => 'Donation',
858 'format.only_id' => TRUE,
859 'membership_type_id' => $membershipTypeID,
860 'price_field_id' => $priceField['id'],
861 ));
862 $this->_ids['price_field_value'][] = $priceFieldValue;
863 }
864 }
865
866 /**
867 * Add text field other amount to the price set.
868 */
869 public function addOtherAmountFieldToMembershipPriceSet() {
870 $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', array(
871 'price_set_id' => reset($this->_ids['price_set']),
872 'name' => 'other_amount',
873 'label' => 'Other Amount',
874 'html_type' => 'Text',
875 'format.only_id' => TRUE,
876 'sequential' => 1,
877 ));
878 $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', array(
879 'financial_type_id' => 'Donation',
880 'format.only_id' => TRUE,
881 'label' => 'Other Amount',
882 'amount' => 1,
883 'price_field_id' => $this->_ids['price_field']['other_amount'],
884 ));
885 }
886
887 /**
888 * Help function to set up contribution page with some defaults.
889 */
890 public function setUpContributionPage() {
891 $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
892 if (empty($this->_ids['price_set'])) {
893 $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams);
894 $this->_ids['price_set'][] = $priceSet['id'];
895 }
896 $priceSetID = reset($this->_ids['price_set']);
897 CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
898
899 if (empty($this->_ids['price_field'])) {
900 $priceField = $this->callAPISuccess('price_field', 'create', array(
901 'price_set_id' => $priceSetID,
902 'label' => 'Goat Breed',
903 'html_type' => 'Radio',
904 ));
905 $this->_ids['price_field'] = array($priceField['id']);
906 }
907 if (empty($this->_ids['price_field_value'])) {
908 $this->callAPISuccess('price_field_value', 'create', array(
909 'price_set_id' => $priceSetID,
910 'price_field_id' => $priceField['id'],
911 'label' => 'Long Haired Goat',
912 'financial_type_id' => 'Donation',
913 'amount' => 20,
914 'financial_type_id' => 'Donation',
915 'non_deductible_amount' => 15,
916 )
917 );
918 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
919 'price_set_id' => $priceSetID,
920 'price_field_id' => $priceField['id'],
921 'label' => 'Shoe-eating Goat',
922 'financial_type_id' => 'Donation',
923 'amount' => 10,
924 'financial_type_id' => 'Donation',
925 'non_deductible_amount' => 5,
926 )
927 );
928 $this->_ids['price_field_value'] = array($priceFieldValue['id']);
929 }
930 $this->_ids['contribution_page'] = $contributionPageResult['id'];
931 }
932
933 public static function setUpBeforeClass() {
934 // put stuff here that should happen before all tests in this unit
935 }
936
937 public static function tearDownAfterClass() {
938 $tablesToTruncate = array(
939 'civicrm_contact',
940 'civicrm_financial_type',
941 'civicrm_contribution',
942 'civicrm_contribution_page',
943 );
944 $unitTest = new CiviUnitTestCase();
945 $unitTest->quickCleanup($tablesToTruncate);
946 }
947
948 /**
949 * Create a payment processor instance.
950 */
951 protected function setupPaymentProcessor() {
952 $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array(
953 'payment_processor_type_id' => 'Dummy',
954 'class_name' => 'Payment_Dummy',
955 'billing_mode' => 1,
956 ));
957 $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id']));
958 }
959
960 /**
961 * Test submit recurring pledge.
962 *
963 * - we process 1 pledge with a future start date. A recur contribution and the pledge should be created with first payment date in the future.
964 */
965 public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() {
966 $this->params['adjust_recur_start_date'] = TRUE;
967 $this->params['is_pay_later'] = FALSE;
968 $this->setUpContributionPage();
969 $this->setUpPledgeBlock();
970 $this->setupPaymentProcessor();
971 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
972 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
973
974 $submitParams = array(
975 'id' => (int) $this->_ids['contribution_page'],
976 'amount' => 100,
977 'billing_first_name' => 'Billy',
978 'billing_middle_name' => 'Goat',
979 'billing_last_name' => 'Gruff',
980 'email' => 'billy@goat.gruff',
981 'payment_processor_id' => 1,
982 'credit_card_number' => '4111111111111111',
983 'credit_card_type' => 'Visa',
984 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
985 'cvv2' => 123,
986 'pledge_frequency_interval' => 1,
987 'pledge_frequency_unit' => 'week',
988 'pledge_installments' => 3,
989 'is_pledge' => TRUE,
990 'pledge_block_id' => (int) $this->_ids['pledge_block_id'],
991 );
992
993 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
994
995 // Check if contribution created.
996 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
997 'contribution_page_id' => $this->_ids['contribution_page'],
998 'contribution_status_id' => 'Completed', // Will be pending when actual payment processor is used (dummy processor does not support future payments).
999 ));
1000
1001 $this->assertEquals('create_first_success', $contribution['trxn_id']);
1002
1003 // Check if pledge created.
1004 $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
1005 $this->assertEquals(date('Ymd', strtotime($pledge['pledge_start_date'])), date('Ymd', strtotime("+1 month")));
1006 $this->assertEquals($pledge['pledge_amount'], 300.00);
1007
1008 // Check if pledge payments created.
1009 $params = array(
1010 'pledge_id' => $pledge['id'],
1011 );
1012 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1013 $this->assertEquals($pledgePayment['count'], 3);
1014 $this->assertEquals(date('Ymd', strtotime($pledgePayment['values'][1]['scheduled_date'])), date('Ymd', strtotime("+1 month")));
1015 $this->assertEquals($pledgePayment['values'][1]['scheduled_amount'], 100.00);
1016 $this->assertEquals($pledgePayment['values'][1]['status_id'], 1); // Will be pending when actual payment processor is used (dummy processor does not support future payments).
1017
1018 // Check contribution recur record.
1019 $recur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
1020 $this->assertEquals(date('Ymd', strtotime($recur['start_date'])), date('Ymd', strtotime("+1 month")));
1021 $this->assertEquals($recur['amount'], 100.00);
1022 $this->assertEquals($recur['contribution_status_id'], 5); // In progress status.
1023 }
1024
1025 /**
1026 * Test submit pledge payment.
1027 *
1028 * - test submitting a pledge payment using contribution form.
1029 */
1030 public function testSubmitPledgePayment() {
1031 $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment();
1032 $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
1033 $params = array(
1034 'pledge_id' => $pledge['id'],
1035 );
1036 $submitParams = array(
1037 'id' => (int) $pledge['pledge_contribution_page_id'],
1038 'pledge_amount' => array(2 => 1),
1039 'billing_first_name' => 'Billy',
1040 'billing_middle_name' => 'Goat',
1041 'billing_last_name' => 'Gruff',
1042 'email' => 'billy@goat.gruff',
1043 'payment_processor_id' => 1,
1044 'credit_card_number' => '4111111111111111',
1045 'credit_card_type' => 'Visa',
1046 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
1047 'cvv2' => 123,
1048 'pledge_id' => $pledge['id'],
1049 'cid' => $pledge['contact_id'],
1050 'contact_id' => $pledge['contact_id'],
1051 'amount' => 100.00,
1052 'is_pledge' => TRUE,
1053 'pledge_block_id' => $this->_ids['pledge_block_id'],
1054 );
1055 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1056 $this->assertEquals($pledgePayment['values'][2]['status_id'], 2);
1057
1058 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
1059
1060 // Check if contribution created.
1061 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1062 'contribution_page_id' => $pledge['pledge_contribution_page_id'],
1063 'contribution_status_id' => 'Completed',
1064 'contact_id' => $pledge['contact_id'],
1065 'contribution_recur_id' => array('IS NULL' => 1),
1066 ));
1067
1068 $this->assertEquals(100.00, $contribution['total_amount']);
1069 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1070 $this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed");
1071 $this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']);
1072 }
1073
1074 }