| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * This class generates form components for processing a contribution |
| 38 | * CRM-16229 - During the event registration bulk action via search we |
| 39 | * need to inherit CRM_Contact_Form_Task so that we can inherit functions |
| 40 | * like getContactIds and make use of controller state. But this is not possible |
| 41 | * because CRM_Event_Form_Participant inherits this class. |
| 42 | * Ideal situation would be something like |
| 43 | * CRM_Event_Form_Participant extends CRM_Contact_Form_Task, |
| 44 | * CRM_Contribute_Form_AbstractEditPayment |
| 45 | * However this is not possible. Currently PHP does not support multiple |
| 46 | * inheritance. So work around solution is to extend this class with |
| 47 | * CRM_Contact_Form_Task which further extends CRM_Core_Form. |
| 48 | * |
| 49 | */ |
| 50 | class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { |
| 51 | public $_mode; |
| 52 | |
| 53 | public $_action; |
| 54 | |
| 55 | public $_bltID; |
| 56 | |
| 57 | public $_fields; |
| 58 | |
| 59 | /** |
| 60 | * @var array current payment processor including a copy of the object in 'object' key |
| 61 | */ |
| 62 | public $_paymentProcessor; |
| 63 | public $_recurPaymentProcessors; |
| 64 | |
| 65 | /** |
| 66 | * Array of processor options in the format id => array($id => $label) |
| 67 | * WARNING it appears that the format used to differ to this and there are places in the code that |
| 68 | * expect the old format. $this->_paymentProcessors provides the additional data which this |
| 69 | * array seems to have provided in the past |
| 70 | * @var array |
| 71 | */ |
| 72 | public $_processors; |
| 73 | |
| 74 | /** |
| 75 | * Available payment processors with full details including the key 'object' indexed by their id |
| 76 | * @var array |
| 77 | */ |
| 78 | protected $_paymentProcessors = array(); |
| 79 | /** |
| 80 | * The id of the contribution that we are processing. |
| 81 | * |
| 82 | * @var int |
| 83 | */ |
| 84 | public $_id; |
| 85 | |
| 86 | /** |
| 87 | * The id of the premium that we are proceessing. |
| 88 | * |
| 89 | * @var int |
| 90 | */ |
| 91 | public $_premiumID = NULL; |
| 92 | |
| 93 | /** |
| 94 | * @var CRM_Contribute_DAO_ContributionProduct |
| 95 | */ |
| 96 | public $_productDAO = NULL; |
| 97 | |
| 98 | /** |
| 99 | * The id of the note |
| 100 | * |
| 101 | * @var int |
| 102 | */ |
| 103 | public $_noteID; |
| 104 | |
| 105 | /** |
| 106 | * The id of the contact associated with this contribution |
| 107 | * |
| 108 | * @var int |
| 109 | */ |
| 110 | public $_contactID; |
| 111 | |
| 112 | /** |
| 113 | * The id of the pledge payment that we are processing |
| 114 | * |
| 115 | * @var int |
| 116 | */ |
| 117 | public $_ppID; |
| 118 | |
| 119 | /** |
| 120 | * The id of the pledge that we are processing |
| 121 | * |
| 122 | * @var int |
| 123 | */ |
| 124 | public $_pledgeID; |
| 125 | |
| 126 | /** |
| 127 | * Is this contribution associated with an online |
| 128 | * financial transaction |
| 129 | * |
| 130 | * @var boolean |
| 131 | */ |
| 132 | public $_online = FALSE; |
| 133 | |
| 134 | /** |
| 135 | * Stores all product option |
| 136 | * |
| 137 | * @var array |
| 138 | */ |
| 139 | public $_options; |
| 140 | |
| 141 | /** |
| 142 | * Stores the honor id |
| 143 | * |
| 144 | * @var int |
| 145 | */ |
| 146 | public $_honorID = NULL; |
| 147 | |
| 148 | /** |
| 149 | * Store the financial Type ID |
| 150 | * |
| 151 | * @var array |
| 152 | */ |
| 153 | public $_contributionType; |
| 154 | |
| 155 | /** |
| 156 | * The contribution values if an existing contribution |
| 157 | */ |
| 158 | public $_values; |
| 159 | |
| 160 | /** |
| 161 | * The pledge values if this contribution is associated with pledge |
| 162 | */ |
| 163 | public $_pledgeValues; |
| 164 | |
| 165 | public $_contributeMode = 'direct'; |
| 166 | |
| 167 | public $_context; |
| 168 | |
| 169 | public $_compId; |
| 170 | |
| 171 | /** |
| 172 | * Store the line items if price set used. |
| 173 | */ |
| 174 | public $_lineItems; |
| 175 | |
| 176 | /** |
| 177 | * Is this a backoffice form |
| 178 | * (this will affect whether paypal express code is displayed) |
| 179 | * @var bool |
| 180 | */ |
| 181 | public $isBackOffice = TRUE; |
| 182 | |
| 183 | protected $_formType; |
| 184 | |
| 185 | /** |
| 186 | * @var mystery variable screaming out for documentation |
| 187 | */ |
| 188 | protected $_cdType; |
| 189 | |
| 190 | /** |
| 191 | * Array of fields to display on billingBlock.tpl - this is not fully implemented but basically intent is the panes/fieldsets on this page should |
| 192 | * be all in this array in order like |
| 193 | * 'credit_card' => array('credit_card_number' ... |
| 194 | * 'billing_details' => array('first_name' ... |
| 195 | * |
| 196 | * such that both the fields and the order can be more easily altered by payment processors & other extensions |
| 197 | * @var array |
| 198 | */ |
| 199 | public $billingFieldSets = array(); |
| 200 | |
| 201 | /** |
| 202 | * @param int $id |
| 203 | */ |
| 204 | public function showRecordLinkMesssage($id) { |
| 205 | $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $id, 'contribution_status_id'); |
| 206 | if (CRM_Contribute_PseudoConstant::contributionStatus($statusId, 'name') == 'Partially paid') { |
| 207 | if ($pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'participant_id', 'contribution_id')) { |
| 208 | $recordPaymentLink = CRM_Utils_System::url('civicrm/payment', |
| 209 | "reset=1&id={$pid}&cid={$this->_contactID}&action=add&component=event" |
| 210 | ); |
| 211 | 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'); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @param int $id |
| 218 | * @param $values |
| 219 | */ |
| 220 | public function buildValuesAndAssignOnline_Note_Type($id, &$values) { |
| 221 | $ids = array(); |
| 222 | $params = array('id' => $id); |
| 223 | CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); |
| 224 | |
| 225 | //Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL) |
| 226 | $this->_online = FALSE; |
| 227 | $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id); |
| 228 | if (!empty($fids['financialTrxnId'])) { |
| 229 | $this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id'); |
| 230 | } |
| 231 | |
| 232 | // Also don't allow user to update some fields for recurring contributions. |
| 233 | if (!$this->_online) { |
| 234 | $this->_online = CRM_Utils_Array::value('contribution_recur_id', $values); |
| 235 | } |
| 236 | |
| 237 | $this->assign('isOnline', $this->_online ? TRUE : FALSE); |
| 238 | |
| 239 | //to get note id |
| 240 | $daoNote = new CRM_Core_BAO_Note(); |
| 241 | $daoNote->entity_table = 'civicrm_contribution'; |
| 242 | $daoNote->entity_id = $id; |
| 243 | if ($daoNote->find(TRUE)) { |
| 244 | $this->_noteID = $daoNote->id; |
| 245 | $values['note'] = $daoNote->note; |
| 246 | } |
| 247 | $this->_contributionType = $values['financial_type_id']; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * @param string $type |
| 252 | * Eg 'Contribution'. |
| 253 | * @param string $subType |
| 254 | * @param int $entityId |
| 255 | */ |
| 256 | public function applyCustomData($type, $subType, $entityId) { |
| 257 | $this->set('type', $type); |
| 258 | $this->set('subType', $subType); |
| 259 | $this->set('entityId', $entityId); |
| 260 | |
| 261 | CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, 1, $type, $entityId); |
| 262 | CRM_Custom_Form_CustomData::buildQuickForm($this); |
| 263 | CRM_Custom_Form_CustomData::setDefaultValues($this); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * @param int $id |
| 268 | * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find(); |
| 269 | */ |
| 270 | public function assignPremiumProduct($id) { |
| 271 | $sql = " |
| 272 | SELECT * |
| 273 | FROM civicrm_contribution_product |
| 274 | WHERE contribution_id = {$id} |
| 275 | "; |
| 276 | $dao = CRM_Core_DAO::executeQuery($sql, |
| 277 | CRM_Core_DAO::$_nullArray |
| 278 | ); |
| 279 | if ($dao->fetch()) { |
| 280 | $this->_premiumID = $dao->id; |
| 281 | $this->_productDAO = $dao; |
| 282 | } |
| 283 | $dao->free(); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * This function process contribution related objects. |
| 288 | * |
| 289 | * @param int $contributionId |
| 290 | * @param int $statusId |
| 291 | * @param int|null $previousStatusId |
| 292 | * |
| 293 | * @return null|string |
| 294 | */ |
| 295 | protected function updateRelatedComponent($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { |
| 296 | $statusMsg = NULL; |
| 297 | if (!$contributionId || !$statusId) { |
| 298 | return $statusMsg; |
| 299 | } |
| 300 | |
| 301 | $params = array( |
| 302 | 'contribution_id' => $contributionId, |
| 303 | 'contribution_status_id' => $statusId, |
| 304 | 'previous_contribution_status_id' => $previousStatusId, |
| 305 | 'receive_date' => $receiveDate, |
| 306 | ); |
| 307 | |
| 308 | $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); |
| 309 | |
| 310 | if (!is_array($updateResult) || |
| 311 | !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || |
| 312 | !is_array($updatedComponents) || |
| 313 | empty($updatedComponents) |
| 314 | ) { |
| 315 | return $statusMsg; |
| 316 | } |
| 317 | |
| 318 | // get the user display name. |
| 319 | $sql = " |
| 320 | SELECT display_name as displayName |
| 321 | FROM civicrm_contact |
| 322 | LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) |
| 323 | WHERE civicrm_contribution.id = {$contributionId}"; |
| 324 | $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); |
| 325 | |
| 326 | // get the status message for user. |
| 327 | foreach ($updatedComponents as $componentName => $updatedStatusId) { |
| 328 | |
| 329 | if ($componentName == 'CiviMember') { |
| 330 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, |
| 331 | CRM_Member_PseudoConstant::membershipStatus() |
| 332 | ); |
| 333 | if ($updatedStatusName == 'Cancelled') { |
| 334 | $statusMsg .= "<br />" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName)); |
| 335 | } |
| 336 | elseif ($updatedStatusName == 'Expired') { |
| 337 | $statusMsg .= "<br />" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName)); |
| 338 | } |
| 339 | else { |
| 340 | $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult); |
| 341 | if ($endDate) { |
| 342 | $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.", |
| 343 | array( |
| 344 | 1 => $userDisplayName, |
| 345 | 2 => $endDate, |
| 346 | ) |
| 347 | ); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if ($componentName == 'CiviEvent') { |
| 353 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, |
| 354 | CRM_Event_PseudoConstant::participantStatus() |
| 355 | ); |
| 356 | if ($updatedStatusName == 'Cancelled') { |
| 357 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been Cancelled.", array(1 => $userDisplayName)); |
| 358 | } |
| 359 | elseif ($updatedStatusName == 'Registered') { |
| 360 | $statusMsg .= "<br />" . ts("Event Registration for %1 has been updated.", array(1 => $userDisplayName)); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if ($componentName == 'CiviPledge') { |
| 365 | $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, |
| 366 | CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') |
| 367 | ); |
| 368 | if ($updatedStatusName == 'Cancelled') { |
| 369 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Cancelled.", array(1 => $userDisplayName)); |
| 370 | } |
| 371 | elseif ($updatedStatusName == 'Failed') { |
| 372 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Failed.", array(1 => $userDisplayName)); |
| 373 | } |
| 374 | elseif ($updatedStatusName == 'Completed') { |
| 375 | $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been updated.", array(1 => $userDisplayName)); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return $statusMsg; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * @return array |
| 385 | * Array of valid processors. The array resembles the DB table but also has 'object' as a key |
| 386 | * @throws Exception |
| 387 | */ |
| 388 | public function getValidProcessors() { |
| 389 | $defaultID = NULL; |
| 390 | $capabilities = array('BackOffice'); |
| 391 | if ($this->_mode) { |
| 392 | $capabilities[] = (ucfirst($this->_mode) . 'Mode'); |
| 393 | } |
| 394 | $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities); |
| 395 | return $processors; |
| 396 | |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Assign billing type id to bltID. |
| 401 | * |
| 402 | * @throws CRM_Core_Exception |
| 403 | * @return void |
| 404 | */ |
| 405 | public function assignBillingType() { |
| 406 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); |
| 407 | $this->_bltID = array_search('Billing', $locationTypes); |
| 408 | if (!$this->_bltID) { |
| 409 | throw new CRM_Core_Exception(ts('Please set a location type of %1', array(1 => 'Billing'))); |
| 410 | } |
| 411 | $this->set('bltID', $this->_bltID); |
| 412 | $this->assign('bltID', $this->_bltID); |
| 413 | } |
| 414 | |
| 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 |
| 421 | |
| 422 | if ($this->_mode) { |
| 423 | $this->assign('processorSupportsFutureStartDate', CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('supportsFutureRecurStartDate'))); |
| 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)) { |
| 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 | } |
| 432 | $this->_processors = array(); |
| 433 | foreach ($this->_paymentProcessors as $id => $processor) { |
| 434 | $this->_processors[$id] = ts($processor['name']); |
| 435 | if (!empty($processor['description'])) { |
| 436 | $this->_processors[$id] .= ' : ' . ts($processor['description']); |
| 437 | } |
| 438 | } |
| 439 | //get the valid recurring processors. |
| 440 | $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; |
| 441 | $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); |
| 442 | $this->_recurPaymentProcessors = array_intersect_assoc($this->_processors, $recurring); |
| 443 | } |
| 444 | $this->assign('recurringPaymentProcessorIds', |
| 445 | empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors)) |
| 446 | ); |
| 447 | |
| 448 | // this required to show billing block |
| 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 |
| 450 | $this->assign_by_ref('paymentProcessor', $processor); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Get current currency from DB or use default currency. |
| 455 | * |
| 456 | * @param $submittedValues |
| 457 | * |
| 458 | * @return mixed |
| 459 | */ |
| 460 | public function getCurrency($submittedValues) { |
| 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 | |
| 476 | /** |
| 477 | * @param int $financialTypeId |
| 478 | * |
| 479 | * @return array |
| 480 | */ |
| 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 | |
| 492 | /** |
| 493 | * @param int $financialTypeId |
| 494 | * @param int $relationTypeId |
| 495 | * |
| 496 | * @return mixed |
| 497 | */ |
| 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, |
| 571 | 3 => $ppSchedDate, |
| 572 | )), ts('Notice'), 'alert'); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * @param $submittedValues |
| 581 | * |
| 582 | * @return mixed |
| 583 | */ |
| 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 | |
| 612 | /** |
| 613 | * Common block for setting up the parts of a form that relate to credit / debit card |
| 614 | * @throws Exception |
| 615 | */ |
| 616 | protected function assignPaymentRelatedVariables() { |
| 617 | try { |
| 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 | } |
| 622 | if ($this->_mode) { |
| 623 | $this->assignProcessors(); |
| 624 | |
| 625 | $this->assignBillingType(); |
| 626 | |
| 627 | $this->_fields = array(); |
| 628 | CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); |
| 629 | } |
| 630 | } |
| 631 | catch (CRM_Core_Exception $e) { |
| 632 | CRM_Core_Error::fatal($e->getMessage()); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | } |