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 | ||
42e8b05c EM |
207 | /** |
208 | * Pre process function with common actions. | |
209 | */ | |
210 | public function preProcess() { | |
211 | $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
212 | $this->assign('contactID', $this->_contactID); | |
213 | ||
214 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); | |
215 | } | |
216 | ||
186c9c17 | 217 | /** |
100fef9d | 218 | * @param int $id |
186c9c17 | 219 | */ |
d5397f2f PJ |
220 | public function showRecordLinkMesssage($id) { |
221 | $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $id, 'contribution_status_id'); | |
222 | if (CRM_Contribute_PseudoConstant::contributionStatus($statusId, 'name') == 'Partially paid') { | |
223 | if ($pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'participant_id', 'contribution_id')) { | |
224 | $recordPaymentLink = CRM_Utils_System::url('civicrm/payment', | |
225 | "reset=1&id={$pid}&cid={$this->_contactID}&action=add&component=event" | |
226 | ); | |
227 | 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'); | |
228 | } | |
229 | } | |
230 | } | |
231 | ||
186c9c17 | 232 | /** |
100fef9d | 233 | * @param int $id |
186c9c17 EM |
234 | * @param $values |
235 | */ | |
6a488035 TO |
236 | public function buildValuesAndAssignOnline_Note_Type($id, &$values) { |
237 | $ids = array(); | |
238 | $params = array('id' => $id); | |
239 | CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); | |
240 | ||
241 | //Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL) | |
242 | $this->_online = FALSE; | |
243 | $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id); | |
a7488080 | 244 | if (!empty($fids['financialTrxnId'])) { |
6a488035 TO |
245 | $this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id'); |
246 | } | |
eea16664 | 247 | |
6a488035 TO |
248 | // Also don't allow user to update some fields for recurring contributions. |
249 | if (!$this->_online) { | |
250 | $this->_online = CRM_Utils_Array::value('contribution_recur_id', $values); | |
251 | } | |
eea16664 | 252 | |
6a488035 TO |
253 | $this->assign('isOnline', $this->_online ? TRUE : FALSE); |
254 | ||
6a488035 TO |
255 | //to get note id |
256 | $daoNote = new CRM_Core_BAO_Note(); | |
257 | $daoNote->entity_table = 'civicrm_contribution'; | |
258 | $daoNote->entity_id = $id; | |
259 | if ($daoNote->find(TRUE)) { | |
260 | $this->_noteID = $daoNote->id; | |
261 | $values['note'] = $daoNote->note; | |
262 | } | |
263 | $this->_contributionType = $values['financial_type_id']; | |
6a488035 TO |
264 | } |
265 | ||
266 | /** | |
014c4014 TO |
267 | * @param string $type |
268 | * Eg 'Contribution'. | |
6a488035 TO |
269 | * @param string $subType |
270 | * @param int $entityId | |
271 | */ | |
272 | public function applyCustomData($type, $subType, $entityId) { | |
273 | $this->set('type', $type); | |
274 | $this->set('subType', $subType); | |
275 | $this->set('entityId', $entityId); | |
276 | ||
277 | CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, 1, $type, $entityId); | |
278 | CRM_Custom_Form_CustomData::buildQuickForm($this); | |
279 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
280 | } | |
281 | ||
4691b077 | 282 | /** |
100fef9d | 283 | * @param int $id |
4691b077 EM |
284 | * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find(); |
285 | */ | |
6ea503d4 | 286 | public function assignPremiumProduct($id) { |
6a488035 TO |
287 | $sql = " |
288 | SELECT * | |
289 | FROM civicrm_contribution_product | |
290 | WHERE contribution_id = {$id} | |
291 | "; | |
292 | $dao = CRM_Core_DAO::executeQuery($sql, | |
293 | CRM_Core_DAO::$_nullArray | |
294 | ); | |
295 | if ($dao->fetch()) { | |
296 | $this->_premiumID = $dao->id; | |
297 | $this->_productDAO = $dao; | |
298 | } | |
299 | $dao->free(); | |
300 | } | |
301 | ||
302 | /** | |
303 | * This function process contribution related objects. | |
03110609 | 304 | * |
014c4014 TO |
305 | * @param int $contributionId |
306 | * @param int $statusId | |
307 | * @param int|null $previousStatusId | |
03110609 EM |
308 | * |
309 | * @return null|string | |
6a488035 | 310 | */ |
35874a67 | 311 | protected function updateRelatedComponent($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { |
6a488035 TO |
312 | $statusMsg = NULL; |
313 | if (!$contributionId || !$statusId) { | |
314 | return $statusMsg; | |
315 | } | |
316 | ||
317 | $params = array( | |
318 | 'contribution_id' => $contributionId, | |
319 | 'contribution_status_id' => $statusId, | |
320 | 'previous_contribution_status_id' => $previousStatusId, | |
35874a67 | 321 | 'receive_date' => $receiveDate, |
6a488035 TO |
322 | ); |
323 | ||
324 | $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); | |
325 | ||
326 | if (!is_array($updateResult) || | |
327 | !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || | |
328 | !is_array($updatedComponents) || | |
329 | empty($updatedComponents) | |
330 | ) { | |
331 | return $statusMsg; | |
332 | } | |
333 | ||
334 | // get the user display name. | |
335 | $sql = " | |
336 | SELECT display_name as displayName | |
337 | FROM civicrm_contact | |
338 | LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) | |
339 | WHERE civicrm_contribution.id = {$contributionId}"; | |
340 | $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); | |
341 | ||
342 | // get the status message for user. | |
343 | foreach ($updatedComponents as $componentName => $updatedStatusId) { | |
344 | ||
345 | if ($componentName == 'CiviMember') { | |
346 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
347 | CRM_Member_PseudoConstant::membershipStatus() | |
348 | ); | |
349 | if ($updatedStatusName == 'Cancelled') { | |
350 | $statusMsg .= "<br />" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
351 | } | |
352 | elseif ($updatedStatusName == 'Expired') { | |
353 | $statusMsg .= "<br />" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName)); | |
354 | } | |
d008a264 | 355 | else { |
13299a2b JM |
356 | $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult); |
357 | if ($endDate) { | |
d008a264 | 358 | $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.", |
353ffa53 TO |
359 | array( |
360 | 1 => $userDisplayName, | |
361 | 2 => $endDate, | |
362 | ) | |
363 | ); | |
d008a264 | 364 | } |
6a488035 TO |
365 | } |
366 | } | |
367 | ||
368 | if ($componentName == 'CiviEvent') { | |
369 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
370 | CRM_Event_PseudoConstant::participantStatus() | |
371 | ); | |
372 | if ($updatedStatusName == 'Cancelled') { | |
373 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
374 | } | |
375 | elseif ($updatedStatusName == 'Registered') { | |
376 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been updated.", array(1 => $userDisplayName)); | |
377 | } | |
378 | } | |
379 | ||
380 | if ($componentName == 'CiviPledge') { | |
381 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, | |
382 | CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') | |
383 | ); | |
384 | if ($updatedStatusName == 'Cancelled') { | |
385 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Cancelled.", array(1 => $userDisplayName)); | |
386 | } | |
387 | elseif ($updatedStatusName == 'Failed') { | |
388 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Failed.", array(1 => $userDisplayName)); | |
389 | } | |
390 | elseif ($updatedStatusName == 'Completed') { | |
391 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been updated.", array(1 => $userDisplayName)); | |
392 | } | |
393 | } | |
394 | } | |
395 | ||
396 | return $statusMsg; | |
397 | } | |
398 | ||
399 | /** | |
a6c01b45 | 400 | * @return array |
16b10e64 | 401 | * Array of valid processors. The array resembles the DB table but also has 'object' as a key |
fbcb6fba EM |
402 | * @throws Exception |
403 | */ | |
404 | public function getValidProcessors() { | |
fbcb6fba EM |
405 | $defaultID = NULL; |
406 | $capabilities = array('BackOffice'); | |
52767de0 EM |
407 | if ($this->_mode) { |
408 | $capabilities[] = (ucfirst($this->_mode) . 'Mode'); | |
fbcb6fba EM |
409 | } |
410 | $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities); | |
44b6505d EM |
411 | return $processors; |
412 | ||
6a488035 TO |
413 | } |
414 | ||
6a488035 TO |
415 | /** |
416 | * Assign $this->processors, $this->recurPaymentProcessors, and related Smarty variables | |
417 | */ | |
418 | public function assignProcessors() { | |
419 | //ensure that processor has a valid config | |
420 | //only valid processors get display to user | |
44b6505d | 421 | |
6a488035 | 422 | if ($this->_mode) { |
52767de0 | 423 | $this->assign('processorSupportsFutureStartDate', CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('supportsFutureRecurStartDate'))); |
dc913073 EM |
424 | $this->_paymentProcessors = $this->getValidProcessors(); |
425 | if (!isset($this->_paymentProcessor['id'])) { | |
426 | // 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 | |
427 | $this->_paymentProcessor = reset($this->_paymentProcessors); | |
428 | } | |
429 | if (empty($this->_paymentProcessors)) { | |
44b6505d EM |
430 | 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))); |
431 | } | |
353ffa53 | 432 | $this->_processors = array(); |
dc913073 | 433 | foreach ($this->_paymentProcessors as $id => $processor) { |
44b6505d | 434 | $this->_processors[$id] = ts($processor['name']); |
a5c78dea EM |
435 | if (!empty($processor['description'])) { |
436 | $this->_processors[$id] .= ' : ' . ts($processor['description']); | |
437 | } | |
44b6505d | 438 | } |
6a488035 | 439 | //get the valid recurring processors. |
239b0928 | 440 | $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; |
dd660b68 | 441 | $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); |
5b67fa51 | 442 | $this->_recurPaymentProcessors = array_intersect_key($this->_processors, $recurring); |
6a488035 TO |
443 | } |
444 | $this->assign('recurringPaymentProcessorIds', | |
445 | empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors)) | |
446 | ); | |
447 | ||
448 | // this required to show billing block | |
03110609 | 449 | // @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 | 450 | $this->assign_by_ref('paymentProcessor', $processor); |
6a488035 TO |
451 | } |
452 | ||
186c9c17 | 453 | /** |
6ea503d4 TO |
454 | * Get current currency from DB or use default currency. |
455 | * | |
186c9c17 EM |
456 | * @param $submittedValues |
457 | * | |
458 | * @return mixed | |
459 | */ | |
6ea503d4 | 460 | public function getCurrency($submittedValues) { |
6a488035 TO |
461 | $config = CRM_Core_Config::singleton(); |
462 | ||
463 | $currentCurrency = CRM_Utils_Array::value('currency', | |
464 | $this->_values, | |
465 | $config->defaultCurrency | |
466 | ); | |
467 | ||
468 | // use submitted currency if present else use current currency | |
469 | $result = CRM_Utils_Array::value('currency', | |
470 | $submittedValues, | |
471 | $currentCurrency | |
472 | ); | |
473 | return $result; | |
474 | } | |
475 | ||
186c9c17 | 476 | /** |
100fef9d | 477 | * @param int $financialTypeId |
186c9c17 EM |
478 | * |
479 | * @return array | |
480 | */ | |
6a488035 TO |
481 | public function getFinancialAccounts($financialTypeId) { |
482 | $financialAccounts = array(); | |
483 | CRM_Core_PseudoConstant::populate($financialAccounts, | |
484 | 'CRM_Financial_DAO_EntityFinancialAccount', | |
485 | $all = TRUE, | |
486 | $retrieve = 'financial_account_id', | |
487 | $filter = NULL, | |
488 | " entity_id = {$financialTypeId} ", NULL, 'account_relationship'); | |
489 | return $financialAccounts; | |
490 | } | |
491 | ||
186c9c17 | 492 | /** |
100fef9d CW |
493 | * @param int $financialTypeId |
494 | * @param int $relationTypeId | |
186c9c17 EM |
495 | * |
496 | * @return mixed | |
497 | */ | |
6a488035 TO |
498 | public function getFinancialAccount($financialTypeId, $relationTypeId) { |
499 | $financialAccounts = $this->getFinancialAccounts($financialTypeId); | |
500 | return CRM_Utils_Array::value($relationTypeId, $financialAccounts); | |
501 | } | |
502 | ||
503 | public function preProcessPledge() { | |
504 | //get the payment values associated with given pledge payment id OR check for payments due. | |
505 | $this->_pledgeValues = array(); | |
506 | if ($this->_ppID) { | |
507 | $payParams = array('id' => $this->_ppID); | |
508 | ||
509 | CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); | |
510 | $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']); | |
511 | $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']); | |
512 | $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']); | |
513 | ||
514 | //get all status | |
515 | $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); | |
516 | if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { | |
517 | CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); | |
518 | } | |
519 | ||
520 | //get the pledge values associated with given pledge payment. | |
521 | ||
522 | $ids = array(); | |
523 | $pledgeParams = array('id' => $this->_pledgeID); | |
524 | CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); | |
525 | $this->assign('ppID', $this->_ppID); | |
526 | } | |
527 | else { | |
528 | // 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 | |
529 | if (isset($this->_contactID)) { | |
530 | $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); | |
531 | ||
532 | if (!empty($contactPledges)) { | |
533 | $payments = $paymentsDue = NULL; | |
534 | $multipleDue = FALSE; | |
535 | foreach ($contactPledges as $key => $pledgeId) { | |
536 | $payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId); | |
537 | if ($payments) { | |
538 | if ($paymentsDue) { | |
539 | $multipleDue = TRUE; | |
540 | break; | |
541 | } | |
542 | else { | |
543 | $paymentsDue = $payments; | |
544 | } | |
545 | } | |
546 | } | |
547 | if ($multipleDue) { | |
548 | // Show link to pledge tab since more than one pledge has a payment due | |
549 | $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', | |
550 | "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge" | |
551 | ); | |
552 | 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'); | |
553 | } | |
554 | elseif ($paymentsDue) { | |
555 | // Show user link to oldest Pending or Overdue pledge payment | |
556 | $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']); | |
557 | $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date')); | |
558 | if ($this->_mode) { | |
559 | $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
560 | "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live" | |
561 | ); | |
562 | } | |
563 | else { | |
564 | $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
565 | "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge" | |
566 | ); | |
567 | } | |
568 | 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( | |
569 | 1 => $ppUrl, | |
570 | 2 => $ppAmountDue, | |
21dfd5f5 | 571 | 3 => $ppSchedDate, |
6a488035 TO |
572 | )), ts('Notice'), 'alert'); |
573 | } | |
574 | } | |
575 | } | |
576 | } | |
577 | } | |
578 | ||
186c9c17 | 579 | /** |
07f8d162 | 580 | * @param array $submittedValues |
186c9c17 EM |
581 | * |
582 | * @return mixed | |
583 | */ | |
6a488035 TO |
584 | public function unsetCreditCardFields($submittedValues) { |
585 | //Offline Contribution. | |
586 | $unsetParams = array( | |
587 | 'payment_processor_id', | |
588 | "email-{$this->_bltID}", | |
589 | 'hidden_buildCreditCard', | |
590 | 'hidden_buildDirectDebit', | |
591 | 'billing_first_name', | |
592 | 'billing_middle_name', | |
593 | 'billing_last_name', | |
594 | 'street_address-5', | |
595 | "city-{$this->_bltID}", | |
596 | "state_province_id-{$this->_bltID}", | |
597 | "postal_code-{$this->_bltID}", | |
598 | "country_id-{$this->_bltID}", | |
599 | 'credit_card_number', | |
600 | 'cvv2', | |
601 | 'credit_card_exp_date', | |
602 | 'credit_card_type', | |
603 | ); | |
604 | foreach ($unsetParams as $key) { | |
605 | if (isset($submittedValues[$key])) { | |
606 | unset($submittedValues[$key]); | |
607 | } | |
608 | } | |
609 | return $submittedValues; | |
610 | } | |
611 | ||
cc984198 | 612 | /** |
100fef9d | 613 | * Common block for setting up the parts of a form that relate to credit / debit card |
cc984198 EM |
614 | * @throws Exception |
615 | */ | |
616 | protected function assignPaymentRelatedVariables() { | |
617 | try { | |
99efbbf8 EM |
618 | if ($this->_contactID) { |
619 | list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); | |
620 | $this->assign('displayName', $this->userDisplayName); | |
621 | } | |
cc984198 EM |
622 | if ($this->_mode) { |
623 | $this->assignProcessors(); | |
cc984198 EM |
624 | |
625 | $this->assignBillingType(); | |
626 | ||
627 | $this->_fields = array(); | |
dfc68e82 | 628 | CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor, FALSE, TRUE); |
cc984198 EM |
629 | } |
630 | } | |
631 | catch (CRM_Core_Exception $e) { | |
632 | CRM_Core_Error::fatal($e->getMessage()); | |
633 | } | |
634 | } | |
96025800 | 635 | |
6a488035 | 636 | } |