Merge pull request #9717 from eileenmcnaughton/comments
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionPageTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
15a4309a 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035 27
6a488035
TO
28/**
29 * Test APIv3 civicrm_contribute_recur* functions
30 *
6c6e6187
TO
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
acb109b7 33 * @group headless
6a488035 34 */
6a488035
TO
35class api_v3_ContributionPageTest extends CiviUnitTestCase {
36 protected $_apiversion = 3;
37 protected $testAmount = 34567;
38 protected $params;
39 protected $id = 0;
40 protected $contactIds = array();
41 protected $_entity = 'contribution_page';
6c6e6187 42 protected $contribution_result = NULL;
f64a217a 43 protected $_priceSetParams = array();
f8fe0df6 44 /**
eceb18cc 45 * Payment processor details.
f8fe0df6 46 * @var array
47 */
48 protected $_paymentProcessor = array();
f64a217a
EM
49
50 /**
51 * @var array
16b10e64
CW
52 * - contribution_page
53 * - price_set
54 * - price_field
55 * - price_field_value
f64a217a
EM
56 */
57 protected $_ids = array();
58
b7c9bc4c 59
6a488035 60 public $DBResetRequired = TRUE;
5896d037 61
6a488035
TO
62 public function setUp() {
63 parent::setUp();
64 $this->contactIds[] = $this->individualCreate();
65 $this->params = array(
6a488035
TO
66 'title' => "Test Contribution Page",
67 'financial_type_id' => 1,
68 'currency' => 'NZD',
69 'goal_amount' => $this->testAmount,
6cdac50b 70 'is_pay_later' => 1,
f64a217a 71 'is_monetary' => TRUE,
dd1b539a 72 'is_email_receipt' => TRUE,
73 'receipt_from_email' => 'yourconscience@donate.com',
74 'receipt_from_name' => 'Ego Freud',
f64a217a
EM
75 );
76
77 $this->_priceSetParams = array(
78 'is_quick_config' => 1,
79 'extends' => 'CiviContribute',
80 'financial_type_id' => 'Donation',
21dfd5f5 81 'title' => 'my Page',
6a488035
TO
82 );
83 }
84
00be9182 85 public function tearDown() {
6a488035 86 foreach ($this->contactIds as $id) {
fc928539 87 $this->callAPISuccess('contact', 'delete', array('id' => $id));
611c7ece 88 }
f9342903 89 $this->quickCleanUpFinancialEntities();
6a488035
TO
90 }
91
92 public function testCreateContributionPage() {
fc928539 93 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
94 $this->assertEquals(1, $result['count']);
95 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
96 $this->getAndCheck($this->params, $result['id'], $this->_entity);
97 }
98
99 public function testGetBasicContributionPage() {
fc928539 100 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
6a488035 101 $this->id = $createResult['id'];
6a488035 102 $getParams = array(
6a488035
TO
103 'currency' => 'NZD',
104 'financial_type_id' => 1,
105 );
fc928539 106 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
107 $this->assertEquals(1, $getResult['count']);
6a488035
TO
108 }
109
110 public function testGetContributionPageByAmount() {
fc928539 111 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
6a488035 112 $this->id = $createResult['id'];
6a488035 113 $getParams = array(
5896d037 114 'amount' => '' . $this->testAmount, // 3456
6a488035
TO
115 'currency' => 'NZD',
116 'financial_type_id' => 1,
117 );
fc928539 118 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
119 $this->assertEquals(1, $getResult['count']);
6a488035
TO
120 }
121
122 public function testDeleteContributionPage() {
fc928539 123 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
124 $deleteParams = array('id' => $createResult['id']);
611c7ece 125 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
fc928539 126 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
127 $this->assertEquals(0, $checkDeleted['count']);
6a488035
TO
128 }
129
130 public function testGetFieldsContributionPage() {
fc928539 131 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
132 $this->assertEquals(12, $result['values']['start_date']['type']);
133 }
134
be26f3e0 135
d58b453e 136 /**
eceb18cc 137 * Test form submission with basic price set.
d58b453e 138 */
be26f3e0 139 public function testSubmit() {
f64a217a
EM
140 $this->setUpContributionPage();
141 $priceFieldID = reset($this->_ids['price_field']);
142 $priceFieldValueID = reset($this->_ids['price_field_value']);
143 $submitParams = array(
144 'price_' . $priceFieldID => $priceFieldValueID,
145 'id' => (int) $this->_ids['contribution_page'],
21dfd5f5 146 'amount' => 10,
be26f3e0
EM
147 );
148
f64a217a 149 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
05465712 150 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
151 //assert non-deductible amount
152 $this->assertEquals(5.00, $contribution['non_deductible_amount']);
f64a217a 153 }
5896d037 154
870156d6 155 /**
156 * Test form submission with billing first & last name where the contact does NOT
157 * otherwise have one.
158 */
159 public function testSubmitNewBillingNameData() {
160 $this->setUpContributionPage();
161 $contact = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com'));
162 $priceFieldID = reset($this->_ids['price_field']);
163 $priceFieldValueID = reset($this->_ids['price_field_value']);
164 $submitParams = array(
165 'price_' . $priceFieldID => $priceFieldValueID,
166 'id' => (int) $this->_ids['contribution_page'],
167 'amount' => 10,
168 'billing_first_name' => 'Wonder',
169 'billing_last_name' => 'Woman',
170 'contactID' => $contact['id'],
171 'email' => 'wonderwoman@amazon.com',
172 );
173
174 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
175 $contact = $this->callAPISuccess('Contact', 'get', array(
176 'id' => $contact['id'],
177 'return' => array(
178 'first_name',
179 'last_name',
180 'sort_name',
181 'display_name',
182 ),
183 ));
184 $this->assertEquals(array(
185 'first_name' => 'Wonder',
186 'last_name' => 'Woman',
187 'display_name' => 'Wonder Woman',
188 'sort_name' => 'Woman, Wonder',
189 'id' => $contact['id'],
190 'contact_id' => $contact['id'],
191 ), $contact['values'][$contact['id']]);
192
193 }
194
195 /**
196 * Test form submission with billing first & last name where the contact does
197 * otherwise have one and should not be overwritten.
198 */
199 public function testSubmitNewBillingNameDoNotOverwrite() {
200 $this->setUpContributionPage();
201 $contact = $this->callAPISuccess('Contact', 'create', array(
202 'contact_type' => 'Individual',
203 'email' => 'wonderwoman@amazon.com',
204 'first_name' => 'Super',
205 'last_name' => 'Boy',
206 ));
207 $priceFieldID = reset($this->_ids['price_field']);
208 $priceFieldValueID = reset($this->_ids['price_field_value']);
209 $submitParams = array(
210 'price_' . $priceFieldID => $priceFieldValueID,
211 'id' => (int) $this->_ids['contribution_page'],
212 'amount' => 10,
213 'billing_first_name' => 'Wonder',
214 'billing_last_name' => 'Woman',
215 'contactID' => $contact['id'],
216 'email' => 'wonderwoman@amazon.com',
217 );
218
219 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
220 $contact = $this->callAPISuccess('Contact', 'get', array(
221 'id' => $contact['id'],
222 'return' => array(
223 'first_name',
224 'last_name',
225 'sort_name',
226 'display_name',
227 ),
228 ));
229 $this->assertEquals(array(
230 'first_name' => 'Super',
231 'last_name' => 'Boy',
232 'display_name' => 'Super Boy',
233 'sort_name' => 'Boy, Super',
234 'id' => $contact['id'],
235 'contact_id' => $contact['id'],
236 ), $contact['values'][$contact['id']]);
237
238 }
239
7bc789a5 240 /**
241 * Test process with instant payment when more than one configured for the page.
242 *
243 * CRM-16923
244 */
245 public function testSubmitRecurMultiProcessorInstantPayment() {
246 $this->setUpContributionPage();
247 $this->setupPaymentProcessor();
d27635dc 248 $paymentProcessor2ID = $this->paymentProcessorCreate(array(
7bc789a5 249 'payment_processor_type_id' => 'Dummy',
250 'name' => 'processor 2',
251 'class_name' => 'Payment_Dummy',
252 'billing_mode' => 1,
253 ));
254 $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID);
70cc8754 255 $dummyPP->setDoDirectPaymentResult(array(
256 'payment_status_id' => 1,
257 'trxn_id' => 'create_first_success',
258 'fee_amount' => .85,
259 ));
f69a9ac3 260 $processor = $dummyPP->getPaymentProcessor();
7bc789a5 261 $this->callAPISuccess('ContributionPage', 'create', array(
d27635dc 262 'id' => $this->_ids['contribution_page'],
263 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']),
7bc789a5 264 ));
265
266 $priceFieldID = reset($this->_ids['price_field']);
267 $priceFieldValueID = reset($this->_ids['price_field_value']);
268 $submitParams = array(
269 'price_' . $priceFieldID => $priceFieldValueID,
270 'id' => (int) $this->_ids['contribution_page'],
271 'amount' => 10,
272 'is_recur' => 1,
273 'frequency_interval' => 1,
274 'frequency_unit' => 'month',
275 'payment_processor_id' => $paymentProcessor2ID,
276 );
277
278 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
70cc8754 279 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
7bc789a5 280 'contribution_page_id' => $this->_ids['contribution_page'],
281 'contribution_status_id' => 1,
282 ));
70cc8754 283 $this->assertEquals('create_first_success', $contribution['trxn_id']);
284 $this->assertEquals(10, $contribution['total_amount']);
285 $this->assertEquals(.85, $contribution['fee_amount']);
286 $this->assertEquals(9.15, $contribution['net_amount']);
bf722049 287 $this->_checkFinancialRecords(array(
288 'id' => $contribution['id'],
289 'total_amount' => $contribution['total_amount'],
f69a9ac3 290 'payment_instrument_id' => $processor['payment_instrument_id'],
bf722049 291 ), 'online');
7bc789a5 292 }
70cc8754 293
f64a217a 294 /**
eceb18cc 295 * Test submit with a membership block in place.
f64a217a 296 */
f9342903
EM
297 public function testSubmitMembershipBlockNotSeparatePayment() {
298 $this->setUpMembershipContributionPage();
f64a217a 299 $submitParams = array(
3e28c791 300 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
f9342903 301 'id' => (int) $this->_ids['contribution_page'],
f64a217a
EM
302 'amount' => 10,
303 'billing_first_name' => 'Billy',
304 'billing_middle_name' => 'Goat',
305 'billing_last_name' => 'Gruff',
306 'selectMembership' => $this->_ids['membership_type'],
307
308 );
309
a828d7b8 310 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
f9342903 311 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
840e3907 312 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
313 $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']));
f9342903
EM
314 }
315
2f59d010 316 /**
317 * Test submit with a membership block in place.
318 */
319 public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() {
320 $mut = new CiviMailUtils($this, TRUE);
321 $this->setUpMembershipContributionPage();
322 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
323
324 $submitParams = array(
325 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
326 'id' => (int) $this->_ids['contribution_page'],
327 'amount' => 10,
328 'billing_first_name' => 'Billy',
329 'billing_middle_name' => 'Goat',
330 'billing_last_name' => 'Gruff',
331 'selectMembership' => $this->_ids['membership_type'],
332 'email-Primary' => 'billy-goat@the-bridge.net',
9daadfce 333 'payment_processor_id' => $this->_paymentProcessor['id'],
334 'credit_card_number' => '4111111111111111',
335 'credit_card_type' => 'Visa',
336 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
337 'cvv2' => 123,
2f59d010 338 );
339
340 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
341 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
342 $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
343 $mut->checkMailLog(array(
344 'Membership Type: General',
345 ));
346 $mut->stop();
347 $mut->clearMessages();
348 }
349
350 /**
351 * Test submit with a membership block in place.
352 */
353 public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() {
354 $mut = new CiviMailUtils($this, TRUE);
355 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
356 $this->setUpMembershipContributionPage();
357 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
358
359 $submitParams = array(
360 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
361 'id' => (int) $this->_ids['contribution_page'],
362 'amount' => 0,
363 'billing_first_name' => 'Billy',
364 'billing_middle_name' => 'Goat',
365 'billing_last_name' => 'Gruffier',
366 'selectMembership' => $this->_ids['membership_type'],
367 'email-Primary' => 'billy-goat@the-new-bridge.net',
368 );
369
370 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
371 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
372 $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
373 $mut->checkMailLog(array(
374 'Membership Type: General',
375 'Gruffier',
376 ),
377 array(
378 'Amount',
379 )
380 );
381 $mut->stop();
9daadfce 382 $mut->clearMessages(999);
2f59d010 383 }
384
f9342903 385 /**
eceb18cc 386 * Test submit with a membership block in place.
f9342903
EM
387 */
388 public function testSubmitMembershipBlockIsSeparatePayment() {
389 $this->setUpMembershipContributionPage(TRUE);
9daadfce 390 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
f9342903 391 $submitParams = array(
3e28c791 392 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
f9342903
EM
393 'id' => (int) $this->_ids['contribution_page'],
394 'amount' => 10,
395 'billing_first_name' => 'Billy',
396 'billing_middle_name' => 'Goat',
397 'billing_last_name' => 'Gruff',
398 'selectMembership' => $this->_ids['membership_type'],
399 );
400
a828d7b8 401 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
f9342903
EM
402 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
403 $this->assertCount(2, $contributions['values']);
8e8d287f 404 $lines = $this->callAPISuccess('LineItem', 'get', array('sequential' => 1));
405 $this->assertEquals(10, $lines['values'][0]['line_total']);
f9342903
EM
406 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
407 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
408 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
409 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
410 }
f64a217a 411
2f59d010 412 /**
413 * Test submit with a membership block in place.
414 */
415 public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() {
416 $mut = new CiviMailUtils($this, TRUE);
417 $this->setUpMembershipContributionPage(TRUE);
418 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
419
420 $submitParams = array(
421 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
422 'id' => (int) $this->_ids['contribution_page'],
423 'amount' => 10,
424 'billing_first_name' => 'Billy',
425 'billing_middle_name' => 'Goat',
426 'billing_last_name' => 'Gruff',
427 'selectMembership' => $this->_ids['membership_type'],
428 'email-Primary' => 'billy-goat@the-bridge.net',
9daadfce 429 'payment_processor_id' => $this->_paymentProcessor['id'],
430 'credit_card_number' => '4111111111111111',
431 'credit_card_type' => 'Visa',
432 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
433 'cvv2' => 123,
2f59d010 434 );
435
436 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
437 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
438 $this->assertCount(2, $contributions['values']);
439 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
440 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
441 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
442 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
de6a9861
JM
443 // We should have two separate email messages, each with their own amount
444 // line and no total line.
445 $mut->checkAllMailLog(
446 array(
447 'Amount: $ 2.00',
448 'Amount: $ 10.00',
449 'Membership Fee',
450 ),
451 array(
c2ce0c2a 452 'Total: $',
461ae02f 453 )
de6a9861 454 );
2f59d010 455 $mut->stop();
9daadfce 456 $mut->clearMessages(999);
2f59d010 457 }
458
459 /**
460 * Test submit with a membership block in place.
461 */
462 public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() {
463 $mut = new CiviMailUtils($this, TRUE);
464 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
465 $this->setUpMembershipContributionPage(TRUE);
466 $this->addProfile('supporter_profile', $this->_ids['contribution_page']);
467
468 $submitParams = array(
469 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
470 'id' => (int) $this->_ids['contribution_page'],
471 'amount' => 0,
472 'billing_first_name' => 'Billy',
473 'billing_middle_name' => 'Goat',
474 'billing_last_name' => 'Gruffalo',
475 'selectMembership' => $this->_ids['membership_type'],
476 'payment_processor_id' => 0,
477 'email-Primary' => 'gruffalo@the-bridge.net',
478 );
479
480 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
481 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
482 $this->assertCount(2, $contributions['values']);
483 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
484 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
485 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
486 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
487 $mut->checkMailLog(array(
488 'Gruffalo',
489 'General Membership: $ 0.00',
490 'Membership Fee',
491 ));
492 $mut->stop();
493 $mut->clearMessages();
494 }
495
797c4f88 496 /**
eceb18cc 497 * Test submit with a membership block in place.
797c4f88
EM
498 */
499 public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
500 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6)));
501 $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50));
502 $this->setUpMembershipContributionPage(TRUE);
503 $submitParams = array(
504 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1],
505 'id' => (int) $this->_ids['contribution_page'],
506 'amount' => 10,
507 'billing_first_name' => 'Billy',
508 'billing_middle_name' => 'Goat',
509 'billing_last_name' => 'Gruff',
510 'selectMembership' => $this->_ids['membership_type'][1],
511 );
512
a828d7b8 513 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
6c6e6187 514 $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
797c4f88
EM
515 $this->assertCount(2, $contributions['values']);
516 $ids = array_keys($contributions['values']);
517 $this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']);
518 $this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']);
519 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
520 $this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']);
521 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
522 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
523 }
524
8ca611b7 525 /**
eceb18cc 526 * Test submit with a membership block in place.
329f3f66
EM
527 *
528 * We are expecting a separate payment for the membership vs the contribution.
8ca611b7 529 */
329f3f66 530 public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() {
58d8c7e2 531 $mut = new CiviMailUtils($this, TRUE);
8ca611b7 532 $this->setUpMembershipContributionPage(TRUE);
0193ebdb 533 $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']);
534 $processor->setDoDirectPaymentResult(array('fee_amount' => .72));
8ca611b7
EM
535 $submitParams = array(
536 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
537 'id' => (int) $this->_ids['contribution_page'],
538 'amount' => 10,
539 'billing_first_name' => 'Billy',
540 'billing_middle_name' => 'Goat',
541 'billing_last_name' => 'Gruff',
58d8c7e2 542 'email-Primary' => 'henry@8th.king',
8ca611b7 543 'selectMembership' => $this->_ids['membership_type'],
7bc789a5 544 'payment_processor_id' => $this->_paymentProcessor['id'],
8ca611b7
EM
545 'credit_card_number' => '4111111111111111',
546 'credit_card_type' => 'Visa',
5896d037 547 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
8ca611b7
EM
548 'cvv2' => 123,
549 );
05990684 550
a828d7b8 551 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
5896d037 552 $contributions = $this->callAPISuccess('contribution', 'get', array(
92915c55
TO
553 'contribution_page_id' => $this->_ids['contribution_page'],
554 'contribution_status_id' => 1,
555 ));
8ca611b7
EM
556 $this->assertCount(2, $contributions['values']);
557 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
558 $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
559 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
560 $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
f2bca231 561 $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_table' => 'civicrm_membership'));
562 $this->assertEquals($lineItem['entity_id'], $membership['id']);
563 $this->assertEquals($lineItem['contribution_id'], $membershipPayment['contribution_id']);
564 $this->assertEquals($lineItem['qty'], 1);
565 $this->assertEquals($lineItem['unit_price'], 2);
566 $this->assertEquals($lineItem['line_total'], 2);
0193ebdb 567 foreach ($contributions['values'] as $contribution) {
568 $this->assertEquals(.72, $contribution['fee_amount']);
569 $this->assertEquals($contribution['total_amount'] - .72, $contribution['net_amount']);
570 }
58d8c7e2 571 // The total string is currently absent & it seems worse with - although at some point
572 // it may have been intended
573 $mut->checkAllMailLog(array('$ 2.00', 'Contribution Amount', '$ 10.00'), array('Total:'));
574 $mut->stop();
575 $mut->clearMessages();
8ca611b7 576 }
f8fe0df6 577
5961bd47
EM
578 /**
579 * Test that when a transaction fails the pending contribution remains.
580 *
581 * An activity should also be created. CRM-16417.
582 */
583 public function testSubmitPaymentProcessorFailure() {
584 $this->setUpContributionPage();
585 $this->setupPaymentProcessor();
586 $this->createLoggedInUser();
587 $priceFieldID = reset($this->_ids['price_field']);
588 $priceFieldValueID = reset($this->_ids['price_field_value']);
589 $submitParams = array(
590 'price_' . $priceFieldID => $priceFieldValueID,
591 'id' => (int) $this->_ids['contribution_page'],
592 'amount' => 10,
593 'payment_processor_id' => 1,
594 'credit_card_number' => '4111111111111111',
595 'credit_card_type' => 'Visa',
596 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008),
597 'cvv2' => 123,
598 );
599
600 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
601 $contribution = $this->callAPISuccessGetSingle('contribution', array(
602 'contribution_page_id' => $this->_ids['contribution_page'],
603 'contribution_status_id' => 2,
604 ));
605
606 $this->callAPISuccessGetSingle('activity', array(
607 'source_record_id' => $contribution['id'],
608 'activity_type_id' => 'Failed Payment',
609 ));
610
5961bd47
EM
611 }
612
f8fe0df6 613 /**
dd1b539a 614 * Test submit recurring membership with immediate confirmation (IATS style).
615 *
e6fa4056 616 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
1fee3ad2 617 * processor (IATS style - denoted by returning trxn_id)
e6fa4056
EM
618 * - the first creates a new membership, completed contribution, in progress recurring. Check these
619 * - create another - end date should be extended
f8fe0df6 620 */
8bef2e38 621 public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment() {
f8fe0df6 622 $this->params['is_recur'] = 1;
f8fe0df6 623 $this->params['recur_frequency_unit'] = 'month';
624 $this->setUpMembershipContributionPage();
7c85dc65 625 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
8bef2e38 626 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
f69a9ac3 627 $processor = $dummyPP->getPaymentProcessor();
f8fe0df6 628
629 $submitParams = array(
630 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
631 'id' => (int) $this->_ids['contribution_page'],
632 'amount' => 10,
633 'billing_first_name' => 'Billy',
634 'billing_middle_name' => 'Goat',
635 'billing_last_name' => 'Gruff',
636 'email' => 'billy@goat.gruff',
637 'selectMembership' => $this->_ids['membership_type'],
579a1fb7 638 'payment_processor_id' => 1,
f8fe0df6 639 'credit_card_number' => '4111111111111111',
640 'credit_card_type' => 'Visa',
5896d037 641 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
f8fe0df6 642 'cvv2' => 123,
643 'is_recur' => 1,
644 'frequency_interval' => 1,
645 'frequency_unit' => 'month',
646 );
647
a828d7b8 648 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
5896d037 649 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
92915c55
TO
650 'contribution_page_id' => $this->_ids['contribution_page'],
651 'contribution_status_id' => 1,
652 ));
f69a9ac3 653 $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
0739d6cf 654
655 $this->assertEquals('create_first_success', $contribution['trxn_id']);
f8fe0df6 656 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
657 $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
658 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
659 $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
660 $this->assertEquals(1, $membership['status_id']);
661 $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
356bfcaf 662
663 $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id']));
f8fe0df6 664 //renew it with processor setting completed - should extend membership
665 $submitParams['contact_id'] = $contribution['contact_id'];
8bef2e38 666 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
f8fe0df6 667 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
5896d037 668 $this->callAPISuccess('contribution', 'getsingle', array(
92915c55
TO
669 'id' => array('NOT IN' => array($contribution['id'])),
670 'contribution_page_id' => $this->_ids['contribution_page'],
671 'contribution_status_id' => 1,
672 ));
f8fe0df6 673 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
674 $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']);
675 $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
f69a9ac3 676 $this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']);
91259407 677 $this->assertEquals(5, $recurringContribution['contribution_status_id']);
f8fe0df6 678 }
679
13a16f43 680 /**
681 * Test submit recurring membership with immediate confirmation (IATS style).
682 *
683 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
684 * processor (IATS style - denoted by returning trxn_id)
685 * - the first creates a new membership, completed contribution, in progress recurring. Check these
686 * - create another - end date should be extended
687 */
65e172a3 688 public function testSubmitMembershipComplexNonPriceSetPaymentPaymentProcessorRecurInstantPayment() {
13a16f43 689 $this->params['is_recur'] = 1;
690 $this->params['recur_frequency_unit'] = 'month';
691 // Add a membership so membership & contribution are not both 1.
692 $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
693 $this->setUpMembershipContributionPage();
694 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
695 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
696 $processor = $dummyPP->getPaymentProcessor();
697
698 $submitParams = array(
699 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
700 'price_' . $this->_ids['price_field']['cont'] => 88,
701 'id' => (int) $this->_ids['contribution_page'],
702 'amount' => 10,
703 'billing_first_name' => 'Billy',
704 'billing_middle_name' => 'Goat',
705 'billing_last_name' => 'Gruff',
706 'email' => 'billy@goat.gruff',
707 'selectMembership' => $this->_ids['membership_type'],
708 'payment_processor_id' => 1,
709 'credit_card_number' => '4111111111111111',
710 'credit_card_type' => 'Visa',
711 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
712 'cvv2' => 123,
713 'is_recur' => 1,
714 'frequency_interval' => 1,
715 'frequency_unit' => 'month',
716 );
717
718 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
719 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
720 'contribution_page_id' => $this->_ids['contribution_page'],
721 'contribution_status_id' => 1,
722 ));
723 $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
724
725 $this->assertEquals('create_first_success', $contribution['trxn_id']);
726 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
727 $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
728 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
729 $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
730 $this->assertEquals(1, $membership['status_id']);
731 $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
732
733 $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id']));
734 $this->assertEquals(2, $lines['count']);
735 $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
736 $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
737 $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
738 $this->assertEquals($contribution['id'], $lines['values'][1]['entity_id']);
739 $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1));
740
741 //renew it with processor setting completed - should extend membership
742 $submitParams['contact_id'] = $contribution['contact_id'];
743 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
744 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
745 $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array(
746 'id' => array('NOT IN' => array($contribution['id'])),
747 'contribution_page_id' => $this->_ids['contribution_page'],
748 'contribution_status_id' => 1,
749 ));
750 $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id']));
751 $this->assertEquals(2, $lines['count']);
752 $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
753 $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
754 $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
755 $this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']);
756
757 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
758 $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']);
759 $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
760 $this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']);
761 $this->assertEquals(5, $recurringContribution['contribution_status_id']);
762 }
763
65e172a3 764 /**
765 * Test submit recurring membership with immediate confirmation (IATS style).
766 *
767 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
768 * processor (IATS style - denoted by returning trxn_id)
769 * - the first creates a new membership, completed contribution, in progress recurring. Check these
770 * - create another - end date should be extended
771 */
772 public function testSubmitMembershipComplexPriceSetPaymentPaymentProcessorRecurInstantPayment() {
773 $this->params['is_recur'] = 1;
774 $this->params['recur_frequency_unit'] = 'month';
775 // Add a membership so membership & contribution are not both 1.
776 $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
777 $this->createPriceSetWithPage();
778 $this->addSecondOrganizationMembershipToPriceSet();
779 $this->setupPaymentProcessor();
780
781 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
782 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
783 $processor = $dummyPP->getPaymentProcessor();
784
785 $submitParams = array(
786 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value']['cont'],
787 'price_' . $this->_ids['price_field']['org1'] => $this->_ids['price_field_value']['org1'],
788 'price_' . $this->_ids['price_field']['org2'] => $this->_ids['price_field_value']['org2'],
789 'id' => (int) $this->_ids['contribution_page'],
790 'amount' => 10,
791 'billing_first_name' => 'Billy',
792 'billing_middle_name' => 'Goat',
793 'billing_last_name' => 'Gruff',
794 'email' => 'billy@goat.gruff',
795 'selectMembership' => NULL,
796 'payment_processor_id' => 1,
797 'credit_card_number' => '4111111111111111',
798 'credit_card_type' => 'Visa',
799 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
800 'cvv2' => 123,
801 'frequency_interval' => 1,
802 'frequency_unit' => 'month',
803 );
804
805 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
806 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
807 'contribution_page_id' => $this->_ids['contribution_page'],
808 'contribution_status_id' => 1,
809 ));
810 $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
811
812 $this->assertEquals('create_first_success', $contribution['trxn_id']);
813 $membershipPayments = $this->callAPISuccess('membership_payment', 'get', array(
814 'sequential' => 1,
815 'contribution_id' => $contribution['id'],
816 ));
817 $this->assertEquals(2, $membershipPayments['count']);
818 $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id']));
819 $this->assertEquals(3, $lines['count']);
820 $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
821 $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
822 $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
823 $this->assertEquals($contribution['id'], $lines['values'][1]['entity_id']);
824 $this->assertEquals('civicrm_membership', $lines['values'][2]['entity_table']);
825 $this->assertEquals($preExistingMembershipID + 2, $lines['values'][2]['entity_id']);
826
827 $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1));
828 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1));
829
830 //renew it with processor setting completed - should extend membership
831 $submitParams['contact_id'] = $contribution['contact_id'];
832 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
833 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
834 $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array(
835 'id' => array('NOT IN' => array($contribution['id'])),
836 'contribution_page_id' => $this->_ids['contribution_page'],
837 'contribution_status_id' => 1,
838 ));
839 $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id']));
840 $this->assertEquals(3, $lines['count']);
841 $this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
842 $this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
843 $this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
844 $this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']);
845
846 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1));
847 $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']);
848 }
849
850 /**
851 * Extend the price set with a second organisation's membership.
852 */
853 public function addSecondOrganizationMembershipToPriceSet() {
854 $organization2ID = $this->organizationCreate();
855 $membershipTypes = $this->callAPISuccess('MembershipType', 'get', array());
856 $this->_ids['membership_type'] = array_keys($membershipTypes['values']);
857 $this->_ids['membership_type']['org2'] = $this->membershipTypeCreate(array('contact_id' => $organization2ID, 'name' => 'Org 2'));
858 $priceField = $this->callAPISuccess('PriceField', 'create', array(
859 'price_set_id' => $this->_ids['price_set'],
860 'html_type' => 'Radio',
861 'name' => 'Org1 Price',
862 'label' => 'Org1Price',
863 ));
864 $this->_ids['price_field']['org1'] = $priceField['id'];
865
866 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
867 'name' => 'org1 amount',
868 'label' => 'org 1 Amount',
869 'amount' => 2,
870 'financial_type_id' => 'Member Dues',
871 'format.only_id' => TRUE,
872 'membership_type_id' => reset($this->_ids['membership_type']),
873 'price_field_id' => $priceField['id'],
874 ));
875 $this->_ids['price_field_value']['org1'] = $priceFieldValue;
876
877 $priceField = $this->callAPISuccess('PriceField', 'create', array(
878 'price_set_id' => $this->_ids['price_set'],
879 'html_type' => 'Radio',
880 'name' => 'Org2 Price',
881 'label' => 'Org2Price',
882 ));
883 $this->_ids['price_field']['org2'] = $priceField['id'];
884
885 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
886 'name' => 'org2 amount',
887 'label' => 'org 2 Amount',
888 'amount' => 200,
889 'financial_type_id' => 'Member Dues',
890 'format.only_id' => TRUE,
891 'membership_type_id' => $this->_ids['membership_type']['org2'],
892 'price_field_id' => $priceField['id'],
893 ));
894 $this->_ids['price_field_value']['org2'] = $priceFieldValue;
895
896 }
897
449f4c90 898 /**
899 * Test submit recurring membership with immediate confirmation (IATS style).
900 *
901 * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate
902 * processor (IATS style - denoted by returning trxn_id)
903 * - the first creates a new membership, completed contribution, in progress recurring. Check these
904 * - create another - end date should be extended
905 */
906 public function testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePaymentRecurInstantPayment() {
907
908 $this->setUpMembershipContributionPage(TRUE);
909 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
910 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
911
912 $submitParams = array(
913 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
914 'id' => (int) $this->_ids['contribution_page'],
915 'amount' => 10,
916 'billing_first_name' => 'Billy',
917 'billing_middle_name' => 'Goat',
918 'billing_last_name' => 'Gruff',
919 'email' => 'billy@goat.gruff',
920 'selectMembership' => $this->_ids['membership_type'],
921 'payment_processor_id' => 1,
922 'credit_card_number' => '4111111111111111',
923 'credit_card_type' => 'Visa',
924 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
925 'cvv2' => 123,
926 'is_recur' => 1,
927 'auto_renew' => TRUE,
928 'frequency_interval' => 1,
929 'frequency_unit' => 'month',
930 );
931
932 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
933 $contribution = $this->callAPISuccess('contribution', 'get', array(
934 'contribution_page_id' => $this->_ids['contribution_page'],
935 'contribution_status_id' => 1,
936 ));
937
938 $this->assertEquals(2, $contribution['count']);
939 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
940 $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
941 $this->assertNotEmpty($contribution['values'][$membershipPayment['contribution_id']]['contribution_recur_id']);
942 $this->callAPISuccess('contribution_recur', 'getsingle', array());
943 }
944
f8fe0df6 945 /**
e6fa4056
EM
946 * Test submit recurring membership with delayed confirmation (Authorize.net style)
947 * - we process 2 membership transactions against with a recurring contribution against a contribution page with a delayed
948 * processor (Authorize.net style - denoted by NOT returning trxn_id)
949 * - the first creates a pending membership, pending contribution, penging recurring. Check these
950 * - complete the transaction
951 * - create another - end date should NOT be extended
f8fe0df6 952 */
953 public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() {
954 $this->params['is_recur'] = 1;
f8fe0df6 955 $this->params['recur_frequency_unit'] = 'month';
956 $this->setUpMembershipContributionPage();
ab30e033 957 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
b5eacf76 958 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
356bfcaf 959 $this->membershipTypeCreate(array('name' => 'Student'));
960
961 // Add a contribution & a couple of memberships so the id will not be 1 & will differ from membership id.
962 // This saves us from 'accidental success'.
51f8c59c 963 $this->contributionCreate(array('contact_id' => $this->contactIds[0]));
356bfcaf 964 $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
965 $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student'));
f8fe0df6 966
967 $submitParams = array(
968 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
969 'id' => (int) $this->_ids['contribution_page'],
970 'amount' => 10,
971 'billing_first_name' => 'Billy',
972 'billing_middle_name' => 'Goat',
973 'billing_last_name' => 'Gruff',
974 'email' => 'billy@goat.gruff',
975 'selectMembership' => $this->_ids['membership_type'],
579a1fb7 976 'payment_processor_id' => 1,
f8fe0df6 977 'credit_card_number' => '4111111111111111',
978 'credit_card_type' => 'Visa',
5896d037 979 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
f8fe0df6 980 'cvv2' => 123,
e6fa4056
EM
981 'is_recur' => 1,
982 'frequency_interval' => 1,
983 'frequency_unit' => 'month',
f8fe0df6 984 );
985
a828d7b8 986 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
5896d037 987 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
92915c55
TO
988 'contribution_page_id' => $this->_ids['contribution_page'],
989 'contribution_status_id' => 2,
990 ));
356bfcaf 991
f8fe0df6 992 $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
993 $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
994 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
995 $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
e6fa4056 996 $this->assertEquals(5, $membership['status_id']);
51f8c59c 997
998 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
999 $this->assertEquals('civicrm_membership', $line['entity_table']);
1000 $this->assertEquals($membership['id'], $line['entity_id']);
1001
5896d037 1002 $this->callAPISuccess('contribution', 'completetransaction', array(
92915c55
TO
1003 'id' => $contribution['id'],
1004 'trxn_id' => 'ipn_called',
b396c447 1005 'payment_processor_id' => $this->_paymentProcessor['id'],
92915c55 1006 ));
51f8c59c 1007 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
1008 $this->assertEquals('civicrm_membership', $line['entity_table']);
1009 $this->assertEquals($membership['id'], $line['entity_id']);
1010
e6fa4056 1011 $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
f8fe0df6 1012 //renew it with processor setting completed - should extend membership
1013 $submitParams = array_merge($submitParams, array(
5896d037
TO
1014 'contact_id' => $contribution['contact_id'],
1015 'is_recur' => 1,
1016 'frequency_interval' => 1,
1017 'frequency_unit' => 'month',
1018 )
f8fe0df6 1019 );
51f8c59c 1020
b5eacf76 1021 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
f8fe0df6 1022 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
6c6e6187 1023 $newContribution = $this->callAPISuccess('contribution', 'getsingle', array(
5896d037 1024 'id' => array(
21dfd5f5 1025 'NOT IN' => array($contribution['id']),
5896d037
TO
1026 ),
1027 'contribution_page_id' => $this->_ids['contribution_page'],
21dfd5f5 1028 'contribution_status_id' => 2,
5896d037 1029 )
f8fe0df6 1030 );
51f8c59c 1031 $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $newContribution['id']));
1032 $this->assertEquals('civicrm_membership', $line['entity_table']);
1033 $this->assertEquals($membership['id'], $line['entity_id']);
e6fa4056 1034
f8fe0df6 1035 $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
1036 //no renewal as the date hasn't changed
1037 $this->assertEquals($membership['end_date'], $renewedMembership['end_date']);
e6fa4056
EM
1038 $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id']));
1039 $this->assertEquals(2, $recurringContribution['contribution_status_id']);
f8fe0df6 1040 }
1041
f9342903 1042 /**
eceb18cc 1043 * Set up membership contribution page.
f9342903
EM
1044 * @param bool $isSeparatePayment
1045 */
00be9182 1046 public function setUpMembershipContributionPage($isSeparatePayment = FALSE) {
f9342903 1047 $this->setUpMembershipBlockPriceSet();
a380f4a0 1048 $this->setupPaymentProcessor();
f9342903
EM
1049 $this->setUpContributionPage();
1050
1051 $this->callAPISuccess('membership_block', 'create', array(
1052 'entity_id' => $this->_ids['contribution_page'],
1053 'entity_table' => 'civicrm_contribution_page',
1054 'is_required' => TRUE,
1055 'is_active' => TRUE,
1056 'is_separate_payment' => $isSeparatePayment,
1057 'membership_type_default' => $this->_ids['membership_type'],
1058 ));
f64a217a
EM
1059 }
1060
dccd9f4f
ERL
1061 /**
1062 * Set up pledge block.
1063 */
1064 public function setUpPledgeBlock() {
1065 $params = array(
1066 'entity_table' => 'civicrm_contribution_page',
1067 'entity_id' => $this->_ids['contribution_page'],
1068 'pledge_frequency_unit' => 'week',
1069 'is_pledge_interval' => 0,
1070 'pledge_start_date' => json_encode(array('calendar_date' => date('Ymd', strtotime("+1 month")))),
1071 );
1072 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
1073 $this->_ids['pledge_block_id'] = $pledgeBlock->id;
1074 }
1075
f9342903 1076 /**
dd1b539a 1077 * The default data set does not include a complete default membership price set - not quite sure why.
1078 *
f9342903
EM
1079 * This function ensures it exists & populates $this->_ids with it's data
1080 */
00be9182 1081 public function setUpMembershipBlockPriceSet() {
5896d037 1082 $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array(
92915c55
TO
1083 'name' => 'default_membership_type_amount',
1084 'return' => 'id',
1085 ));
f9342903 1086 if (empty($this->_ids['membership_type'])) {
3e28c791 1087 $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
f9342903 1088 }
3e28c791
EM
1089 $priceField = $this->callAPISuccess('price_field', 'create', array(
1090 'price_set_id' => reset($this->_ids['price_set']),
1091 'name' => 'membership_amount',
1092 'label' => 'Membership Amount',
1093 'html_type' => 'Radio',
1094 'sequential' => 1,
1095 ));
1096 $this->_ids['price_field'][] = $priceField['id'];
dd1b539a 1097
3e28c791
EM
1098 foreach ($this->_ids['membership_type'] as $membershipTypeID) {
1099 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
f9342903
EM
1100 'name' => 'membership_amount',
1101 'label' => 'Membership Amount',
65e172a3 1102 'amount' => 2,
43dbd988 1103 'financial_type_id' => 'Donation',
3e28c791
EM
1104 'format.only_id' => TRUE,
1105 'membership_type_id' => $membershipTypeID,
1106 'price_field_id' => $priceField['id'],
f9342903 1107 ));
840e3907 1108 $this->_ids['price_field_value'][] = $priceFieldValue;
f9342903 1109 }
65e172a3 1110 if (!empty($this->_ids['membership_type']['org2'])) {
1111 $priceField = $this->callAPISuccess('price_field', 'create', array(
1112 'price_set_id' => reset($this->_ids['price_set']),
1113 'name' => 'membership_org2',
1114 'label' => 'Membership Org2',
1115 'html_type' => 'Checkbox',
1116 'sequential' => 1,
1117 ));
1118 $this->_ids['price_field']['org2'] = $priceField['id'];
1119
1120 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1121 'name' => 'membership_org2',
1122 'label' => 'Membership org 2',
1123 'amount' => 55,
1124 'financial_type_id' => 'Member Dues',
1125 'format.only_id' => TRUE,
1126 'membership_type_id' => $this->_ids['membership_type']['org2'],
1127 'price_field_id' => $priceField['id'],
1128 ));
1129 $this->_ids['price_field_value']['org2'] = $priceFieldValue;
1130 }
13a16f43 1131 $priceField = $this->callAPISuccess('price_field', 'create', array(
1132 'price_set_id' => reset($this->_ids['price_set']),
1133 'name' => 'Contribution',
1134 'label' => 'Contribution',
1135 'html_type' => 'Text',
1136 'sequential' => 1,
1137 'is_enter_qty' => 1,
1138 ));
1139 $this->_ids['price_field']['cont'] = $priceField['id'];
1140 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1141 'name' => 'contribution',
1142 'label' => 'Give me money',
1143 'amount' => 88,
1144 'financial_type_id' => 'Donation',
1145 'format.only_id' => TRUE,
1146 'price_field_id' => $priceField['id'],
1147 ));
1148 $this->_ids['price_field_value'][] = $priceFieldValue;
f9342903 1149 }
3e28c791 1150
2f59d010 1151 /**
1152 * Add text field other amount to the price set.
1153 */
1154 public function addOtherAmountFieldToMembershipPriceSet() {
1155 $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', array(
1156 'price_set_id' => reset($this->_ids['price_set']),
1157 'name' => 'other_amount',
1158 'label' => 'Other Amount',
1159 'html_type' => 'Text',
1160 'format.only_id' => TRUE,
1161 'sequential' => 1,
1162 ));
1163 $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', array(
1164 'financial_type_id' => 'Donation',
1165 'format.only_id' => TRUE,
1166 'label' => 'Other Amount',
1167 'amount' => 1,
1168 'price_field_id' => $this->_ids['price_field']['other_amount'],
1169 ));
1170 }
1171
f64a217a 1172 /**
eceb18cc 1173 * Help function to set up contribution page with some defaults.
f64a217a 1174 */
00be9182 1175 public function setUpContributionPage() {
f64a217a
EM
1176 $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
1177 if (empty($this->_ids['price_set'])) {
1178 $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams);
1179 $this->_ids['price_set'][] = $priceSet['id'];
1180 }
1181 $priceSetID = reset($this->_ids['price_set']);
5896d037 1182 CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
f9342903
EM
1183
1184 if (empty($this->_ids['price_field'])) {
1185 $priceField = $this->callAPISuccess('price_field', 'create', array(
1186 'price_set_id' => $priceSetID,
1187 'label' => 'Goat Breed',
1188 'html_type' => 'Radio',
1189 ));
1190 $this->_ids['price_field'] = array($priceField['id']);
1191 }
1192 if (empty($this->_ids['price_field_value'])) {
1193 $this->callAPISuccess('price_field_value', 'create', array(
1194 'price_set_id' => $priceSetID,
1195 'price_field_id' => $priceField['id'],
1196 'label' => 'Long Haired Goat',
43dbd988 1197 'financial_type_id' => 'Donation',
f9342903 1198 'amount' => 20,
05465712 1199 'non_deductible_amount' => 15,
f9342903
EM
1200 )
1201 );
1202 $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
1203 'price_set_id' => $priceSetID,
1204 'price_field_id' => $priceField['id'],
1205 'label' => 'Shoe-eating Goat',
43dbd988 1206 'financial_type_id' => 'Donation',
f9342903 1207 'amount' => 10,
05465712 1208 'non_deductible_amount' => 5,
f9342903
EM
1209 )
1210 );
1211 $this->_ids['price_field_value'] = array($priceFieldValue['id']);
1212 }
f64a217a 1213 $this->_ids['contribution_page'] = $contributionPageResult['id'];
be26f3e0
EM
1214 }
1215
6a488035 1216 public static function setUpBeforeClass() {
6c6e6187 1217 // put stuff here that should happen before all tests in this unit
6a488035
TO
1218 }
1219
5896d037 1220 public static function tearDownAfterClass() {
6a488035
TO
1221 $tablesToTruncate = array(
1222 'civicrm_contact',
1223 'civicrm_financial_type',
1224 'civicrm_contribution',
1225 'civicrm_contribution_page',
1226 );
1227 $unitTest = new CiviUnitTestCase();
1228 $unitTest->quickCleanup($tablesToTruncate);
1229 }
96025800 1230
a380f4a0
EM
1231 /**
1232 * Create a payment processor instance.
1233 */
1234 protected function setupPaymentProcessor() {
1235 $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array(
1236 'payment_processor_type_id' => 'Dummy',
1237 'class_name' => 'Payment_Dummy',
1238 'billing_mode' => 1,
1239 ));
1240 $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id']));
1241 }
1242
dccd9f4f
ERL
1243 /**
1244 * Test submit recurring pledge.
1245 *
1246 * - we process 1 pledge with a future start date. A recur contribution and the pledge should be created with first payment date in the future.
1247 */
1248 public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() {
1249 $this->params['adjust_recur_start_date'] = TRUE;
1250 $this->params['is_pay_later'] = FALSE;
1251 $this->setUpContributionPage();
1252 $this->setUpPledgeBlock();
1253 $this->setupPaymentProcessor();
1254 $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
1255 $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
1256
1257 $submitParams = array(
1258 'id' => (int) $this->_ids['contribution_page'],
1259 'amount' => 100,
1260 'billing_first_name' => 'Billy',
1261 'billing_middle_name' => 'Goat',
1262 'billing_last_name' => 'Gruff',
1263 'email' => 'billy@goat.gruff',
1264 'payment_processor_id' => 1,
1265 'credit_card_number' => '4111111111111111',
1266 'credit_card_type' => 'Visa',
1267 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
1268 'cvv2' => 123,
1269 'pledge_frequency_interval' => 1,
1270 'pledge_frequency_unit' => 'week',
1271 'pledge_installments' => 3,
1272 'is_pledge' => TRUE,
1273 'pledge_block_id' => (int) $this->_ids['pledge_block_id'],
1274 );
1275
1276 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
1277
1278 // Check if contribution created.
1279 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1280 'contribution_page_id' => $this->_ids['contribution_page'],
1281 'contribution_status_id' => 'Completed', // Will be pending when actual payment processor is used (dummy processor does not support future payments).
1282 ));
1283
1284 $this->assertEquals('create_first_success', $contribution['trxn_id']);
1285
1286 // Check if pledge created.
1287 $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
1288 $this->assertEquals(date('Ymd', strtotime($pledge['pledge_start_date'])), date('Ymd', strtotime("+1 month")));
1289 $this->assertEquals($pledge['pledge_amount'], 300.00);
1290
1291 // Check if pledge payments created.
1292 $params = array(
1293 'pledge_id' => $pledge['id'],
1294 );
1295 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1296 $this->assertEquals($pledgePayment['count'], 3);
1297 $this->assertEquals(date('Ymd', strtotime($pledgePayment['values'][1]['scheduled_date'])), date('Ymd', strtotime("+1 month")));
1298 $this->assertEquals($pledgePayment['values'][1]['scheduled_amount'], 100.00);
1299 $this->assertEquals($pledgePayment['values'][1]['status_id'], 1); // Will be pending when actual payment processor is used (dummy processor does not support future payments).
1300
1301 // Check contribution recur record.
1302 $recur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
1303 $this->assertEquals(date('Ymd', strtotime($recur['start_date'])), date('Ymd', strtotime("+1 month")));
1304 $this->assertEquals($recur['amount'], 100.00);
1305 $this->assertEquals($recur['contribution_status_id'], 5); // In progress status.
1306 }
1307
603577b2
E
1308 /**
1309 * Test submit pledge payment.
1310 *
1311 * - test submitting a pledge payment using contribution form.
1312 */
1313 public function testSubmitPledgePayment() {
1314 $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment();
1315 $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
1316 $params = array(
1317 'pledge_id' => $pledge['id'],
1318 );
1319 $submitParams = array(
1320 'id' => (int) $pledge['pledge_contribution_page_id'],
1321 'pledge_amount' => array(2 => 1),
1322 'billing_first_name' => 'Billy',
1323 'billing_middle_name' => 'Goat',
1324 'billing_last_name' => 'Gruff',
1325 'email' => 'billy@goat.gruff',
1326 'payment_processor_id' => 1,
1327 'credit_card_number' => '4111111111111111',
1328 'credit_card_type' => 'Visa',
1329 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
1330 'cvv2' => 123,
1331 'pledge_id' => $pledge['id'],
1332 'cid' => $pledge['contact_id'],
1333 'contact_id' => $pledge['contact_id'],
1334 'amount' => 100.00,
1335 'is_pledge' => TRUE,
1336 'pledge_block_id' => $this->_ids['pledge_block_id'],
1337 );
1338 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1339 $this->assertEquals($pledgePayment['values'][2]['status_id'], 2);
1340
1341 $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
1342
1343 // Check if contribution created.
1344 $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
1345 'contribution_page_id' => $pledge['pledge_contribution_page_id'],
1346 'contribution_status_id' => 'Completed',
1347 'contact_id' => $pledge['contact_id'],
1348 'contribution_recur_id' => array('IS NULL' => 1),
1349 ));
1350
1351 $this->assertEquals(100.00, $contribution['total_amount']);
1352 $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
1353 $this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed");
1354 $this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']);
1355 }
1356
a93e9452
PN
1357 /**
1358 * Test form submission with multiple option price set.
1359 */
1360 public function testSubmitContributionPageWithPriceSet() {
1361 $this->_priceSetParams['is_quick_config'] = 0;
1362 $this->setUpContributionPage();
1363 $submitParams = array(
1364 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
1365 'id' => (int) $this->_ids['contribution_page'],
1366 'amount' => 80,
1367 'first_name' => 'Billy',
1368 'last_name' => 'Gruff',
1369 'email' => 'billy@goat.gruff',
1370 'is_pay_later' => TRUE,
1371 );
1372 $this->addPriceFields($submitParams);
1373
1374 $this->callAPISuccess('contribution_page', 'submit', $submitParams);
1375 $contribution = $this->callAPISuccessGetSingle('contribution', array(
1376 'contribution_page_id' => $this->_ids['contribution_page'],
1377 'contribution_status_id' => 2,
1378 ));
1379 $this->callAPISuccessGetCount(
1380 'LineItem',
1381 array(
1382 'contribution_id' => $contribution['id'],
1383 ),
1384 3
1385 );
1386 }
1387
1388 /**
1389 * Function to add additional price fields to priceset.
1390 * @param array $params
1391 */
1392 public function addPriceFields(&$params) {
1393 $priceSetID = reset($this->_ids['price_set']);
1394 $priceField = $this->callAPISuccess('price_field', 'create', array(
1395 'price_set_id' => $priceSetID,
1396 'label' => 'Chicken Breed',
1397 'html_type' => 'CheckBox',
1398 ));
1399 $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', array(
1400 'price_set_id' => $priceSetID,
1401 'price_field_id' => $priceField['id'],
1402 'label' => 'Shoe-eating chicken -1',
1403 'financial_type_id' => 'Donation',
1404 'amount' => 30,
1405 ));
1406 $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', array(
1407 'price_set_id' => $priceSetID,
1408 'price_field_id' => $priceField['id'],
1409 'label' => 'Shoe-eating chicken -2',
1410 'financial_type_id' => 'Donation',
1411 'amount' => 40,
1412 ));
1413 $params['price_' . $priceField['id']] = array(
1414 $priceFieldValue1['id'] => 1,
1415 $priceFieldValue2['id'] => 1,
1416 );
1417 }
1418
6a488035 1419}