Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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); | |
167 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); | |
168 | $this->callAPISuccess('ContributionPage', 'create', array( | |
d27635dc | 169 | 'id' => $this->_ids['contribution_page'], |
170 | 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']), | |
7bc789a5 | 171 | )); |
172 | ||
173 | $priceFieldID = reset($this->_ids['price_field']); | |
174 | $priceFieldValueID = reset($this->_ids['price_field_value']); | |
175 | $submitParams = array( | |
176 | 'price_' . $priceFieldID => $priceFieldValueID, | |
177 | 'id' => (int) $this->_ids['contribution_page'], | |
178 | 'amount' => 10, | |
179 | 'is_recur' => 1, | |
180 | 'frequency_interval' => 1, | |
181 | 'frequency_unit' => 'month', | |
182 | 'payment_processor_id' => $paymentProcessor2ID, | |
183 | ); | |
184 | ||
185 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); | |
186 | $this->callAPISuccess('contribution', 'getsingle', array( | |
187 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
188 | 'contribution_status_id' => 1, | |
189 | )); | |
190 | } | |
f64a217a | 191 | /** |
eceb18cc | 192 | * Test submit with a membership block in place. |
f64a217a | 193 | */ |
f9342903 EM |
194 | public function testSubmitMembershipBlockNotSeparatePayment() { |
195 | $this->setUpMembershipContributionPage(); | |
f64a217a | 196 | $submitParams = array( |
3e28c791 | 197 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), |
f9342903 | 198 | 'id' => (int) $this->_ids['contribution_page'], |
f64a217a EM |
199 | 'amount' => 10, |
200 | 'billing_first_name' => 'Billy', | |
201 | 'billing_middle_name' => 'Goat', | |
202 | 'billing_last_name' => 'Gruff', | |
203 | 'selectMembership' => $this->_ids['membership_type'], | |
204 | ||
205 | ); | |
206 | ||
a828d7b8 | 207 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
f9342903 | 208 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); |
f64a217a | 209 | $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id'])); |
f9342903 EM |
210 | } |
211 | ||
212 | /** | |
eceb18cc | 213 | * Test submit with a membership block in place. |
f9342903 EM |
214 | */ |
215 | public function testSubmitMembershipBlockIsSeparatePayment() { | |
216 | $this->setUpMembershipContributionPage(TRUE); | |
217 | $submitParams = array( | |
3e28c791 | 218 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), |
f9342903 EM |
219 | 'id' => (int) $this->_ids['contribution_page'], |
220 | 'amount' => 10, | |
221 | 'billing_first_name' => 'Billy', | |
222 | 'billing_middle_name' => 'Goat', | |
223 | 'billing_last_name' => 'Gruff', | |
224 | 'selectMembership' => $this->_ids['membership_type'], | |
225 | ); | |
226 | ||
a828d7b8 | 227 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
f9342903 EM |
228 | $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); |
229 | $this->assertCount(2, $contributions['values']); | |
230 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
231 | $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); | |
232 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
233 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
234 | } | |
f64a217a | 235 | |
797c4f88 | 236 | /** |
eceb18cc | 237 | * Test submit with a membership block in place. |
797c4f88 EM |
238 | */ |
239 | public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() { | |
240 | $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6))); | |
241 | $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50)); | |
242 | $this->setUpMembershipContributionPage(TRUE); | |
243 | $submitParams = array( | |
244 | 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1], | |
245 | 'id' => (int) $this->_ids['contribution_page'], | |
246 | 'amount' => 10, | |
247 | 'billing_first_name' => 'Billy', | |
248 | 'billing_middle_name' => 'Goat', | |
249 | 'billing_last_name' => 'Gruff', | |
250 | 'selectMembership' => $this->_ids['membership_type'][1], | |
251 | ); | |
252 | ||
a828d7b8 | 253 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
6c6e6187 | 254 | $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); |
797c4f88 EM |
255 | $this->assertCount(2, $contributions['values']); |
256 | $ids = array_keys($contributions['values']); | |
257 | $this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']); | |
258 | $this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']); | |
259 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
260 | $this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']); | |
261 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
262 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
263 | } | |
264 | ||
8ca611b7 | 265 | /** |
eceb18cc | 266 | * Test submit with a membership block in place. |
329f3f66 EM |
267 | * |
268 | * We are expecting a separate payment for the membership vs the contribution. | |
8ca611b7 | 269 | */ |
329f3f66 | 270 | public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() { |
8ca611b7 EM |
271 | $this->setUpMembershipContributionPage(TRUE); |
272 | $submitParams = array( | |
273 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
274 | 'id' => (int) $this->_ids['contribution_page'], | |
275 | 'amount' => 10, | |
276 | 'billing_first_name' => 'Billy', | |
277 | 'billing_middle_name' => 'Goat', | |
278 | 'billing_last_name' => 'Gruff', | |
279 | 'selectMembership' => $this->_ids['membership_type'], | |
7bc789a5 | 280 | 'payment_processor_id' => $this->_paymentProcessor['id'], |
8ca611b7 EM |
281 | 'credit_card_number' => '4111111111111111', |
282 | 'credit_card_type' => 'Visa', | |
5896d037 | 283 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
8ca611b7 EM |
284 | 'cvv2' => 123, |
285 | ); | |
05990684 | 286 | |
a828d7b8 | 287 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 288 | $contributions = $this->callAPISuccess('contribution', 'get', array( |
92915c55 TO |
289 | 'contribution_page_id' => $this->_ids['contribution_page'], |
290 | 'contribution_status_id' => 1, | |
291 | )); | |
8ca611b7 EM |
292 | $this->assertCount(2, $contributions['values']); |
293 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); | |
294 | $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); | |
295 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
296 | $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); | |
297 | } | |
f8fe0df6 | 298 | |
5961bd47 EM |
299 | /** |
300 | * Test that when a transaction fails the pending contribution remains. | |
301 | * | |
302 | * An activity should also be created. CRM-16417. | |
303 | */ | |
304 | public function testSubmitPaymentProcessorFailure() { | |
305 | $this->setUpContributionPage(); | |
306 | $this->setupPaymentProcessor(); | |
307 | $this->createLoggedInUser(); | |
308 | $priceFieldID = reset($this->_ids['price_field']); | |
309 | $priceFieldValueID = reset($this->_ids['price_field_value']); | |
310 | $submitParams = array( | |
311 | 'price_' . $priceFieldID => $priceFieldValueID, | |
312 | 'id' => (int) $this->_ids['contribution_page'], | |
313 | 'amount' => 10, | |
314 | 'payment_processor_id' => 1, | |
315 | 'credit_card_number' => '4111111111111111', | |
316 | 'credit_card_type' => 'Visa', | |
317 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008), | |
318 | 'cvv2' => 123, | |
319 | ); | |
320 | ||
321 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); | |
322 | $contribution = $this->callAPISuccessGetSingle('contribution', array( | |
323 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
324 | 'contribution_status_id' => 2, | |
325 | )); | |
326 | ||
327 | $this->callAPISuccessGetSingle('activity', array( | |
328 | 'source_record_id' => $contribution['id'], | |
329 | 'activity_type_id' => 'Failed Payment', | |
330 | )); | |
331 | ||
5961bd47 EM |
332 | } |
333 | ||
f8fe0df6 | 334 | /** |
e6fa4056 EM |
335 | * Test submit recurring membership with immediate confirmation (IATS style) |
336 | * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate | |
1fee3ad2 | 337 | * processor (IATS style - denoted by returning trxn_id) |
e6fa4056 EM |
338 | * - the first creates a new membership, completed contribution, in progress recurring. Check these |
339 | * - create another - end date should be extended | |
f8fe0df6 | 340 | */ |
8bef2e38 | 341 | public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment() { |
f8fe0df6 | 342 | $this->params['is_recur'] = 1; |
f8fe0df6 | 343 | $this->params['recur_frequency_unit'] = 'month'; |
344 | $this->setUpMembershipContributionPage(); | |
7c85dc65 | 345 | $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); |
8bef2e38 | 346 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); |
f8fe0df6 | 347 | |
348 | $submitParams = array( | |
349 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
350 | 'id' => (int) $this->_ids['contribution_page'], | |
351 | 'amount' => 10, | |
352 | 'billing_first_name' => 'Billy', | |
353 | 'billing_middle_name' => 'Goat', | |
354 | 'billing_last_name' => 'Gruff', | |
355 | 'email' => 'billy@goat.gruff', | |
356 | 'selectMembership' => $this->_ids['membership_type'], | |
579a1fb7 | 357 | 'payment_processor_id' => 1, |
f8fe0df6 | 358 | 'credit_card_number' => '4111111111111111', |
359 | 'credit_card_type' => 'Visa', | |
5896d037 | 360 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
f8fe0df6 | 361 | 'cvv2' => 123, |
362 | 'is_recur' => 1, | |
363 | 'frequency_interval' => 1, | |
364 | 'frequency_unit' => 'month', | |
365 | ); | |
366 | ||
a828d7b8 | 367 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 368 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
369 | 'contribution_page_id' => $this->_ids['contribution_page'], |
370 | 'contribution_status_id' => 1, | |
371 | )); | |
f8fe0df6 | 372 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); |
373 | $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); | |
374 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
375 | $this->assertEquals($membership['contact_id'], $contribution['contact_id']); | |
376 | $this->assertEquals(1, $membership['status_id']); | |
377 | $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); | |
e6fa4056 EM |
378 | //@todo - check with Joe about these not existing |
379 | //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); | |
f8fe0df6 | 380 | //renew it with processor setting completed - should extend membership |
381 | $submitParams['contact_id'] = $contribution['contact_id']; | |
8bef2e38 | 382 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); |
f8fe0df6 | 383 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); |
5896d037 | 384 | $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
385 | 'id' => array('NOT IN' => array($contribution['id'])), |
386 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
387 | 'contribution_status_id' => 1, | |
388 | )); | |
f8fe0df6 | 389 | $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
390 | $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']); | |
391 | $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); | |
e6fa4056 | 392 | $this->assertEquals(2, $recurringContribution['contribution_status_id']); |
f8fe0df6 | 393 | } |
394 | ||
395 | /** | |
e6fa4056 EM |
396 | * Test submit recurring membership with delayed confirmation (Authorize.net style) |
397 | * - we process 2 membership transactions against with a recurring contribution against a contribution page with a delayed | |
398 | * processor (Authorize.net style - denoted by NOT returning trxn_id) | |
399 | * - the first creates a pending membership, pending contribution, penging recurring. Check these | |
400 | * - complete the transaction | |
401 | * - create another - end date should NOT be extended | |
f8fe0df6 | 402 | */ |
403 | public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() { | |
404 | $this->params['is_recur'] = 1; | |
f8fe0df6 | 405 | $this->params['recur_frequency_unit'] = 'month'; |
406 | $this->setUpMembershipContributionPage(); | |
ab30e033 | 407 | $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); |
b5eacf76 | 408 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); |
f8fe0df6 | 409 | |
410 | $submitParams = array( | |
411 | 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), | |
412 | 'id' => (int) $this->_ids['contribution_page'], | |
413 | 'amount' => 10, | |
414 | 'billing_first_name' => 'Billy', | |
415 | 'billing_middle_name' => 'Goat', | |
416 | 'billing_last_name' => 'Gruff', | |
417 | 'email' => 'billy@goat.gruff', | |
418 | 'selectMembership' => $this->_ids['membership_type'], | |
579a1fb7 | 419 | 'payment_processor_id' => 1, |
f8fe0df6 | 420 | 'credit_card_number' => '4111111111111111', |
421 | 'credit_card_type' => 'Visa', | |
5896d037 | 422 | 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), |
f8fe0df6 | 423 | 'cvv2' => 123, |
e6fa4056 EM |
424 | 'is_recur' => 1, |
425 | 'frequency_interval' => 1, | |
426 | 'frequency_unit' => 'month', | |
f8fe0df6 | 427 | ); |
428 | ||
a828d7b8 | 429 | $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); |
5896d037 | 430 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array( |
92915c55 TO |
431 | 'contribution_page_id' => $this->_ids['contribution_page'], |
432 | 'contribution_status_id' => 2, | |
433 | )); | |
f8fe0df6 | 434 | $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); |
435 | $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); | |
436 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); | |
437 | $this->assertEquals($membership['contact_id'], $contribution['contact_id']); | |
e6fa4056 EM |
438 | $this->assertEquals(5, $membership['status_id']); |
439 | //@todo - check with Joe about these not existing | |
440 | //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); | |
5896d037 | 441 | $this->callAPISuccess('contribution', 'completetransaction', array( |
92915c55 TO |
442 | 'id' => $contribution['id'], |
443 | 'trxn_id' => 'ipn_called', | |
b396c447 | 444 | 'payment_processor_id' => $this->_paymentProcessor['id'], |
92915c55 | 445 | )); |
e6fa4056 | 446 | $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
f8fe0df6 | 447 | //renew it with processor setting completed - should extend membership |
448 | $submitParams = array_merge($submitParams, array( | |
5896d037 TO |
449 | 'contact_id' => $contribution['contact_id'], |
450 | 'is_recur' => 1, | |
451 | 'frequency_interval' => 1, | |
452 | 'frequency_unit' => 'month', | |
453 | ) | |
f8fe0df6 | 454 | ); |
b5eacf76 | 455 | $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); |
f8fe0df6 | 456 | $this->callAPISuccess('contribution_page', 'submit', $submitParams); |
6c6e6187 | 457 | $newContribution = $this->callAPISuccess('contribution', 'getsingle', array( |
5896d037 | 458 | 'id' => array( |
21dfd5f5 | 459 | 'NOT IN' => array($contribution['id']), |
5896d037 TO |
460 | ), |
461 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
21dfd5f5 | 462 | 'contribution_status_id' => 2, |
5896d037 | 463 | ) |
f8fe0df6 | 464 | ); |
e6fa4056 | 465 | |
f8fe0df6 | 466 | $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); |
467 | //no renewal as the date hasn't changed | |
468 | $this->assertEquals($membership['end_date'], $renewedMembership['end_date']); | |
e6fa4056 EM |
469 | $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id'])); |
470 | $this->assertEquals(2, $recurringContribution['contribution_status_id']); | |
f8fe0df6 | 471 | } |
472 | ||
f9342903 | 473 | /** |
eceb18cc | 474 | * Set up membership contribution page. |
f9342903 EM |
475 | * @param bool $isSeparatePayment |
476 | */ | |
00be9182 | 477 | public function setUpMembershipContributionPage($isSeparatePayment = FALSE) { |
f9342903 | 478 | $this->setUpMembershipBlockPriceSet(); |
a380f4a0 | 479 | $this->setupPaymentProcessor(); |
f9342903 EM |
480 | $this->setUpContributionPage(); |
481 | ||
482 | $this->callAPISuccess('membership_block', 'create', array( | |
483 | 'entity_id' => $this->_ids['contribution_page'], | |
484 | 'entity_table' => 'civicrm_contribution_page', | |
485 | 'is_required' => TRUE, | |
486 | 'is_active' => TRUE, | |
487 | 'is_separate_payment' => $isSeparatePayment, | |
488 | 'membership_type_default' => $this->_ids['membership_type'], | |
489 | )); | |
f64a217a EM |
490 | } |
491 | ||
f9342903 EM |
492 | /** |
493 | * The default data set does not include a complete default membership price set - not quite sure why | |
494 | * This function ensures it exists & populates $this->_ids with it's data | |
495 | */ | |
00be9182 | 496 | public function setUpMembershipBlockPriceSet() { |
5896d037 | 497 | $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array( |
92915c55 TO |
498 | 'name' => 'default_membership_type_amount', |
499 | 'return' => 'id', | |
500 | )); | |
f9342903 | 501 | if (empty($this->_ids['membership_type'])) { |
3e28c791 | 502 | $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2))); |
f9342903 | 503 | } |
3e28c791 EM |
504 | $priceField = $this->callAPISuccess('price_field', 'create', array( |
505 | 'price_set_id' => reset($this->_ids['price_set']), | |
506 | 'name' => 'membership_amount', | |
507 | 'label' => 'Membership Amount', | |
508 | 'html_type' => 'Radio', | |
509 | 'sequential' => 1, | |
510 | )); | |
511 | $this->_ids['price_field'][] = $priceField['id']; | |
512 | foreach ($this->_ids['membership_type'] as $membershipTypeID) { | |
513 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
f9342903 EM |
514 | 'name' => 'membership_amount', |
515 | 'label' => 'Membership Amount', | |
3e28c791 EM |
516 | 'amount' => 1, |
517 | 'financial_type_id' => 1, | |
518 | 'format.only_id' => TRUE, | |
519 | 'membership_type_id' => $membershipTypeID, | |
520 | 'price_field_id' => $priceField['id'], | |
f9342903 | 521 | )); |
3e28c791 | 522 | $this->_ids['price_field_value'][] = $priceFieldValue['id']; |
f9342903 EM |
523 | } |
524 | } | |
3e28c791 | 525 | |
f64a217a | 526 | /** |
eceb18cc | 527 | * Help function to set up contribution page with some defaults. |
f64a217a | 528 | */ |
00be9182 | 529 | public function setUpContributionPage() { |
f64a217a EM |
530 | $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
531 | if (empty($this->_ids['price_set'])) { | |
532 | $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams); | |
533 | $this->_ids['price_set'][] = $priceSet['id']; | |
534 | } | |
535 | $priceSetID = reset($this->_ids['price_set']); | |
5896d037 | 536 | CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); |
f9342903 EM |
537 | |
538 | if (empty($this->_ids['price_field'])) { | |
539 | $priceField = $this->callAPISuccess('price_field', 'create', array( | |
540 | 'price_set_id' => $priceSetID, | |
541 | 'label' => 'Goat Breed', | |
542 | 'html_type' => 'Radio', | |
543 | )); | |
544 | $this->_ids['price_field'] = array($priceField['id']); | |
545 | } | |
546 | if (empty($this->_ids['price_field_value'])) { | |
547 | $this->callAPISuccess('price_field_value', 'create', array( | |
548 | 'price_set_id' => $priceSetID, | |
549 | 'price_field_id' => $priceField['id'], | |
550 | 'label' => 'Long Haired Goat', | |
551 | 'amount' => 20, | |
552 | ) | |
553 | ); | |
554 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
555 | 'price_set_id' => $priceSetID, | |
556 | 'price_field_id' => $priceField['id'], | |
557 | 'label' => 'Shoe-eating Goat', | |
558 | 'amount' => 10, | |
559 | ) | |
560 | ); | |
561 | $this->_ids['price_field_value'] = array($priceFieldValue['id']); | |
562 | } | |
f64a217a | 563 | $this->_ids['contribution_page'] = $contributionPageResult['id']; |
be26f3e0 EM |
564 | } |
565 | ||
6a488035 | 566 | public static function setUpBeforeClass() { |
6c6e6187 | 567 | // put stuff here that should happen before all tests in this unit |
6a488035 TO |
568 | } |
569 | ||
5896d037 | 570 | public static function tearDownAfterClass() { |
6a488035 TO |
571 | $tablesToTruncate = array( |
572 | 'civicrm_contact', | |
573 | 'civicrm_financial_type', | |
574 | 'civicrm_contribution', | |
575 | 'civicrm_contribution_page', | |
576 | ); | |
577 | $unitTest = new CiviUnitTestCase(); | |
578 | $unitTest->quickCleanup($tablesToTruncate); | |
579 | } | |
96025800 | 580 | |
a380f4a0 EM |
581 | /** |
582 | * Create a payment processor instance. | |
583 | */ | |
584 | protected function setupPaymentProcessor() { | |
585 | $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array( | |
586 | 'payment_processor_type_id' => 'Dummy', | |
587 | 'class_name' => 'Payment_Dummy', | |
588 | 'billing_mode' => 1, | |
589 | )); | |
590 | $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id'])); | |
591 | } | |
592 | ||
6a488035 | 593 | } |