Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 TO |
27 | |
28 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
30 | |
31 | /** | |
32 | * Class CRM_Core_Payment_BaseIPNTest | |
33 | */ | |
6a488035 | 34 | class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { |
00e3870f | 35 | |
6a488035 TO |
36 | protected $_contributionTypeId; |
37 | protected $_contributionParams; | |
38 | protected $_contactId; | |
39 | protected $_contributionId; | |
40 | protected $_participantId; | |
41 | protected $_pledgeId; | |
42 | protected $_eventId; | |
43 | protected $_processorId; | |
44 | protected $_contributionRecurParams; | |
45 | protected $_paymentProcessor; | |
46 | protected $IPN; | |
47 | protected $_recurId; | |
48 | protected $_membershipId; | |
49 | protected $input; | |
50 | protected $ids; | |
51 | protected $objects; | |
430ae6dd TO |
52 | public $DBResetRequired = FALSE; |
53 | ||
00be9182 | 54 | public function setUp() { |
6a488035 TO |
55 | parent::setUp(); |
56 | $this->input = $this->ids = $this->objects = array(); | |
0dbefed3 | 57 | $this->IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->input); |
6a488035 TO |
58 | |
59 | $this->_contactId = $this->individualCreate(); | |
60 | $this->ids['contact'] = $this->_contactId; | |
61 | $this->paymentProcessor = new CRM_Financial_BAO_PaymentProcessor(); | |
62 | ||
63 | $paymentProcessorParams = array( | |
64 | 'user_name' => 'user_name', | |
65 | 'password' => 'password', | |
66 | 'url_recur' => 'url_recur', | |
cc0c30cc E |
67 | //@todo - if we used the api then we could pass in 'AuthNet & the api will resolve |
68 | // (as least it will once the pseudoconstant s in the schema) | |
69 | 'payment_processor_type_id' => $this->callAPISuccess('payment_processor_type', 'getvalue', array( | |
70 | 'return' => 'id', | |
21dfd5f5 | 71 | 'name' => 'AuthNet', |
cc0c30cc | 72 | )), |
6a488035 TO |
73 | ); |
74 | ||
6a488035 TO |
75 | $paymentProcessorParams['domain_id'] = 1; |
76 | $paymentProcessorParams['is_active'] = 1; | |
77 | $paymentProcessorParams['is_test'] = 1; | |
78 | $paymentProcessorParams['billing_mode'] = 1; | |
79 | $paymentProcessorParams['class_name'] = "Payment_AuthorizeNet"; | |
80 | $processorEntity = $this->paymentProcessor->create($paymentProcessorParams); | |
81 | ||
82 | $this->_processorId = $processorEntity->id; | |
83 | $this->_contributionTypeId = 1; | |
84 | ||
85 | $this->_contributionParams = array( | |
86 | 'contact_id' => $this->_contactId, | |
87 | 'version' => 3, | |
92915c55 | 88 | 'financial_type_id' => $this->_contributionTypeId, |
6a488035 TO |
89 | 'recieve_date' => date('Ymd'), |
90 | 'total_amount' => 150.00, | |
91 | 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885', | |
92 | 'currency' => 'USD', | |
93 | 'contribution_recur_id' => $this->_recurId, | |
94 | 'is_test' => 1, | |
95 | 'contribution_status_id' => 2, | |
96 | ); | |
97 | $contribution = civicrm_api('contribution', 'create', $this->_contributionParams); | |
98 | $this->assertAPISuccess($contribution, 'line ' . __LINE__ . ' set-up of contribution '); | |
99 | $this->_contributionId = $contribution['id']; | |
100 | ||
101 | $contribution = new CRM_Contribute_BAO_Contribution(); | |
102 | $contribution->id = $this->_contributionId; | |
92915c55 | 103 | $contribution->find(TRUE); |
6a488035 TO |
104 | $this->objects['contribution'] = $contribution; |
105 | } | |
106 | ||
00be9182 | 107 | public function tearDown() { |
b38530f2 | 108 | $this->quickCleanUpFinancialEntities(); |
cc0c30cc | 109 | CRM_Member_PseudoConstant::membershipType(NULL, TRUE); |
6a488035 TO |
110 | CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE); |
111 | } | |
112 | ||
113 | /** | |
eceb18cc | 114 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 115 | */ |
00be9182 | 116 | public function testLoadMembershipObjects() { |
6a488035 TO |
117 | $this->_setUpMembershipObjects(); |
118 | $this->_setUpRecurringContribution(); | |
119 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); | |
120 | $this->assertFalse(empty($this->objects['membership']), 'in line ' . __LINE__); | |
121 | $this->assertArrayHasKey($this->_membershipTypeID, $this->objects['membership'], 'in line ' . __LINE__); | |
122 | $this->assertTrue(is_a($this->objects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership')); | |
92915c55 | 123 | $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType')); |
6a488035 TO |
124 | $this->assertFalse(empty($this->objects['contributionRecur']), __LINE__); |
125 | $this->assertFalse(empty($this->objects['paymentProcessor']), __LINE__); | |
126 | } | |
92915c55 | 127 | |
6a488035 | 128 | /** |
eceb18cc | 129 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 130 | */ |
00be9182 | 131 | public function testLoadMembershipObjectsLoadAll() { |
6a488035 TO |
132 | $this->_setUpMembershipObjects(); |
133 | $this->_setUpRecurringContribution(); | |
134 | unset($this->ids['membership']); | |
135 | $contribution = new CRM_Contribute_BAO_Contribution(); | |
136 | $contribution->id = $this->_contributionId; | |
92915c55 TO |
137 | $contribution->find(TRUE); |
138 | $contribution->loadRelatedObjects($this->input, $this->ids, FALSE, TRUE); | |
6a488035 TO |
139 | $this->assertFalse(empty($contribution->_relatedObjects['membership']), 'in line ' . __LINE__); |
140 | $this->assertArrayHasKey($this->_membershipTypeID, $contribution->_relatedObjects['membership'], 'in line ' . __LINE__); | |
141 | $this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership')); | |
142 | $this->assertTrue(is_a($contribution->_relatedObjects['contributionType'], 'CRM_Financial_BAO_FinancialType')); | |
143 | $this->assertFalse(empty($contribution->_relatedObjects['contributionRecur']), __LINE__); | |
144 | $this->assertFalse(empty($contribution->_relatedObjects['paymentProcessor']), __LINE__); | |
145 | } | |
92915c55 | 146 | |
6a488035 | 147 | /** |
eceb18cc | 148 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 149 | */ |
00be9182 | 150 | public function testsendMailMembershipObjects() { |
6a488035 TO |
151 | $this->_setUpMembershipObjects(); |
152 | $values = array(); | |
153 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); | |
154 | $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); | |
155 | $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__); | |
156 | $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); | |
157 | $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']); | |
158 | $this->assertContains('Membership Type: General', $msg['body']); | |
159 | } | |
160 | ||
161 | /** | |
eceb18cc | 162 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 163 | */ |
00be9182 | 164 | public function testsendMailMembershipWithoutLoadObjects() { |
6a488035 TO |
165 | $this->_setUpMembershipObjects(); |
166 | $values = array(); | |
167 | $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); | |
168 | $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__); | |
169 | $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); | |
170 | $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']); | |
171 | $this->assertContains('Membership Type: General', $msg['body']); | |
172 | } | |
c490a46a CW |
173 | |
174 | /** | |
eceb18cc | 175 | * Test that loadObjects works with participant values. |
c490a46a | 176 | */ |
00be9182 | 177 | public function testLoadParticipantObjects() { |
6a488035 TO |
178 | $this->_setUpParticipantObjects(); |
179 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); | |
180 | $this->assertFalse(empty($this->objects['participant']), 'in line ' . __LINE__); | |
181 | $this->assertTrue(is_a($this->objects['participant'], 'CRM_Event_BAO_Participant')); | |
92915c55 | 182 | $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType')); |
6a488035 TO |
183 | $this->assertFalse(empty($this->objects['event'])); |
184 | $this->assertTrue(is_a($this->objects['event'], 'CRM_Event_BAO_Event')); | |
185 | $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution')); | |
186 | $this->assertFalse(empty($this->objects['event']->id)); | |
187 | } | |
188 | ||
189 | /** | |
eceb18cc | 190 | * Test the LoadObjects function with a participant. |
6a488035 | 191 | */ |
00be9182 | 192 | public function testComposeMailParticipant() { |
6a488035 TO |
193 | $this->_setUpParticipantObjects(); |
194 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); | |
195 | $values = array(); | |
196 | $this->assertFalse(empty($this->objects['event'])); | |
92915c55 | 197 | $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); |
afc59fef | 198 | $this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']); |
6a488035 TO |
199 | $this->assertContains('Annual CiviCRM meet', $msg['html']); |
200 | } | |
201 | ||
202 | /** | |
6a488035 | 203 | */ |
00be9182 | 204 | public function testComposeMailParticipantObjects() { |
6a488035 TO |
205 | $this->_setUpParticipantObjects(); |
206 | $values = array(); | |
207 | $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); | |
208 | $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__); | |
209 | $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); | |
210 | $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']); | |
211 | $this->assertContains('Thank you for your participation', $msg['body']); | |
212 | } | |
213 | ||
214 | /** | |
eceb18cc | 215 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 216 | */ |
00be9182 | 217 | public function testsendMailParticipantObjectsCheckLog() { |
6a488035 TO |
218 | $this->_setUpParticipantObjects(); |
219 | $values = array(); | |
220 | require_once 'CiviTest/CiviMailUtils.php'; | |
92915c55 | 221 | $mut = new CiviMailUtils($this, TRUE); |
6a488035 TO |
222 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); |
223 | $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE); | |
224 | $mut->checkMailLog(array( | |
92915c55 TO |
225 | 'Thank you for your participation', |
226 | 'Annual CiviCRM meet', | |
af9b09df | 227 | 'Mr. Anthony Anderson II', |
92915c55 | 228 | ) |
6a488035 TO |
229 | ); |
230 | $mut->stop(); | |
231 | } | |
c490a46a | 232 | |
6a488035 | 233 | /** |
eceb18cc | 234 | * Test the LoadObjects function with recurring membership data. |
6a488035 | 235 | */ |
00be9182 | 236 | public function testsendMailParticipantObjectsNoMail() { |
6a488035 TO |
237 | $this->_setUpParticipantObjects(); |
238 | $event = new CRM_Event_BAO_Event(); | |
239 | $event->id = $this->_eventId; | |
240 | $event->is_email_confirm = FALSE; | |
241 | $event->save(); | |
242 | $values = array(); | |
243 | $tablesToTruncate = array( | |
244 | 'civicrm_mailing_spool', | |
245 | ); | |
246 | $this->quickCleanup($tablesToTruncate, FALSE); | |
247 | require_once 'CiviTest/CiviMailUtils.php'; | |
92915c55 | 248 | $mut = new CiviMailUtils($this, TRUE); |
6a488035 TO |
249 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); |
250 | $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE); | |
251 | $mut->assertMailLogEmpty('no mail should have been send as event set to no confirm'); | |
252 | $mut->stop(); | |
253 | } | |
254 | ||
c490a46a | 255 | /** |
eceb18cc | 256 | * Test that loadObjects works with participant values. |
c490a46a | 257 | */ |
00be9182 | 258 | public function testLoadPledgeObjects() { |
6a488035 TO |
259 | $this->_setUpPledgeObjects(); |
260 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); | |
261 | $this->assertFalse(empty($this->objects['pledge_payment'][0]), 'in line ' . __LINE__); | |
92915c55 | 262 | $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType')); |
6a488035 TO |
263 | $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution')); |
264 | $this->assertTrue(is_a($this->objects['pledge_payment'][0], 'CRM_Pledge_BAO_PledgePayment')); | |
265 | $this->assertFalse(empty($this->objects['pledge_payment'][0]->id)); | |
266 | $this->assertEquals($this->_contributionTypeId, $this->objects['contributionType']->id); | |
267 | $this->assertEquals($this->_processorId, $this->objects['paymentProcessor']['id']); | |
268 | $this->assertEquals($this->_contributionId, $this->objects['contribution']->id); | |
269 | $this->assertEquals($this->_contactId, $this->objects['contact']->id); | |
270 | $this->assertEquals($this->_pledgeId, $this->objects['pledge_payment'][0]->pledge_id); | |
271 | } | |
272 | ||
c490a46a | 273 | /** |
eceb18cc | 274 | * Test that loadObjects works with participant values. |
c490a46a | 275 | */ |
00be9182 | 276 | public function testLoadPledgeObjectsInvalidPledgeID() { |
6a488035 TO |
277 | $this->_setUpPledgeObjects(); |
278 | $this->ids['pledge_payment'][0] = 0; | |
279 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
280 | $this->assertArrayHasKey('error_message', $result); | |
281 | $this->assertArrayNotHasKey('pledge_payment', $this->objects); | |
282 | $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); | |
283 | $this->ids['pledge_payment'][0] = NULL; | |
284 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
285 | $this->assertArrayHasKey('error_message', $result); | |
286 | $this->assertArrayNotHasKey('pledge_payment', $this->objects); | |
287 | $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); | |
288 | $this->ids['pledge_payment'][0] = ''; | |
289 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
290 | $this->assertArrayHasKey('error_message', $result); | |
291 | $this->assertArrayNotHasKey('pledge_payment', $this->objects); | |
292 | $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); | |
293 | ||
6a488035 TO |
294 | $this->ids['pledge_payment'][0] = 999; |
295 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, array('return_error' => 1)); | |
296 | $this->assertArrayHasKey('error_message', $result); | |
297 | $this->assertEquals('Could not find pledge payment record: 999', $result['error_message']); | |
298 | } | |
299 | ||
300 | /** | |
eceb18cc | 301 | * Test the LoadObjects function with a pledge. |
6a488035 | 302 | */ |
00be9182 | 303 | public function testsendMailPledge() { |
6a488035 TO |
304 | $this->_setUpPledgeObjects(); |
305 | $values = array(); | |
306 | $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL); | |
307 | $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); | |
308 | $this->assertContains('Contribution Information', $msg['html']); | |
309 | } | |
310 | ||
311 | /** | |
312 | * Test that an error is returned if required set & no contribution page | |
6a488035 | 313 | */ |
00be9182 | 314 | public function testRequiredWithoutProcessorID() { |
6a488035 TO |
315 | $this->_setUpPledgeObjects(); |
316 | $values = array(); | |
317 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
318 | $this->assertArrayHasKey('error_message', $result); | |
319 | $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']); | |
320 | // error is only returned if $required set to True | |
321 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1)); | |
322 | $this->assertFalse(is_array($result)); | |
323 | //check that error is not returned if error checking not set | |
324 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1)); | |
325 | $this->assertFalse(is_array($result)); | |
326 | } | |
327 | ||
328 | /** | |
329 | * | |
330 | * Test that an error is not if required set & no processor ID | |
331 | */ | |
00be9182 | 332 | public function testRequiredWithContributionPage() { |
6a488035 TO |
333 | $this->_setUpContributionObjects(TRUE); |
334 | ||
335 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
336 | $this->assertFalse(is_array($result), $result['error_message']); | |
337 | } | |
338 | ||
339 | /** | |
340 | * Test that an error is returned if required set & contribution page exists | |
6a488035 | 341 | */ |
00be9182 | 342 | public function testRequiredWithContributionPageError() { |
6a488035 TO |
343 | $this->_setUpContributionObjects(); |
344 | $values = array(); | |
345 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)); | |
346 | $this->assertArrayHasKey('error_message', $result); | |
347 | $this->assertEquals('Could not find contribution page for contribution record: 1', $result['error_message']); | |
348 | // error is only returned if $required set to True | |
349 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1)); | |
350 | $this->assertFalse(is_array($result)); | |
351 | //check that error is not returned if error checking not set | |
352 | $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1)); | |
353 | $this->assertFalse(is_array($result)); | |
354 | } | |
355 | ||
e70a7fc0 | 356 | /* @codingStandardsIgnoreStart |
6a488035 TO |
357 | * Test calls main functions in sequence per 'main' - I had hoped to test the functions more |
358 | * fully but the calls to the POST happen in more than one function | |
359 | * keeping this as good example of data to bring back to life later | |
360 | ||
9b873358 | 361 | public function testMainFunctionActions() { |
6a488035 TO |
362 | $ids = $objects = array( ); |
363 | $input['component'] = 'Contribute'; | |
364 | $postedParams = array( | |
365 | 'x_response_code' => 1, | |
366 | 'x_response_reason_code' => 1, | |
367 | 'x_response_reason_text' => 'This transaction has been approved.', | |
368 | 'x_avs_code' => 'Y', | |
369 | 'x_auth_code' => 140454, | |
370 | 'x_trans_id' => 4353599599, | |
371 | 'x_method' => 'CC', | |
372 | 'x_card_type' => 'American Express', | |
373 | 'x_account_number' => 'XXXX2701', | |
374 | 'x_first_name' => 'Arthur', | |
375 | 'x_last_name' => 'Jacobs', | |
376 | 'x_company' => null, | |
377 | 'x_address' => '866 2166th St SN', | |
378 | 'x_city' => 'Edwardstown', | |
379 | 'x_state' => 'WA', | |
380 | 'x_zip' => 98026, | |
381 | 'x_country' => 'US', | |
382 | 'x_phone' => null, | |
383 | 'x_fax' => null, | |
384 | 'x_email' => null, | |
385 | 'x_invoice_num' => 'a9fb56c24576lk4c9490f6', | |
386 | 'x_description' => 'my desc', | |
387 | 'x_type' => 'auth_capture', | |
388 | 'x_cust_id' => 5191, | |
389 | 'x_ship_to_first_name' => null, | |
390 | 'x_ship_to_last_name' => null, | |
391 | 'x_ship_to_company' => null, | |
392 | 'x_ship_to_address' => null, | |
393 | 'x_ship_to_city' => null, | |
394 | 'x_ship_to_state' => null, | |
395 | 'x_ship_to_zip' => null, | |
396 | 'x_ship_to_country' => null, | |
397 | 'x_amount' => 60.00, | |
398 | 'x_tax' => 0.00, | |
399 | 'x_duty' => 0.00, | |
400 | 'x_freight' => 0.00, | |
401 | 'x_tax_exempt' => FALSE, | |
402 | 'x_po_num' => null, | |
403 | 'x_MD5_Hash' => '069ECAD13C8E15AC205CDF92B8B58CC7', | |
404 | 'x_cvv2_resp_code' => null, | |
405 | 'x_cavv_response' => null, | |
406 | 'x_test_request' => false, | |
407 | 'description' => 'my description' | |
408 | ); | |
409 | $this->IPN->getInput( $input, $ids ); | |
410 | $this->IPN->getIDs( $ids, $input ); | |
411 | ||
412 | CRM_Core_Error::debug_var( '$ids', $ids ); | |
413 | CRM_Core_Error::debug_var( '$input', $input ); | |
414 | ||
415 | $paymentProcessorID = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_PaymentProcessorType', | |
416 | 'AuthNet', 'id', 'name' ); | |
417 | ||
418 | if ( ! $this->IPN->validateData( $input, $ids, $objects, true, $paymentProcessorID ) ) { | |
419 | return false; | |
420 | } | |
421 | ||
422 | if ( $component == 'contribute' && $ids['contributionRecur'] ) { | |
423 | // check if first contribution is completed, else complete first contribution | |
424 | $first = true; | |
425 | if ( $objects['contribution']->contribution_status_id == 1 ) { | |
426 | $first = false; | |
427 | } | |
428 | return $this->IPN->recur( $input, $ids, $objects, $first ); | |
429 | } | |
430 | } | |
e70a7fc0 | 431 | @codingStandardsIgnoreEnd */ |
6a488035 | 432 | |
4cbe18b8 | 433 | /** |
c490a46a CW |
434 | * Prepare for contribution Test - involving only contribution objects |
435 | * | |
4cbe18b8 EM |
436 | * @param bool $contributionPage |
437 | */ | |
00be9182 | 438 | public function _setUpContributionObjects($contributionPage = FALSE) { |
6a488035 | 439 | |
6a488035 TO |
440 | $contribution = new CRM_Contribute_BAO_Contribution(); |
441 | $contribution->id = $this->_contributionId; | |
442 | $contribution->find(TRUE); | |
cc0c30cc | 443 | $contributionPageID = NULL; |
6a488035 TO |
444 | if (!empty($contributionPage)) { |
445 | $dao = new CRM_Core_DAO(); | |
446 | $contribution_page = $dao->createTestObject('CRM_Contribute_DAO_ContributionPage'); | |
cc0c30cc | 447 | $contribution->contribution_page_id = $contributionPageID = $contribution_page->id; |
d5d148ab EM |
448 | //for unknown reasons trying to do a find & save on a contribution with a receive_date set |
449 | // doesn't work. This seems of minimal relevance to this test so ignoring | |
450 | // note that in tests it worked sometimes & not others - dependent on which other tests run. | |
451 | // running all CRM_Core tests caused failure as did just the single failing test. But running | |
452 | // just this class succeeds - because it actually doesn't do a mysql update on the following save | |
453 | // (unknown reason) | |
454 | unset($contribution->receive_date); | |
cc0c30cc | 455 | $contribution->save(); |
6a488035 TO |
456 | } |
457 | ||
458 | $this->objects['contribution'] = $contribution; | |
459 | $this->input = array( | |
460 | 'component' => 'contribute', | |
cc0c30cc | 461 | 'contribution_page_id' => $contributionPageID, |
6a488035 TO |
462 | 'total_amount' => 110.00, |
463 | 'invoiceID' => "c8acb91e080ad7777a2adc119c192885", | |
464 | 'contactID' => $this->_contactId, | |
465 | 'contributionID' => $this->objects['contribution']->id, | |
466 | ); | |
467 | } | |
468 | ||
c490a46a | 469 | /** |
eceb18cc | 470 | * Prepare for membership test. |
c490a46a | 471 | */ |
00be9182 | 472 | public function _setUpMembershipObjects() { |
6a488035 | 473 | try { |
c1135109 | 474 | $this->_membershipTypeID = $this->membershipTypeCreate(); |
6a488035 TO |
475 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
476 | } | |
92915c55 | 477 | catch (Exception$e) { |
6a488035 TO |
478 | echo $e->getMessage(); |
479 | } | |
480 | CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE); | |
481 | CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE); | |
482 | $this->_membershipParams = array( | |
483 | 'contact_id' => $this->_contactId, | |
484 | 'membership_type_id' => $this->_membershipTypeID, | |
485 | 'join_date' => '2009-01-21', | |
486 | 'start_date' => '2009-01-21', | |
487 | 'end_date' => '2009-12-21', | |
488 | 'source' => 'Payment', | |
489 | 'is_override' => 1, | |
490 | 'status_id' => $this->_membershipStatusID, | |
491 | 'version' => 3, | |
492 | ); | |
493 | ||
c1135109 | 494 | $membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams); |
6a488035 TO |
495 | |
496 | $this->_membershipId = $membership['id']; | |
497 | //we'll create membership payment here because to make setup more re-usable | |
498 | civicrm_api('membership_payment', 'create', array( | |
92915c55 TO |
499 | 'version' => 3, |
500 | 'contribution_id' => $this->_contributionId, | |
501 | 'membership_id' => $this->_membershipId, | |
502 | )); | |
6a488035 TO |
503 | |
504 | $contribution = new CRM_Contribute_BAO_Contribution(); | |
505 | $contribution->id = $this->_contributionId; | |
506 | $contribution->find(); | |
507 | $this->objects['contribution'] = $contribution; | |
508 | $this->input = array( | |
509 | 'component' => 'contribute', | |
510 | 'total_amount' => 150.00, | |
511 | 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", | |
512 | 'contactID' => $this->_contactId, | |
513 | 'contributionID' => $this->objects['contribution']->id, | |
514 | 'membershipID' => $this->_membershipId, | |
515 | ); | |
516 | ||
517 | $this->ids['membership'] = $this->_membershipId; | |
518 | } | |
519 | ||
00be9182 | 520 | public function _setUpRecurringContribution() { |
6a488035 TO |
521 | $this->_contributionRecurParams = array( |
522 | 'contact_id' => $this->_contactId, | |
523 | 'amount' => 150.00, | |
524 | 'currency' => 'USD', | |
525 | 'frequency_unit' => 'week', | |
526 | 'frequency_interval' => 1, | |
527 | 'installments' => 2, | |
528 | 'start_date' => date('Ymd'), | |
529 | 'create_date' => date('Ymd'), | |
530 | 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885', | |
531 | 'contribution_status_id' => 2, | |
532 | 'is_test' => 1, | |
92915c55 | 533 | 'financial_type_id' => $this->_contributionTypeId, |
6a488035 TO |
534 | 'version' => 3, |
535 | 'payment_processor_id' => $this->_processorId, | |
536 | ); | |
537 | $this->_recurId = civicrm_api('contribution_recur', 'create', $this->_contributionRecurParams); | |
538 | $this->assertAPISuccess($this->_recurId, 'line ' . __LINE__ . ' set-up of recurring contrib'); | |
539 | $this->_recurId = $this->_recurId['id']; | |
540 | $this->input['contributionRecurId'] = $this->_recurId; | |
541 | $this->ids['contributionRecur'] = $this->_recurId; | |
542 | } | |
543 | ||
c490a46a | 544 | /** |
eceb18cc | 545 | * Set up participant requirements for test. |
c490a46a | 546 | */ |
00be9182 | 547 | public function _setUpParticipantObjects() { |
6a488035 TO |
548 | $event = $this->eventCreate(array('is_email_confirm' => 1)); |
549 | $this->assertAPISuccess($event, 'line ' . __LINE__ . ' set-up of event'); | |
550 | $this->_eventId = $event['id']; | |
551 | $this->_participantId = $this->participantCreate(array( | |
92915c55 TO |
552 | 'event_id' => $this->_eventId, |
553 | 'contact_id' => $this->_contactId, | |
554 | )); | |
6a488035 TO |
555 | //we'll create membership payment here because to make setup more re-usable |
556 | $participantPayment = civicrm_api('participant_payment', 'create', array( | |
92915c55 TO |
557 | 'version' => 3, |
558 | 'contribution_id' => $this->_contributionId, | |
559 | 'participant_id' => $this->_participantId, | |
560 | )); | |
6a488035 TO |
561 | $this->assertAPISuccess($participantPayment, 'line ' . __LINE__ . ' set-up of event'); |
562 | $contribution = new CRM_Contribute_BAO_Contribution(); | |
563 | $contribution->id = $this->_contributionId; | |
564 | $contribution->find(); | |
565 | $this->objects['contribution'] = $contribution; | |
566 | $this->input = array( | |
567 | 'component' => 'event', | |
568 | 'total_amount' => 150.00, | |
569 | 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", | |
570 | 'contactID' => $this->_contactId, | |
571 | 'contributionID' => $contribution->id, | |
572 | 'participantID' => $this->_participantId, | |
573 | ); | |
574 | ||
575 | $this->ids['participant'] = $this->_participantId; | |
576 | $this->ids['event'] = $this->_eventId; | |
577 | } | |
578 | ||
c490a46a | 579 | /** |
eceb18cc | 580 | * Set up participant requirements for test. |
c490a46a | 581 | */ |
00be9182 | 582 | public function _setUpPledgeObjects() { |
6a488035 TO |
583 | $this->_pledgeId = $this->pledgeCreate($this->_contactId); |
584 | //we'll create membership payment here because to make setup more re-usable | |
585 | $pledgePayment = civicrm_api('pledge_payment', 'create', array( | |
92915c55 TO |
586 | 'version' => 3, |
587 | 'pledge_id' => $this->_pledgeId, | |
588 | 'contribution_id' => $this->_contributionId, | |
589 | 'status_id' => 1, | |
590 | 'actual_amount' => 50, | |
591 | )); | |
6a488035 TO |
592 | $this->assertAPISuccess($pledgePayment, 'line ' . __LINE__ . ' set-up of pledge payment'); |
593 | $this->input = array( | |
594 | 'component' => 'contribute', | |
595 | 'total_amount' => 150.00, | |
596 | 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", | |
597 | 'contactID' => $this->_contactId, | |
598 | 'contributionID' => $this->_contributionId, | |
599 | 'pledgeID' => $this->_pledgeId, | |
600 | ); | |
601 | ||
602 | $this->ids['pledge_payment'][] = $pledgePayment['id']; | |
603 | } | |
96025800 | 604 | |
6a488035 | 605 | } |