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