Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_contribute_* functions | |
30 | * | |
6c6e6187 TO |
31 | * @package CiviCRM_APIv3 |
32 | * @subpackage API_Contribution | |
acb109b7 | 33 | * @group headless |
6a488035 | 34 | */ |
6a488035 TO |
35 | class api_v3_ContributionTest extends CiviUnitTestCase { |
36 | ||
37 | /** | |
fe482240 | 38 | * Assume empty database with just civicrm_data. |
6a488035 TO |
39 | */ |
40 | protected $_individualId; | |
41 | protected $_contribution; | |
4ab7d517 | 42 | protected $_financialTypeId = 1; |
6a488035 TO |
43 | protected $_apiversion; |
44 | protected $_entity = 'Contribution'; | |
45 | public $debug = 0; | |
46 | protected $_params; | |
858d0bf8 EM |
47 | protected $_ids = array(); |
48 | protected $_pageParams = array(); | |
1eade77d | 49 | /** |
50 | * Payment processor ID (dummy processor). | |
51 | * | |
52 | * @var int | |
53 | */ | |
54 | protected $paymentProcessorID; | |
b7c9bc4c | 55 | |
1e52837d EM |
56 | /** |
57 | * Parameters to create payment processor. | |
58 | * | |
59 | * @var array | |
60 | */ | |
61 | protected $_processorParams = array(); | |
62 | ||
63 | /** | |
64 | * ID of created event. | |
65 | * | |
66 | * @var int | |
67 | */ | |
68 | protected $_eventID; | |
69 | ||
ec7e3954 E |
70 | /** |
71 | * @var CiviMailUtils | |
72 | */ | |
73 | protected $mut; | |
74 | ||
22f80e87 EM |
75 | /** |
76 | * Setup function. | |
77 | */ | |
00be9182 | 78 | public function setUp() { |
6a488035 TO |
79 | parent::setUp(); |
80 | ||
81 | $this->_apiversion = 3; | |
82 | $this->_individualId = $this->individualCreate(); | |
6a488035 TO |
83 | $this->_params = array( |
84 | 'contact_id' => $this->_individualId, | |
85 | 'receive_date' => '20120511', | |
86 | 'total_amount' => 100.00, | |
5896d037 | 87 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
88 | 'non_deductible_amount' => 10.00, |
89 | 'fee_amount' => 5.00, | |
90 | 'net_amount' => 95.00, | |
91 | 'source' => 'SSF', | |
92 | 'contribution_status_id' => 1, | |
6a488035 TO |
93 | ); |
94 | $this->_processorParams = array( | |
95 | 'domain_id' => 1, | |
96 | 'name' => 'Dummy', | |
97502bac | 97 | 'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'), |
6a488035 TO |
98 | 'financial_account_id' => 12, |
99 | 'is_active' => 1, | |
100 | 'user_name' => '', | |
101 | 'url_site' => 'http://dummy.com', | |
102 | 'url_recur' => 'http://dummy.com', | |
103 | 'billing_mode' => 1, | |
104 | ); | |
1eade77d | 105 | $this->paymentProcessorID = $this->processorCreate(); |
6a488035 | 106 | $this->_pageParams = array( |
6a488035 TO |
107 | 'title' => 'Test Contribution Page', |
108 | 'financial_type_id' => 1, | |
109 | 'currency' => 'USD', | |
110 | 'financial_account_id' => 1, | |
1eade77d | 111 | 'payment_processor' => $this->paymentProcessorID, |
6a488035 TO |
112 | 'is_active' => 1, |
113 | 'is_allow_other_amount' => 1, | |
114 | 'min_amount' => 10, | |
115 | 'max_amount' => 1000, | |
5896d037 | 116 | ); |
6a488035 TO |
117 | } |
118 | ||
22f80e87 EM |
119 | /** |
120 | * Clean up after each test. | |
121 | */ | |
00be9182 | 122 | public function tearDown() { |
39d632fd | 123 | $this->quickCleanUpFinancialEntities(); |
225d474b | 124 | $this->quickCleanup(array('civicrm_uf_match')); |
6a488035 TO |
125 | } |
126 | ||
22f80e87 EM |
127 | /** |
128 | * Test Get. | |
129 | */ | |
00be9182 | 130 | public function testGetContribution() { |
6a488035 TO |
131 | $p = array( |
132 | 'contact_id' => $this->_individualId, | |
133 | 'receive_date' => '2010-01-20', | |
134 | 'total_amount' => 100.00, | |
4ab7d517 | 135 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
136 | 'non_deductible_amount' => 10.00, |
137 | 'fee_amount' => 5.00, | |
138 | 'net_amount' => 95.00, | |
139 | 'trxn_id' => 23456, | |
140 | 'invoice_id' => 78910, | |
141 | 'source' => 'SSF', | |
142 | 'contribution_status_id' => 1, | |
6a488035 | 143 | ); |
2f45e1c2 | 144 | $this->_contribution = $this->callAPISuccess('contribution', 'create', $p); |
6a488035 TO |
145 | |
146 | $params = array( | |
147 | 'contribution_id' => $this->_contribution['id'], | |
6a488035 | 148 | ); |
e0e3c51b | 149 | |
2f45e1c2 | 150 | $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__); |
4ab7d517 | 151 | $financialParams['id'] = $this->_financialTypeId; |
6c6e6187 | 152 | $default = NULL; |
858d0bf8 | 153 | CRM_Financial_BAO_FinancialType::retrieve($financialParams, $default); |
2f45e1c2 | 154 | |
e0e3c51b | 155 | $this->assertEquals(1, $contribution['count']); |
2bfae985 | 156 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
22f80e87 EM |
157 | // Note there was an assertion converting financial_type_id to 'Donation' which wasn't working. |
158 | // Passing back a string rather than an id seems like an error/cruft. | |
159 | // If it is to be introduced we should discuss. | |
6a488035 | 160 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
161 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); |
162 | $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00); | |
163 | $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00); | |
164 | $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00); | |
165 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456); | |
166 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910); | |
167 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF'); | |
168 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed'); | |
22f80e87 | 169 | // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id). |
6a488035 TO |
170 | $p['trxn_id'] = '3847'; |
171 | $p['invoice_id'] = '3847'; | |
172 | ||
2f45e1c2 | 173 | $contribution2 = $this->callAPISuccess('contribution', 'create', $p); |
174 | ||
22f80e87 | 175 | // Now we have 2 - test getcount. |
4ab7d517 | 176 | $contribution = $this->callAPISuccess('contribution', 'getcount', array()); |
6a488035 | 177 | $this->assertEquals(2, $contribution); |
22f80e87 | 178 | // Test id only format. |
4ab7d517 | 179 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
180 | 'id' => $this->_contribution['id'], | |
181 | 'format.only_id' => 1, | |
182 | )); | |
22f80e87 EM |
183 | $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE)); |
184 | // Test id only format. | |
2f45e1c2 | 185 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
4ab7d517 | 186 | 'id' => $contribution2['id'], |
187 | 'format.only_id' => 1, | |
188 | )); | |
189 | $this->assertEquals($contribution2['id'], $contribution); | |
22f80e87 | 190 | // Test id as field. |
4ab7d517 | 191 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
192 | 'id' => $this->_contribution['id'], | |
193 | )); | |
2bfae985 | 194 | $this->assertEquals(1, $contribution['count']); |
4ab7d517 | 195 | |
22f80e87 | 196 | // Test get by contact id works. |
4ab7d517 | 197 | $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId)); |
6a488035 | 198 | |
2bfae985 | 199 | $this->assertEquals(2, $contribution['count']); |
2f45e1c2 | 200 | $this->callAPISuccess('Contribution', 'Delete', array( |
6a488035 | 201 | 'id' => $this->_contribution['id'], |
4ab7d517 | 202 | )); |
2f45e1c2 | 203 | $this->callAPISuccess('Contribution', 'Delete', array( |
6a488035 | 204 | 'id' => $contribution2['id'], |
4ab7d517 | 205 | )); |
6a488035 TO |
206 | } |
207 | ||
71d5a412 | 208 | /** |
209 | * Test that test contributions can be retrieved. | |
210 | */ | |
211 | public function testGetTestContribution() { | |
212 | $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('is_test' => 1))); | |
213 | $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1)); | |
214 | } | |
215 | ||
6c6e6187 | 216 | /** |
22f80e87 | 217 | * We need to ensure previous tested behaviour still works as part of the api contract. |
6c6e6187 | 218 | */ |
00be9182 | 219 | public function testGetContributionLegacyBehaviour() { |
6a488035 TO |
220 | $p = array( |
221 | 'contact_id' => $this->_individualId, | |
222 | 'receive_date' => '2010-01-20', | |
223 | 'total_amount' => 100.00, | |
4ab7d517 | 224 | 'contribution_type_id' => $this->_financialTypeId, |
6a488035 TO |
225 | 'non_deductible_amount' => 10.00, |
226 | 'fee_amount' => 5.00, | |
227 | 'net_amount' => 95.00, | |
228 | 'trxn_id' => 23456, | |
229 | 'invoice_id' => 78910, | |
230 | 'source' => 'SSF', | |
231 | 'contribution_status_id' => 1, | |
6a488035 | 232 | ); |
71d5a412 | 233 | $this->_contribution = $this->callAPISuccess('Contribution', 'create', $p); |
6a488035 TO |
234 | |
235 | $params = array( | |
236 | 'contribution_id' => $this->_contribution['id'], | |
6a488035 | 237 | ); |
2f45e1c2 | 238 | $contribution = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__); |
4ab7d517 | 239 | $financialParams['id'] = $this->_financialTypeId; |
6c6e6187 | 240 | $default = NULL; |
858d0bf8 | 241 | CRM_Financial_BAO_FinancialType::retrieve($financialParams, $default); |
2f45e1c2 | 242 | |
6c6e6187 | 243 | $this->assertEquals(1, $contribution['count']); |
2bfae985 | 244 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
4ab7d517 | 245 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->_financialTypeId); |
246 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_type_id'], $this->_financialTypeId); | |
2bfae985 EM |
247 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); |
248 | $this->assertEquals($contribution['values'][$contribution['id']]['non_deductible_amount'], 10.00); | |
249 | $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 5.00); | |
250 | $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 95.00); | |
251 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 23456); | |
252 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910); | |
253 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF'); | |
254 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed'); | |
22f80e87 EM |
255 | |
256 | // Create a second contribution - we are testing that 'id' gets the right contribution id (not the contact id). | |
6a488035 TO |
257 | $p['trxn_id'] = '3847'; |
258 | $p['invoice_id'] = '3847'; | |
259 | ||
2f45e1c2 | 260 | $contribution2 = $this->callAPISuccess('contribution', 'create', $p); |
6a488035 | 261 | |
6a488035 | 262 | // now we have 2 - test getcount |
4ab7d517 | 263 | $contribution = $this->callAPISuccess('contribution', 'getcount', array()); |
6a488035 TO |
264 | $this->assertEquals(2, $contribution); |
265 | //test id only format | |
4ab7d517 | 266 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
267 | 'id' => $this->_contribution['id'], | |
268 | 'format.only_id' => 1, | |
269 | )); | |
22f80e87 | 270 | $this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE)); |
6a488035 | 271 | //test id only format |
4ab7d517 | 272 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
273 | 'id' => $contribution2['id'], | |
274 | 'format.only_id' => 1, | |
275 | )); | |
6a488035 | 276 | $this->assertEquals($contribution2['id'], $contribution); |
2f45e1c2 | 277 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
6a488035 TO |
278 | 'id' => $this->_contribution['id'], |
279 | )); | |
280 | //test id as field | |
2bfae985 | 281 | $this->assertEquals(1, $contribution['count']); |
6a488035 TO |
282 | // $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ; |
283 | //test get by contact id works | |
4ab7d517 | 284 | $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId)); |
6a488035 | 285 | |
2bfae985 | 286 | $this->assertEquals(2, $contribution['count']); |
2f45e1c2 | 287 | $this->callAPISuccess('Contribution', 'Delete', array( |
5896d037 | 288 | 'id' => $this->_contribution['id'], |
6a488035 | 289 | )); |
2f45e1c2 | 290 | $this->callAPISuccess('Contribution', 'Delete', array( |
5896d037 | 291 | 'id' => $contribution2['id'], |
6a488035 TO |
292 | )); |
293 | } | |
5896d037 | 294 | |
a1a2a83d TO |
295 | /** |
296 | * Create an contribution_id=FALSE and financial_type_id=Donation. | |
297 | */ | |
00be9182 | 298 | public function testCreateEmptyContributionIDUseDonation() { |
6a488035 TO |
299 | $params = array( |
300 | 'contribution_id' => FALSE, | |
301 | 'contact_id' => 1, | |
302 | 'total_amount' => 1, | |
6c6e6187 | 303 | 'check_permissions' => FALSE, |
6a488035 TO |
304 | 'financial_type_id' => 'Donation', |
305 | ); | |
858d0bf8 | 306 | $this->callAPISuccess('contribution', 'create', $params); |
6c6e6187 | 307 | } |
6a488035 | 308 | |
6a488035 | 309 | /** |
1e52837d EM |
310 | * Check with complete array + custom field. |
311 | * | |
6a488035 TO |
312 | * Note that the test is written on purpose without any |
313 | * variables specific to participant so it can be replicated into other entities | |
314 | * and / or moved to the automated test suite | |
315 | */ | |
00be9182 | 316 | public function testCreateWithCustom() { |
6a488035 TO |
317 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
318 | ||
319 | $params = $this->_params; | |
320 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
321 | ||
6c6e6187 | 322 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 323 | $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); |
2f45e1c2 | 324 | $check = $this->callAPISuccess($this->_entity, 'get', array( |
4ab7d517 | 325 | 'return.custom_' . $ids['custom_field_id'] => 1, |
326 | 'id' => $result['id'], | |
327 | )); | |
6a488035 TO |
328 | $this->customFieldDelete($ids['custom_field_id']); |
329 | $this->customGroupDelete($ids['custom_group_id']); | |
22f80e87 | 330 | $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); |
6a488035 TO |
331 | } |
332 | ||
333 | /** | |
fd786d03 EM |
334 | * Check with complete array + custom field. |
335 | * | |
6a488035 TO |
336 | * Note that the test is written on purpose without any |
337 | * variables specific to participant so it can be replicated into other entities | |
338 | * and / or moved to the automated test suite | |
339 | */ | |
00be9182 | 340 | public function testCreateGetFieldsWithCustom() { |
5896d037 | 341 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
6a488035 | 342 | $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php'); |
5896d037 | 343 | $result = $this->callAPISuccess('Contribution', 'getfields', array()); |
6a488035 TO |
344 | $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']); |
345 | $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']); | |
346 | $this->customFieldDelete($ids['custom_field_id']); | |
347 | $this->customGroupDelete($ids['custom_group_id']); | |
348 | $this->customFieldDelete($idsContact['custom_field_id']); | |
349 | $this->customGroupDelete($idsContact['custom_group_id']); | |
350 | } | |
351 | ||
00be9182 | 352 | public function testCreateContributionNoLineItems() { |
6a488035 TO |
353 | |
354 | $params = array( | |
355 | 'contact_id' => $this->_individualId, | |
356 | 'receive_date' => '20120511', | |
357 | 'total_amount' => 100.00, | |
5896d037 | 358 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
359 | 'payment_instrument_id' => 1, |
360 | 'non_deductible_amount' => 10.00, | |
361 | 'fee_amount' => 50.00, | |
362 | 'net_amount' => 90.00, | |
363 | 'trxn_id' => 12345, | |
364 | 'invoice_id' => 67890, | |
365 | 'source' => 'SSF', | |
366 | 'contribution_status_id' => 1, | |
6a488035 TO |
367 | 'skipLineItem' => 1, |
368 | ); | |
369 | ||
2f45e1c2 | 370 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
6c6e6187 | 371 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
6a488035 TO |
372 | 'entity_id' => $contribution['id'], |
373 | 'entity_table' => 'civicrm_contribution', | |
374 | 'sequential' => 1, | |
375 | )); | |
376 | $this->assertEquals(0, $lineItems['count']); | |
377 | } | |
5896d037 | 378 | |
a1a2a83d | 379 | /** |
eceb18cc | 380 | * Test checks that passing in line items suppresses the create mechanism. |
6a488035 | 381 | */ |
00be9182 | 382 | public function testCreateContributionChainedLineItems() { |
6a488035 TO |
383 | $params = array( |
384 | 'contact_id' => $this->_individualId, | |
385 | 'receive_date' => '20120511', | |
386 | 'total_amount' => 100.00, | |
4ab7d517 | 387 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
388 | 'payment_instrument_id' => 1, |
389 | 'non_deductible_amount' => 10.00, | |
390 | 'fee_amount' => 50.00, | |
391 | 'net_amount' => 90.00, | |
392 | 'trxn_id' => 12345, | |
393 | 'invoice_id' => 67890, | |
394 | 'source' => 'SSF', | |
395 | 'contribution_status_id' => 1, | |
6a488035 TO |
396 | 'skipLineItem' => 1, |
397 | 'api.line_item.create' => array( | |
398 | array( | |
399 | 'price_field_id' => 1, | |
400 | 'qty' => 2, | |
401 | 'line_total' => '20', | |
402 | 'unit_price' => '10', | |
403 | ), | |
404 | array( | |
405 | 'price_field_id' => 1, | |
406 | 'qty' => 1, | |
407 | 'line_total' => '80', | |
408 | 'unit_price' => '80', | |
409 | ), | |
410 | ), | |
411 | ); | |
412 | ||
5c49fee0 | 413 | $description = "Create Contribution with Nested Line Items."; |
6a488035 | 414 | $subfile = "CreateWithNestedLineItems"; |
6c6e6187 | 415 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
2f45e1c2 | 416 | |
6c6e6187 | 417 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
6a488035 | 418 | 'entity_id' => $contribution['id'], |
4ede4532 | 419 | 'contribution_id' => $contribution['id'], |
6a488035 TO |
420 | 'entity_table' => 'civicrm_contribution', |
421 | 'sequential' => 1, | |
422 | )); | |
423 | $this->assertEquals(2, $lineItems['count']); | |
424 | } | |
425 | ||
00be9182 | 426 | public function testCreateContributionOffline() { |
6a488035 TO |
427 | $params = array( |
428 | 'contact_id' => $this->_individualId, | |
429 | 'receive_date' => '20120511', | |
430 | 'total_amount' => 100.00, | |
431 | 'financial_type_id' => 1, | |
432 | 'trxn_id' => 12345, | |
433 | 'invoice_id' => 67890, | |
434 | 'source' => 'SSF', | |
435 | 'contribution_status_id' => 1, | |
6a488035 TO |
436 | ); |
437 | ||
4ab7d517 | 438 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); |
2bfae985 EM |
439 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
440 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); | |
5896d037 | 441 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
442 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); |
443 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
444 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
445 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); | |
6c6e6187 | 446 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
6a488035 | 447 | 'entity_id' => $contribution['id'], |
4ede4532 | 448 | 'contribution_id' => $contribution['id'], |
6a488035 TO |
449 | 'entity_table' => 'civicrm_contribution', |
450 | 'sequential' => 1, | |
5896d037 | 451 | )); |
6a488035 TO |
452 | $this->assertEquals(1, $lineItems['count']); |
453 | $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); | |
4ede4532 | 454 | $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); |
6a488035 TO |
455 | $this->_checkFinancialRecords($contribution, 'offline'); |
456 | $this->contributionGetnCheck($params, $contribution['id']); | |
457 | } | |
5896d037 | 458 | |
f70a6752 | 459 | /** |
28de42d1 | 460 | * Test create with valid payment instrument. |
6a488035 | 461 | */ |
00be9182 | 462 | public function testCreateContributionWithPaymentInstrument() { |
6a488035 | 463 | $params = $this->_params + array('payment_instrument' => 'EFT'); |
53191813 | 464 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
6c6e6187 | 465 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
53191813 | 466 | 'sequential' => 1, |
21dfd5f5 | 467 | 'id' => $contribution['id'], |
53191813 | 468 | )); |
6a488035 | 469 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
53191813 CW |
470 | $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); |
471 | ||
5896d037 | 472 | $this->callAPISuccess('contribution', 'create', array( |
92915c55 TO |
473 | 'id' => $contribution['id'], |
474 | 'payment_instrument' => 'Credit Card', | |
475 | )); | |
6c6e6187 | 476 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
53191813 | 477 | 'sequential' => 1, |
21dfd5f5 | 478 | 'id' => $contribution['id'], |
53191813 CW |
479 | )); |
480 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); | |
481 | $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']); | |
6a488035 TO |
482 | } |
483 | ||
00be9182 | 484 | public function testGetContributionByPaymentInstrument() { |
6a488035 | 485 | $params = $this->_params + array('payment_instrument' => 'EFT'); |
53191813 | 486 | $params2 = $this->_params + array('payment_instrument' => 'Cash'); |
6c6e6187 TO |
487 | $this->callAPISuccess('contribution', 'create', $params); |
488 | $this->callAPISuccess('contribution', 'create', $params2); | |
5896d037 | 489 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
92915c55 | 490 | 'sequential' => 1, |
7d543448 | 491 | 'contribution_payment_instrument' => 'Cash', |
92915c55 | 492 | )); |
6a488035 | 493 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
ff977830 EM |
494 | $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']); |
495 | $this->assertEquals(1, $contribution['count']); | |
868e247d | 496 | $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument' => 'Cash')); |
6a488035 | 497 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
868e247d | 498 | $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']); |
6a488035 | 499 | $this->assertEquals(1, $contribution['count']); |
5896d037 | 500 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
92915c55 TO |
501 | 'sequential' => 1, |
502 | 'payment_instrument_id' => 5, | |
503 | )); | |
6a488035 | 504 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
6c6e6187 TO |
505 | $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); |
506 | $this->assertEquals(1, $contribution['count']); | |
5896d037 | 507 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
92915c55 TO |
508 | 'sequential' => 1, |
509 | 'payment_instrument' => 'EFT', | |
510 | )); | |
6a488035 | 511 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
53191813 CW |
512 | $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); |
513 | $this->assertEquals(1, $contribution['count']); | |
5896d037 | 514 | $contribution = $this->callAPISuccess('contribution', 'create', array( |
92915c55 TO |
515 | 'id' => $contribution['id'], |
516 | 'payment_instrument' => 'Credit Card', | |
517 | )); | |
5896d037 | 518 | $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id'])); |
6a488035 | 519 | $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); |
6c6e6187 TO |
520 | $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']); |
521 | $this->assertEquals(1, $contribution['count']); | |
6a488035 TO |
522 | } |
523 | ||
b5a37491 EM |
524 | /** |
525 | * CRM-16227 introduces invoice_id as a parameter. | |
526 | */ | |
527 | public function testGetContributionByInvoice() { | |
528 | $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('invoice_id' => 'curly'))); | |
529 | $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), array('invoice_id' => 'churlish')); | |
530 | $this->callAPISuccessGetCount('Contribution', array(), 2); | |
531 | $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => 'curly')); | |
532 | // The following don't work. They are the format we are trying to introduce but although the form uses this format | |
533 | // CRM_Contact_BAO_Query::convertFormValues puts them into the other format & the where only supports that. | |
534 | // ideally the where clause would support this format (as it does on contact_BAO_Query) and those lines would | |
535 | // come out of convertFormValues | |
536 | // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('LIKE' => '%ish%'))); | |
537 | // $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => array('NOT IN' => array('curly')))); | |
538 | // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('LIKE' => '%ly%')), 2); | |
539 | // $this->callAPISuccessGetCount('Contribution', array('invoice_id' => array('IN' => array('curly', 'churlish'))), | |
540 | // 2); | |
541 | } | |
542 | ||
e58a3abb | 543 | /** |
544 | * Test retrieval by total_amount works. | |
545 | * | |
546 | * @throws Exception | |
547 | */ | |
548 | public function testGetContributionByTotalAmount() { | |
549 | $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '5'))); | |
550 | $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '10'))); | |
551 | $this->callAPISuccessGetCount('Contribution', array('total_amount' => 10), 1); | |
552 | $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 6)), 1); | |
553 | $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 0)), 2); | |
554 | $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => -5)), 2); | |
555 | $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('<' => 0)), 0); | |
556 | $this->callAPISuccessGetCount('Contribution', array(), 2); | |
557 | } | |
558 | ||
c490a46a | 559 | /** |
eceb18cc | 560 | * Create test with unique field name on source. |
c490a46a | 561 | */ |
00be9182 | 562 | public function testCreateContributionSource() { |
6a488035 TO |
563 | |
564 | $params = array( | |
565 | 'contact_id' => $this->_individualId, | |
566 | 'receive_date' => date('Ymd'), | |
567 | 'total_amount' => 100.00, | |
4ab7d517 | 568 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
569 | 'payment_instrument_id' => 1, |
570 | 'non_deductible_amount' => 10.00, | |
571 | 'fee_amount' => 50.00, | |
572 | 'net_amount' => 90.00, | |
573 | 'trxn_id' => 12345, | |
574 | 'invoice_id' => 67890, | |
575 | 'contribution_source' => 'SSF', | |
576 | 'contribution_status_id' => 1, | |
6a488035 TO |
577 | ); |
578 | ||
4ab7d517 | 579 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
2bfae985 EM |
580 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); |
581 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
6a488035 | 582 | } |
d5d148ab | 583 | |
d424ffde | 584 | /** |
eceb18cc | 585 | * Create test with unique field name on source. |
d424ffde | 586 | */ |
00be9182 | 587 | public function testCreateDefaultNow() { |
d5d148ab EM |
588 | |
589 | $params = $this->_params; | |
590 | unset($params['receive_date']); | |
591 | ||
592 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
593 | $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id'])); | |
594 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date']))); | |
595 | } | |
596 | ||
c490a46a | 597 | /** |
55d2c6f1 | 598 | * Create test with unique field name on source. |
c490a46a | 599 | */ |
55d2c6f1 | 600 | public function testCreateContributionSourceInvalidContact() { |
6a488035 TO |
601 | |
602 | $params = array( | |
603 | 'contact_id' => 999, | |
604 | 'receive_date' => date('Ymd'), | |
605 | 'total_amount' => 100.00, | |
4ab7d517 | 606 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
607 | 'payment_instrument_id' => 1, |
608 | 'non_deductible_amount' => 10.00, | |
609 | 'fee_amount' => 50.00, | |
610 | 'net_amount' => 90.00, | |
611 | 'trxn_id' => 12345, | |
612 | 'invoice_id' => 67890, | |
613 | 'contribution_source' => 'SSF', | |
614 | 'contribution_status_id' => 1, | |
6a488035 TO |
615 | ); |
616 | ||
858d0bf8 | 617 | $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999'); |
6a488035 TO |
618 | } |
619 | ||
00be9182 | 620 | public function testCreateContributionSourceInvalidContContact() { |
6a488035 TO |
621 | |
622 | $params = array( | |
623 | 'contribution_contact_id' => 999, | |
624 | 'receive_date' => date('Ymd'), | |
625 | 'total_amount' => 100.00, | |
4ab7d517 | 626 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
627 | 'payment_instrument_id' => 1, |
628 | 'non_deductible_amount' => 10.00, | |
629 | 'fee_amount' => 50.00, | |
630 | 'net_amount' => 90.00, | |
631 | 'trxn_id' => 12345, | |
632 | 'invoice_id' => 67890, | |
633 | 'contribution_source' => 'SSF', | |
634 | 'contribution_status_id' => 1, | |
6a488035 TO |
635 | ); |
636 | ||
33139905 | 637 | $this->callAPIFailure('contribution', 'create', $params); |
6a488035 TO |
638 | } |
639 | ||
858d0bf8 | 640 | /** |
442cf836 | 641 | * Test note created correctly. |
858d0bf8 | 642 | */ |
00be9182 | 643 | public function testCreateContributionWithNote() { |
5c49fee0 | 644 | $description = "Demonstrates creating contribution with Note Entity."; |
5896d037 TO |
645 | $subfile = "ContributionCreateWithNote"; |
646 | $params = array( | |
6a488035 TO |
647 | 'contact_id' => $this->_individualId, |
648 | 'receive_date' => '2012-01-01', | |
649 | 'total_amount' => 100.00, | |
4ab7d517 | 650 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
651 | 'payment_instrument_id' => 1, |
652 | 'non_deductible_amount' => 10.00, | |
653 | 'fee_amount' => 50.00, | |
654 | 'net_amount' => 90.00, | |
655 | 'trxn_id' => 12345, | |
656 | 'invoice_id' => 67890, | |
657 | 'source' => 'SSF', | |
658 | 'contribution_status_id' => 1, | |
6a488035 TO |
659 | 'note' => 'my contribution note', |
660 | ); | |
661 | ||
4ab7d517 | 662 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
5896d037 | 663 | $result = $this->callAPISuccess('note', 'get', array( |
92915c55 TO |
664 | 'entity_table' => 'civicrm_contribution', |
665 | 'entity_id' => $contribution['id'], | |
666 | 'sequential' => 1, | |
667 | )); | |
6a488035 | 668 | $this->assertEquals('my contribution note', $result['values'][0]['note']); |
4ab7d517 | 669 | $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); |
6a488035 TO |
670 | } |
671 | ||
00be9182 | 672 | public function testCreateContributionWithNoteUniqueNameAliases() { |
5896d037 | 673 | $params = array( |
6a488035 TO |
674 | 'contact_id' => $this->_individualId, |
675 | 'receive_date' => '2012-01-01', | |
676 | 'total_amount' => 100.00, | |
4ab7d517 | 677 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
678 | 'payment_instrument_id' => 1, |
679 | 'non_deductible_amount' => 10.00, | |
680 | 'fee_amount' => 50.00, | |
681 | 'net_amount' => 90.00, | |
682 | 'trxn_id' => 12345, | |
683 | 'invoice_id' => 67890, | |
684 | 'source' => 'SSF', | |
685 | 'contribution_status_id' => 1, | |
6a488035 TO |
686 | 'contribution_note' => 'my contribution note', |
687 | ); | |
688 | ||
4ab7d517 | 689 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
5896d037 | 690 | $result = $this->callAPISuccess('note', 'get', array( |
92915c55 TO |
691 | 'entity_table' => 'civicrm_contribution', |
692 | 'entity_id' => $contribution['id'], | |
693 | 'sequential' => 1, | |
694 | )); | |
6a488035 | 695 | $this->assertEquals('my contribution note', $result['values'][0]['note']); |
4ab7d517 | 696 | $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); |
6a488035 | 697 | } |
c490a46a CW |
698 | |
699 | /** | |
55d2c6f1 | 700 | * This is the test for creating soft credits. |
c490a46a | 701 | */ |
55d2c6f1 | 702 | public function testCreateContributionWithSoftCredit() { |
5c49fee0 | 703 | $description = "Demonstrates creating contribution with SoftCredit."; |
5896d037 TO |
704 | $subfile = "ContributionCreateWithSoftCredit"; |
705 | $contact2 = $this->callAPISuccess('Contact', 'create', array( | |
92915c55 TO |
706 | 'display_name' => 'superman', |
707 | 'contact_type' => 'Individual', | |
708 | )); | |
55d2c6f1 | 709 | $softParams = array( |
bcc03b98 | 710 | 'contact_id' => $contact2['id'], |
711 | 'amount' => 50, | |
21dfd5f5 | 712 | 'soft_credit_type_id' => 3, |
6a488035 TO |
713 | ); |
714 | ||
55d2c6f1 | 715 | $params = $this->_params + array('soft_credit' => array(1 => $softParams)); |
4ab7d517 | 716 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6c6e6187 | 717 | $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); |
a1c68fd2 | 718 | |
55d2c6f1 EM |
719 | $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']); |
720 | $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']); | |
721 | $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']); | |
6a516bd6 DG |
722 | |
723 | $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); | |
724 | $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); | |
725 | } | |
726 | ||
00be9182 | 727 | public function testCreateContributionWithSoftCreditDefaults() { |
5c49fee0 | 728 | $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type."; |
5896d037 TO |
729 | $subfile = "ContributionCreateWithSoftCreditDefaults"; |
730 | $contact2 = $this->callAPISuccess('Contact', 'create', array( | |
92915c55 TO |
731 | 'display_name' => 'superman', |
732 | 'contact_type' => 'Individual', | |
733 | )); | |
6a516bd6 | 734 | $params = $this->_params + array( |
442cf836 EM |
735 | 'soft_credit_to' => $contact2['id'], |
736 | ); | |
6a516bd6 | 737 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6c6e6187 | 738 | $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); |
6a516bd6 DG |
739 | |
740 | $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']); | |
741 | // Default soft credit amount = contribution.total_amount | |
742 | $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']); | |
743 | $this->assertEquals(CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']); | |
744 | ||
745 | $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); | |
746 | $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); | |
747 | } | |
748 | ||
00be9182 | 749 | public function testCreateContributionWithHonoreeContact() { |
5c49fee0 | 750 | $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id."; |
5896d037 TO |
751 | $subfile = "ContributionCreateWithHonoreeContact"; |
752 | $contact2 = $this->callAPISuccess('Contact', 'create', array( | |
92915c55 TO |
753 | 'display_name' => 'superman', |
754 | 'contact_type' => 'Individual', | |
755 | )); | |
6a516bd6 | 756 | $params = $this->_params + array( |
442cf836 EM |
757 | 'honor_contact_id' => $contact2['id'], |
758 | ); | |
6a516bd6 | 759 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6c6e6187 | 760 | $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); |
6a516bd6 DG |
761 | |
762 | $this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']); | |
763 | // Default soft credit amount = contribution.total_amount | |
764 | // Legacy mode in create api (honor_contact_id param) uses the standard "In Honor of" soft credit type | |
765 | $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']); | |
766 | $this->assertEquals(CRM_Core_OptionGroup::getValue('soft_credit_type', 'in_honor_of', 'name'), $result['values'][0]['soft_credit'][1]['soft_credit_type']); | |
6a488035 | 767 | |
4ab7d517 | 768 | $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); |
769 | $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); | |
6a488035 TO |
770 | } |
771 | ||
772 | /** | |
92c99a4a | 773 | * Test using example code. |
6a488035 | 774 | */ |
00be9182 | 775 | public function testContributionCreateExample() { |
6a488035 | 776 | //make sure at least on page exists since there is a truncate in tear down |
8be629ac | 777 | $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); |
3ec6e38d | 778 | require_once 'api/v3/examples/Contribution/Create.php'; |
5896d037 | 779 | $result = contribution_create_example(); |
006d6361 | 780 | $id = $result['id']; |
6a488035 | 781 | $expectedResult = contribution_create_expectedresult(); |
8e342a79 | 782 | $this->checkArrayEquals($expectedResult, $result); |
006d6361 | 783 | $this->contributionDelete($id); |
6a488035 TO |
784 | } |
785 | ||
a1a2a83d | 786 | /** |
f55c5fa8 | 787 | * Function tests that additional financial records are created when fee amount is recorded. |
6a488035 | 788 | */ |
00be9182 | 789 | public function testCreateContributionWithFee() { |
6a488035 TO |
790 | $params = array( |
791 | 'contact_id' => $this->_individualId, | |
792 | 'receive_date' => '20120511', | |
793 | 'total_amount' => 100.00, | |
794 | 'fee_amount' => 50, | |
795 | 'financial_type_id' => 1, | |
796 | 'trxn_id' => 12345, | |
797 | 'invoice_id' => 67890, | |
798 | 'source' => 'SSF', | |
799 | 'contribution_status_id' => 1, | |
6a488035 TO |
800 | ); |
801 | ||
4ab7d517 | 802 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); |
2bfae985 EM |
803 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
804 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); | |
e0e3c51b EM |
805 | $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 50.00); |
806 | $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 50.00); | |
5896d037 | 807 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
808 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); |
809 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
810 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
811 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); | |
e0e3c51b | 812 | |
6c6e6187 | 813 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
4ab7d517 | 814 | |
6a488035 TO |
815 | 'entity_id' => $contribution['id'], |
816 | 'entity_table' => 'civicrm_contribution', | |
817 | 'sequential' => 1, | |
5896d037 | 818 | )); |
6a488035 TO |
819 | $this->assertEquals(1, $lineItems['count']); |
820 | $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); | |
4ede4532 | 821 | $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); |
6c6e6187 | 822 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
4ab7d517 | 823 | |
5896d037 TO |
824 | 'entity_id' => $contribution['id'], |
825 | 'contribution_id' => $contribution['id'], | |
826 | 'entity_table' => 'civicrm_contribution', | |
827 | 'sequential' => 1, | |
6a488035 TO |
828 | )); |
829 | $this->assertEquals(1, $lineItems['count']); | |
830 | $this->_checkFinancialRecords($contribution, 'feeAmount'); | |
831 | } | |
832 | ||
833 | ||
f70a6752 | 834 | /** |
442cf836 | 835 | * Function tests that additional financial records are created when online contribution is created. |
6a488035 | 836 | */ |
00be9182 | 837 | public function testCreateContributionOnline() { |
858d0bf8 | 838 | CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); |
5896d037 | 839 | $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); |
fc928539 | 840 | $this->assertAPISuccess($contributionPage); |
6a488035 TO |
841 | $params = array( |
842 | 'contact_id' => $this->_individualId, | |
843 | 'receive_date' => '20120511', | |
844 | 'total_amount' => 100.00, | |
845 | 'financial_type_id' => 1, | |
846 | 'contribution_page_id' => $contributionPage['id'], | |
847 | 'payment_processor' => 1, | |
848 | 'trxn_id' => 12345, | |
849 | 'invoice_id' => 67890, | |
850 | 'source' => 'SSF', | |
851 | 'contribution_status_id' => 1, | |
4ab7d517 | 852 | |
6a488035 TO |
853 | ); |
854 | ||
4ab7d517 | 855 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); |
2bfae985 EM |
856 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
857 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); | |
5896d037 | 858 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
859 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); |
860 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
861 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
862 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); | |
6a488035 TO |
863 | $this->_checkFinancialRecords($contribution, 'online'); |
864 | } | |
865 | ||
f70a6752 | 866 | /** |
442cf836 EM |
867 | * Check handling of financial type. |
868 | * | |
100fef9d | 869 | * In the interests of removing financial type / contribution type checks from |
f70a6752 | 870 | * legacy format function lets test that the api is doing this for us |
871 | */ | |
00be9182 | 872 | public function testCreateInvalidFinancialType() { |
f70a6752 | 873 | $params = $this->_params; |
874 | $params['financial_type_id'] = 99999; | |
858d0bf8 | 875 | $this->callAPIFailure($this->_entity, 'create', $params, "'99999' is not a valid option for field financial_type_id"); |
f70a6752 | 876 | } |
877 | ||
4302618d | 878 | /** |
442cf836 EM |
879 | * Check handling of financial type. |
880 | * | |
100fef9d | 881 | * In the interests of removing financial type / contribution type checks from |
4302618d | 882 | * legacy format function lets test that the api is doing this for us |
883 | */ | |
00be9182 | 884 | public function testValidNamedFinancialType() { |
4302618d | 885 | $params = $this->_params; |
886 | $params['financial_type_id'] = 'Donation'; | |
858d0bf8 | 887 | $this->callAPISuccess($this->_entity, 'create', $params); |
4302618d | 888 | } |
889 | ||
f70a6752 | 890 | /** |
92c99a4a EM |
891 | * Tests that additional financial records are created. |
892 | * | |
893 | * Checks when online contribution with pay later option is created | |
6a488035 | 894 | */ |
00be9182 | 895 | public function testCreateContributionPayLaterOnline() { |
858d0bf8 | 896 | CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); |
6a488035 | 897 | $this->_pageParams['is_pay_later'] = 1; |
5896d037 | 898 | $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); |
fc928539 | 899 | $this->assertAPISuccess($contributionPage); |
6a488035 TO |
900 | $params = array( |
901 | 'contact_id' => $this->_individualId, | |
902 | 'receive_date' => '20120511', | |
903 | 'total_amount' => 100.00, | |
904 | 'financial_type_id' => 1, | |
905 | 'contribution_page_id' => $contributionPage['id'], | |
906 | 'trxn_id' => 12345, | |
907 | 'is_pay_later' => 1, | |
908 | 'invoice_id' => 67890, | |
909 | 'source' => 'SSF', | |
910 | 'contribution_status_id' => 2, | |
4ab7d517 | 911 | |
6a488035 TO |
912 | ); |
913 | ||
4ab7d517 | 914 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); |
2bfae985 EM |
915 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
916 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); | |
5896d037 | 917 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
918 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); |
919 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
920 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
921 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2); | |
6a488035 TO |
922 | $this->_checkFinancialRecords($contribution, 'payLater'); |
923 | } | |
924 | ||
a1a2a83d | 925 | /** |
1e52837d | 926 | * Function tests that additional financial records are created for online contribution with pending option. |
6a488035 | 927 | */ |
00be9182 | 928 | public function testCreateContributionPendingOnline() { |
6a488035 | 929 | $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); |
5896d037 | 930 | $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); |
fc928539 | 931 | $this->assertAPISuccess($contributionPage); |
6a488035 TO |
932 | $params = array( |
933 | 'contact_id' => $this->_individualId, | |
934 | 'receive_date' => '20120511', | |
935 | 'total_amount' => 100.00, | |
936 | 'financial_type_id' => 1, | |
937 | 'contribution_page_id' => $contributionPage['id'], | |
938 | 'trxn_id' => 12345, | |
939 | 'invoice_id' => 67890, | |
940 | 'source' => 'SSF', | |
941 | 'contribution_status_id' => 2, | |
6a488035 TO |
942 | ); |
943 | ||
4ab7d517 | 944 | $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); |
2bfae985 EM |
945 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
946 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); | |
5896d037 | 947 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); |
2bfae985 EM |
948 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); |
949 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
950 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); | |
951 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2); | |
6a488035 TO |
952 | $this->_checkFinancialRecords($contribution, 'pending'); |
953 | } | |
954 | ||
e748bf60 | 955 | /** |
92c99a4a | 956 | * Test that BAO defaults work. |
e748bf60 | 957 | */ |
00be9182 | 958 | public function testCreateBAODefaults() { |
e748bf60 EM |
959 | unset($this->_params['contribution_source_id'], $this->_params['payment_instrument_id']); |
960 | $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); | |
5896d037 | 961 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
962 | 'id' => $contribution['id'], |
963 | 'api.contribution.delete' => 1, | |
964 | )); | |
e748bf60 | 965 | $this->assertEquals(1, $contribution['contribution_status_id']); |
12879069 | 966 | $this->assertEquals('Check', $contribution['payment_instrument']); |
e748bf60 EM |
967 | } |
968 | ||
a1a2a83d | 969 | /** |
1e52837d | 970 | * Function tests that line items, financial records are updated when contribution amount is changed. |
6a488035 | 971 | */ |
00be9182 | 972 | public function testCreateUpdateContributionChangeTotal() { |
4ab7d517 | 973 | $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); |
6c6e6187 | 974 | $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( |
4ab7d517 | 975 | |
6a488035 TO |
976 | 'entity_id' => $contribution['id'], |
977 | 'entity_table' => 'civicrm_contribution', | |
978 | 'sequential' => 1, | |
979 | 'return' => 'line_total', | |
980 | )); | |
981 | $this->assertEquals('100.00', $lineItems); | |
982 | $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); | |
983 | // Financial trxn SUM = 100 + 5 (fee) | |
984 | $this->assertEquals('105.00', $trxnAmount); | |
985 | $newParams = array( | |
4ab7d517 | 986 | |
6a488035 | 987 | 'id' => $contribution['id'], |
21dfd5f5 | 988 | 'total_amount' => '125', |
5896d037 | 989 | ); |
694769da | 990 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
4ab7d517 | 991 | |
6c6e6187 | 992 | $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( |
6a488035 | 993 | |
5896d037 TO |
994 | 'entity_id' => $contribution['id'], |
995 | 'entity_table' => 'civicrm_contribution', | |
996 | 'sequential' => 1, | |
997 | 'return' => 'line_total', | |
6a488035 TO |
998 | )); |
999 | ||
1000 | $this->assertEquals('125.00', $lineItems); | |
1001 | $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); | |
28de42d1 EM |
1002 | |
1003 | // Financial trxn SUM = 125 + 5 (fee). | |
6a488035 | 1004 | $this->assertEquals('130.00', $trxnAmount); |
28de42d1 | 1005 | $this->assertEquals('125.00', $this->_getFinancialItemAmount($contribution['id'])); |
6a488035 TO |
1006 | } |
1007 | ||
a1a2a83d | 1008 | /** |
1e52837d | 1009 | * Function tests that line items, financial records are updated when pay later contribution is received. |
6a488035 | 1010 | */ |
00be9182 | 1011 | public function testCreateUpdateContributionPayLater() { |
6a488035 TO |
1012 | $contribParams = array( |
1013 | 'contact_id' => $this->_individualId, | |
1014 | 'receive_date' => '2012-01-01', | |
1015 | 'total_amount' => 100.00, | |
4ab7d517 | 1016 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 | 1017 | 'payment_instrument_id' => 1, |
8f39a111 | 1018 | 'contribution_status_id' => 2, |
1019 | 'is_pay_later' => 1, | |
4ab7d517 | 1020 | |
6a488035 | 1021 | ); |
4ab7d517 | 1022 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); |
6a488035 TO |
1023 | |
1024 | $newParams = array_merge($contribParams, array( | |
5896d037 TO |
1025 | 'id' => $contribution['id'], |
1026 | 'contribution_status_id' => 1, | |
1027 | ) | |
c71ae314 | 1028 | ); |
694769da | 1029 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
6a488035 | 1030 | $contribution = $contribution['values'][$contribution['id']]; |
6c6e6187 | 1031 | $this->assertEquals($contribution['contribution_status_id'], '1'); |
6a488035 TO |
1032 | $this->_checkFinancialItem($contribution['id'], 'paylater'); |
1033 | $this->_checkFinancialTrxn($contribution, 'payLater'); | |
1034 | } | |
1035 | ||
a1a2a83d | 1036 | /** |
eceb18cc | 1037 | * Function tests that financial records are updated when Payment Instrument is changed. |
6a488035 | 1038 | */ |
00be9182 | 1039 | public function testCreateUpdateContributionPaymentInstrument() { |
6a488035 TO |
1040 | $instrumentId = $this->_addPaymentInstrument(); |
1041 | $contribParams = array( | |
1042 | 'contact_id' => $this->_individualId, | |
1043 | 'total_amount' => 100.00, | |
4ab7d517 | 1044 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1045 | 'payment_instrument_id' => 4, |
1046 | 'contribution_status_id' => 1, | |
4ab7d517 | 1047 | |
6a488035 | 1048 | ); |
4ab7d517 | 1049 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); |
6a488035 TO |
1050 | |
1051 | $newParams = array_merge($contribParams, array( | |
5896d037 TO |
1052 | 'id' => $contribution['id'], |
1053 | 'payment_instrument_id' => $instrumentId, | |
1054 | ) | |
6a488035 | 1055 | ); |
694769da | 1056 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
fc928539 | 1057 | $this->assertAPISuccess($contribution); |
4ecc6d4b | 1058 | $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId); |
6a488035 TO |
1059 | } |
1060 | ||
122250ec SL |
1061 | /** |
1062 | * Function tests that financial records are updated when Payment Instrument is changed when amount is negative. | |
1063 | */ | |
1064 | public function testCreateUpdateNegativeContributionPaymentInstrument() { | |
1065 | $instrumentId = $this->_addPaymentInstrument(); | |
1066 | $contribParams = array( | |
1067 | 'contact_id' => $this->_individualId, | |
1068 | 'total_amount' => -100.00, | |
1069 | 'financial_type_id' => $this->_financialTypeId, | |
1070 | 'payment_instrument_id' => 4, | |
1071 | 'contribution_status_id' => 1, | |
1072 | ||
1073 | ); | |
1074 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); | |
1075 | ||
1076 | $newParams = array_merge($contribParams, array( | |
1077 | 'id' => $contribution['id'], | |
1078 | 'payment_instrument_id' => $instrumentId, | |
1079 | ) | |
1080 | ); | |
1081 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); | |
1082 | $this->assertAPISuccess($contribution); | |
1083 | $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId, array('total_amount' => '-100.00')); | |
1084 | } | |
1085 | ||
a1a2a83d | 1086 | /** |
eceb18cc | 1087 | * Function tests that financial records are added when Contribution is Refunded. |
6a488035 | 1088 | */ |
00be9182 | 1089 | public function testCreateUpdateContributionRefund() { |
797d4c52 | 1090 | $contributionParams = array( |
6a488035 TO |
1091 | 'contact_id' => $this->_individualId, |
1092 | 'receive_date' => '2012-01-01', | |
1093 | 'total_amount' => 100.00, | |
4ab7d517 | 1094 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1095 | 'payment_instrument_id' => 4, |
1096 | 'contribution_status_id' => 1, | |
797d4c52 | 1097 | 'trxn_id' => 'original_payment', |
1098 | ); | |
1099 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); | |
1100 | $newParams = array_merge($contributionParams, array( | |
1101 | 'id' => $contribution['id'], | |
1102 | 'contribution_status_id' => 'Refunded', | |
1103 | 'cancel_date' => '2015-01-01 09:00', | |
1104 | 'refund_trxn_id' => 'the refund', | |
1105 | ) | |
1106 | ); | |
1107 | ||
1108 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); | |
1109 | $this->_checkFinancialTrxn($contribution, 'refund'); | |
1110 | $this->_checkFinancialItem($contribution['id'], 'refund'); | |
1111 | $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', array( | |
1112 | 'id' => $contribution['id'], | |
1113 | 'return' => 'trxn_id', | |
1114 | ))); | |
1115 | } | |
4ab7d517 | 1116 | |
52da5b1e | 1117 | /** |
1118 | * Refund a contribution for a financial type with a contra account. | |
1119 | * | |
1120 | * CRM-17951 the contra account is a financial account with a relationship to a | |
1121 | * financial type. It is not always configured but should be reflected | |
1122 | * in the financial_trxn & financial_item table if it is. | |
1123 | */ | |
1124 | public function testCreateUpdateChargebackContributionDefaultAccount() { | |
1125 | $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); | |
1126 | $this->callAPISuccess('Contribution', 'create', array( | |
1127 | 'id' => $contribution['id'], | |
1128 | 'contribution_status_id' => 'Chargeback', | |
1129 | )); | |
1130 | $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback')); | |
1131 | ||
1132 | $lineItems = $this->callAPISuccessGetSingle('LineItem', array( | |
1133 | 'contribution_id' => $contribution['id'], | |
1134 | 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), | |
1135 | )); | |
1136 | $this->assertEquals(1, $lineItems['api.FinancialItem.getsingle']['financial_account_id']); | |
1137 | $this->callAPISuccessGetSingle('FinancialTrxn', array( | |
1138 | 'total_amount' => -100, | |
1139 | 'status_id' => 'Chargeback', | |
1140 | 'to_financial_account_id' => 6, | |
1141 | )); | |
1142 | } | |
1143 | ||
1144 | /** | |
1145 | * Refund a contribution for a financial type with a contra account. | |
1146 | * | |
1147 | * CRM-17951 the contra account is a financial account with a relationship to a | |
1148 | * financial type. It is not always configured but should be reflected | |
1149 | * in the financial_trxn & financial_item table if it is. | |
1150 | */ | |
1151 | public function testCreateUpdateChargebackContributionCustomAccount() { | |
1152 | $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array( | |
1153 | 'name' => 'Chargeback Account', | |
1154 | 'is_active' => TRUE, | |
1155 | )); | |
1156 | ||
1157 | $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array( | |
1158 | 'entity_id' => $this->_financialTypeId, | |
1159 | 'entity_table' => 'civicrm_financial_type', | |
1160 | 'account_relationship' => 'Chargeback Account is', | |
1161 | 'financial_account_id' => 'Chargeback Account', | |
1162 | )); | |
1163 | ||
1164 | $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); | |
1165 | $this->callAPISuccess('Contribution', 'create', array( | |
1166 | 'id' => $contribution['id'], | |
1167 | 'contribution_status_id' => 'Chargeback', | |
1168 | )); | |
1169 | $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback')); | |
1170 | ||
1171 | $lineItems = $this->callAPISuccessGetSingle('LineItem', array( | |
1172 | 'contribution_id' => $contribution['id'], | |
1173 | 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), | |
1174 | )); | |
1175 | $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']); | |
1176 | ||
1177 | $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); | |
1178 | $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id'])); | |
1179 | $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id'])); | |
1180 | } | |
1181 | ||
bf2cf926 | 1182 | /** |
1183 | * Refund a contribution for a financial type with a contra account. | |
1184 | * | |
1185 | * CRM-17951 the contra account is a financial account with a relationship to a | |
1186 | * financial type. It is not always configured but should be reflected | |
1187 | * in the financial_trxn & financial_item table if it is. | |
1188 | */ | |
1189 | public function testCreateUpdateRefundContributionConfiguredContraAccount() { | |
1190 | $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array( | |
1191 | 'name' => 'Refund Account', | |
1192 | 'is_active' => TRUE, | |
1193 | )); | |
1194 | ||
1195 | $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array( | |
1196 | 'entity_id' => $this->_financialTypeId, | |
1197 | 'entity_table' => 'civicrm_financial_type', | |
1198 | 'account_relationship' => 'Credit/Contra Revenue Account is', | |
1199 | 'financial_account_id' => 'Refund Account', | |
1200 | )); | |
1201 | ||
1202 | $contribution = $this->callAPISuccess('Contribution', 'create', $this->_params); | |
1203 | $this->callAPISuccess('Contribution', 'create', array( | |
1204 | 'id' => $contribution['id'], | |
1205 | 'contribution_status_id' => 'Refunded', | |
1206 | )); | |
1207 | ||
52da5b1e | 1208 | $lineItems = $this->callAPISuccessGetSingle('LineItem', array( |
bf2cf926 | 1209 | 'contribution_id' => $contribution['id'], |
1210 | 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)), | |
1211 | )); | |
1212 | $this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']); | |
1213 | ||
1214 | $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); | |
1215 | $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id'])); | |
1216 | $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id'])); | |
bf2cf926 | 1217 | } |
1218 | ||
797d4c52 | 1219 | /** |
1220 | * Function tests that trxn_id is set when passed in. | |
1221 | * | |
1222 | * Here we ensure that the civicrm_financial_trxn.trxn_id & the civicrm_contribution.trxn_id are set | |
1223 | * when trxn_id is passed in. | |
1224 | */ | |
1225 | public function testCreateUpdateContributionRefundTrxnIDPassedIn() { | |
1226 | $contributionParams = array( | |
1227 | 'contact_id' => $this->_individualId, | |
1228 | 'receive_date' => '2012-01-01', | |
1229 | 'total_amount' => 100.00, | |
1230 | 'financial_type_id' => $this->_financialTypeId, | |
1231 | 'payment_instrument_id' => 4, | |
1232 | 'contribution_status_id' => 1, | |
1233 | 'trxn_id' => 'original_payment', | |
6a488035 | 1234 | ); |
797d4c52 | 1235 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); |
1236 | $newParams = array_merge($contributionParams, array( | |
1237 | 'id' => $contribution['id'], | |
1238 | 'contribution_status_id' => 'Refunded', | |
1239 | 'cancel_date' => '2015-01-01 09:00', | |
1240 | 'trxn_id' => 'the refund', | |
1241 | ) | |
1242 | ); | |
1243 | ||
1244 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); | |
1245 | $this->_checkFinancialTrxn($contribution, 'refund'); | |
1246 | $this->_checkFinancialItem($contribution['id'], 'refund'); | |
1247 | $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', array( | |
1248 | 'id' => $contribution['id'], | |
1249 | 'return' => 'trxn_id', | |
1250 | ))); | |
1251 | } | |
1252 | ||
1253 | /** | |
1254 | * Function tests that trxn_id is set when passed in. | |
1255 | * | |
1256 | * Here we ensure that the civicrm_contribution.trxn_id is set | |
1257 | * when trxn_id is passed in but if refund_trxn_id is different then that | |
1258 | * is kept for the refund transaction. | |
1259 | */ | |
1260 | public function testCreateUpdateContributionRefundRefundAndTrxnIDPassedIn() { | |
1261 | $contributionParams = array( | |
1262 | 'contact_id' => $this->_individualId, | |
1263 | 'receive_date' => '2012-01-01', | |
1264 | 'total_amount' => 100.00, | |
1265 | 'financial_type_id' => $this->_financialTypeId, | |
1266 | 'payment_instrument_id' => 4, | |
1267 | 'contribution_status_id' => 1, | |
1268 | 'trxn_id' => 'original_payment', | |
1269 | ); | |
1270 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); | |
1271 | $newParams = array_merge($contributionParams, array( | |
5896d037 | 1272 | 'id' => $contribution['id'], |
b7990bb6 | 1273 | 'contribution_status_id' => 'Refunded', |
1274 | 'cancel_date' => '2015-01-01 09:00', | |
797d4c52 | 1275 | 'trxn_id' => 'cont id', |
1276 | 'refund_trxn_id' => 'the refund', | |
6a488035 TO |
1277 | ) |
1278 | ); | |
1279 | ||
694769da | 1280 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
6a488035 TO |
1281 | $this->_checkFinancialTrxn($contribution, 'refund'); |
1282 | $this->_checkFinancialItem($contribution['id'], 'refund'); | |
797d4c52 | 1283 | $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array( |
1284 | 'id' => $contribution['id'], | |
1285 | 'return' => 'trxn_id', | |
1286 | ))); | |
1287 | } | |
1288 | ||
1289 | /** | |
1290 | * Function tests that refund_trxn_id is set when passed in empty. | |
1291 | * | |
1292 | * Here we ensure that the civicrm_contribution.trxn_id is set | |
1293 | * when trxn_id is passed in but if refund_trxn_id isset but empty then that | |
1294 | * is kept for the refund transaction. | |
1295 | */ | |
1296 | public function testCreateUpdateContributionRefundRefundNullTrxnIDPassedIn() { | |
1297 | $contributionParams = array( | |
1298 | 'contact_id' => $this->_individualId, | |
1299 | 'receive_date' => '2012-01-01', | |
1300 | 'total_amount' => 100.00, | |
1301 | 'financial_type_id' => $this->_financialTypeId, | |
1302 | 'payment_instrument_id' => 4, | |
1303 | 'contribution_status_id' => 1, | |
1304 | 'trxn_id' => 'original_payment', | |
1305 | ); | |
1306 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); | |
1307 | $newParams = array_merge($contributionParams, array( | |
1308 | 'id' => $contribution['id'], | |
1309 | 'contribution_status_id' => 'Refunded', | |
1310 | 'cancel_date' => '2015-01-01 09:00', | |
1311 | 'trxn_id' => 'cont id', | |
1312 | 'refund_trxn_id' => '', | |
1313 | ) | |
1314 | ); | |
1315 | ||
1316 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); | |
1317 | $this->_checkFinancialTrxn($contribution, 'refund', NULL, array('trxn_id' => NULL)); | |
1318 | $this->_checkFinancialItem($contribution['id'], 'refund'); | |
1319 | $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array( | |
1320 | 'id' => $contribution['id'], | |
1321 | 'return' => 'trxn_id', | |
1322 | ))); | |
8f39a111 | 1323 | } |
c71ae314 | 1324 | |
a1a2a83d | 1325 | /** |
eceb18cc | 1326 | * Function tests invalid contribution status change. |
c71ae314 | 1327 | */ |
00be9182 | 1328 | public function testCreateUpdateContributionInValidStatusChange() { |
c71ae314 PN |
1329 | $contribParams = array( |
1330 | 'contact_id' => 1, | |
1331 | 'receive_date' => '2012-01-01', | |
1332 | 'total_amount' => 100.00, | |
1333 | 'financial_type_id' => 1, | |
1334 | 'payment_instrument_id' => 1, | |
1335 | 'contribution_status_id' => 1, | |
c71ae314 | 1336 | ); |
4ab7d517 | 1337 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); |
c71ae314 | 1338 | $newParams = array_merge($contribParams, array( |
5896d037 TO |
1339 | 'id' => $contribution['id'], |
1340 | 'contribution_status_id' => 2, | |
c71ae314 PN |
1341 | ) |
1342 | ); | |
6c6e6187 | 1343 | $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.')); |
c71ae314 | 1344 | |
6a488035 TO |
1345 | } |
1346 | ||
a1a2a83d | 1347 | /** |
eceb18cc | 1348 | * Function tests that financial records are added when Pending Contribution is Canceled. |
6a488035 | 1349 | */ |
00be9182 | 1350 | public function testCreateUpdateContributionCancelPending() { |
6a488035 TO |
1351 | $contribParams = array( |
1352 | 'contact_id' => $this->_individualId, | |
1353 | 'receive_date' => '2012-01-01', | |
1354 | 'total_amount' => 100.00, | |
4ab7d517 | 1355 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1356 | 'payment_instrument_id' => 1, |
1357 | 'contribution_status_id' => 2, | |
c71ae314 | 1358 | 'is_pay_later' => 1, |
4ab7d517 | 1359 | |
6a488035 | 1360 | ); |
4ab7d517 | 1361 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); |
6a488035 | 1362 | $newParams = array_merge($contribParams, array( |
5896d037 TO |
1363 | 'id' => $contribution['id'], |
1364 | 'contribution_status_id' => 3, | |
6a488035 TO |
1365 | ) |
1366 | ); | |
694769da | 1367 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
6a488035 TO |
1368 | $this->_checkFinancialTrxn($contribution, 'cancelPending'); |
1369 | $this->_checkFinancialItem($contribution['id'], 'cancelPending'); | |
1370 | } | |
1371 | ||
a1a2a83d | 1372 | /** |
eceb18cc | 1373 | * Function tests that financial records are added when Financial Type is Changed. |
6a488035 | 1374 | */ |
00be9182 | 1375 | public function testCreateUpdateContributionChangeFinancialType() { |
6a488035 TO |
1376 | $contribParams = array( |
1377 | 'contact_id' => $this->_individualId, | |
1378 | 'receive_date' => '2012-01-01', | |
1379 | 'total_amount' => 100.00, | |
1380 | 'financial_type_id' => 1, | |
1381 | 'payment_instrument_id' => 1, | |
1382 | 'contribution_status_id' => 1, | |
4ab7d517 | 1383 | |
6a488035 | 1384 | ); |
4ab7d517 | 1385 | $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); |
6a488035 | 1386 | $newParams = array_merge($contribParams, array( |
5896d037 TO |
1387 | 'id' => $contribution['id'], |
1388 | 'financial_type_id' => 3, | |
6a488035 TO |
1389 | ) |
1390 | ); | |
694769da | 1391 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
6a488035 TO |
1392 | $this->_checkFinancialTrxn($contribution, 'changeFinancial'); |
1393 | $this->_checkFinancialItem($contribution['id'], 'changeFinancial'); | |
1394 | } | |
1395 | ||
694769da | 1396 | /** |
1e52837d | 1397 | * Test that update does not change status id CRM-15105. |
694769da | 1398 | */ |
00be9182 | 1399 | public function testCreateUpdateWithoutChangingPendingStatus() { |
694769da VU |
1400 | $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2))); |
1401 | $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source')); | |
5896d037 | 1402 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
1403 | 'id' => $contribution['id'], |
1404 | 'api.contribution.delete' => 1, | |
1405 | )); | |
694769da VU |
1406 | $this->assertEquals(2, $contribution['contribution_status_id']); |
1407 | } | |
a1a2a83d TO |
1408 | |
1409 | /** | |
28de42d1 EM |
1410 | * Test Updating a Contribution. |
1411 | * | |
a1a2a83d TO |
1412 | * CHANGE: we require the API to do an incremental update |
1413 | */ | |
00be9182 | 1414 | public function testCreateUpdateContribution() { |
6a488035 | 1415 | |
78ab0ca4 | 1416 | $contributionID = $this->contributionCreate(array( |
1417 | 'contact_id' => $this->_individualId, | |
1418 | 'trxn_id' => 212355, | |
1419 | 'financial_type_id' => $this->_financialTypeId, | |
1420 | 'invoice_id' => 'old_invoice', | |
1421 | )); | |
6a488035 TO |
1422 | $old_params = array( |
1423 | 'contribution_id' => $contributionID, | |
6a488035 | 1424 | ); |
4ab7d517 | 1425 | $original = $this->callAPISuccess('contribution', 'get', $old_params); |
2bfae985 | 1426 | $this->assertEquals($original['id'], $contributionID); |
6a488035 TO |
1427 | //set up list of old params, verify |
1428 | ||
1429 | //This should not be required on update: | |
1430 | $old_contact_id = $original['values'][$contributionID]['contact_id']; | |
7d543448 | 1431 | $old_payment_instrument = $original['values'][$contributionID]['instrument_id']; |
6a488035 TO |
1432 | $old_fee_amount = $original['values'][$contributionID]['fee_amount']; |
1433 | $old_source = $original['values'][$contributionID]['contribution_source']; | |
1434 | ||
6a488035 TO |
1435 | $old_trxn_id = $original['values'][$contributionID]['trxn_id']; |
1436 | $old_invoice_id = $original['values'][$contributionID]['invoice_id']; | |
1437 | ||
1438 | //check against values in CiviUnitTestCase::createContribution() | |
2bfae985 EM |
1439 | $this->assertEquals($old_contact_id, $this->_individualId); |
1440 | $this->assertEquals($old_fee_amount, 5.00); | |
1441 | $this->assertEquals($old_source, 'SSF'); | |
1442 | $this->assertEquals($old_trxn_id, 212355); | |
78ab0ca4 | 1443 | $this->assertEquals($old_invoice_id, 'old_invoice'); |
6a488035 TO |
1444 | $params = array( |
1445 | 'id' => $contributionID, | |
1446 | 'contact_id' => $this->_individualId, | |
1447 | 'total_amount' => 110.00, | |
4ab7d517 | 1448 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1449 | 'non_deductible_amount' => 10.00, |
1450 | 'net_amount' => 100.00, | |
1451 | 'contribution_status_id' => 1, | |
1452 | 'note' => 'Donating for Nobel Cause', | |
4ab7d517 | 1453 | |
6a488035 TO |
1454 | ); |
1455 | ||
4ab7d517 | 1456 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
6a488035 TO |
1457 | |
1458 | $new_params = array( | |
1459 | 'contribution_id' => $contribution['id'], | |
4ab7d517 | 1460 | |
6a488035 | 1461 | ); |
4ab7d517 | 1462 | $contribution = $this->callAPISuccess('contribution', 'get', $new_params); |
6a488035 | 1463 | |
2bfae985 EM |
1464 | $this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId); |
1465 | $this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00); | |
ff977830 | 1466 | $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId); |
7d543448 | 1467 | $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument); |
2bfae985 EM |
1468 | $this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00); |
1469 | $this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount); | |
1470 | $this->assertEquals($contribution['values'][$contributionID]['net_amount'], 100.00); | |
1471 | $this->assertEquals($contribution['values'][$contributionID]['trxn_id'], $old_trxn_id); | |
1472 | $this->assertEquals($contribution['values'][$contributionID]['invoice_id'], $old_invoice_id); | |
1473 | $this->assertEquals($contribution['values'][$contributionID]['contribution_source'], $old_source); | |
1474 | $this->assertEquals($contribution['values'][$contributionID]['contribution_status'], 'Completed'); | |
6a488035 TO |
1475 | $params = array( |
1476 | 'contribution_id' => $contributionID, | |
4ab7d517 | 1477 | |
6a488035 | 1478 | ); |
4ab7d517 | 1479 | $result = $this->callAPISuccess('contribution', 'delete', $params); |
22f80e87 | 1480 | $this->assertAPISuccess($result); |
6a488035 TO |
1481 | } |
1482 | ||
1483 | ///////////////// civicrm_contribution_delete methods | |
a1a2a83d TO |
1484 | |
1485 | /** | |
1486 | * Attempt (but fail) to delete a contribution without parameters. | |
1487 | */ | |
00be9182 | 1488 | public function testDeleteEmptyParamsContribution() { |
4ab7d517 | 1489 | $params = array(); |
858d0bf8 | 1490 | $this->callAPIFailure('contribution', 'delete', $params); |
6a488035 TO |
1491 | } |
1492 | ||
00be9182 | 1493 | public function testDeleteParamsNotArrayContribution() { |
6a488035 | 1494 | $params = 'contribution_id= 1'; |
d0e1eff2 | 1495 | $contribution = $this->callAPIFailure('contribution', 'delete', $params); |
6a488035 TO |
1496 | $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array'); |
1497 | } | |
1498 | ||
00be9182 | 1499 | public function testDeleteWrongParamContribution() { |
6a488035 TO |
1500 | $params = array( |
1501 | 'contribution_source' => 'SSF', | |
4ab7d517 | 1502 | |
6a488035 | 1503 | ); |
858d0bf8 | 1504 | $this->callAPIFailure('contribution', 'delete', $params); |
6a488035 TO |
1505 | } |
1506 | ||
00be9182 | 1507 | public function testDeleteContribution() { |
78ab0ca4 | 1508 | $contributionID = $this->contributionCreate(array( |
1509 | 'contact_id' => $this->_individualId, | |
1510 | 'financial_type_id' => $this->_financialTypeId, | |
1511 | )); | |
6a488035 TO |
1512 | $params = array( |
1513 | 'id' => $contributionID, | |
6a488035 | 1514 | ); |
4ab7d517 | 1515 | $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
1516 | } |
1517 | ||
1518 | /** | |
d177a2a6 | 1519 | * Test civicrm_contribution_search with empty params. |
1e52837d | 1520 | * |
d177a2a6 | 1521 | * All available contributions expected. |
6a488035 | 1522 | */ |
00be9182 | 1523 | public function testSearchEmptyParams() { |
4ab7d517 | 1524 | $params = array(); |
6a488035 TO |
1525 | |
1526 | $p = array( | |
1527 | 'contact_id' => $this->_individualId, | |
1528 | 'receive_date' => date('Ymd'), | |
1529 | 'total_amount' => 100.00, | |
4ab7d517 | 1530 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1531 | 'non_deductible_amount' => 10.00, |
1532 | 'fee_amount' => 5.00, | |
1533 | 'net_amount' => 95.00, | |
1534 | 'trxn_id' => 23456, | |
1535 | 'invoice_id' => 78910, | |
1536 | 'source' => 'SSF', | |
1537 | 'contribution_status_id' => 1, | |
4ab7d517 | 1538 | |
6a488035 | 1539 | ); |
4ab7d517 | 1540 | $contribution = $this->callAPISuccess('contribution', 'create', $p); |
6a488035 | 1541 | |
4ab7d517 | 1542 | $result = $this->callAPISuccess('contribution', 'get', $params); |
6a488035 TO |
1543 | // We're taking the first element. |
1544 | $res = $result['values'][$contribution['id']]; | |
1545 | ||
2bfae985 EM |
1546 | $this->assertEquals($p['contact_id'], $res['contact_id']); |
1547 | $this->assertEquals($p['total_amount'], $res['total_amount']); | |
5896d037 | 1548 | $this->assertEquals($p['financial_type_id'], $res['financial_type_id']); |
2bfae985 EM |
1549 | $this->assertEquals($p['net_amount'], $res['net_amount']); |
1550 | $this->assertEquals($p['non_deductible_amount'], $res['non_deductible_amount']); | |
1551 | $this->assertEquals($p['fee_amount'], $res['fee_amount']); | |
1552 | $this->assertEquals($p['trxn_id'], $res['trxn_id']); | |
1553 | $this->assertEquals($p['invoice_id'], $res['invoice_id']); | |
1554 | $this->assertEquals($p['source'], $res['contribution_source']); | |
6a488035 | 1555 | // contribution_status_id = 1 => Completed |
2bfae985 | 1556 | $this->assertEquals('Completed', $res['contribution_status']); |
6a488035 TO |
1557 | |
1558 | $this->contributionDelete($contribution['id']); | |
1559 | } | |
1560 | ||
1561 | /** | |
d177a2a6 | 1562 | * Test civicrm_contribution_search. Success expected. |
6a488035 | 1563 | */ |
00be9182 | 1564 | public function testSearch() { |
6a488035 TO |
1565 | $p1 = array( |
1566 | 'contact_id' => $this->_individualId, | |
1567 | 'receive_date' => date('Ymd'), | |
1568 | 'total_amount' => 100.00, | |
4ab7d517 | 1569 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1570 | 'non_deductible_amount' => 10.00, |
1571 | 'contribution_status_id' => 1, | |
4ab7d517 | 1572 | |
6a488035 | 1573 | ); |
4ab7d517 | 1574 | $contribution1 = $this->callAPISuccess('contribution', 'create', $p1); |
6a488035 TO |
1575 | |
1576 | $p2 = array( | |
1577 | 'contact_id' => $this->_individualId, | |
1578 | 'receive_date' => date('Ymd'), | |
1579 | 'total_amount' => 200.00, | |
4ab7d517 | 1580 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
1581 | 'non_deductible_amount' => 20.00, |
1582 | 'trxn_id' => 5454565, | |
1583 | 'invoice_id' => 1212124, | |
1584 | 'fee_amount' => 50.00, | |
1585 | 'net_amount' => 60.00, | |
1586 | 'contribution_status_id' => 2, | |
4ab7d517 | 1587 | |
6a488035 | 1588 | ); |
2f45e1c2 | 1589 | $contribution2 = $this->callAPISuccess('contribution', 'create', $p2); |
6a488035 TO |
1590 | |
1591 | $params = array( | |
1592 | 'contribution_id' => $contribution2['id'], | |
4ab7d517 | 1593 | |
6a488035 | 1594 | ); |
2f45e1c2 | 1595 | $result = $this->callAPISuccess('contribution', 'get', $params); |
6a488035 TO |
1596 | $res = $result['values'][$contribution2['id']]; |
1597 | ||
2bfae985 EM |
1598 | $this->assertEquals($p2['contact_id'], $res['contact_id']); |
1599 | $this->assertEquals($p2['total_amount'], $res['total_amount']); | |
5896d037 | 1600 | $this->assertEquals($p2['financial_type_id'], $res['financial_type_id']); |
2bfae985 EM |
1601 | $this->assertEquals($p2['net_amount'], $res['net_amount']); |
1602 | $this->assertEquals($p2['non_deductible_amount'], $res['non_deductible_amount']); | |
1603 | $this->assertEquals($p2['fee_amount'], $res['fee_amount']); | |
1604 | $this->assertEquals($p2['trxn_id'], $res['trxn_id']); | |
1605 | $this->assertEquals($p2['invoice_id'], $res['invoice_id']); | |
6a488035 | 1606 | // contribution_status_id = 2 => Pending |
2bfae985 | 1607 | $this->assertEquals('Pending', $res['contribution_status']); |
6a488035 TO |
1608 | |
1609 | $this->contributionDelete($contribution1['id']); | |
1610 | $this->contributionDelete($contribution2['id']); | |
1611 | } | |
2f45e1c2 | 1612 | |
0efa8efe | 1613 | /** |
eceb18cc | 1614 | * Test completing a transaction via the API. |
0efa8efe | 1615 | * |
1616 | * Note that we are creating a logged in user because email goes out from | |
1617 | * that person | |
1618 | */ | |
00be9182 | 1619 | public function testCompleteTransaction() { |
5896d037 | 1620 | $mut = new CiviMailUtils($this, TRUE); |
ec7e3954 | 1621 | $this->swapMessageTemplateForTestTemplate(); |
0efa8efe | 1622 | $this->createLoggedInUser(); |
6c6e6187 TO |
1623 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); |
1624 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
66d3f9be | 1625 | $this->callAPISuccess('contribution', 'completetransaction', array( |
0efa8efe | 1626 | 'id' => $contribution['id'], |
66d3f9be | 1627 | )); |
cc7b912f | 1628 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); |
d5580ed4 | 1629 | $this->assertEquals('SSF', $contribution['contribution_source']); |
cc7b912f | 1630 | $this->assertEquals('Completed', $contribution['contribution_status']); |
1631 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date']))); | |
0efa8efe | 1632 | $mut->checkMailLog(array( |
ec7e3954 E |
1633 | 'email:::anthony_anderson@civicrm.org', |
1634 | 'is_monetary:::1', | |
1635 | 'amount:::100.00', | |
1636 | 'currency:::USD', | |
1637 | 'receive_date:::' . date('Ymd', strtotime($contribution['receive_date'])), | |
76e8d9c4 | 1638 | "receipt_date:::\n", |
ec7e3954 E |
1639 | 'contributeMode:::notify', |
1640 | 'title:::Contribution', | |
1641 | 'displayName:::Mr. Anthony Anderson II', | |
0efa8efe | 1642 | )); |
46fa5206 | 1643 | $mut->stop(); |
ec7e3954 | 1644 | $this->revertTemplateToReservedTemplate(); |
46fa5206 EM |
1645 | } |
1646 | ||
e05d2e11 | 1647 | /** |
1648 | * Test to ensure mail is sent on chosing pay later | |
1649 | */ | |
1650 | public function testpayLater() { | |
1651 | $mut = new CiviMailUtils($this, TRUE); | |
1652 | $this->swapMessageTemplateForTestTemplate(); | |
1653 | $this->createLoggedInUser(); | |
1654 | ||
1655 | // create contribution page first | |
1656 | $contributionPageParams = array( | |
1657 | 'title' => 'Help Support CiviCRM!', | |
1658 | 'financial_type_id' => 1, | |
1659 | 'is_monetary' => TRUE, | |
1660 | 'is_pay_later' => 1, | |
1661 | 'is_quick_config' => TRUE, | |
1662 | 'pay_later_text' => 'I will send payment by check', | |
1663 | 'pay_later_receipt' => 'This is a pay later reciept', | |
1664 | 'is_allow_other_amount' => 1, | |
1665 | 'min_amount' => 10.00, | |
1666 | 'max_amount' => 10000.00, | |
1667 | 'goal_amount' => 100000.00, | |
1668 | 'is_email_receipt' => 1, | |
1669 | 'is_active' => 1, | |
1670 | 'amount_block_is_active' => 1, | |
1671 | 'currency' => 'USD', | |
1672 | 'is_billing_required' => 0, | |
1673 | ); | |
1674 | $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', $contributionPageParams); | |
1675 | ||
1676 | // submit form values | |
1677 | $priceSet = $this->callAPISuccess('price_set', 'getsingle', array('name' => 'default_contribution_amount')); | |
1678 | $params = array( | |
1679 | 'id' => $contributionPageResult['id'], | |
1680 | 'contact_id' => $this->_individualId, | |
1681 | 'email-5' => 'anthony_anderson@civicrm.org', | |
1682 | 'payment_processor_id' => 0, | |
1683 | 'amount' => 100.00, | |
1684 | 'tax_amount' => '', | |
1685 | 'currencyID' => 'USD', | |
1686 | 'is_pay_later' => 1, | |
1687 | 'invoiceID' => 'f28e1ddc86f8c4a0ff5bcf46393e4bc8', | |
1688 | 'is_quick_config' => 1, | |
1689 | 'description' => 'Online Contribution: Help Support CiviCRM!', | |
1690 | 'price_set_id' => $priceSet['id'], | |
1691 | ); | |
1692 | $this->callAPISuccess('contribution_page', 'submit', $params); | |
1693 | ||
1694 | $mut->checkMailLog(array( | |
1695 | 'is_pay_later:::1', | |
1696 | 'email:::anthony_anderson@civicrm.org', | |
1697 | 'pay_later_receipt:::' . $contributionPageParams['pay_later_receipt'], | |
1698 | 'displayName:::Mr. Anthony Anderson II', | |
1699 | 'contributionPageId:::' . $contributionPageResult['id'], | |
1700 | 'title:::' . $contributionPageParams['title'], | |
8beee0e8 | 1701 | 'amount:::' . $params['amount'], |
e05d2e11 | 1702 | )); |
1703 | $mut->stop(); | |
1704 | $this->revertTemplateToReservedTemplate(); | |
1705 | } | |
1706 | ||
1707 | ||
2a0df9d9 | 1708 | /** |
1709 | * Test to check whether contact billing address is used when no contribution address | |
1710 | */ | |
1711 | public function testBillingAddress() { | |
1712 | $mut = new CiviMailUtils($this, TRUE); | |
1713 | $this->swapMessageTemplateForTestTemplate(); | |
1714 | $this->createLoggedInUser(); | |
1715 | ||
1716 | //Scenario 1: When Contact don't have any address | |
1717 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); | |
1718 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
1719 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
1720 | 'id' => $contribution['id'], | |
1721 | )); | |
1722 | $mut->checkMailLog(array( | |
1723 | 'address:::', | |
1724 | )); | |
1725 | ||
1726 | // Scenario 2: Contribution using address | |
1727 | $address = $this->callAPISuccess('address', 'create', array( | |
1728 | 'street_address' => 'contribution billing st', | |
1729 | 'location_type_id' => 2, | |
1730 | 'contact_id' => $this->_params['contact_id'], | |
1731 | )); | |
76e8d9c4 E |
1732 | $params = array_merge($this->_params, array( |
1733 | 'contribution_status_id' => 2, | |
2a0df9d9 | 1734 | 'address_id' => $address['id'], |
1735 | ) | |
1736 | ); | |
1737 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
1738 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
1739 | 'id' => $contribution['id'], | |
1740 | )); | |
1741 | $mut->checkMailLog(array( | |
1742 | 'address:::contribution billing st', | |
1743 | )); | |
1744 | ||
1745 | // Scenario 3: Contribution wtth no address but contact has a billing address | |
1746 | $this->callAPISuccess('address', 'create', array( | |
1747 | 'id' => $address['id'], | |
1748 | 'street_address' => 'is billing st', | |
1749 | 'contact_id' => $this->_params['contact_id'], | |
1750 | )); | |
1751 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); | |
1752 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
1753 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
1754 | 'id' => $contribution['id'], | |
1755 | )); | |
1756 | $mut->checkMailLog(array( | |
1757 | 'address:::is billing st', | |
1758 | )); | |
1759 | ||
1760 | $mut->stop(); | |
1761 | $this->revertTemplateToReservedTemplate(); | |
1762 | } | |
1763 | ||
080a561b | 1764 | /** |
1765 | * Test completing a transaction via the API. | |
1766 | * | |
1767 | * Note that we are creating a logged in user because email goes out from | |
1768 | * that person | |
1769 | */ | |
1770 | public function testCompleteTransactionFeeAmount() { | |
1771 | $this->createLoggedInUser(); | |
1772 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); | |
1773 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
1774 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
1775 | 'id' => $contribution['id'], | |
1776 | 'fee_amount' => '.56', | |
1777 | 'trxn_id' => '7778888', | |
1778 | )); | |
1779 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1)); | |
1780 | $this->assertEquals('Completed', $contribution['contribution_status']); | |
1781 | $this->assertEquals('7778888', $contribution['trxn_id']); | |
1782 | $this->assertEquals('.56', $contribution['fee_amount']); | |
1783 | $this->assertEquals('99.44', $contribution['net_amount']); | |
1784 | } | |
1785 | ||
effb4d85 SL |
1786 | /** |
1787 | * CRM-19126 Add test to verify when complete transaction is called tax amount is not changed | |
1788 | */ | |
1789 | public function testCheckTaxAmount() { | |
1790 | $contact = $this->createLoggedInUser(); | |
1791 | $financialType = $this->callAPISuccess('financial_type', 'create', array( | |
1792 | 'name' => 'Test taxable financial Type', | |
1793 | 'is_reserved' => 0, | |
1794 | 'is_active' => 1, | |
1795 | )); | |
1796 | $financialAccount = $this->callAPISuccess('financial_account', 'create', array( | |
1797 | 'name' => 'Test Tax financial account ', | |
1798 | 'contact_id' => $contact, | |
1799 | 'financial_account_type_id' => 2, | |
1800 | 'is_tax' => 1, | |
1801 | 'tax_rate' => 5.00, | |
1802 | 'is_reserved' => 0, | |
1803 | 'is_active' => 1, | |
1804 | 'is_default' => 0, | |
1805 | )); | |
1806 | $financialTypeId = $financialType['id']; | |
1807 | $financialAccountId = $financialAccount['id']; | |
1808 | $financialAccountParams = array( | |
1809 | 'entity_table' => 'civicrm_financial_type', | |
1810 | 'entity_id' => $financialTypeId, | |
1811 | 'account_relationship' => 10, | |
1812 | 'financial_account_id' => $financialAccountId, | |
1813 | ); | |
a76b8bd8 | 1814 | CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams); |
effb4d85 SL |
1815 | $taxRates = CRM_Core_PseudoConstant::getTaxRates(); |
1816 | $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => $financialTypeId)); | |
1817 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
1818 | $contribution1 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1)); | |
1819 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
1820 | 'id' => $contribution['id'], | |
1821 | 'trxn_id' => '777788888', | |
99a4cd32 | 1822 | 'fee_amount' => '6.00', |
effb4d85 | 1823 | )); |
99a4cd32 | 1824 | $contribution2 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => array('tax_amount', 'fee_amount', 'net_amount'), 'sequential' => 1)); |
effb4d85 | 1825 | $this->assertEquals($contribution1['values'][0]['tax_amount'], $contribution2['values'][0]['tax_amount']); |
99a4cd32 | 1826 | $this->assertEquals('6.00', $contribution2['values'][0]['fee_amount']); |
f836984d | 1827 | $this->assertEquals('99.00', $contribution2['values'][0]['net_amount']); |
effb4d85 SL |
1828 | } |
1829 | ||
d97c96dc | 1830 | /** |
0e6ccb2e | 1831 | * Test repeat contribution successfully creates line item. |
d97c96dc | 1832 | */ |
1e52837d | 1833 | public function testRepeatTransaction() { |
0e6ccb2e | 1834 | $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single'); |
d97c96dc EM |
1835 | $this->callAPISuccess('contribution', 'repeattransaction', array( |
1836 | 'original_contribution_id' => $originalContribution['id'], | |
1837 | 'contribution_status_id' => 'Completed', | |
1838 | 'trxn_id' => uniqid(), | |
1839 | )); | |
1840 | $lineItemParams = array( | |
1841 | 'entity_id' => $originalContribution['id'], | |
1842 | 'sequential' => 1, | |
1843 | 'return' => array( | |
1844 | 'entity_table', | |
1845 | 'qty', | |
1846 | 'unit_price', | |
1847 | 'line_total', | |
1848 | 'label', | |
1849 | 'financial_type_id', | |
1850 | 'deductible_amount', | |
1851 | 'price_field_value_id', | |
1852 | 'price_field_id', | |
1e52837d | 1853 | ), |
d97c96dc EM |
1854 | ); |
1855 | $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
1856 | 'entity_id' => $originalContribution['id'], | |
1857 | ))); | |
1858 | $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
1859 | 'entity_id' => $originalContribution['id'] + 1, | |
1860 | ))); | |
1861 | unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']); | |
1862 | unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); | |
1863 | $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]); | |
43c8d1dd | 1864 | $this->_checkFinancialRecords(array('id' => $originalContribution['id'] + 1), 'online'); |
d97c96dc EM |
1865 | $this->quickCleanUpFinancialEntities(); |
1866 | } | |
1867 | ||
893a550c | 1868 | /** |
0e6ccb2e K |
1869 | * Test repeat contribution successfully creates line items (plural). |
1870 | */ | |
1871 | public function testRepeatTransactionLineItems() { | |
7150b1c8 | 1872 | // CRM-19309 |
0e6ccb2e K |
1873 | $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'multiple'); |
1874 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
1875 | 'original_contribution_id' => $originalContribution['id'], | |
1876 | 'contribution_status_id' => 'Completed', | |
1877 | 'trxn_id' => uniqid(), | |
1878 | )); | |
1879 | ||
1880 | $lineItemParams = array( | |
1881 | 'entity_id' => $originalContribution['id'], | |
1882 | 'sequential' => 1, | |
1883 | 'return' => array( | |
1884 | 'entity_table', | |
1885 | 'qty', | |
1886 | 'unit_price', | |
1887 | 'line_total', | |
1888 | 'label', | |
1889 | 'financial_type_id', | |
1890 | 'deductible_amount', | |
1891 | 'price_field_value_id', | |
1892 | 'price_field_id', | |
1893 | ), | |
1894 | ); | |
1895 | $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
1896 | 'entity_id' => $originalContribution['id'], | |
1897 | ))); | |
1898 | $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
1899 | 'entity_id' => $originalContribution['id'] + 1, | |
1900 | ))); | |
1901 | ||
1902 | // unset id and entity_id for all of them to be able to compare the lineItems: | |
1903 | unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']); | |
1904 | unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); | |
1905 | $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]); | |
1906 | ||
1907 | unset($lineItem1['values'][1]['id'], $lineItem1['values'][1]['entity_id']); | |
1908 | unset($lineItem2['values'][1]['id'], $lineItem2['values'][1]['entity_id']); | |
1909 | $this->assertEquals($lineItem1['values'][1], $lineItem2['values'][1]); | |
1910 | ||
7150b1c8 K |
1911 | // CRM-19309 so in future we also want to: |
1912 | // check that financial_line_items have been created for entity_id 3 and 4; | |
0e6ccb2e K |
1913 | |
1914 | $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0); | |
1915 | $this->quickCleanUpFinancialEntities(); | |
1916 | } | |
1917 | ||
1918 | /** | |
1919 | * Test repeat contribution successfully creates is_test transaction. | |
893a550c | 1920 | */ |
1921 | public function testRepeatTransactionIsTest() { | |
1922 | $this->_params['is_test'] = 1; | |
0e6ccb2e | 1923 | $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1), 'single'); |
893a550c | 1924 | |
1925 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
1926 | 'original_contribution_id' => $originalContribution['id'], | |
1927 | 'contribution_status_id' => 'Completed', | |
1928 | 'trxn_id' => uniqid(), | |
1929 | )); | |
1930 | $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2); | |
1931 | } | |
1932 | ||
d5580ed4 | 1933 | /** |
1934 | * Test repeat contribution passed in status. | |
1935 | */ | |
1936 | public function testRepeatTransactionPassedInStatus() { | |
0e6ccb2e | 1937 | $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single'); |
d5580ed4 | 1938 | |
1939 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
1940 | 'original_contribution_id' => $originalContribution['id'], | |
1941 | 'contribution_status_id' => 'Pending', | |
1942 | 'trxn_id' => uniqid(), | |
1943 | )); | |
1944 | $this->callAPISuccessGetCount('Contribution', array('contribution_status_id' => 2), 1); | |
1945 | } | |
1946 | ||
1eade77d | 1947 | /** |
1948 | * Test repeat contribution accepts recur_id instead of original_contribution_id. | |
1949 | */ | |
1950 | public function testRepeatTransactionAcceptRecurID() { | |
1951 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( | |
1952 | 'contact_id' => $this->_individualId, | |
1953 | 'installments' => '12', | |
1954 | 'frequency_interval' => '1', | |
1955 | 'amount' => '100', | |
1956 | 'contribution_status_id' => 1, | |
1957 | 'start_date' => '2012-01-01 00:00:00', | |
1958 | 'currency' => 'USD', | |
1959 | 'frequency_unit' => 'month', | |
1960 | 'payment_processor_id' => $this->paymentProcessorID, | |
1961 | )); | |
1962 | $this->callAPISuccess('contribution', 'create', array_merge( | |
1963 | $this->_params, | |
1964 | array('contribution_recur_id' => $contributionRecur['id'])) | |
1965 | ); | |
1966 | ||
1967 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
1968 | 'contribution_recur_id' => $contributionRecur['id'], | |
1969 | 'contribution_status_id' => 'Completed', | |
1970 | 'trxn_id' => uniqid(), | |
1971 | )); | |
1972 | ||
1973 | $this->quickCleanUpFinancialEntities(); | |
1974 | } | |
1975 | ||
c03f1689 EM |
1976 | /** |
1977 | * CRM-16397 test appropriate action if total amount has changed for single line items. | |
1978 | */ | |
1979 | public function testRepeatTransactionAlteredAmount() { | |
1980 | $paymentProcessorID = $this->paymentProcessorCreate(); | |
c03f1689 EM |
1981 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( |
1982 | 'contact_id' => $this->_individualId, | |
1983 | 'installments' => '12', | |
1984 | 'frequency_interval' => '1', | |
1985 | 'amount' => '500', | |
1986 | 'contribution_status_id' => 1, | |
1987 | 'start_date' => '2012-01-01 00:00:00', | |
1988 | 'currency' => 'USD', | |
1989 | 'frequency_unit' => 'month', | |
1990 | 'payment_processor_id' => $paymentProcessorID, | |
1991 | )); | |
1992 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( | |
1993 | $this->_params, | |
1994 | array( | |
1995 | 'contribution_recur_id' => $contributionRecur['id'], | |
c03f1689 EM |
1996 | )) |
1997 | ); | |
1998 | ||
1999 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
2000 | 'original_contribution_id' => $originalContribution['id'], | |
2001 | 'contribution_status_id' => 'Completed', | |
2002 | 'trxn_id' => uniqid(), | |
2003 | 'total_amount' => '400', | |
2004 | 'fee_amount' => 50, | |
c03f1689 | 2005 | )); |
0e6ccb2e | 2006 | |
c03f1689 EM |
2007 | $lineItemParams = array( |
2008 | 'entity_id' => $originalContribution['id'], | |
2009 | 'sequential' => 1, | |
2010 | 'return' => array( | |
2011 | 'entity_table', | |
2012 | 'qty', | |
2013 | 'unit_price', | |
2014 | 'line_total', | |
2015 | 'label', | |
2016 | 'financial_type_id', | |
2017 | 'deductible_amount', | |
2018 | 'price_field_value_id', | |
2019 | 'price_field_id', | |
2020 | ), | |
2021 | ); | |
2022 | $this->callAPISuccessGetSingle('contribution', array( | |
2023 | 'total_amount' => 400, | |
c03f1689 EM |
2024 | 'fee_amount' => 50, |
2025 | 'net_amount' => 350, | |
2026 | )); | |
2027 | $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
2028 | 'entity_id' => $originalContribution['id'], | |
2029 | ))); | |
2030 | $expectedLineItem = array_merge( | |
2031 | $lineItem1['values'][0], array( | |
2032 | 'line_total' => '400.00', | |
2033 | 'unit_price' => '400.00', | |
542d9e2c EM |
2034 | ) |
2035 | ); | |
c03f1689 EM |
2036 | |
2037 | $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
2038 | 'entity_id' => $originalContribution['id'] + 1, | |
2039 | ))); | |
0e6ccb2e | 2040 | |
c03f1689 EM |
2041 | unset($expectedLineItem['id'], $expectedLineItem['entity_id']); |
2042 | unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); | |
2043 | $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); | |
c02c17df | 2044 | } |
c03f1689 | 2045 | |
3c49d90c | 2046 | /** |
2047 | * CRM-17718 test appropriate action if financial type has changed for single line items. | |
2048 | */ | |
2049 | public function testRepeatTransactionPassedInFinancialType() { | |
2050 | $originalContribution = $this->setUpRecurringContribution(); | |
2051 | ||
2052 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
2053 | 'original_contribution_id' => $originalContribution['id'], | |
2054 | 'contribution_status_id' => 'Completed', | |
2055 | 'trxn_id' => uniqid(), | |
2056 | 'financial_type_id' => 2, | |
2057 | )); | |
2058 | $lineItemParams = array( | |
2059 | 'entity_id' => $originalContribution['id'], | |
2060 | 'sequential' => 1, | |
2061 | 'return' => array( | |
2062 | 'entity_table', | |
2063 | 'qty', | |
2064 | 'unit_price', | |
2065 | 'line_total', | |
2066 | 'label', | |
2067 | 'financial_type_id', | |
2068 | 'deductible_amount', | |
2069 | 'price_field_value_id', | |
2070 | 'price_field_id', | |
2071 | ), | |
2072 | ); | |
2073 | ||
2074 | $this->callAPISuccessGetSingle('contribution', array( | |
2075 | 'total_amount' => 100, | |
2076 | 'financial_type_id' => 2, | |
2077 | )); | |
2078 | $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
2079 | 'entity_id' => $originalContribution['id'], | |
2080 | ))); | |
2081 | $expectedLineItem = array_merge( | |
2082 | $lineItem1['values'][0], array( | |
2083 | 'line_total' => '100.00', | |
2084 | 'unit_price' => '100.00', | |
2085 | 'financial_type_id' => 2, | |
257ab382 | 2086 | 'contribution_type_id' => 2, |
3c49d90c | 2087 | ) |
2088 | ); | |
3c49d90c | 2089 | $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( |
2090 | 'entity_id' => $originalContribution['id'] + 1, | |
2091 | ))); | |
2092 | unset($expectedLineItem['id'], $expectedLineItem['entity_id']); | |
2093 | unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); | |
2094 | $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); | |
2095 | } | |
2096 | ||
7f4ef731 | 2097 | /** |
2098 | * CRM-17718 test appropriate action if financial type has changed for single line items. | |
2099 | */ | |
2100 | public function testRepeatTransactionUpdatedFinancialType() { | |
2101 | $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2)); | |
2102 | ||
2103 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
2104 | 'contribution_recur_id' => $originalContribution['id'], | |
2105 | 'contribution_status_id' => 'Completed', | |
2106 | 'trxn_id' => uniqid(), | |
2107 | )); | |
2108 | $lineItemParams = array( | |
2109 | 'entity_id' => $originalContribution['id'], | |
2110 | 'sequential' => 1, | |
2111 | 'return' => array( | |
2112 | 'entity_table', | |
2113 | 'qty', | |
2114 | 'unit_price', | |
2115 | 'line_total', | |
2116 | 'label', | |
2117 | 'financial_type_id', | |
2118 | 'deductible_amount', | |
2119 | 'price_field_value_id', | |
2120 | 'price_field_id', | |
2121 | ), | |
2122 | ); | |
2123 | ||
2124 | $this->callAPISuccessGetSingle('contribution', array( | |
2125 | 'total_amount' => 100, | |
2126 | 'financial_type_id' => 2, | |
2127 | )); | |
2128 | $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
2129 | 'entity_id' => $originalContribution['id'], | |
2130 | ))); | |
2131 | $expectedLineItem = array_merge( | |
2132 | $lineItem1['values'][0], array( | |
2133 | 'line_total' => '100.00', | |
2134 | 'unit_price' => '100.00', | |
2135 | 'financial_type_id' => 2, | |
257ab382 | 2136 | 'contribution_type_id' => 2, |
7f4ef731 | 2137 | ) |
2138 | ); | |
2139 | ||
2140 | $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array( | |
2141 | 'entity_id' => $originalContribution['id'] + 1, | |
2142 | ))); | |
2143 | unset($expectedLineItem['id'], $expectedLineItem['entity_id']); | |
2144 | unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']); | |
2145 | $this->assertEquals($expectedLineItem, $lineItem2['values'][0]); | |
2146 | } | |
2147 | ||
c02c17df | 2148 | /** |
1eade77d | 2149 | * CRM-16397 test appropriate action if campaign has been passed in. |
c02c17df | 2150 | */ |
2151 | public function testRepeatTransactionPassedInCampaign() { | |
2152 | $paymentProcessorID = $this->paymentProcessorCreate(); | |
2153 | $campaignID = $this->campaignCreate(); | |
2154 | $campaignID2 = $this->campaignCreate(); | |
2155 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( | |
2156 | 'contact_id' => $this->_individualId, | |
2157 | 'installments' => '12', | |
2158 | 'frequency_interval' => '1', | |
2159 | 'amount' => '100', | |
2160 | 'contribution_status_id' => 1, | |
2161 | 'start_date' => '2012-01-01 00:00:00', | |
2162 | 'currency' => 'USD', | |
2163 | 'frequency_unit' => 'month', | |
2164 | 'payment_processor_id' => $paymentProcessorID, | |
2165 | )); | |
2166 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( | |
2167 | $this->_params, | |
2168 | array( | |
2169 | 'contribution_recur_id' => $contributionRecur['id'], | |
2170 | 'campaign_id' => $campaignID, | |
2171 | )) | |
2172 | ); | |
2173 | ||
2174 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
2175 | 'original_contribution_id' => $originalContribution['id'], | |
2176 | 'contribution_status_id' => 'Completed', | |
2177 | 'trxn_id' => uniqid(), | |
2178 | 'campaign_id' => $campaignID2, | |
2179 | )); | |
2180 | ||
2181 | $this->callAPISuccessGetSingle('contribution', array( | |
2182 | 'total_amount' => 100, | |
2183 | 'campaign_id' => $campaignID2, | |
2184 | )); | |
2185 | } | |
2186 | ||
2187 | /** | |
2188 | * CRM-17718 campaign stored on contribution recur gets priority. | |
2189 | * | |
2190 | * This reflects the fact we permit people to update them. | |
2191 | */ | |
2192 | public function testRepeatTransactionUpdatedCampaign() { | |
2193 | $paymentProcessorID = $this->paymentProcessorCreate(); | |
2194 | $campaignID = $this->campaignCreate(); | |
2195 | $campaignID2 = $this->campaignCreate(); | |
2196 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( | |
2197 | 'contact_id' => $this->_individualId, | |
2198 | 'installments' => '12', | |
2199 | 'frequency_interval' => '1', | |
2200 | 'amount' => '100', | |
2201 | 'contribution_status_id' => 1, | |
2202 | 'start_date' => '2012-01-01 00:00:00', | |
2203 | 'currency' => 'USD', | |
2204 | 'frequency_unit' => 'month', | |
2205 | 'payment_processor_id' => $paymentProcessorID, | |
2206 | 'campaign_id' => $campaignID, | |
2207 | )); | |
2208 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( | |
2209 | $this->_params, | |
2210 | array( | |
2211 | 'contribution_recur_id' => $contributionRecur['id'], | |
2212 | 'campaign_id' => $campaignID2, | |
2213 | )) | |
2214 | ); | |
2215 | ||
2216 | $this->callAPISuccess('contribution', 'repeattransaction', array( | |
2217 | 'original_contribution_id' => $originalContribution['id'], | |
2218 | 'contribution_status_id' => 'Completed', | |
2219 | 'trxn_id' => uniqid(), | |
2220 | )); | |
2221 | ||
2222 | $this->callAPISuccessGetSingle('contribution', array( | |
2223 | 'total_amount' => 100, | |
2224 | 'campaign_id' => $campaignID, | |
2225 | )); | |
c03f1689 EM |
2226 | } |
2227 | ||
2936c3b5 EM |
2228 | /** |
2229 | * Test completing a transaction does not 'mess' with net amount (CRM-15960). | |
2230 | */ | |
2231 | public function testCompleteTransactionNetAmountOK() { | |
2232 | $this->createLoggedInUser(); | |
2233 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); | |
2234 | unset($params['net_amount']); | |
2235 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
2236 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
2237 | 'id' => $contribution['id'], | |
2238 | )); | |
2239 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); | |
2240 | $this->assertEquals('Completed', $contribution['contribution_status']); | |
2241 | $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']); | |
2242 | } | |
2243 | ||
46fa5206 | 2244 | /** |
1e52837d | 2245 | * CRM-14151 - Test completing a transaction via the API. |
46fa5206 | 2246 | */ |
00be9182 | 2247 | public function testCompleteTransactionWithReceiptDateSet() { |
76e8d9c4 | 2248 | $this->swapMessageTemplateForTestTemplate(); |
5896d037 | 2249 | $mut = new CiviMailUtils($this, TRUE); |
46fa5206 | 2250 | $this->createLoggedInUser(); |
6c6e6187 TO |
2251 | $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); |
2252 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
7104593e | 2253 | $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d'))); |
6c6e6187 | 2254 | $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1)); |
46fa5206 | 2255 | $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']); |
7104593e | 2256 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date']))); |
46fa5206 EM |
2257 | $mut->checkMailLog(array( |
2258 | 'Receipt - Contribution', | |
76e8d9c4 | 2259 | 'receipt_date:::' . date('Ymd'), |
46fa5206 | 2260 | )); |
0efa8efe | 2261 | $mut->stop(); |
76e8d9c4 | 2262 | $this->revertTemplateToReservedTemplate(); |
0efa8efe | 2263 | } |
2264 | ||
e2ca457d KG |
2265 | /** |
2266 | * CRM-1960 - Test to ensure that completetransaction respects the is_email_receipt setting | |
2267 | */ | |
2268 | public function testCompleteTransactionWithEmailReceiptInput() { | |
2269 | // Create a Contribution Page with is_email_receipt = TRUE | |
2270 | $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( | |
2271 | 'receipt_from_name' => 'Mickey Mouse', | |
2272 | 'receipt_from_email' => 'mickey@mouse.com', | |
2273 | 'title' => "Test Contribution Page", | |
2274 | 'financial_type_id' => 1, | |
2275 | 'currency' => 'CAD', | |
2276 | 'is_monetary' => TRUE, | |
2277 | 'is_email_receipt' => TRUE, | |
2278 | )); | |
2279 | $this->_params['contribution_page_id'] = $contributionPage['id']; | |
2280 | $params = array_merge($this->_params, array('contribution_status_id' => 2)); | |
2281 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
2282 | // Complete the transaction overriding is_email_receipt to = FALSE | |
2283 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
2284 | 'id' => $contribution['id'], | |
2285 | 'trxn_date' => date('2011-04-09'), | |
2286 | 'trxn_id' => 'kazam', | |
2287 | 'is_email_receipt' => 0, | |
2288 | )); | |
2289 | // Check if a receipt was issued | |
2290 | $receipt_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receipt_date')); | |
2291 | $this->assertEquals('', $receipt_date); | |
2292 | } | |
2293 | ||
b80f2ad1 E |
2294 | /** |
2295 | * Complete the transaction using the template with all the possible. | |
2296 | */ | |
2297 | public function testCompleteTransactionWithTestTemplate() { | |
2298 | $this->swapMessageTemplateForTestTemplate(); | |
ec7e3954 | 2299 | $contribution = $this->setUpForCompleteTransaction(); |
b80f2ad1 E |
2300 | $this->callAPISuccess('contribution', 'completetransaction', array( |
2301 | 'id' => $contribution['id'], | |
2302 | 'trxn_date' => date('2011-04-09'), | |
2303 | 'trxn_id' => 'kazam', | |
2304 | )); | |
2305 | $receive_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receive_date')); | |
ec7e3954 | 2306 | $this->mut->checkMailLog(array( |
b80f2ad1 E |
2307 | 'email:::anthony_anderson@civicrm.org', |
2308 | 'is_monetary:::1', | |
2309 | 'amount:::100.00', | |
2310 | 'currency:::USD', | |
2311 | 'receive_date:::' . date('Ymd', strtotime($receive_date)), | |
2312 | 'receipt_date:::' . date('Ymd'), | |
2313 | 'contributeMode:::notify', | |
2314 | 'title:::Contribution', | |
2315 | 'displayName:::Mr. Anthony Anderson II', | |
2316 | 'trxn_id:::kazam', | |
ec7e3954 | 2317 | 'contactID:::' . $this->_params['contact_id'], |
b80f2ad1 E |
2318 | 'contributionID:::' . $contribution['id'], |
2319 | 'financialTypeId:::1', | |
2320 | 'financialTypeName:::Donation', | |
2321 | )); | |
ec7e3954 | 2322 | $this->mut->stop(); |
b80f2ad1 E |
2323 | $this->revertTemplateToReservedTemplate(); |
2324 | } | |
2325 | ||
ec7e3954 E |
2326 | /** |
2327 | * Complete the transaction using the template with all the possible. | |
2328 | */ | |
2329 | public function testCompleteTransactionContributionPageFromAddress() { | |
2330 | $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( | |
2331 | 'receipt_from_name' => 'Mickey Mouse', | |
2332 | 'receipt_from_email' => 'mickey@mouse.com', | |
2333 | 'title' => "Test Contribution Page", | |
2334 | 'financial_type_id' => 1, | |
2335 | 'currency' => 'NZD', | |
2336 | 'goal_amount' => 50, | |
2337 | 'is_pay_later' => 1, | |
2338 | 'is_monetary' => TRUE, | |
2339 | 'is_email_receipt' => TRUE, | |
2340 | )); | |
2341 | $this->_params['contribution_page_id'] = $contributionPage['id']; | |
2342 | $contribution = $this->setUpForCompleteTransaction(); | |
2343 | $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'])); | |
2344 | $this->mut->checkMailLog(array( | |
2345 | 'mickey@mouse.com', | |
2346 | 'Mickey Mouse <', | |
2347 | )); | |
2348 | $this->mut->stop(); | |
2349 | } | |
2350 | ||
91259407 | 2351 | /** |
2352 | * Test completing first transaction in a recurring series. | |
2353 | * | |
2354 | * The status should be set to 'in progress' and the next scheduled payment date calculated. | |
2355 | */ | |
2356 | public function testCompleteTransactionSetStatusToInProgress() { | |
2357 | $paymentProcessorID = $this->paymentProcessorCreate(); | |
2358 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( | |
2359 | 'contact_id' => $this->_individualId, | |
2360 | 'installments' => '12', | |
2361 | 'frequency_interval' => '1', | |
2362 | 'amount' => '500', | |
2363 | 'contribution_status_id' => 'Pending', | |
2364 | 'start_date' => '2012-01-01 00:00:00', | |
2365 | 'currency' => 'USD', | |
2366 | 'frequency_unit' => 'month', | |
2367 | 'payment_processor_id' => $paymentProcessorID, | |
2368 | )); | |
2369 | $contribution = $this->callAPISuccess('contribution', 'create', array_merge( | |
2370 | $this->_params, | |
2371 | array( | |
2372 | 'contribution_recur_id' => $contributionRecur['id'], | |
2373 | 'contribution_status_id' => 'Pending', | |
2374 | )) | |
2375 | ); | |
2376 | $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $contribution)); | |
2377 | $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array( | |
2378 | 'id' => $contributionRecur['id'], | |
2379 | 'return' => array('next_sched_contribution_date', 'contribution_status_id'), | |
2380 | )); | |
2381 | $this->assertEquals(5, $contributionRecur['contribution_status_id']); | |
2382 | $this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']); | |
2383 | } | |
2384 | ||
294cc627 | 2385 | /** |
2386 | * Test completing a pledge with the completeTransaction api.. | |
2387 | * | |
2388 | * Note that we are creating a logged in user because email goes out from | |
2389 | * that person. | |
2390 | */ | |
2391 | public function testCompleteTransactionUpdatePledgePayment() { | |
9f9fa558 | 2392 | $this->swapMessageTemplateForTestTemplate(); |
294cc627 | 2393 | $mut = new CiviMailUtils($this, TRUE); |
2394 | $mut->clearMessages(); | |
2395 | $this->createLoggedInUser(); | |
2396 | $contributionID = $this->createPendingPledgeContribution(); | |
2397 | $this->callAPISuccess('contribution', 'completetransaction', array( | |
2398 | 'id' => $contributionID, | |
2399 | 'trxn_date' => '1 Feb 2013', | |
2400 | )); | |
2401 | $pledge = $this->callAPISuccessGetSingle('Pledge', array( | |
2402 | 'id' => $this->_ids['pledge'], | |
2403 | )); | |
2404 | $this->assertEquals('Completed', $pledge['pledge_status']); | |
2405 | ||
2406 | $status = $this->callAPISuccessGetValue('PledgePayment', array( | |
2407 | 'pledge_id' => $this->_ids['pledge'], | |
2408 | 'return' => 'status_id', | |
2409 | )); | |
2410 | $this->assertEquals(1, $status); | |
2411 | $mut->checkMailLog(array( | |
9f9fa558 EM |
2412 | 'amount:::500.00', |
2413 | 'receive_date:::20130201000000', | |
76e8d9c4 | 2414 | "receipt_date:::\n", |
294cc627 | 2415 | )); |
2416 | $mut->stop(); | |
9f9fa558 | 2417 | $this->revertTemplateToReservedTemplate(); |
294cc627 | 2418 | } |
2419 | ||
0efa8efe | 2420 | /** |
eceb18cc | 2421 | * Test completing a transaction with an event via the API. |
0efa8efe | 2422 | * |
2423 | * Note that we are creating a logged in user because email goes out from | |
2424 | * that person | |
2425 | */ | |
00be9182 | 2426 | public function testCompleteTransactionWithParticipantRecord() { |
5896d037 | 2427 | $mut = new CiviMailUtils($this, TRUE); |
0efa8efe | 2428 | $mut->clearMessages(); |
2429 | $this->createLoggedInUser(); | |
2430 | $contributionID = $this->createPendingParticipantContribution(); | |
66d3f9be | 2431 | $this->callAPISuccess('contribution', 'completetransaction', array( |
5896d037 TO |
2432 | 'id' => $contributionID, |
2433 | ) | |
0efa8efe | 2434 | ); |
5896d037 | 2435 | $participantStatus = $this->callAPISuccessGetValue('participant', array( |
92915c55 TO |
2436 | 'id' => $this->_ids['participant'], |
2437 | 'return' => 'participant_status_id', | |
2438 | )); | |
0efa8efe | 2439 | $this->assertEquals(1, $participantStatus); |
2440 | $mut->checkMailLog(array( | |
2441 | 'Annual CiviCRM meet', | |
2442 | 'Event', | |
afc59fef | 2443 | 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.', |
0efa8efe | 2444 | )); |
66d3f9be EM |
2445 | $mut->stop(); |
2446 | } | |
2447 | ||
2448 | /** | |
eceb18cc | 2449 | * Test membership is renewed when transaction completed. |
66d3f9be | 2450 | */ |
00be9182 | 2451 | public function testCompleteTransactionMembershipPriceSet() { |
66d3f9be | 2452 | $this->createPriceSetWithPage('membership'); |
4ff927bc | 2453 | $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array( |
2454 | 'name' => 'Grace', | |
2455 | 'return' => 'id') | |
2456 | ); | |
66d3f9be | 2457 | $this->setUpPendingContribution($this->_ids['price_field_value'][0]); |
4ff927bc | 2458 | $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); |
2459 | $logs = $this->callAPISuccess('MembershipLog', 'get', array( | |
2460 | 'membership_id' => $this->_ids['membership'], | |
2461 | )); | |
2462 | $this->assertEquals(1, $logs['count']); | |
2463 | $this->assertEquals($stateOfGrace, $membership['status_id']); | |
6c6e6187 | 2464 | $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution'])); |
66d3f9be EM |
2465 | $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); |
2466 | $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']); | |
4ff927bc | 2467 | $this->callAPISuccessGetSingle('LineItem', array( |
2468 | 'entity_id' => $this->_ids['membership'], | |
2469 | 'entity_table' => 'civicrm_membership', | |
2470 | )); | |
2471 | $logs = $this->callAPISuccess('MembershipLog', 'get', array( | |
2472 | 'membership_id' => $this->_ids['membership'], | |
2473 | )); | |
2474 | $this->assertEquals(2, $logs['count']); | |
2475 | $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']); | |
66d3f9be EM |
2476 | $this->cleanUpAfterPriceSets(); |
2477 | } | |
2478 | ||
2479 | /** | |
eceb18cc | 2480 | * Test membership is renewed when transaction completed. |
66d3f9be | 2481 | */ |
00be9182 | 2482 | public function testCompleteTransactionMembershipPriceSetTwoTerms() { |
66d3f9be EM |
2483 | $this->createPriceSetWithPage('membership'); |
2484 | $this->setUpPendingContribution($this->_ids['price_field_value'][1]); | |
6c6e6187 | 2485 | $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution'])); |
66d3f9be EM |
2486 | $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); |
2487 | $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']); | |
2488 | $this->cleanUpAfterPriceSets(); | |
2489 | } | |
2490 | ||
00be9182 | 2491 | public function cleanUpAfterPriceSets() { |
1cf3c2b1 | 2492 | $this->quickCleanUpFinancialEntities(); |
66d3f9be | 2493 | $this->contactDelete($this->_ids['contact']); |
66d3f9be EM |
2494 | } |
2495 | ||
2496 | ||
2497 | /** | |
1e52837d EM |
2498 | * Create price set with contribution test for test setup. |
2499 | * | |
100fef9d | 2500 | * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage |
28de42d1 | 2501 | * on parent class at some point (fn is not in 4.4). |
1e52837d | 2502 | * |
66d3f9be EM |
2503 | * @param $entity |
2504 | * @param array $params | |
2505 | */ | |
00be9182 | 2506 | public function createPriceSetWithPage($entity, $params = array()) { |
66d3f9be EM |
2507 | $membershipTypeID = $this->membershipTypeCreate(); |
2508 | $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array( | |
2509 | 'title' => "Test Contribution Page", | |
2510 | 'financial_type_id' => 1, | |
2511 | 'currency' => 'NZD', | |
2512 | 'goal_amount' => 50, | |
2513 | 'is_pay_later' => 1, | |
2514 | 'is_monetary' => TRUE, | |
2515 | 'is_email_receipt' => FALSE, | |
2516 | )); | |
2517 | $priceSet = $this->callAPISuccess('price_set', 'create', array( | |
2518 | 'is_quick_config' => 0, | |
2519 | 'extends' => 'CiviMember', | |
2520 | 'financial_type_id' => 1, | |
21dfd5f5 | 2521 | 'title' => 'my Page', |
66d3f9be EM |
2522 | )); |
2523 | $priceSetID = $priceSet['id']; | |
2524 | ||
5896d037 | 2525 | CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); |
66d3f9be | 2526 | $priceField = $this->callAPISuccess('price_field', 'create', array( |
5896d037 | 2527 | 'price_set_id' => $priceSetID, |
66d3f9be EM |
2528 | 'label' => 'Goat Breed', |
2529 | 'html_type' => 'Radio', | |
2530 | )); | |
2531 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
5896d037 | 2532 | 'price_set_id' => $priceSetID, |
66d3f9be EM |
2533 | 'price_field_id' => $priceField['id'], |
2534 | 'label' => 'Long Haired Goat', | |
2535 | 'amount' => 20, | |
43dbd988 | 2536 | 'financial_type_id' => 'Donation', |
66d3f9be EM |
2537 | 'membership_type_id' => $membershipTypeID, |
2538 | 'membership_num_terms' => 1, | |
2539 | ) | |
2540 | ); | |
2541 | $this->_ids['price_field_value'] = array($priceFieldValue['id']); | |
2542 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
5896d037 | 2543 | 'price_set_id' => $priceSetID, |
66d3f9be EM |
2544 | 'price_field_id' => $priceField['id'], |
2545 | 'label' => 'Shoe-eating Goat', | |
2546 | 'amount' => 10, | |
43dbd988 | 2547 | 'financial_type_id' => 'Donation', |
66d3f9be EM |
2548 | 'membership_type_id' => $membershipTypeID, |
2549 | 'membership_num_terms' => 2, | |
2550 | ) | |
2551 | ); | |
2552 | $this->_ids['price_field_value'][] = $priceFieldValue['id']; | |
2553 | $this->_ids['price_set'] = $priceSetID; | |
2554 | $this->_ids['contribution_page'] = $contributionPageResult['id']; | |
2555 | $this->_ids['price_field'] = array($priceField['id']); | |
0efa8efe | 2556 | |
66d3f9be EM |
2557 | $this->_ids['membership_type'] = $membershipTypeID; |
2558 | } | |
2559 | ||
2560 | /** | |
eceb18cc | 2561 | * Set up a pending transaction with a specific price field id. |
1e52837d | 2562 | * |
100fef9d | 2563 | * @param int $priceFieldValueID |
66d3f9be | 2564 | */ |
5896d037 | 2565 | public function setUpPendingContribution($priceFieldValueID) { |
66d3f9be EM |
2566 | $contactID = $this->individualCreate(); |
2567 | $membership = $this->callAPISuccess('membership', 'create', array( | |
2568 | 'contact_id' => $contactID, | |
2569 | 'membership_type_id' => $this->_ids['membership_type'], | |
2570 | 'start_date' => 'yesterday - 1 year', | |
2571 | 'end_date' => 'yesterday', | |
4ff927bc | 2572 | 'join_date' => 'yesterday - 1 year', |
66d3f9be EM |
2573 | )); |
2574 | $contribution = $this->callAPISuccess('contribution', 'create', array( | |
2575 | 'domain_id' => 1, | |
2576 | 'contact_id' => $contactID, | |
2577 | 'receive_date' => date('Ymd'), | |
2578 | 'total_amount' => 100.00, | |
2579 | 'financial_type_id' => 1, | |
2580 | 'payment_instrument_id' => 'Credit Card', | |
2581 | 'non_deductible_amount' => 10.00, | |
2582 | 'trxn_id' => 'jdhfi88', | |
2583 | 'invoice_id' => 'djfhiewuyr', | |
2584 | 'source' => 'SSF', | |
2585 | 'contribution_status_id' => 2, | |
2586 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
2587 | 'api.membership_payment.create' => array('membership_id' => $membership['id']), | |
2588 | )); | |
2589 | ||
2590 | $this->callAPISuccess('line_item', 'create', array( | |
2591 | 'entity_id' => $contribution['id'], | |
2592 | 'entity_table' => 'civicrm_contribution', | |
1274acef | 2593 | 'contribution_id' => $contribution['id'], |
66d3f9be EM |
2594 | 'price_field_id' => $this->_ids['price_field'][0], |
2595 | 'qty' => 1, | |
2596 | 'unit_price' => 20, | |
2597 | 'line_total' => 20, | |
2598 | 'financial_type_id' => 1, | |
2599 | 'price_field_value_id' => $priceFieldValueID, | |
2600 | )); | |
2601 | $this->_ids['contact'] = $contactID; | |
2602 | $this->_ids['contribution'] = $contribution['id']; | |
2603 | $this->_ids['membership'] = $membership['id']; | |
0efa8efe | 2604 | } |
2605 | ||
2f45e1c2 | 2606 | /** |
eceb18cc | 2607 | * Test sending a mail via the API. |
6a488035 | 2608 | */ |
00be9182 | 2609 | public function testSendMail() { |
5896d037 | 2610 | $mut = new CiviMailUtils($this, TRUE); |
6c6e6187 | 2611 | $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); |
858d0bf8 | 2612 | $this->callAPISuccess('contribution', 'sendconfirmation', array( |
5896d037 TO |
2613 | 'id' => $contribution['id'], |
2614 | 'receipt_from_email' => 'api@civicrm.org', | |
6a488035 TO |
2615 | ) |
2616 | ); | |
6a488035 TO |
2617 | $mut->checkMailLog(array( |
2618 | '$ 100.00', | |
2619 | 'Contribution Information', | |
2620 | 'Please print this confirmation for your records', | |
2621 | ), array( | |
21dfd5f5 | 2622 | 'Event', |
6a488035 TO |
2623 | ) |
2624 | ); | |
128d44a1 | 2625 | |
2626 | $this->checkCreditCardDetails($mut, $contribution['id']); | |
6a488035 TO |
2627 | $mut->stop(); |
2628 | } | |
2629 | ||
128d44a1 | 2630 | /** |
2631 | * Check credit card details in sent mail via API | |
2632 | * | |
2633 | * @param $mut obj CiviMailUtils instance | |
2634 | * @param int $contributionID Contribution ID | |
2635 | * | |
2636 | */ | |
2637 | public function checkCreditCardDetails($mut, $contributionID) { | |
2638 | $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); | |
2639 | $this->callAPISuccess('contribution', 'sendconfirmation', array( | |
2640 | 'id' => $contributionID, | |
2641 | 'receipt_from_email' => 'api@civicrm.org', | |
2642 | 'payment_processor_id' => $this->paymentProcessorID, | |
2643 | ) | |
2644 | ); | |
2645 | $mut->checkMailLog(array( | |
2646 | 'Credit Card Information', // credit card header | |
2647 | 'Billing Name and Address', // billing header | |
2648 | 'anthony_anderson@civicrm.org', // billing name | |
2649 | ), array( | |
2650 | 'Event', | |
2651 | ) | |
2652 | ); | |
2653 | } | |
2654 | ||
2f45e1c2 | 2655 | /** |
eceb18cc | 2656 | * Test sending a mail via the API. |
6a488035 | 2657 | */ |
00be9182 | 2658 | public function testSendMailEvent() { |
5896d037 | 2659 | $mut = new CiviMailUtils($this, TRUE); |
6c6e6187 | 2660 | $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); |
2f45e1c2 | 2661 | $event = $this->eventCreate(array( |
6a488035 TO |
2662 | 'is_email_confirm' => 1, |
2663 | 'confirm_from_email' => 'test@civicrm.org', | |
2664 | )); | |
2665 | $this->_eventID = $event['id']; | |
2666 | $participantParams = array( | |
2667 | 'contact_id' => $this->_individualId, | |
2668 | 'event_id' => $this->_eventID, | |
2669 | 'status_id' => 1, | |
2670 | 'role_id' => 1, | |
2671 | // to ensure it matches later on | |
2672 | 'register_date' => '2007-07-21 00:00:00', | |
2673 | 'source' => 'Online Event Registration: API Testing', | |
4ab7d517 | 2674 | |
6a488035 | 2675 | ); |
2f45e1c2 | 2676 | $participant = $this->callAPISuccess('participant', 'create', $participantParams); |
2677 | $this->callAPISuccess('participant_payment', 'create', array( | |
6a488035 TO |
2678 | 'participant_id' => $participant['id'], |
2679 | 'contribution_id' => $contribution['id'], | |
2f45e1c2 | 2680 | )); |
66d3f9be | 2681 | $this->callAPISuccess('contribution', 'sendconfirmation', array( |
5896d037 TO |
2682 | 'id' => $contribution['id'], |
2683 | 'receipt_from_email' => 'api@civicrm.org', | |
6a488035 TO |
2684 | ) |
2685 | ); | |
2686 | ||
6a488035 TO |
2687 | $mut->checkMailLog(array( |
2688 | 'Annual CiviCRM meet', | |
2689 | 'Event', | |
2690 | 'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>', | |
6c6e6187 | 2691 | ), array() |
6a488035 TO |
2692 | ); |
2693 | $mut->stop(); | |
2694 | } | |
2695 | ||
4302618d | 2696 | /** |
1e52837d EM |
2697 | * This function does a GET & compares the result against the $params. |
2698 | * | |
2699 | * Use as a double check on Creates. | |
2700 | * | |
2701 | * @param array $params | |
2702 | * @param int $id | |
67f947ac | 2703 | * @param bool $delete |
6c6e6187 | 2704 | */ |
1e52837d | 2705 | public function contributionGetnCheck($params, $id, $delete = TRUE) { |
6a488035 | 2706 | |
4ab7d517 | 2707 | $contribution = $this->callAPISuccess('Contribution', 'Get', array( |
6a488035 | 2708 | 'id' => $id, |
4ab7d517 | 2709 | |
5896d037 | 2710 | )); |
6a488035 TO |
2711 | |
2712 | if ($delete) { | |
4ab7d517 | 2713 | $this->callAPISuccess('contribution', 'delete', array('id' => $id)); |
6a488035 | 2714 | } |
2bfae985 | 2715 | $this->assertAPISuccess($contribution, 0); |
6a488035 TO |
2716 | $values = $contribution['values'][$contribution['id']]; |
2717 | $params['receive_date'] = date('Y-m-d H:i:s', strtotime($params['receive_date'])); | |
2718 | // this is not returned in id format | |
2719 | unset($params['payment_instrument_id']); | |
2720 | $params['contribution_source'] = $params['source']; | |
2721 | unset($params['source']); | |
2722 | foreach ($params as $key => $value) { | |
22f80e87 | 2723 | $this->assertEquals($value, $values[$key], $key . " value: $value doesn't match " . print_r($values, TRUE)); |
6a488035 TO |
2724 | } |
2725 | } | |
2726 | ||
294cc627 | 2727 | /** |
2728 | * Create a pending contribution & linked pending pledge record. | |
2729 | */ | |
2730 | public function createPendingPledgeContribution() { | |
2731 | ||
2732 | $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500)); | |
2733 | $this->_ids['pledge'] = $pledgeID; | |
2734 | $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array( | |
2735 | 'contribution_status_id' => 'Pending', | |
2736 | 'total_amount' => 500, | |
2737 | )) | |
2738 | ); | |
2739 | $paymentID = $this->callAPISuccessGetValue('PledgePayment', array( | |
2740 | 'options' => array('limit' => 1), | |
2741 | 'return' => 'id', | |
2742 | )); | |
2743 | $this->callAPISuccess('PledgePayment', 'create', array( | |
2744 | 'id' => $paymentID, | |
2745 | 'contribution_id' => | |
2746 | $contribution['id'], | |
2747 | 'status_id' => 'Pending', | |
2748 | 'scheduled_amount' => 500, | |
2749 | )); | |
2750 | ||
2751 | return $contribution['id']; | |
2752 | } | |
2753 | ||
0efa8efe | 2754 | /** |
1e52837d | 2755 | * Create a pending contribution & linked pending participant record (along with an event). |
0efa8efe | 2756 | */ |
5896d037 | 2757 | public function createPendingParticipantContribution() { |
6c6e6187 | 2758 | $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org')); |
0efa8efe | 2759 | $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6)); |
5896d037 | 2760 | $this->_ids['participant'] = $participantID; |
0efa8efe | 2761 | $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee')); |
6c6e6187 | 2762 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
5896d037 | 2763 | $this->callAPISuccess('participant_payment', 'create', array( |
92915c55 TO |
2764 | 'contribution_id' => $contribution['id'], |
2765 | 'participant_id' => $participantID, | |
2766 | )); | |
858d0bf8 | 2767 | $this->callAPISuccess('line_item', 'get', array( |
0efa8efe | 2768 | 'entity_id' => $contribution['id'], |
2769 | 'entity_table' => 'civicrm_contribution', | |
2770 | 'api.line_item.create' => array( | |
2771 | 'entity_id' => $participantID, | |
2772 | 'entity_table' => 'civicrm_participant', | |
2773 | ), | |
2774 | )); | |
2775 | return $contribution['id']; | |
2776 | } | |
2777 | ||
4cbe18b8 | 2778 | /** |
1e52837d EM |
2779 | * Get financial transaction amount. |
2780 | * | |
100fef9d | 2781 | * @param int $contId |
4cbe18b8 EM |
2782 | * |
2783 | * @return null|string | |
f4d89200 | 2784 | */ |
2da40d21 | 2785 | public function _getFinancialTrxnAmount($contId) { |
6c6e6187 | 2786 | $query = "SELECT |
6a488035 TO |
2787 | SUM( ft.total_amount ) AS total |
2788 | FROM civicrm_financial_trxn AS ft | |
2789 | LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id | |
2790 | WHERE ceft.entity_table = 'civicrm_contribution' | |
2791 | AND ceft.entity_id = {$contId}"; | |
2792 | ||
6c6e6187 TO |
2793 | $result = CRM_Core_DAO::singleValueQuery($query); |
2794 | return $result; | |
2795 | } | |
6a488035 | 2796 | |
4cbe18b8 | 2797 | /** |
100fef9d | 2798 | * @param int $contId |
4cbe18b8 EM |
2799 | * |
2800 | * @return null|string | |
f4d89200 | 2801 | */ |
2da40d21 | 2802 | public function _getFinancialItemAmount($contId) { |
6c6e6187 TO |
2803 | $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution')); |
2804 | $query = "SELECT | |
6a488035 TO |
2805 | SUM(amount) |
2806 | FROM civicrm_financial_item | |
2807 | WHERE entity_table = 'civicrm_line_item' | |
2808 | AND entity_id = {$lineItem}"; | |
6c6e6187 TO |
2809 | $result = CRM_Core_DAO::singleValueQuery($query); |
2810 | return $result; | |
2811 | } | |
6a488035 | 2812 | |
4cbe18b8 | 2813 | /** |
100fef9d | 2814 | * @param int $contId |
4cbe18b8 EM |
2815 | * @param $context |
2816 | */ | |
00be9182 | 2817 | public function _checkFinancialItem($contId, $context) { |
6c6e6187 TO |
2818 | if ($context != 'paylater') { |
2819 | $params = array( | |
5896d037 TO |
2820 | 'entity_id' => $contId, |
2821 | 'entity_table' => 'civicrm_contribution', | |
6c6e6187 TO |
2822 | ); |
2823 | $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params, TRUE)); | |
2824 | $entityParams = array( | |
6a488035 TO |
2825 | 'financial_trxn_id' => $trxn['financial_trxn_id'], |
2826 | 'entity_table' => 'civicrm_financial_item', | |
6c6e6187 TO |
2827 | ); |
2828 | $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); | |
2829 | $params = array( | |
6a488035 | 2830 | 'id' => $entityTrxn['entity_id'], |
6c6e6187 TO |
2831 | ); |
2832 | } | |
2833 | if ($context == 'paylater') { | |
2834 | $lineItems = CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'); | |
2835 | foreach ($lineItems as $key => $item) { | |
2836 | $params = array( | |
5896d037 TO |
2837 | 'entity_id' => $key, |
2838 | 'entity_table' => 'civicrm_line_item', | |
6c6e6187 TO |
2839 | ); |
2840 | $compareParams = array('status_id' => 1); | |
2841 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); | |
2842 | } | |
2843 | } | |
2844 | elseif ($context == 'refund') { | |
2845 | $compareParams = array( | |
5896d037 TO |
2846 | 'status_id' => 1, |
2847 | 'financial_account_id' => 1, | |
2848 | 'amount' => -100, | |
6c6e6187 TO |
2849 | ); |
2850 | } | |
2851 | elseif ($context == 'cancelPending') { | |
2852 | $compareParams = array( | |
5896d037 TO |
2853 | 'status_id' => 3, |
2854 | 'financial_account_id' => 1, | |
2855 | 'amount' => -100, | |
6c6e6187 TO |
2856 | ); |
2857 | } | |
2858 | elseif ($context == 'changeFinancial') { | |
2859 | $lineKey = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution')); | |
2860 | $params = array( | |
5896d037 TO |
2861 | 'entity_id' => $lineKey, |
2862 | 'amount' => -100, | |
6c6e6187 TO |
2863 | ); |
2864 | $compareParams = array( | |
5896d037 | 2865 | 'financial_account_id' => 1, |
6c6e6187 TO |
2866 | ); |
2867 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); | |
2868 | $params = array( | |
5896d037 TO |
2869 | 'financial_account_id' => 3, |
2870 | 'entity_id' => $lineKey, | |
6c6e6187 TO |
2871 | ); |
2872 | $compareParams = array( | |
5896d037 | 2873 | 'amount' => 100, |
6c6e6187 TO |
2874 | ); |
2875 | } | |
2876 | if ($context != 'paylater') { | |
2877 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); | |
2878 | } | |
2879 | } | |
6a488035 | 2880 | |
4cbe18b8 | 2881 | /** |
52da5b1e | 2882 | * Check financial transaction. |
2883 | * | |
2884 | * @todo break this down into sensible functions - most calls to it only use a few lines out of the big if. | |
2885 | * | |
4ff927bc | 2886 | * @param array $contribution |
2887 | * @param string $context | |
100fef9d | 2888 | * @param int $instrumentId |
52da5b1e | 2889 | * @param array $extraParams |
4cbe18b8 | 2890 | */ |
797d4c52 | 2891 | public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) { |
6c6e6187 | 2892 | $trxnParams = array( |
5896d037 TO |
2893 | 'entity_id' => $contribution['id'], |
2894 | 'entity_table' => 'civicrm_contribution', | |
6c6e6187 TO |
2895 | ); |
2896 | $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, TRUE)); | |
2897 | $params = array( | |
5896d037 | 2898 | 'id' => $trxn['financial_trxn_id'], |
6c6e6187 TO |
2899 | ); |
2900 | if ($context == 'payLater') { | |
2901 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); | |
2902 | $compareParams = array( | |
5896d037 TO |
2903 | 'status_id' => 1, |
2904 | 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId), | |
6c6e6187 TO |
2905 | ); |
2906 | } | |
2907 | elseif ($context == 'refund') { | |
2908 | $compareParams = array( | |
5896d037 TO |
2909 | 'to_financial_account_id' => 6, |
2910 | 'total_amount' => -100, | |
2911 | 'status_id' => 7, | |
b7990bb6 | 2912 | 'trxn_date' => '2015-01-01 09:00:00', |
797d4c52 | 2913 | 'trxn_id' => 'the refund', |
6c6e6187 TO |
2914 | ); |
2915 | } | |
2916 | elseif ($context == 'cancelPending') { | |
2917 | $compareParams = array( | |
ed4d0aea | 2918 | 'to_financial_account_id' => 7, |
5896d037 TO |
2919 | 'total_amount' => -100, |
2920 | 'status_id' => 3, | |
6c6e6187 TO |
2921 | ); |
2922 | } | |
2923 | elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') { | |
2924 | $entityParams = array( | |
5896d037 TO |
2925 | 'entity_id' => $contribution['id'], |
2926 | 'entity_table' => 'civicrm_contribution', | |
2927 | 'amount' => -100, | |
6c6e6187 TO |
2928 | ); |
2929 | $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); | |
2930 | $trxnParams1 = array( | |
6a488035 | 2931 | 'id' => $trxn['financial_trxn_id'], |
6c6e6187 | 2932 | ); |
122250ec SL |
2933 | if (empty($extraParams)) { |
2934 | $compareParams = array( | |
2935 | 'total_amount' => -100, | |
2936 | 'status_id' => 1, | |
2937 | ); | |
2938 | } | |
2939 | else { | |
2940 | $compareParams = array( | |
2941 | 'total_amount' => 100, | |
2942 | 'status_id' => 1, | |
2943 | ); | |
2944 | } | |
6c6e6187 TO |
2945 | if ($context == 'paymentInstrument') { |
2946 | $compareParams += array( | |
5896d037 TO |
2947 | 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4), |
2948 | 'payment_instrument_id' => 4, | |
6c6e6187 TO |
2949 | ); |
2950 | } | |
2951 | else { | |
2952 | $compareParams['to_financial_account_id'] = 12; | |
2953 | } | |
797d4c52 | 2954 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams)); |
6c6e6187 TO |
2955 | $compareParams['total_amount'] = 100; |
2956 | if ($context == 'paymentInstrument') { | |
2957 | $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId); | |
2958 | $compareParams['payment_instrument_id'] = $instrumentId; | |
2959 | } | |
2960 | else { | |
2961 | $compareParams['to_financial_account_id'] = 12; | |
2962 | } | |
2963 | } | |
2964 | ||
797d4c52 | 2965 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams)); |
6c6e6187 | 2966 | } |
6a488035 | 2967 | |
4cbe18b8 EM |
2968 | /** |
2969 | * @return mixed | |
2970 | */ | |
5896d037 | 2971 | public function _addPaymentInstrument() { |
6c6e6187 TO |
2972 | $gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name'); |
2973 | $optionParams = array( | |
5896d037 TO |
2974 | 'option_group_id' => $gId, |
2975 | 'label' => 'Test Card', | |
2976 | 'name' => 'Test Card', | |
2977 | 'value' => '6', | |
2978 | 'weight' => '6', | |
2979 | 'is_active' => 1, | |
6c6e6187 TO |
2980 | ); |
2981 | $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams); | |
2982 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); | |
2983 | $financialParams = array( | |
5896d037 TO |
2984 | 'entity_table' => 'civicrm_option_value', |
2985 | 'entity_id' => $optionValue['id'], | |
2986 | 'account_relationship' => $relationTypeId, | |
2987 | 'financial_account_id' => 7, | |
6c6e6187 TO |
2988 | ); |
2989 | CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, CRM_Core_DAO::$_nullArray); | |
2990 | $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']); | |
2991 | return $optionValue['values'][$optionValue['id']]['value']; | |
2992 | } | |
6a488035 | 2993 | |
3c49d90c | 2994 | /** |
2995 | * Set up the basic recurring contribution for tests. | |
2996 | * | |
2997 | * @param array $generalParams | |
2998 | * Parameters that can be merged into the recurring AND the contribution. | |
7f4ef731 | 2999 | * |
3000 | * @param array $recurParams | |
3001 | * Parameters to merge into the recur only. | |
3c49d90c | 3002 | * |
3003 | * @return array|int | |
3004 | */ | |
7f4ef731 | 3005 | protected function setUpRecurringContribution($generalParams = array(), $recurParams = array()) { |
3c49d90c | 3006 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( |
3007 | 'contact_id' => $this->_individualId, | |
3008 | 'installments' => '12', | |
3009 | 'frequency_interval' => '1', | |
3010 | 'amount' => '100', | |
3011 | 'contribution_status_id' => 1, | |
3012 | 'start_date' => '2012-01-01 00:00:00', | |
3013 | 'currency' => 'USD', | |
3014 | 'frequency_unit' => 'month', | |
3015 | 'payment_processor_id' => $this->paymentProcessorID, | |
7f4ef731 | 3016 | ), $generalParams, $recurParams)); |
3c49d90c | 3017 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( |
3018 | $this->_params, | |
3019 | array( | |
3020 | 'contribution_recur_id' => $contributionRecur['id'], | |
3021 | ), $generalParams) | |
3022 | ); | |
3023 | return $originalContribution; | |
3024 | } | |
3025 | ||
893a550c | 3026 | /** |
3027 | * Set up a repeat transaction. | |
3028 | * | |
3029 | * @param array $recurParams | |
3030 | * | |
3031 | * @return array | |
3032 | */ | |
0e6ccb2e | 3033 | protected function setUpRepeatTransaction($recurParams = array(), $flag) { |
893a550c | 3034 | $paymentProcessorID = $this->paymentProcessorCreate(); |
3035 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( | |
3036 | 'contact_id' => $this->_individualId, | |
3037 | 'installments' => '12', | |
3038 | 'frequency_interval' => '1', | |
3039 | 'amount' => '500', | |
3040 | 'contribution_status_id' => 1, | |
3041 | 'start_date' => '2012-01-01 00:00:00', | |
3042 | 'currency' => 'USD', | |
3043 | 'frequency_unit' => 'month', | |
3044 | 'payment_processor_id' => $paymentProcessorID, | |
3045 | ), $recurParams)); | |
0e6ccb2e | 3046 | |
7150b1c8 | 3047 | $originalContribution = ''; |
0e6ccb2e | 3048 | if ($flag == 'multiple') { |
7150b1c8 | 3049 | // CRM-19309 create a contribution + also add in line_items (plural): |
0e6ccb2e K |
3050 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( |
3051 | $this->_params, | |
3052 | array( | |
3053 | 'contribution_recur_id' => $contributionRecur['id'], | |
3054 | 'skipLineItem' => 1, | |
3055 | 'api.line_item.create' => array( | |
3056 | array( | |
3057 | 'price_field_id' => 1, | |
3058 | 'qty' => 2, | |
3059 | 'line_total' => '20', | |
3060 | 'unit_price' => '10', | |
3061 | 'financial_type_id' => 1, | |
3062 | ), | |
3063 | array( | |
3064 | 'price_field_id' => 1, | |
3065 | 'qty' => 1, | |
3066 | 'line_total' => '80', | |
3067 | 'unit_price' => '80', | |
3068 | 'financial_type_id' => 2, | |
3069 | ), | |
3070 | ), | |
3071 | ) | |
3072 | ) | |
3073 | ); | |
3074 | } | |
3075 | elseif ($flag == 'single') { | |
3076 | $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge( | |
3077 | $this->_params, | |
3078 | array('contribution_recur_id' => $contributionRecur['id'])) | |
3079 | ); | |
3080 | } | |
3081 | ||
893a550c | 3082 | return $originalContribution; |
3083 | } | |
3084 | ||
ec7e3954 E |
3085 | /** |
3086 | * Common set up routine. | |
3087 | * | |
3088 | * @return array | |
3089 | */ | |
3090 | protected function setUpForCompleteTransaction() { | |
3091 | $this->mut = new CiviMailUtils($this, TRUE); | |
3092 | $this->createLoggedInUser(); | |
3093 | $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); | |
3094 | $contribution = $this->callAPISuccess('contribution', 'create', $params); | |
3095 | return $contribution; | |
3096 | } | |
3097 | ||
6a488035 | 3098 | } |