Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test APIv3 civicrm_contribute_recur* functions | |
33 | * | |
6c6e6187 TO |
34 | * @package CiviCRM_APIv3 |
35 | * @subpackage API_Contribution | |
6a488035 | 36 | */ |
6a488035 TO |
37 | class api_v3_ContributionPageTest extends CiviUnitTestCase { |
38 | protected $_apiversion = 3; | |
39 | protected $testAmount = 34567; | |
40 | protected $params; | |
41 | protected $id = 0; | |
42 | protected $contactIds = array(); | |
43 | protected $_entity = 'contribution_page'; | |
6c6e6187 | 44 | protected $contribution_result = NULL; |
f64a217a | 45 | protected $_priceSetParams = array(); |
f8fe0df6 | 46 | /** |
eceb18cc | 47 | * Payment processor details. |
f8fe0df6 | 48 | * @var array |
49 | */ | |
50 | protected $_paymentProcessor = array(); | |
f64a217a EM |
51 | |
52 | /** | |
53 | * @var array | |
16b10e64 CW |
54 | * - contribution_page |
55 | * - price_set | |
56 | * - price_field | |
57 | * - price_field_value | |
f64a217a EM |
58 | */ |
59 | protected $_ids = array(); | |
60 | ||
b7c9bc4c | 61 | |
6a488035 | 62 | public $DBResetRequired = TRUE; |
5896d037 | 63 | |
6a488035 TO |
64 | public function setUp() { |
65 | parent::setUp(); | |
66 | $this->contactIds[] = $this->individualCreate(); | |
67 | $this->params = array( | |
6a488035 TO |
68 | 'title' => "Test Contribution Page", |
69 | 'financial_type_id' => 1, | |
70 | 'currency' => 'NZD', | |
71 | 'goal_amount' => $this->testAmount, | |
6cdac50b | 72 | 'is_pay_later' => 1, |
f64a217a EM |
73 | 'is_monetary' => TRUE, |
74 | ); | |
75 | ||
76 | $this->_priceSetParams = array( | |
77 | 'is_quick_config' => 1, | |
78 | 'extends' => 'CiviContribute', | |
79 | 'financial_type_id' => 'Donation', | |
21dfd5f5 | 80 | 'title' => 'my Page', |
6a488035 TO |
81 | ); |
82 | } | |
83 | ||
00be9182 | 84 | public function tearDown() { |
6a488035 | 85 | foreach ($this->contactIds as $id) { |
fc928539 | 86 | $this->callAPISuccess('contact', 'delete', array('id' => $id)); |
611c7ece | 87 | } |
f9342903 | 88 | $this->quickCleanUpFinancialEntities(); |
6a488035 TO |
89 | } |
90 | ||
91 | public function testCreateContributionPage() { | |
fc928539 | 92 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__); |
93 | $this->assertEquals(1, $result['count']); | |
94 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
95 | $this->getAndCheck($this->params, $result['id'], $this->_entity); |
96 | } | |
97 | ||
98 | public function testGetBasicContributionPage() { | |
fc928539 | 99 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
6a488035 | 100 | $this->id = $createResult['id']; |
6a488035 | 101 | $getParams = array( |
6a488035 TO |
102 | 'currency' => 'NZD', |
103 | 'financial_type_id' => 1, | |
104 | ); | |
fc928539 | 105 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
106 | $this->assertEquals(1, $getResult['count']); | |
6a488035 TO |
107 | } |
108 | ||
109 | public function testGetContributionPageByAmount() { | |
fc928539 | 110 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
6a488035 | 111 | $this->id = $createResult['id']; |
6a488035 | 112 | $getParams = array( |
5896d037 | 113 | 'amount' => '' . $this->testAmount, // 3456 |
6a488035 TO |
114 | 'currency' => 'NZD', |
115 | 'financial_type_id' => 1, | |
116 | ); | |
fc928539 | 117 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
118 | $this->assertEquals(1, $getResult['count']); | |
6a488035 TO |
119 | } |
120 | ||
121 | public function testDeleteContributionPage() { | |
fc928539 | 122 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
123 | $deleteParams = array('id' => $createResult['id']); | |
611c7ece | 124 | $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
fc928539 | 125 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); |
126 | $this->assertEquals(0, $checkDeleted['count']); | |
6a488035 TO |
127 | } |
128 | ||
129 | public function testGetFieldsContributionPage() { | |
fc928539 | 130 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
131 | $this->assertEquals(12, $result['values']['start_date']['type']); |
132 | } | |
133 | ||
be26f3e0 | 134 | |
d58b453e | 135 | /** |
eceb18cc | 136 | * Test form submission with basic price set. |
d58b453e | 137 | */ |
be26f3e0 | 138 | public function testSubmit() { |
f64a217a EM |
139 | $this->setUpContributionPage(); |
140 | $priceFieldID = reset($this->_ids['price_field']); | |
141 | $priceFieldValueID = reset($this->_ids['price_field_value']); | |
142 | $submitParams = array( | |
143 | 'price_' . $priceFieldID => $priceFieldValueID, | |
144 | 'id' => (int) $this->_ids['contribution_page'], | |
21dfd5f5 | 145 | 'amount' => 10, |
be26f3e0 EM |
146 | ); |
147 | ||
f64a217a EM |
148 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); |
149 | $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); | |
150 | } | |
5896d037 | 151 | |
7bc789a5 | 152 | /** |
153 | * Test process with instant payment when more than one configured for the page. | |
154 | * | |
155 | * CRM-16923 | |
156 | */ | |
157 | public function testSubmitRecurMultiProcessorInstantPayment() { | |
158 | $this->setUpContributionPage(); | |
159 | $this->setupPaymentProcessor(); | |
d27635dc | 160 | $paymentProcessor2ID = $this->paymentProcessorCreate(array( |
7bc789a5 | 161 | 'payment_processor_type_id' => 'Dummy', |
162 | 'name' => 'processor 2', | |
163 | 'class_name' => 'Payment_Dummy', | |
164 | 'billing_mode' => 1, | |
165 | )); | |
166 | $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID); | |
70cc8754 | 167 | $dummyPP->setDoDirectPaymentResult(array( |
168 | 'payment_status_id' => 1, | |
169 | 'trxn_id' => 'create_first_success', | |
170 | 'fee_amount' => .85, | |
171 | )); | |
7bc789a5 | 172 | $this->callAPISuccess('ContributionPage', 'create', array( |
d27635dc | 173 | 'id' => $this->_ids['contribution_page'], |
174 | 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']), | |
7bc789a5 | 175 | )); |
176 | ||
177 | $priceFieldID = reset($this->_ids['price_field']); | |
178 | $priceFieldValueID = reset($this->_ids['price_field_value']); | |
179 | $submitParams = array( | |
180 | 'price_' . $priceFieldID => $priceFieldValueID, | |
181 | 'id' => (int) $this->_ids['contribution_page'], | |
182 | 'amount' => 10, | |
183 | 'is_recur' => 1, | |
184 | 'frequency_interval' => 1, | |
185 | 'frequency_unit' => 'month', | |
186 | 'payment_processor_id' => $paymentProcessor2ID, | |
187 | ); | |
188 | ||
189 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); | |
70cc8754 | 190 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
7bc789a5 | 191 | 'contribution_page_id' => $this->_ids['contribution_page'], |
192 | 'contribution_status_id' => 1, | |
193 | )); | |
70cc8754 | 194 | $this->assertEquals('create_first_success', $contribution['trxn_id']); |
195 | $this->assertEquals(10, $contribution['total_amount']); | |
196 | $this->assertEquals(.85, $contribution['fee_amount']); | |
197 | $this->assertEquals(9.15, $contribution['net_amount']); | |
7bc789a5 | 198 | } |
70cc8754 | 199 | |
f64a217a | 200 | /** |
eceb18cc | 201 | * Test submit with a membership block in place. |
f64a217a | 202 | */ |
f9342903 EM |
203 | public function testSubmitMembershipBlockNotSeparatePayment() { |
204 | $this->setUpMembershipContributionPage(); | |
f64a217a | 205 | $submitParams = array( |
3e28c791 | 206 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), |
f9342903 | 207 | 'id' => (int) $this->_ids['contribution_page'], |
f64a217a EM |
208 | 'amount' => 10, |
209 | 'billing_first_name' => 'Billy', | |
210 | 'billing_middle_name' => 'Goat', | |
211 | 'billing_last_name' => 'Gruff', | |
212 | 'selectMembership' => $this->_ids['membership_type'], | |
213 | ||
214 | ); | |
215 | ||
a828d7b8 | 216 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
f9342903 | 217 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); |
f64a217a | 218 | $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); |
f9342903 EM |
219 | } |
220 | ||
221 | /** | |
eceb18cc | 222 | * Test submit with a membership block in place. |
f9342903 EM |
223 | */ |
224 | public function testSubmitMembershipBlockIsSeparatePayment() { | |
225 | $this->setUpMembershipContributionPage(TRUE); | |
226 | $submitParams = array( | |
3e28c791 | 227 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), |
f9342903 EM |
228 | 'id' => (int) $this->_ids['contribution_page'], |
229 | 'amount' => 10, | |
230 | 'billing_first_name' => 'Billy', | |
231 | 'billing_middle_name' => 'Goat', | |
232 | 'billing_last_name' => 'Gruff', | |
233 | 'selectMembership' => $this->_ids['membership_type'], | |
234 | ); | |
235 | ||
a828d7b8 | 236 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
f9342903 EM |
237 | $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); |
238 | $this->assertCount(2, $contributions['values']); | |
239 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
240 | $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); | |
241 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
242 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
243 | } | |
f64a217a | 244 | |
797c4f88 | 245 | /** |
eceb18cc | 246 | * Test submit with a membership block in place. |
797c4f88 EM |
247 | */ |
248 | public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() { | |
249 | $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6))); | |
250 | $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50)); | |
251 | $this->setUpMembershipContributionPage(TRUE); | |
252 | $submitParams = array( | |
253 | 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1], | |
254 | 'id' => (int) $this->_ids['contribution_page'], | |
255 | 'amount' => 10, | |
256 | 'billing_first_name' => 'Billy', | |
257 | 'billing_middle_name' => 'Goat', | |
258 | 'billing_last_name' => 'Gruff', | |
259 | 'selectMembership' => $this->_ids['membership_type'][1], | |
260 | ); | |
261 | ||
a828d7b8 | 262 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
6c6e6187 | 263 | $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); |
797c4f88 EM |
264 | $this->assertCount(2, $contributions['values']); |
265 | $ids = array_keys($contributions['values']); | |
266 | $this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']); | |
267 | $this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']); | |
268 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
269 | $this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']); | |
270 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
271 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
272 | } | |
273 | ||
8ca611b7 | 274 | /** |
eceb18cc | 275 | * Test submit with a membership block in place. |
329f3f66 EM |
276 | * |
277 | * We are expecting a separate payment for the membership vs the contribution. | |
8ca611b7 | 278 | */ |
329f3f66 | 279 | public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() { |
8ca611b7 | 280 | $this->setUpMembershipContributionPage(TRUE); |
0193ebdb | 281 | $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']); |
282 | $processor->setDoDirectPaymentResult(array('fee_amount' => .72)); | |
8ca611b7 EM |
283 | $submitParams = array( |
284 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
285 | 'id' => (int) $this->_ids['contribution_page'], | |
286 | 'amount' => 10, | |
287 | 'billing_first_name' => 'Billy', | |
288 | 'billing_middle_name' => 'Goat', | |
289 | 'billing_last_name' => 'Gruff', | |
290 | 'selectMembership' => $this->_ids['membership_type'], | |
7bc789a5 | 291 | 'payment_processor_id' => $this->_paymentProcessor['id'], |
8ca611b7 EM |
292 | 'credit_card_number' => '4111111111111111', |
293 | 'credit_card_type' => 'Visa', | |
5896d037 | 294 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
8ca611b7 EM |
295 | 'cvv2' => 123, |
296 | ); | |
05990684 | 297 | |
a828d7b8 | 298 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 299 | $contributions = $this->callAPISuccess('contribution', 'get', array( |
92915c55 TO |
300 | 'contribution_page_id' => $this->_ids['contribution_page'], |
301 | 'contribution_status_id' => 1, | |
302 | )); | |
8ca611b7 EM |
303 | $this->assertCount(2, $contributions['values']); |
304 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
305 | $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); | |
306 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
307 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
0193ebdb | 308 | foreach ($contributions['values'] as $contribution) { |
309 | $this->assertEquals(.72, $contribution['fee_amount']); | |
310 | $this->assertEquals($contribution['total_amount'] - .72, $contribution['net_amount']); | |
311 | } | |
8ca611b7 | 312 | } |
f8fe0df6 | 313 | |
5961bd47 EM |
314 | /** |
315 | * Test that when a transaction fails the pending contribution remains. | |
316 | * | |
317 | * An activity should also be created. CRM-16417. | |
318 | */ | |
319 | public function testSubmitPaymentProcessorFailure() { | |
320 | $this->setUpContributionPage(); | |
321 | $this->setupPaymentProcessor(); | |
322 | $this->createLoggedInUser(); | |
323 | $priceFieldID = reset($this->_ids['price_field']); | |
324 | $priceFieldValueID = reset($this->_ids['price_field_value']); | |
325 | $submitParams = array( | |
326 | 'price_' . $priceFieldID => $priceFieldValueID, | |
327 | 'id' => (int) $this->_ids['contribution_page'], | |
328 | 'amount' => 10, | |
329 | 'payment_processor_id' => 1, | |
330 | 'credit_card_number' => '4111111111111111', | |
331 | 'credit_card_type' => 'Visa', | |
332 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008), | |
333 | 'cvv2' => 123, | |
334 | ); | |
335 | ||
336 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); | |
337 | $contribution = $this->callAPISuccessGetSingle('contribution', array( | |
338 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
339 | 'contribution_status_id' => 2, | |
340 | )); | |
341 | ||
342 | $this->callAPISuccessGetSingle('activity', array( | |
343 | 'source_record_id' => $contribution['id'], | |
344 | 'activity_type_id' => 'Failed Payment', | |
345 | )); | |
346 | ||
5961bd47 EM |
347 | } |
348 | ||
f8fe0df6 | 349 | /** |
e6fa4056 EM |
350 | * Test submit recurring membership with immediate confirmation (IATS style) |
351 | * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate | |
1fee3ad2 | 352 | * processor (IATS style - denoted by returning trxn_id) |
e6fa4056 EM |
353 | * - the first creates a new membership, completed contribution, in progress recurring. Check these |
354 | * - create another - end date should be extended | |
f8fe0df6 | 355 | */ |
8bef2e38 | 356 | public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment() { |
f8fe0df6 | 357 | $this->params['is_recur'] = 1; |
f8fe0df6 | 358 | $this->params['recur_frequency_unit'] = 'month'; |
359 | $this->setUpMembershipContributionPage(); | |
7c85dc65 | 360 | $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); |
8bef2e38 | 361 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); |
f8fe0df6 | 362 | |
363 | $submitParams = array( | |
364 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
365 | 'id' => (int) $this->_ids['contribution_page'], | |
366 | 'amount' => 10, | |
367 | 'billing_first_name' => 'Billy', | |
368 | 'billing_middle_name' => 'Goat', | |
369 | 'billing_last_name' => 'Gruff', | |
370 | 'email' => 'billy@goat.gruff', | |
371 | 'selectMembership' => $this->_ids['membership_type'], | |
579a1fb7 | 372 | 'payment_processor_id' => 1, |
f8fe0df6 | 373 | 'credit_card_number' => '4111111111111111', |
374 | 'credit_card_type' => 'Visa', | |
5896d037 | 375 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
f8fe0df6 | 376 | 'cvv2' => 123, |
377 | 'is_recur' => 1, | |
378 | 'frequency_interval' => 1, | |
379 | 'frequency_unit' => 'month', | |
380 | ); | |
381 | ||
a828d7b8 | 382 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 383 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
384 | 'contribution_page_id' => $this->_ids['contribution_page'], |
385 | 'contribution_status_id' => 1, | |
386 | )); | |
0739d6cf | 387 | |
388 | $this->assertEquals('create_first_success', $contribution['trxn_id']); | |
f8fe0df6 | 389 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); |
390 | $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); | |
391 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
392 | $this->assertEquals($membership['contact_id'], $contribution['contact_id']); | |
393 | $this->assertEquals(1, $membership['status_id']); | |
394 | $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); | |
e6fa4056 EM |
395 | //@todo - check with Joe about these not existing |
396 | //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); | |
f8fe0df6 | 397 | //renew it with processor setting completed - should extend membership |
398 | $submitParams['contact_id'] = $contribution['contact_id']; | |
8bef2e38 | 399 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); |
f8fe0df6 | 400 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); |
5896d037 | 401 | $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
402 | 'id' => array('NOT IN' => array($contribution['id'])), |
403 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
404 | 'contribution_status_id' => 1, | |
405 | )); | |
f8fe0df6 | 406 | $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
407 | $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']); | |
408 | $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); | |
e6fa4056 | 409 | $this->assertEquals(2, $recurringContribution['contribution_status_id']); |
f8fe0df6 | 410 | } |
411 | ||
412 | /** | |
e6fa4056 EM |
413 | * Test submit recurring membership with delayed confirmation (Authorize.net style) |
414 | * - we process 2 membership transactions against with a recurring contribution against a contribution page with a delayed | |
415 | * processor (Authorize.net style - denoted by NOT returning trxn_id) | |
416 | * - the first creates a pending membership, pending contribution, penging recurring. Check these | |
417 | * - complete the transaction | |
418 | * - create another - end date should NOT be extended | |
f8fe0df6 | 419 | */ |
420 | public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() { | |
421 | $this->params['is_recur'] = 1; | |
f8fe0df6 | 422 | $this->params['recur_frequency_unit'] = 'month'; |
423 | $this->setUpMembershipContributionPage(); | |
ab30e033 | 424 | $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); |
b5eacf76 | 425 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); |
f8fe0df6 | 426 | |
427 | $submitParams = array( | |
428 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
429 | 'id' => (int) $this->_ids['contribution_page'], | |
430 | 'amount' => 10, | |
431 | 'billing_first_name' => 'Billy', | |
432 | 'billing_middle_name' => 'Goat', | |
433 | 'billing_last_name' => 'Gruff', | |
434 | 'email' => 'billy@goat.gruff', | |
435 | 'selectMembership' => $this->_ids['membership_type'], | |
579a1fb7 | 436 | 'payment_processor_id' => 1, |
f8fe0df6 | 437 | 'credit_card_number' => '4111111111111111', |
438 | 'credit_card_type' => 'Visa', | |
5896d037 | 439 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
f8fe0df6 | 440 | 'cvv2' => 123, |
e6fa4056 EM |
441 | 'is_recur' => 1, |
442 | 'frequency_interval' => 1, | |
443 | 'frequency_unit' => 'month', | |
f8fe0df6 | 444 | ); |
445 | ||
a828d7b8 | 446 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 447 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
448 | 'contribution_page_id' => $this->_ids['contribution_page'], |
449 | 'contribution_status_id' => 2, | |
450 | )); | |
f8fe0df6 | 451 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); |
452 | $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); | |
453 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
454 | $this->assertEquals($membership['contact_id'], $contribution['contact_id']); | |
e6fa4056 EM |
455 | $this->assertEquals(5, $membership['status_id']); |
456 | //@todo - check with Joe about these not existing | |
457 | //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); | |
5896d037 | 458 | $this->callAPISuccess('contribution', 'completetransaction', array( |
92915c55 TO |
459 | 'id' => $contribution['id'], |
460 | 'trxn_id' => 'ipn_called', | |
b396c447 | 461 | 'payment_processor_id' => $this->_paymentProcessor['id'], |
92915c55 | 462 | )); |
e6fa4056 | 463 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
f8fe0df6 | 464 | //renew it with processor setting completed - should extend membership |
465 | $submitParams = array_merge($submitParams, array( | |
5896d037 TO |
466 | 'contact_id' => $contribution['contact_id'], |
467 | 'is_recur' => 1, | |
468 | 'frequency_interval' => 1, | |
469 | 'frequency_unit' => 'month', | |
470 | ) | |
f8fe0df6 | 471 | ); |
b5eacf76 | 472 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); |
f8fe0df6 | 473 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); |
6c6e6187 | 474 | $newContribution = $this->callAPISuccess('contribution', 'getsingle', array( |
5896d037 | 475 | 'id' => array( |
21dfd5f5 | 476 | 'NOT IN' => array($contribution['id']), |
5896d037 TO |
477 | ), |
478 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
21dfd5f5 | 479 | 'contribution_status_id' => 2, |
5896d037 | 480 | ) |
f8fe0df6 | 481 | ); |
e6fa4056 | 482 | |
f8fe0df6 | 483 | $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
484 | //no renewal as the date hasn't changed | |
485 | $this->assertEquals($membership['end_date'], $renewedMembership['end_date']); | |
e6fa4056 EM |
486 | $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id'])); |
487 | $this->assertEquals(2, $recurringContribution['contribution_status_id']); | |
f8fe0df6 | 488 | } |
489 | ||
f9342903 | 490 | /** |
eceb18cc | 491 | * Set up membership contribution page. |
f9342903 EM |
492 | * @param bool $isSeparatePayment |
493 | */ | |
00be9182 | 494 | public function setUpMembershipContributionPage($isSeparatePayment = FALSE) { |
f9342903 | 495 | $this->setUpMembershipBlockPriceSet(); |
a380f4a0 | 496 | $this->setupPaymentProcessor(); |
f9342903 EM |
497 | $this->setUpContributionPage(); |
498 | ||
499 | $this->callAPISuccess('membership_block', 'create', array( | |
500 | 'entity_id' => $this->_ids['contribution_page'], | |
501 | 'entity_table' => 'civicrm_contribution_page', | |
502 | 'is_required' => TRUE, | |
503 | 'is_active' => TRUE, | |
504 | 'is_separate_payment' => $isSeparatePayment, | |
505 | 'membership_type_default' => $this->_ids['membership_type'], | |
506 | )); | |
f64a217a EM |
507 | } |
508 | ||
f9342903 EM |
509 | /** |
510 | * The default data set does not include a complete default membership price set - not quite sure why | |
511 | * This function ensures it exists & populates $this->_ids with it's data | |
512 | */ | |
00be9182 | 513 | public function setUpMembershipBlockPriceSet() { |
5896d037 | 514 | $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array( |
92915c55 TO |
515 | 'name' => 'default_membership_type_amount', |
516 | 'return' => 'id', | |
517 | )); | |
f9342903 | 518 | if (empty($this->_ids['membership_type'])) { |
3e28c791 | 519 | $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2))); |
f9342903 | 520 | } |
3e28c791 EM |
521 | $priceField = $this->callAPISuccess('price_field', 'create', array( |
522 | 'price_set_id' => reset($this->_ids['price_set']), | |
523 | 'name' => 'membership_amount', | |
524 | 'label' => 'Membership Amount', | |
525 | 'html_type' => 'Radio', | |
526 | 'sequential' => 1, | |
527 | )); | |
528 | $this->_ids['price_field'][] = $priceField['id']; | |
529 | foreach ($this->_ids['membership_type'] as $membershipTypeID) { | |
530 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
f9342903 EM |
531 | 'name' => 'membership_amount', |
532 | 'label' => 'Membership Amount', | |
3e28c791 | 533 | 'amount' => 1, |
43dbd988 | 534 | 'financial_type_id' => 'Donation', |
3e28c791 EM |
535 | 'format.only_id' => TRUE, |
536 | 'membership_type_id' => $membershipTypeID, | |
537 | 'price_field_id' => $priceField['id'], | |
f9342903 | 538 | )); |
3e28c791 | 539 | $this->_ids['price_field_value'][] = $priceFieldValue['id']; |
f9342903 EM |
540 | } |
541 | } | |
3e28c791 | 542 | |
f64a217a | 543 | /** |
eceb18cc | 544 | * Help function to set up contribution page with some defaults. |
f64a217a | 545 | */ |
00be9182 | 546 | public function setUpContributionPage() { |
f64a217a EM |
547 | $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
548 | if (empty($this->_ids['price_set'])) { | |
549 | $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams); | |
550 | $this->_ids['price_set'][] = $priceSet['id']; | |
551 | } | |
552 | $priceSetID = reset($this->_ids['price_set']); | |
5896d037 | 553 | CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); |
f9342903 EM |
554 | |
555 | if (empty($this->_ids['price_field'])) { | |
556 | $priceField = $this->callAPISuccess('price_field', 'create', array( | |
557 | 'price_set_id' => $priceSetID, | |
558 | 'label' => 'Goat Breed', | |
559 | 'html_type' => 'Radio', | |
560 | )); | |
561 | $this->_ids['price_field'] = array($priceField['id']); | |
562 | } | |
563 | if (empty($this->_ids['price_field_value'])) { | |
564 | $this->callAPISuccess('price_field_value', 'create', array( | |
565 | 'price_set_id' => $priceSetID, | |
566 | 'price_field_id' => $priceField['id'], | |
567 | 'label' => 'Long Haired Goat', | |
43dbd988 | 568 | 'financial_type_id' => 'Donation', |
f9342903 EM |
569 | 'amount' => 20, |
570 | ) | |
571 | ); | |
572 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
573 | 'price_set_id' => $priceSetID, | |
574 | 'price_field_id' => $priceField['id'], | |
575 | 'label' => 'Shoe-eating Goat', | |
43dbd988 | 576 | 'financial_type_id' => 'Donation', |
f9342903 EM |
577 | 'amount' => 10, |
578 | ) | |
579 | ); | |
580 | $this->_ids['price_field_value'] = array($priceFieldValue['id']); | |
581 | } | |
f64a217a | 582 | $this->_ids['contribution_page'] = $contributionPageResult['id']; |
be26f3e0 EM |
583 | } |
584 | ||
6a488035 | 585 | public static function setUpBeforeClass() { |
6c6e6187 | 586 | // put stuff here that should happen before all tests in this unit |
6a488035 TO |
587 | } |
588 | ||
5896d037 | 589 | public static function tearDownAfterClass() { |
6a488035 TO |
590 | $tablesToTruncate = array( |
591 | 'civicrm_contact', | |
592 | 'civicrm_financial_type', | |
593 | 'civicrm_contribution', | |
594 | 'civicrm_contribution_page', | |
595 | ); | |
596 | $unitTest = new CiviUnitTestCase(); | |
597 | $unitTest->quickCleanup($tablesToTruncate); | |
598 | } | |
96025800 | 599 | |
a380f4a0 EM |
600 | /** |
601 | * Create a payment processor instance. | |
602 | */ | |
603 | protected function setupPaymentProcessor() { | |
604 | $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array( | |
605 | 'payment_processor_type_id' => 'Dummy', | |
606 | 'class_name' => 'Payment_Dummy', | |
607 | 'billing_mode' => 1, | |
608 | )); | |
609 | $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id'])); | |
610 | } | |
611 | ||
6a488035 | 612 | } |