3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class generates form components for processing a ontribution
40 class CRM_Contribute_Form_ContributionBase
extends CRM_Core_Form
{
43 * the id of the contribution page that we are proceessing
51 * the mode that we are in
59 * the contact id related to a membership
64 public $_membershipContactID;
67 * the values for the contribution db object
75 * the paymentProcessor attributes for this page
80 public $_paymentProcessor;
81 public $_paymentObject = NULL;
84 * The membership block for this page
89 public $_membershipBlock = NULL;
92 * the default values for the form
100 * The params submitted by the form and computed by the app
108 * The fields involved in this contribution page
116 * The billing location id for this contribiution page
124 * Cache the amount to make things easier
156 * The contact id of the person for whom membership is being added or renewed based on the cid in the url,
157 * checksum, or session
160 protected $_contactID;
165 * the Membership ID for membership renewal
170 public $_membershipId;
173 * Price Set ID, if the new price set method is used
181 * Array of fields for the price set
191 * Is honor block is enabled for this contribution?
196 public $_honor_block_is_active = FALSE;
199 * Function to set variables up before form is built
204 public function preProcess() {
205 $config = CRM_Core_Config
::singleton();
206 $session = CRM_Core_Session
::singleton();
208 // current contribution page id
209 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
211 // seems like the session is corrupted and/or we lost the id trail
212 // lets just bump this to a regular session error and redirect user to main page
213 $this->controller
->invalidKeyRedirect();
216 // this was used prior to the cleverer this_>getContactID - unsure now
217 $this->_userID
= $session->get('userID');
219 //Check if honor block is enabled for current contribution
220 $ufJoinParams = array(
221 'module' => 'soft_credit',
222 'entity_table' => 'civicrm_contribution_page',
223 'entity_id' => $this->_id
,
225 $ufJoin = new CRM_Core_DAO_UFJoin();
226 $ufJoin->copyValues($ufJoinParams);
228 $this->_honor_block_is_active
= $ufJoin->is_active
;
230 $this->_contactID
= $this->_membershipContactID
= $this->getContactID();
232 if ($this->_contactID
) {
233 $this->_mid
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
235 $membership = new CRM_Member_DAO_Membership();
236 $membership->id
= $this->_mid
;
238 if ($membership->find(TRUE)) {
239 $this->_defaultMemTypeId
= $membership->membership_type_id
;
240 if ($membership->contact_id
!= $this->_contactID
) {
241 $validMembership = FALSE;
242 $employers = CRM_Contact_BAO_Relationship
::getPermissionedEmployer($this->_userID
);
243 if (!empty($employers) && array_key_exists($membership->contact_id
, $employers)) {
244 $this->_membershipContactID
= $membership->contact_id
;
245 $this->assign('membershipContactID', $this->_membershipContactID
);
246 $this->assign('membershipContactName', $employers[$this->_membershipContactID
]['name']);
247 $validMembership = TRUE;
249 $membershipType = new CRM_Member_BAO_MembershipType();
250 $membershipType->id
= $membership->membership_type_id
;
251 if ($membershipType->find(TRUE)) {
252 // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
253 // Convert to commma separated list.
254 $inheritedRelTypes = implode(CRM_Utils_Array
::explodePadded($membershipType->relationship_type_id
), ',');
255 $permContacts = CRM_Contact_BAO_Relationship
::getPermissionedContacts($this->_userID
, $membershipType->relationship_type_id
);
256 if (array_key_exists($membership->contact_id
, $permContacts)) {
257 $this->_membershipContactID
= $membership->contact_id
;
258 $validMembership = TRUE;
262 if (!$validMembership) {
263 CRM_Core_Session
::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
268 CRM_Core_Session
::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
274 // we do not want to display recently viewed items, so turn off
275 $this->assign('displayRecent', FALSE);
276 // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
277 // Use Browser Print instead.
278 $this->assign('browserPrint', TRUE);
281 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
282 $this->assign('action', $this->_action
);
285 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
287 $this->_values
= $this->get('values');
288 $this->_fields
= $this->get('fields');
289 $this->_bltID
= $this->get('bltID');
290 $this->_paymentProcessor
= $this->get('paymentProcessor');
291 $this->_priceSetId
= $this->get('priceSetId');
292 $this->_priceSet
= $this->get('priceSet');
294 if (!$this->_values
) {
295 // get all the values from the dao object
296 $this->_values
= array();
297 $this->_fields
= array();
299 CRM_Contribute_BAO_ContributionPage
::setValues($this->_id
, $this->_values
);
301 // check if form is active
302 if (empty($this->_values
['is_active'])) {
303 // form is inactive, die a fatal death
304 CRM_Core_Error
::fatal(ts('The page you requested is currently unavailable.'));
307 // also check for billing informatin
308 // get the billing location type
309 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
310 // CRM-8108 remove ts around Billing location type
311 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
312 $this->_bltID
= array_search('Billing', $locationTypes);
313 if (!$this->_bltID
) {
314 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
316 $this->set('bltID', $this->_bltID
);
318 // check for is_monetary status
319 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
);
320 $isPayLater = CRM_Utils_Array
::value('is_pay_later', $this->_values
);
322 //FIXME: to support multiple payment processors
324 (!$isPayLater ||
!empty($this->_values
['payment_processor']))
326 $ppID = CRM_Utils_Array
::value('payment_processor', $this->_values
);
328 CRM_Core_Error
::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
331 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
332 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds, $this->_mode
);
334 $this->set('paymentProcessors', $this->_paymentProcessors
);
336 //set default payment processor
337 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
338 foreach ($this->_paymentProcessors
as $ppId => $values) {
339 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
340 $defaultProcessorId = $ppId;
346 if (isset($defaultProcessorId)) {
347 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
348 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
351 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
352 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
353 // check selected payment processor is active
354 if (empty($eachPaymentProcessor)) {
355 CRM_Core_Error
::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
358 // ensure that processor has a valid config
359 $this->_paymentObject
= &CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
360 $error = $this->_paymentObject
->checkConfig();
361 if (!empty($error)) {
362 CRM_Core_Error
::fatal($error);
370 CRM_Price_BAO_PriceSet
::initSet($this, $this->_id
, 'civicrm_contribution_page');
372 // this avoids getting E_NOTICE errors in php
373 $setNullFields = array(
374 'amount_block_is_active',
375 'is_allow_other_amount',
378 foreach ($setNullFields as $f) {
379 if (!isset($this->_values
[$f])) {
380 $this->_values
[$f] = NULL;
384 //check if Membership Block is enabled, if Membership Fields are included in profile
385 //get membership section for this contribution page
386 $this->_membershipBlock
= CRM_Member_BAO_Membership
::getMembershipBlock($this->_id
);
387 $this->set('membershipBlock', $this->_membershipBlock
);
389 if ($this->_values
['custom_pre_id']) {
390 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_pre_id']);
393 if ($this->_values
['custom_post_id']) {
394 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_post_id']);
397 if (((isset($postProfileType) && $postProfileType == 'Membership') ||
398 (isset($preProfileType) && $preProfileType == 'Membership')
400 !$this->_membershipBlock
['is_active']
402 CRM_Core_Error
::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
405 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::getPledgeBlock($this->_id
);
408 $this->_values
['pledge_block_id'] = CRM_Utils_Array
::value('id', $pledgeBlock);
409 $this->_values
['max_reminders'] = CRM_Utils_Array
::value('max_reminders', $pledgeBlock);
410 $this->_values
['initial_reminder_day'] = CRM_Utils_Array
::value('initial_reminder_day', $pledgeBlock);
411 $this->_values
['additional_reminder_day'] = CRM_Utils_Array
::value('additional_reminder_day', $pledgeBlock);
413 //set pledge id in values
414 $pledgeId = CRM_Utils_Request
::retrieve('pledgeId', 'Positive', $this);
416 //authenticate pledge user for pledge payment.
418 $this->_values
['pledge_id'] = $pledgeId;
420 //lets override w/ pledge campaign.
421 $this->_values
['campaign_id'] = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
425 self
::authenticatePledgeUser();
428 $this->set('values', $this->_values
);
429 $this->set('fields', $this->_fields
);
433 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
435 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'contribute', $this->_values
);
436 $this->_pcpId
= $pcp['pcpId'];
437 $this->_pcpBlock
= $pcp['pcpBlock'];
438 $this->_pcpInfo
= $pcp['pcpInfo'];
441 // Link (button) for users to create their own Personal Campaign page
442 if ($linkText = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute')) {
443 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
444 "action=add&reset=1&pageId={$this->_id}&component=contribute",
447 $this->assign('linkTextUrl', $linkTextUrl);
448 $this->assign('linkText', $linkText);
451 //set pledge block if block id is set
452 if (!empty($this->_values
['pledge_block_id'])) {
453 $this->assign('pledgeBlock', TRUE);
456 // check if one of the (amount , membership) bloks is active or not
457 $this->_membershipBlock
= $this->get('membershipBlock');
459 if (!$this->_values
['amount_block_is_active'] &&
460 !$this->_membershipBlock
['is_active'] &&
463 CRM_Core_Error
::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.'));
466 if ($this->_values
['amount_block_is_active']) {
467 $this->set('amount_block_is_active', $this->_values
['amount_block_is_active']);
470 $this->_contributeMode
= $this->get('contributeMode');
471 $this->assign('contributeMode', $this->_contributeMode
);
473 //assigning is_monetary and is_email_receipt to template
474 $this->assign('is_monetary', $this->_values
['is_monetary']);
475 $this->assign('is_email_receipt', $this->_values
['is_email_receipt']);
476 $this->assign('bltID', $this->_bltID
);
478 //assign cancelSubscription URL to templates
479 $this->assign('cancelSubscriptionUrl',
480 CRM_Utils_Array
::value('cancelSubscriptionUrl', $this->_values
)
483 // assigning title to template in case someone wants to use it, also setting CMS page title
485 $this->assign('title', $this->_pcpInfo
['title']);
486 CRM_Utils_System
::setTitle($this->_pcpInfo
['title']);
489 $this->assign('title', $this->_values
['title']);
490 CRM_Utils_System
::setTitle($this->_values
['title']);
492 $this->_defaults
= array();
494 $this->_amount
= $this->get('amount');
497 $config = CRM_Core_Config
::singleton();
498 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
500 $config->defaultCurrency
503 //lets allow user to override campaign.
504 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
505 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
506 $this->_values
['campaign_id'] = $campID;
509 //do check for cancel recurring and clean db, CRM-7696
510 if (CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject)) {
511 self
::cancelRecurring();
516 * set the default values
521 function setDefaultValues() {
522 return $this->_defaults
;
526 * assign the minimal set of variables to the template
531 function assignToTemplate() {
532 $name = CRM_Utils_Array
::value('billing_first_name', $this->_params
);
533 if (!empty($this->_params
['billing_middle_name'])) {
534 $name .= " {$this->_params['billing_middle_name']}";
536 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $this->_params
);
538 $this->assign('billingName', $name);
539 $this->set('name', $name);
541 $this->assign('paymentProcessor', $this->_paymentProcessor
);
543 'amount', 'currencyID',
544 'credit_card_type', 'trxn_id', 'amount_level',
547 $config = CRM_Core_Config
::singleton();
548 if (isset($this->_values
['is_recur']) && !empty($this->_paymentProcessor
['is_recur'])) {
549 $this->assign('is_recur_enabled', 1);
550 $vars = array_merge($vars, array(
551 'is_recur', 'frequency_interval', 'frequency_unit',
556 if (in_array('CiviPledge', $config->enableComponents
) &&
557 CRM_Utils_Array
::value('is_pledge', $this->_params
) == 1
559 $this->assign('pledge_enabled', 1);
561 $vars = array_merge($vars, array(
563 'pledge_frequency_interval',
564 'pledge_frequency_unit',
565 'pledge_installments',
569 if (isset($this->_params
['amount_other']) ||
isset($this->_params
['selectMembership'])) {
570 $this->_params
['amount_level'] = '';
573 foreach ($vars as $v) {
574 if (isset($this->_params
[$v])) {
575 if ($v == 'frequency_unit' ||
$v == 'pledge_frequency_unit') {
576 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units');
577 if (array_key_exists($this->_params
[$v], $frequencyUnits)) {
578 $this->_params
[$v] = $frequencyUnits[$this->_params
[$v]];
581 if ($v == "amount" && $this->_params
[$v] === 0) {
582 $this->_params
[$v] = CRM_Utils_Money
::format($this->_params
[$v], NULL, NULL, TRUE);
584 $this->assign($v, $this->_params
[$v]);
588 // assign the address formatted up for display
589 $addressParts = array(
590 "street_address-{$this->_bltID}",
591 "city-{$this->_bltID}",
592 "postal_code-{$this->_bltID}",
593 "state_province-{$this->_bltID}",
594 "country-{$this->_bltID}",
597 $addressFields = array();
598 foreach ($addressParts as $part) {
599 list($n, $id) = explode('-', $part);
600 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $this->_params
);
603 $this->assign('address', CRM_Utils_Address
::format($addressFields));
605 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
606 $this->assign('onBehalfName', $this->_params
['organization_name']);
607 $locTypeId = array_keys($this->_params
['onbehalf_location']['email']);
608 $this->assign('onBehalfEmail', $this->_params
['onbehalf_location']['email'][$locTypeId[0]]['email']);
612 $assignCCInfo = FALSE;
613 if ($this->_amount
> 0.0) {
614 $assignCCInfo = TRUE;
616 elseif (!empty($this->_params
['selectMembership'])) {
617 $memFee = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params
['selectMembership'], 'minimum_fee');
619 $assignCCInfo = TRUE;
623 if ($this->_contributeMode
== 'direct' && $assignCCInfo) {
624 if ($this->_paymentProcessor
&&
625 $this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
627 $this->assign('payment_type', $this->_paymentProcessor
['payment_type']);
628 $this->assign('account_holder', $this->_params
['account_holder']);
629 $this->assign('bank_identification_number', $this->_params
['bank_identification_number']);
630 $this->assign('bank_name', $this->_params
['bank_name']);
631 $this->assign('bank_account_number', $this->_params
['bank_account_number']);
634 $date = CRM_Utils_Date
::format(CRM_Utils_array
::value('credit_card_exp_date', $this->_params
));
635 $date = CRM_Utils_Date
::mysqlToIso($date);
636 $this->assign('credit_card_exp_date', $date);
637 $this->assign('credit_card_number',
638 CRM_Utils_System
::mungeCreditCard(CRM_Utils_array
::value('credit_card_number', $this->_params
))
643 $this->assign('email',
644 $this->controller
->exportValue('Main', "email-{$this->_bltID}")
647 // also assign the receipt_text
648 if (isset($this->_values
['receipt_text'])) {
649 $this->assign('receipt_text', $this->_values
['receipt_text']);
654 * Function to add the custom fields
659 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
660 $stateCountryMap = array();
663 $contactID = $this->getContactID();
665 // we don't allow conflicting fields to be
666 // configured via profile - CRM 2100
667 $fieldsToIgnore = array(
673 'non_deductible_amount' => 1,
676 'contribution_status_id' => 1,
677 'payment_instrument' => 1,
679 'financial_type' => 1,
683 if ($contactID && CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
684 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
685 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
689 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
690 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
695 // unset any email-* fields since we already collect it, CRM-2888
696 foreach (array_keys($fields) as $fieldName) {
697 if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
698 unset($fields[$fieldName]);
702 if (array_intersect_key($fields, $fieldsToIgnore)) {
703 $fields = array_diff_key($fields, $fieldsToIgnore);
704 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
707 $fields = array_diff_assoc($fields, $this->_fields
);
709 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
711 foreach ($fields as $key => $field) {
713 isset($field['data_type']) &&
714 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
716 // ignore file upload fields
720 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
721 if ($prefixName == 'state_province' ||
$prefixName == 'country' ||
$prefixName == 'county') {
722 if (!array_key_exists($index, $stateCountryMap)) {
723 $stateCountryMap[$index] = array();
725 $stateCountryMap[$index][$prefixName] = $key;
727 if ($prefixName == "state_province") {
728 if ($profileContactType == 'onbehalf') {
729 //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
730 //as already done during Contribution registration via onBehalf's quickForm
731 $field['is_required'] = FALSE;
734 if (count($this->_submitValues
)) {
735 $locationTypeId = $field['location_type_id'];
736 if (array_key_exists("country-{$locationTypeId}", $fields) &&
737 array_key_exists("state_province-{$locationTypeId}", $fields) &&
738 !empty($this->_submitValues
["country-{$locationTypeId}"])) {
739 $field['is_required'] =
740 CRM_Core_Payment_Form
::checkRequiredStateProvince($this, "country-{$locationTypeId}");
747 if ($profileContactType) {
748 //Since we are showing honoree name separately so we are removing it from honoree profile just for display
749 $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
750 if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
751 unset($fields[$field['name']]);
754 if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
755 CRM_Core_BAO_UFGroup
::buildProfile(
758 CRM_Profile_Form
::MODE_CREATE
,
763 $this->_fields
[$profileContactType][$key] = $field;
766 unset($fields[$key]);
770 CRM_Core_BAO_UFGroup
::buildProfile(
773 CRM_Profile_Form
::MODE_CREATE
,
777 $this->_fields
[$key] = $field;
779 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
780 if ($field['add_captcha'] && !$this->_userID
) {
785 $this->assign($name, $fields);
787 CRM_Core_BAO_Address
::addStateCountryMap($stateCountryMap);
789 if ($addCaptcha && !$viewOnly) {
790 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
791 $captcha->add($this);
792 $this->assign('isCaptcha', TRUE);
798 function checkTemplateFileExists($suffix = NULL) {
800 $templateFile = "CRM/Contribute/Form/Contribution/{$this->_id}/{$this->_name}.{$suffix}tpl";
801 $template = CRM_Core_Form
::getTemplate();
802 if ($template->template_exists($templateFile)) {
803 return $templateFile;
809 function getTemplateFileName() {
810 $fileName = $this->checkTemplateFileExists();
811 return $fileName ?
$fileName : parent
::getTemplateFileName();
814 function overrideExtraTemplateFileName() {
815 $fileName = $this->checkTemplateFileExists('extra.');
816 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
820 * Function to authenticate pledge user during online payment.
826 public function authenticatePledgeUser() {
827 //get the userChecksum and contact id
828 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
829 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
831 //get pledge status and contact id
832 $pledgeValues = array();
833 $pledgeParams = array('id' => $this->_values
['pledge_id']);
834 $returnProperties = array('contact_id', 'status_id');
835 CRM_Core_DAO
::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties);
838 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
839 $validStatus = array(array_search('Pending', $allStatus),
840 array_search('In Progress', $allStatus),
841 array_search('Overdue', $allStatus),
845 if ($this->_userID
&&
846 $this->_userID
== $pledgeValues['contact_id']
848 //check for authenticated user.
851 elseif ($userChecksum && $pledgeValues['contact_id']) {
852 //check for anonymous user.
853 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($pledgeValues['contact_id'], $userChecksum);
855 //make sure cid is same as pledge contact id
856 if ($validUser && ($pledgeValues['contact_id'] != $contactID)) {
862 CRM_Core_Error
::fatal(ts("Oops. It looks like you have an incorrect or incomplete link (URL). Please make sure you've copied the entire link, and try again. Contact the site administrator if this error persists."));
865 //check for valid pledge status.
866 if (!in_array($pledgeValues['status_id'], $validStatus)) {
867 CRM_Core_Error
::fatal(ts('Oops. You cannot make a payment for this pledge - pledge status is %1.', array(1 => CRM_Utils_Array
::value($pledgeValues['status_id'], $allStatus))));
872 * In case user cancel recurring contribution,
873 * When we get the control back from payment gate way
874 * lets delete the recurring and related contribution.
877 public function cancelRecurring() {
878 $isCancel = CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject);
880 $isRecur = CRM_Utils_Request
::retrieve('isRecur', 'Boolean', CRM_Core_DAO
::$_nullObject);
881 $recurId = CRM_Utils_Request
::retrieve('recurId', 'Positive', CRM_Core_DAO
::$_nullObject);
882 //clean db for recurring contribution.
883 if ($isRecur && $recurId) {
884 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($recurId);
886 $contribId = CRM_Utils_Request
::retrieve('contribId', 'Positive', CRM_Core_DAO
::$_nullObject);
888 CRM_Contribute_BAO_Contribution
::deleteContribution($contribId);