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 usefusul, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class generates form components for processing a contribution | |
803d4bc0 | 36 | * CRM-16229 - During the event registration bulk action via search we |
37 | * need to inherit CRM_Contact_Form_Task so that we can inherit functions | |
38 | * like getContactIds and make use of controller state. But this is not possible | |
39 | * because CRM_Event_Form_Participant inherits this class. | |
40 | * Ideal situation would be something like | |
41 | * CRM_Event_Form_Participant extends CRM_Contact_Form_Task, | |
42 | * CRM_Contribute_Form_AbstractEditPayment | |
43 | * However this is not possible. Currently PHP does not support multiple | |
44 | * inheritance. So work around solution is to extend this class with | |
45 | * CRM_Contact_Form_Task which further extends CRM_Core_Form. | |
6a488035 TO |
46 | * |
47 | */ | |
5b7c9ebc | 48 | class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { |
6a488035 TO |
49 | public $_mode; |
50 | ||
51 | public $_action; | |
52 | ||
53 | public $_bltID; | |
54 | ||
55 | public $_fields; | |
56 | ||
a6513ad5 EM |
57 | /** |
58 | * @var array current payment processor including a copy of the object in 'object' key | |
59 | */ | |
6a488035 TO |
60 | public $_paymentProcessor; |
61 | public $_recurPaymentProcessors; | |
62 | ||
dc913073 | 63 | /** |
100fef9d | 64 | * Array of processor options in the format id => array($id => $label) |
dc913073 EM |
65 | * WARNING it appears that the format used to differ to this and there are places in the code that |
66 | * expect the old format. $this->_paymentProcessors provides the additional data which this | |
67 | * array seems to have provided in the past | |
68 | * @var array | |
69 | */ | |
6a488035 TO |
70 | public $_processors; |
71 | ||
72 | /** | |
100fef9d | 73 | * Available payment processors with full details including the key 'object' indexed by their id |
dc913073 EM |
74 | * @var array |
75 | */ | |
76 | protected $_paymentProcessors = array(); | |
bf4253e7 EM |
77 | |
78 | /** | |
79 | * Instance of the payment processor object. | |
80 | * | |
81 | * @var CRM_Core_Payment | |
82 | */ | |
83 | protected $_paymentObject; | |
84 | ||
dc913073 | 85 | /** |
fe482240 | 86 | * The id of the contribution that we are processing. |
6a488035 TO |
87 | * |
88 | * @var int | |
6a488035 TO |
89 | */ |
90 | public $_id; | |
91 | ||
92 | /** | |
fe482240 | 93 | * The id of the premium that we are proceessing. |
6a488035 TO |
94 | * |
95 | * @var int | |
6a488035 TO |
96 | */ |
97 | public $_premiumID = NULL; | |
4691b077 EM |
98 | |
99 | /** | |
100 | * @var CRM_Contribute_DAO_ContributionProduct | |
101 | */ | |
6a488035 TO |
102 | public $_productDAO = NULL; |
103 | ||
104 | /** | |
100fef9d | 105 | * The id of the note |
6a488035 TO |
106 | * |
107 | * @var int | |
6a488035 TO |
108 | */ |
109 | public $_noteID; | |
110 | ||
111 | /** | |
100fef9d | 112 | * The id of the contact associated with this contribution |
6a488035 TO |
113 | * |
114 | * @var int | |
6a488035 TO |
115 | */ |
116 | public $_contactID; | |
117 | ||
118 | /** | |
100fef9d | 119 | * The id of the pledge payment that we are processing |
6a488035 TO |
120 | * |
121 | * @var int | |
6a488035 TO |
122 | */ |
123 | public $_ppID; | |
124 | ||
125 | /** | |
100fef9d | 126 | * The id of the pledge that we are processing |
6a488035 TO |
127 | * |
128 | * @var int | |
6a488035 TO |
129 | */ |
130 | public $_pledgeID; | |
131 | ||
132 | /** | |
100fef9d | 133 | * Is this contribution associated with an online |
6a488035 TO |
134 | * financial transaction |
135 | * | |
136 | * @var boolean | |
6a488035 TO |
137 | */ |
138 | public $_online = FALSE; | |
139 | ||
140 | /** | |
141 | * Stores all product option | |
142 | * | |
143 | * @var array | |
6a488035 TO |
144 | */ |
145 | public $_options; | |
146 | ||
147 | /** | |
100fef9d | 148 | * Stores the honor id |
6a488035 TO |
149 | * |
150 | * @var int | |
6a488035 TO |
151 | */ |
152 | public $_honorID = NULL; | |
153 | ||
154 | /** | |
dde5a0ef | 155 | * Store the financial Type ID |
6a488035 TO |
156 | * |
157 | * @var array | |
158 | */ | |
159 | public $_contributionType; | |
160 | ||
161 | /** | |
162 | * The contribution values if an existing contribution | |
163 | */ | |
164 | public $_values; | |
165 | ||
166 | /** | |
167 | * The pledge values if this contribution is associated with pledge | |
168 | */ | |
169 | public $_pledgeValues; | |
170 | ||
171 | public $_contributeMode = 'direct'; | |
172 | ||
173 | public $_context; | |
174 | ||
175 | public $_compId; | |
176 | ||
d424ffde | 177 | /** |
6a488035 TO |
178 | * Store the line items if price set used. |
179 | */ | |
180 | public $_lineItems; | |
181 | ||
0be0b79d EM |
182 | /** |
183 | * Is this a backoffice form | |
184 | * (this will affect whether paypal express code is displayed) | |
185 | * @var bool | |
186 | */ | |
187 | public $isBackOffice = TRUE; | |
188 | ||
6a488035 | 189 | protected $_formType; |
dde5a0ef EM |
190 | |
191 | /** | |
192 | * @var mystery variable screaming out for documentation | |
193 | */ | |
6a488035 TO |
194 | protected $_cdType; |
195 | ||
dde5a0ef | 196 | /** |
100fef9d | 197 | * Array of fields to display on billingBlock.tpl - this is not fully implemented but basically intent is the panes/fieldsets on this page should |
dde5a0ef EM |
198 | * be all in this array in order like |
199 | * 'credit_card' => array('credit_card_number' ... | |
200 | * 'billing_details' => array('first_name' ... | |
201 | * | |
202 | * such that both the fields and the order can be more easily altered by payment processors & other extensions | |
203 | * @var array | |
204 | */ | |
205 | public $billingFieldSets = array(); | |
206 | ||
186c9c17 | 207 | /** |
100fef9d | 208 | * @param int $id |
186c9c17 | 209 | */ |
d5397f2f PJ |
210 | public function showRecordLinkMesssage($id) { |
211 | $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $id, 'contribution_status_id'); | |
212 | if (CRM_Contribute_PseudoConstant::contributionStatus($statusId, 'name') == 'Partially paid') { | |
213 | if ($pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'participant_id', 'contribution_id')) { | |
214 | $recordPaymentLink = CRM_Utils_System::url('civicrm/payment', | |
215 | "reset=1&id={$pid}&cid={$this->_contactID}&action=add&component=event" | |
216 | ); | |
217 | CRM_Core_Session::setStatus(ts('Please use the <a href="%1">Record Payment</a> form if you have received an additional payment for this Partially paid contribution record.', array(1 => $recordPaymentLink)), ts('Notice'), 'alert'); | |
218 | } | |
219 | } | |
220 | } | |
221 | ||
186c9c17 | 222 | /** |
100fef9d | 223 | * @param int $id |
186c9c17 EM |
224 | * @param $values |
225 | */ | |
6a488035 TO |
226 | public function buildValuesAndAssignOnline_Note_Type($id, &$values) { |
227 | $ids = array(); | |
228 | $params = array('id' => $id); | |
229 | CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); | |
230 | ||
231 | //Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL) | |
232 | $this->_online = FALSE; | |
233 | $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id); | |
a7488080 | 234 | if (!empty($fids['financialTrxnId'])) { |
6a488035 TO |
235 | $this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id'); |
236 | } | |
eea16664 | 237 | |
6a488035 TO |
238 | // Also don't allow user to update some fields for recurring contributions. |
239 | if (!$this->_online) { | |
240 | $this->_online = CRM_Utils_Array::value('contribution_recur_id', $values); | |
241 | } | |
eea16664 | 242 | |
6a488035 TO |
243 | $this->assign('isOnline', $this->_online ? TRUE : FALSE); |
244 | ||
6a488035 TO |
245 | //to get note id |
246 | $daoNote = new CRM_Core_BAO_Note(); | |
247 | $daoNote->entity_table = 'civicrm_contribution'; | |
248 | $daoNote->entity_id = $id; | |
249 | if ($daoNote->find(TRUE)) { | |
250 | $this->_noteID = $daoNote->id; | |
251 | $values['note'] = $daoNote->note; | |
252 | } | |
253 | $this->_contributionType = $values['financial_type_id']; | |
6a488035 TO |
254 | } |
255 | ||
256 | /** | |
014c4014 TO |
257 | * @param string $type |
258 | * Eg 'Contribution'. | |
6a488035 TO |
259 | * @param string $subType |
260 | * @param int $entityId | |
261 | */ | |
262 | public function applyCustomData($type, $subType, $entityId) { | |
263 | $this->set('type', $type); | |
264 | $this->set('subType', $subType); | |
265 | $this->set('entityId', $entityId); | |
266 | ||
267 | CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, 1, $type, $entityId); | |
268 | CRM_Custom_Form_CustomData::buildQuickForm($this); | |
269 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
270 | } | |
271 | ||
4691b077 | 272 | /** |
100fef9d | 273 | * @param int $id |
4691b077 EM |
274 | * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find(); |
275 | */ | |
6ea503d4 | 276 | public function assignPremiumProduct($id) { |
6a488035 TO |
277 | $sql = " |
278 | SELECT * | |
279 | FROM civicrm_contribution_product | |
280 | WHERE contribution_id = {$id} | |
281 | "; | |
282 | $dao = CRM_Core_DAO::executeQuery($sql, | |
283 | CRM_Core_DAO::$_nullArray | |
284 | ); | |
285 | if ($dao->fetch()) { | |
286 | $this->_premiumID = $dao->id; | |
287 | $this->_productDAO = $dao; | |
288 | } | |
289 | $dao->free(); | |
290 | } | |
291 | ||
292 | /** | |
293 | * This function process contribution related objects. | |
03110609 | 294 | * |
014c4014 TO |
295 | * @param int $contributionId |
296 | * @param int $statusId | |
297 | * @param int|null $previousStatusId | |
03110609 EM |
298 | * |
299 | * @return null|string | |
6a488035 | 300 | */ |
35874a67 | 301 | protected function updateRelatedComponent($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { |
6a488035 TO |
302 | $statusMsg = NULL; |
303 | if (!$contributionId || !$statusId) { | |
304 | return $statusMsg; | |
305 | } | |
306 | ||
307 | $params = array( | |
308 | 'contribution_id' => $contributionId, | |
309 | 'contribution_status_id' => $statusId, | |
310 | 'previous_contribution_status_id' => $previousStatusId, | |
35874a67 | 311 | 'receive_date' => $receiveDate, |
6a488035 TO |
312 | ); |
313 | ||
314 | $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); | |
315 | ||
316 | if (!is_array($updateResult) || | |
317 | !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || | |
318 | !is_array($updatedComponents) || | |
319 | empty($updatedComponents) | |
320 | ) { | |
321 | return $statusMsg; | |
322 | } | |
323 | ||
324 | // get the user display name. | |
325 | $sql = " | |
326 | SELECT display_name as displayName | |
327 | FROM civicrm_contact | |
328 | LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) | |
329 | WHERE civicrm_contribution.id = {$contributionId}"; | |
330 | $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); | |
331 | ||
332 | // get the status message for user. | |
333 | foreach ($updatedComponents as $componentName => $updatedStatusId) { | |
334 | ||
335 | if ($componentName == 'CiviMember') { | |
336 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
337 | CRM_Member_PseudoConstant::membershipStatus() | |
338 | ); | |
339 | if ($updatedStatusName == 'Cancelled') { | |
340 | $statusMsg .= "<br />" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
341 | } | |
342 | elseif ($updatedStatusName == 'Expired') { | |
343 | $statusMsg .= "<br />" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName)); | |
344 | } | |
d008a264 | 345 | else { |
13299a2b JM |
346 | $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult); |
347 | if ($endDate) { | |
d008a264 | 348 | $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.", |
353ffa53 TO |
349 | array( |
350 | 1 => $userDisplayName, | |
351 | 2 => $endDate, | |
352 | ) | |
353 | ); | |
d008a264 | 354 | } |
6a488035 TO |
355 | } |
356 | } | |
357 | ||
358 | if ($componentName == 'CiviEvent') { | |
359 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
360 | CRM_Event_PseudoConstant::participantStatus() | |
361 | ); | |
362 | if ($updatedStatusName == 'Cancelled') { | |
363 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
364 | } | |
365 | elseif ($updatedStatusName == 'Registered') { | |
366 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been updated.", array(1 => $userDisplayName)); | |
367 | } | |
368 | } | |
369 | ||
370 | if ($componentName == 'CiviPledge') { | |
371 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
372 | CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') | |
373 | ); | |
374 | if ($updatedStatusName == 'Cancelled') { | |
375 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
376 | } | |
377 | elseif ($updatedStatusName == 'Failed') { | |
378 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Failed.", array(1 => $userDisplayName)); | |
379 | } | |
380 | elseif ($updatedStatusName == 'Completed') { | |
381 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been updated.", array(1 => $userDisplayName)); | |
382 | } | |
383 | } | |
384 | } | |
385 | ||
386 | return $statusMsg; | |
387 | } | |
388 | ||
389 | /** | |
a6c01b45 | 390 | * @return array |
16b10e64 | 391 | * Array of valid processors. The array resembles the DB table but also has 'object' as a key |
fbcb6fba EM |
392 | * @throws Exception |
393 | */ | |
394 | public function getValidProcessors() { | |
fbcb6fba EM |
395 | $defaultID = NULL; |
396 | $capabilities = array('BackOffice'); | |
52767de0 EM |
397 | if ($this->_mode) { |
398 | $capabilities[] = (ucfirst($this->_mode) . 'Mode'); | |
fbcb6fba EM |
399 | } |
400 | $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities); | |
44b6505d EM |
401 | return $processors; |
402 | ||
6a488035 TO |
403 | } |
404 | ||
405 | /** | |
fe482240 | 406 | * Assign billing type id to bltID. |
6a488035 | 407 | * |
44b6505d | 408 | * @throws CRM_Core_Exception |
6a488035 TO |
409 | * @return void |
410 | */ | |
411 | public function assignBillingType() { | |
180409a4 | 412 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); |
6a488035 TO |
413 | $this->_bltID = array_search('Billing', $locationTypes); |
414 | if (!$this->_bltID) { | |
44b6505d | 415 | throw new CRM_Core_Exception(ts('Please set a location type of %1', array(1 => 'Billing'))); |
6a488035 TO |
416 | } |
417 | $this->set('bltID', $this->_bltID); | |
418 | $this->assign('bltID', $this->_bltID); | |
419 | } | |
420 | ||
421 | /** | |
422 | * Assign $this->processors, $this->recurPaymentProcessors, and related Smarty variables | |
423 | */ | |
424 | public function assignProcessors() { | |
425 | //ensure that processor has a valid config | |
426 | //only valid processors get display to user | |
44b6505d | 427 | |
6a488035 | 428 | if ($this->_mode) { |
52767de0 | 429 | $this->assign('processorSupportsFutureStartDate', CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('supportsFutureRecurStartDate'))); |
dc913073 EM |
430 | $this->_paymentProcessors = $this->getValidProcessors(); |
431 | if (!isset($this->_paymentProcessor['id'])) { | |
432 | // if the payment processor isn't set yet (as indicated by the presence of an id,) we'll grab the first one which should be the default | |
433 | $this->_paymentProcessor = reset($this->_paymentProcessors); | |
434 | } | |
435 | if (empty($this->_paymentProcessors)) { | |
44b6505d EM |
436 | throw new CRM_Core_Exception(ts('You will need to configure the %1 settings for your Payment Processor before you can submit a credit card transactions.', array(1 => $this->_mode))); |
437 | } | |
353ffa53 | 438 | $this->_processors = array(); |
dc913073 | 439 | foreach ($this->_paymentProcessors as $id => $processor) { |
44b6505d | 440 | $this->_processors[$id] = ts($processor['name']); |
a5c78dea EM |
441 | if (!empty($processor['description'])) { |
442 | $this->_processors[$id] .= ' : ' . ts($processor['description']); | |
443 | } | |
44b6505d | 444 | } |
6a488035 | 445 | //get the valid recurring processors. |
239b0928 | 446 | $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; |
dd660b68 | 447 | $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); |
5b67fa51 | 448 | $this->_recurPaymentProcessors = array_intersect_key($this->_processors, $recurring); |
6a488035 TO |
449 | } |
450 | $this->assign('recurringPaymentProcessorIds', | |
451 | empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors)) | |
452 | ); | |
453 | ||
454 | // this required to show billing block | |
03110609 | 455 | // @todo remove this assignment the billing block is now designed to be always included but will not show fieldsets unless those sets of fields are assigned |
44b6505d | 456 | $this->assign_by_ref('paymentProcessor', $processor); |
6a488035 TO |
457 | } |
458 | ||
186c9c17 | 459 | /** |
6ea503d4 TO |
460 | * Get current currency from DB or use default currency. |
461 | * | |
186c9c17 EM |
462 | * @param $submittedValues |
463 | * | |
464 | * @return mixed | |
465 | */ | |
6ea503d4 | 466 | public function getCurrency($submittedValues) { |
6a488035 TO |
467 | $config = CRM_Core_Config::singleton(); |
468 | ||
469 | $currentCurrency = CRM_Utils_Array::value('currency', | |
470 | $this->_values, | |
471 | $config->defaultCurrency | |
472 | ); | |
473 | ||
474 | // use submitted currency if present else use current currency | |
475 | $result = CRM_Utils_Array::value('currency', | |
476 | $submittedValues, | |
477 | $currentCurrency | |
478 | ); | |
479 | return $result; | |
480 | } | |
481 | ||
186c9c17 | 482 | /** |
100fef9d | 483 | * @param int $financialTypeId |
186c9c17 EM |
484 | * |
485 | * @return array | |
486 | */ | |
6a488035 TO |
487 | public function getFinancialAccounts($financialTypeId) { |
488 | $financialAccounts = array(); | |
489 | CRM_Core_PseudoConstant::populate($financialAccounts, | |
490 | 'CRM_Financial_DAO_EntityFinancialAccount', | |
491 | $all = TRUE, | |
492 | $retrieve = 'financial_account_id', | |
493 | $filter = NULL, | |
494 | " entity_id = {$financialTypeId} ", NULL, 'account_relationship'); | |
495 | return $financialAccounts; | |
496 | } | |
497 | ||
186c9c17 | 498 | /** |
100fef9d CW |
499 | * @param int $financialTypeId |
500 | * @param int $relationTypeId | |
186c9c17 EM |
501 | * |
502 | * @return mixed | |
503 | */ | |
6a488035 TO |
504 | public function getFinancialAccount($financialTypeId, $relationTypeId) { |
505 | $financialAccounts = $this->getFinancialAccounts($financialTypeId); | |
506 | return CRM_Utils_Array::value($relationTypeId, $financialAccounts); | |
507 | } | |
508 | ||
509 | public function preProcessPledge() { | |
510 | //get the payment values associated with given pledge payment id OR check for payments due. | |
511 | $this->_pledgeValues = array(); | |
512 | if ($this->_ppID) { | |
513 | $payParams = array('id' => $this->_ppID); | |
514 | ||
515 | CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); | |
516 | $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']); | |
517 | $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']); | |
518 | $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']); | |
519 | ||
520 | //get all status | |
521 | $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); | |
522 | if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { | |
523 | CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); | |
524 | } | |
525 | ||
526 | //get the pledge values associated with given pledge payment. | |
527 | ||
528 | $ids = array(); | |
529 | $pledgeParams = array('id' => $this->_pledgeID); | |
530 | CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); | |
531 | $this->assign('ppID', $this->_ppID); | |
532 | } | |
533 | else { | |
534 | // Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206 | |
535 | if (isset($this->_contactID)) { | |
536 | $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); | |
537 | ||
538 | if (!empty($contactPledges)) { | |
539 | $payments = $paymentsDue = NULL; | |
540 | $multipleDue = FALSE; | |
541 | foreach ($contactPledges as $key => $pledgeId) { | |
542 | $payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId); | |
543 | if ($payments) { | |
544 | if ($paymentsDue) { | |
545 | $multipleDue = TRUE; | |
546 | break; | |
547 | } | |
548 | else { | |
549 | $paymentsDue = $payments; | |
550 | } | |
551 | } | |
552 | } | |
553 | if ($multipleDue) { | |
554 | // Show link to pledge tab since more than one pledge has a payment due | |
555 | $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', | |
556 | "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge" | |
557 | ); | |
558 | CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab)), ts('Notice'), 'alert'); | |
559 | } | |
560 | elseif ($paymentsDue) { | |
561 | // Show user link to oldest Pending or Overdue pledge payment | |
562 | $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']); | |
563 | $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date')); | |
564 | if ($this->_mode) { | |
565 | $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
566 | "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live" | |
567 | ); | |
568 | } | |
569 | else { | |
570 | $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
571 | "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge" | |
572 | ); | |
573 | } | |
574 | CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to enter a pledge payment</a>.', array( | |
575 | 1 => $ppUrl, | |
576 | 2 => $ppAmountDue, | |
21dfd5f5 | 577 | 3 => $ppSchedDate, |
6a488035 TO |
578 | )), ts('Notice'), 'alert'); |
579 | } | |
580 | } | |
581 | } | |
582 | } | |
583 | } | |
584 | ||
186c9c17 EM |
585 | /** |
586 | * @param $submittedValues | |
587 | * | |
588 | * @return mixed | |
589 | */ | |
6a488035 TO |
590 | public function unsetCreditCardFields($submittedValues) { |
591 | //Offline Contribution. | |
592 | $unsetParams = array( | |
593 | 'payment_processor_id', | |
594 | "email-{$this->_bltID}", | |
595 | 'hidden_buildCreditCard', | |
596 | 'hidden_buildDirectDebit', | |
597 | 'billing_first_name', | |
598 | 'billing_middle_name', | |
599 | 'billing_last_name', | |
600 | 'street_address-5', | |
601 | "city-{$this->_bltID}", | |
602 | "state_province_id-{$this->_bltID}", | |
603 | "postal_code-{$this->_bltID}", | |
604 | "country_id-{$this->_bltID}", | |
605 | 'credit_card_number', | |
606 | 'cvv2', | |
607 | 'credit_card_exp_date', | |
608 | 'credit_card_type', | |
609 | ); | |
610 | foreach ($unsetParams as $key) { | |
611 | if (isset($submittedValues[$key])) { | |
612 | unset($submittedValues[$key]); | |
613 | } | |
614 | } | |
615 | return $submittedValues; | |
616 | } | |
617 | ||
cc984198 | 618 | /** |
100fef9d | 619 | * Common block for setting up the parts of a form that relate to credit / debit card |
cc984198 EM |
620 | * @throws Exception |
621 | */ | |
622 | protected function assignPaymentRelatedVariables() { | |
623 | try { | |
99efbbf8 EM |
624 | if ($this->_contactID) { |
625 | list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); | |
626 | $this->assign('displayName', $this->userDisplayName); | |
627 | } | |
cc984198 EM |
628 | if ($this->_mode) { |
629 | $this->assignProcessors(); | |
cc984198 EM |
630 | |
631 | $this->assignBillingType(); | |
632 | ||
633 | $this->_fields = array(); | |
634 | CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); | |
635 | } | |
636 | } | |
637 | catch (CRM_Core_Exception $e) { | |
638 | CRM_Core_Error::fatal($e->getMessage()); | |
639 | } | |
640 | } | |
96025800 | 641 | |
6a488035 | 642 | } |