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 contribution
40 class CRM_Contribute_Form_ContributionBase
extends CRM_Core_Form
{
43 * the id of the contribution page that we are processsing
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 * Does this form support a separate membership payment
95 protected $_separateMembershipPayment;
97 * the default values for the form
102 protected $_defaults;
105 * The params submitted by the form and computed by the app
113 * The fields involved in this contribution page
118 public $_fields = array();
121 * The billing location id for this contribiution page
129 * Cache the amount to make things easier
161 * The contact id of the person for whom membership is being added or renewed based on the cid in the url,
162 * checksum, or session
170 * the Membership ID for membership renewal
175 public $_membershipId;
178 * Price Set ID, if the new price set method is used
186 * Array of fields for the price set
196 * Is honor block is enabled for this contribution?
201 public $_honor_block_is_active = FALSE;
204 * Contribution mode e.g express for payment express, notify for off-site + notification back to CiviCRM
207 public $_contributeMode;
210 * contribution page supports memberships
213 public $_useForMember;
215 public $_isBillingAddressRequiredForPayLater;
217 * Function to set variables up before form is built
222 public function preProcess() {
223 $config = CRM_Core_Config
::singleton();
224 $session = CRM_Core_Session
::singleton();
226 // current contribution page id
227 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
229 // seems like the session is corrupted and/or we lost the id trail
230 // lets just bump this to a regular session error and redirect user to main page
231 $this->controller
->invalidKeyRedirect();
234 // this was used prior to the cleverer this_>getContactID - unsure now
235 $this->_userID
= $session->get('userID');
237 //Check if honor block is enabled for current contribution
238 $ufJoinParams = array(
239 'module' => 'soft_credit',
240 'entity_table' => 'civicrm_contribution_page',
241 'entity_id' => $this->_id
,
243 $ufJoin = new CRM_Core_DAO_UFJoin();
244 $ufJoin->copyValues($ufJoinParams);
246 $this->_honor_block_is_active
= $ufJoin->is_active
;
248 $this->_contactID
= $this->_membershipContactID
= $this->getContactID();
250 if ($this->_contactID
) {
251 $this->_mid
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
253 $membership = new CRM_Member_DAO_Membership();
254 $membership->id
= $this->_mid
;
256 if ($membership->find(TRUE)) {
257 $this->_defaultMemTypeId
= $membership->membership_type_id
;
258 if ($membership->contact_id
!= $this->_contactID
) {
259 $validMembership = FALSE;
260 $employers = CRM_Contact_BAO_Relationship
::getPermissionedEmployer($this->_userID
);
261 if (!empty($employers) && array_key_exists($membership->contact_id
, $employers)) {
262 $this->_membershipContactID
= $membership->contact_id
;
263 $this->assign('membershipContactID', $this->_membershipContactID
);
264 $this->assign('membershipContactName', $employers[$this->_membershipContactID
]['name']);
265 $validMembership = TRUE;
267 $membershipType = new CRM_Member_BAO_MembershipType();
268 $membershipType->id
= $membership->membership_type_id
;
269 if ($membershipType->find(TRUE)) {
270 // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
271 // Convert to commma separated list.
272 $inheritedRelTypes = implode(CRM_Utils_Array
::explodePadded($membershipType->relationship_type_id
), ',');
273 $permContacts = CRM_Contact_BAO_Relationship
::getPermissionedContacts($this->_userID
, $membershipType->relationship_type_id
);
274 if (array_key_exists($membership->contact_id
, $permContacts)) {
275 $this->_membershipContactID
= $membership->contact_id
;
276 $validMembership = TRUE;
280 if (!$validMembership) {
281 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');
286 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');
292 // we do not want to display recently viewed items, so turn off
293 $this->assign('displayRecent', FALSE);
294 // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
295 // Use Browser Print instead.
296 $this->assign('browserPrint', TRUE);
299 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
300 $this->assign('action', $this->_action
);
303 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
305 $this->_values
= $this->get('values');
306 $this->_fields
= $this->get('fields');
307 $this->_bltID
= $this->get('bltID');
308 $this->_paymentProcessor
= $this->get('paymentProcessor');
309 $this->_priceSetId
= $this->get('priceSetId');
310 $this->_priceSet
= $this->get('priceSet');
312 if (!$this->_values
) {
313 // get all the values from the dao object
314 $this->_values
= array();
315 $this->_fields
= array();
317 CRM_Contribute_BAO_ContributionPage
::setValues($this->_id
, $this->_values
);
319 // check if form is active
320 if (empty($this->_values
['is_active'])) {
321 // form is inactive, die a fatal death
322 CRM_Core_Error
::fatal(ts('The page you requested is currently unavailable.'));
325 // also check for billing informatin
326 // get the billing location type
327 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
328 // CRM-8108 remove ts around Billing location type
329 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
330 $this->_bltID
= array_search('Billing', $locationTypes);
331 if (!$this->_bltID
) {
332 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
334 $this->set('bltID', $this->_bltID
);
336 // check for is_monetary status
337 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
);
338 $isPayLater = CRM_Utils_Array
::value('is_pay_later', $this->_values
);
340 //FIXME: to support multiple payment processors
342 (!$isPayLater ||
!empty($this->_values
['payment_processor']))
344 $ppID = CRM_Utils_Array
::value('payment_processor', $this->_values
);
346 CRM_Core_Error
::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
349 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
350 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds, $this->_mode
);
352 $this->set('paymentProcessors', $this->_paymentProcessors
);
354 //set default payment processor
355 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
356 foreach ($this->_paymentProcessors
as $ppId => $values) {
357 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
358 $defaultProcessorId = $ppId;
364 if (isset($defaultProcessorId)) {
365 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
366 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
369 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
370 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
371 // check selected payment processor is active
372 if (empty($eachPaymentProcessor)) {
373 CRM_Core_Error
::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
376 // ensure that processor has a valid config
377 $this->_paymentObject
= &CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
378 $error = $this->_paymentObject
->checkConfig();
379 if (!empty($error)) {
380 CRM_Core_Error
::fatal($error);
388 CRM_Price_BAO_PriceSet
::initSet($this, $this->_id
, 'civicrm_contribution_page');
390 // this avoids getting E_NOTICE errors in php
391 $setNullFields = array(
392 'amount_block_is_active',
393 'is_allow_other_amount',
396 foreach ($setNullFields as $f) {
397 if (!isset($this->_values
[$f])) {
398 $this->_values
[$f] = NULL;
402 //check if Membership Block is enabled, if Membership Fields are included in profile
403 //get membership section for this contribution page
404 $this->_membershipBlock
= CRM_Member_BAO_Membership
::getMembershipBlock($this->_id
);
405 $this->set('membershipBlock', $this->_membershipBlock
);
407 if ($this->_values
['custom_pre_id']) {
408 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_pre_id']);
411 if ($this->_values
['custom_post_id']) {
412 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_post_id']);
415 if (((isset($postProfileType) && $postProfileType == 'Membership') ||
416 (isset($preProfileType) && $preProfileType == 'Membership')
418 !$this->_membershipBlock
['is_active']
420 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.'));
423 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::getPledgeBlock($this->_id
);
426 $this->_values
['pledge_block_id'] = CRM_Utils_Array
::value('id', $pledgeBlock);
427 $this->_values
['max_reminders'] = CRM_Utils_Array
::value('max_reminders', $pledgeBlock);
428 $this->_values
['initial_reminder_day'] = CRM_Utils_Array
::value('initial_reminder_day', $pledgeBlock);
429 $this->_values
['additional_reminder_day'] = CRM_Utils_Array
::value('additional_reminder_day', $pledgeBlock);
431 //set pledge id in values
432 $pledgeId = CRM_Utils_Request
::retrieve('pledgeId', 'Positive', $this);
434 //authenticate pledge user for pledge payment.
436 $this->_values
['pledge_id'] = $pledgeId;
438 //lets override w/ pledge campaign.
439 $this->_values
['campaign_id'] = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
443 self
::authenticatePledgeUser();
446 $this->set('values', $this->_values
);
447 $this->set('fields', $this->_fields
);
451 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
453 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'contribute', $this->_values
);
454 $this->_pcpId
= $pcp['pcpId'];
455 $this->_pcpBlock
= $pcp['pcpBlock'];
456 $this->_pcpInfo
= $pcp['pcpInfo'];
459 // Link (button) for users to create their own Personal Campaign page
460 if ($linkText = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute')) {
461 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
462 "action=add&reset=1&pageId={$this->_id}&component=contribute",
465 $this->assign('linkTextUrl', $linkTextUrl);
466 $this->assign('linkText', $linkText);
469 //set pledge block if block id is set
470 if (!empty($this->_values
['pledge_block_id'])) {
471 $this->assign('pledgeBlock', TRUE);
474 // check if one of the (amount , membership) bloks is active or not
475 $this->_membershipBlock
= $this->get('membershipBlock');
477 if (!$this->_values
['amount_block_is_active'] &&
478 !$this->_membershipBlock
['is_active'] &&
481 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.'));
484 if ($this->_values
['amount_block_is_active']) {
485 $this->set('amount_block_is_active', $this->_values
['amount_block_is_active']);
488 $this->_contributeMode
= $this->get('contributeMode');
489 $this->assign('contributeMode', $this->_contributeMode
);
491 //assigning is_monetary and is_email_receipt to template
492 $this->assign('is_monetary', $this->_values
['is_monetary']);
493 $this->assign('is_email_receipt', $this->_values
['is_email_receipt']);
494 $this->assign('bltID', $this->_bltID
);
496 //assign cancelSubscription URL to templates
497 $this->assign('cancelSubscriptionUrl',
498 CRM_Utils_Array
::value('cancelSubscriptionUrl', $this->_values
)
501 // assigning title to template in case someone wants to use it, also setting CMS page title
503 $this->assign('title', $this->_pcpInfo
['title']);
504 CRM_Utils_System
::setTitle($this->_pcpInfo
['title']);
507 $this->assign('title', $this->_values
['title']);
508 CRM_Utils_System
::setTitle($this->_values
['title']);
510 $this->_defaults
= array();
512 $this->_amount
= $this->get('amount');
515 $config = CRM_Core_Config
::singleton();
516 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
518 $config->defaultCurrency
521 //lets allow user to override campaign.
522 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
523 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
524 $this->_values
['campaign_id'] = $campID;
527 //do check for cancel recurring and clean db, CRM-7696
528 if (CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject)) {
529 self
::cancelRecurring();
532 // check if billing block is required for pay later
533 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
)) {
534 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
);
535 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
540 * set the default values
545 function setDefaultValues() {
546 return $this->_defaults
;
550 * assign the minimal set of variables to the template
555 function assignToTemplate() {
556 $name = CRM_Utils_Array
::value('billing_first_name', $this->_params
);
557 if (!empty($this->_params
['billing_middle_name'])) {
558 $name .= " {$this->_params['billing_middle_name']}";
560 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $this->_params
);
562 $this->assign('billingName', $name);
563 $this->set('name', $name);
565 $this->assign('paymentProcessor', $this->_paymentProcessor
);
567 'amount', 'currencyID',
568 'credit_card_type', 'trxn_id', 'amount_level',
571 $config = CRM_Core_Config
::singleton();
572 if (isset($this->_values
['is_recur']) && !empty($this->_paymentProcessor
['is_recur'])) {
573 $this->assign('is_recur_enabled', 1);
574 $vars = array_merge($vars, array(
575 'is_recur', 'frequency_interval', 'frequency_unit',
580 if (in_array('CiviPledge', $config->enableComponents
) &&
581 CRM_Utils_Array
::value('is_pledge', $this->_params
) == 1
583 $this->assign('pledge_enabled', 1);
585 $vars = array_merge($vars, array(
587 'pledge_frequency_interval',
588 'pledge_frequency_unit',
589 'pledge_installments',
593 if (isset($this->_params
['amount_other']) ||
isset($this->_params
['selectMembership'])) {
594 $this->_params
['amount_level'] = '';
597 foreach ($vars as $v) {
598 if (isset($this->_params
[$v])) {
599 if ($v == 'frequency_unit' ||
$v == 'pledge_frequency_unit') {
600 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units');
601 if (array_key_exists($this->_params
[$v], $frequencyUnits)) {
602 $this->_params
[$v] = $frequencyUnits[$this->_params
[$v]];
605 if ($v == "amount" && $this->_params
[$v] === 0) {
606 $this->_params
[$v] = CRM_Utils_Money
::format($this->_params
[$v], NULL, NULL, TRUE);
608 $this->assign($v, $this->_params
[$v]);
612 // assign the address formatted up for display
613 $addressParts = array(
614 "street_address-{$this->_bltID}",
615 "city-{$this->_bltID}",
616 "postal_code-{$this->_bltID}",
617 "state_province-{$this->_bltID}",
618 "country-{$this->_bltID}",
621 $addressFields = array();
622 foreach ($addressParts as $part) {
623 list($n, $id) = explode('-', $part);
624 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $this->_params
);
627 $this->assign('address', CRM_Utils_Address
::format($addressFields));
629 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
630 $this->assign('onBehalfName', $this->_params
['organization_name']);
631 $locTypeId = array_keys($this->_params
['onbehalf_location']['email']);
632 $this->assign('onBehalfEmail', $this->_params
['onbehalf_location']['email'][$locTypeId[0]]['email']);
636 $assignCCInfo = FALSE;
637 if ($this->_amount
> 0.0) {
638 $assignCCInfo = TRUE;
640 elseif (!empty($this->_params
['selectMembership'])) {
641 $memFee = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params
['selectMembership'], 'minimum_fee');
643 $assignCCInfo = TRUE;
647 if ($this->_contributeMode
== 'direct' && $assignCCInfo) {
648 if ($this->_paymentProcessor
&&
649 $this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
651 $this->assign('payment_type', $this->_paymentProcessor
['payment_type']);
652 $this->assign('account_holder', $this->_params
['account_holder']);
653 $this->assign('bank_identification_number', $this->_params
['bank_identification_number']);
654 $this->assign('bank_name', $this->_params
['bank_name']);
655 $this->assign('bank_account_number', $this->_params
['bank_account_number']);
658 $date = CRM_Utils_Date
::format(CRM_Utils_array
::value('credit_card_exp_date', $this->_params
));
659 $date = CRM_Utils_Date
::mysqlToIso($date);
660 $this->assign('credit_card_exp_date', $date);
661 $this->assign('credit_card_number',
662 CRM_Utils_System
::mungeCreditCard(CRM_Utils_array
::value('credit_card_number', $this->_params
))
667 $this->assign('email',
668 $this->controller
->exportValue('Main', "email-{$this->_bltID}")
671 // also assign the receipt_text
672 if (isset($this->_values
['receipt_text'])) {
673 $this->assign('receipt_text', $this->_values
['receipt_text']);
678 * Function to add the custom fields
682 * @param bool $viewOnly
683 * @param null $profileContactType
684 * @param null $fieldTypes
689 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
690 $stateCountryMap = array();
693 $contactID = $this->getContactID();
695 // we don't allow conflicting fields to be
696 // configured via profile - CRM 2100
697 $fieldsToIgnore = array(
703 'non_deductible_amount' => 1,
706 'contribution_status_id' => 1,
707 'payment_instrument' => 1,
709 'financial_type' => 1,
713 if ($contactID && CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
714 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
715 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
719 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
720 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
725 // unset any email-* fields since we already collect it, CRM-2888
726 foreach (array_keys($fields) as $fieldName) {
727 if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
728 unset($fields[$fieldName]);
732 if (array_intersect_key($fields, $fieldsToIgnore)) {
733 $fields = array_diff_key($fields, $fieldsToIgnore);
734 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
737 $fields = array_diff_assoc($fields, $this->_fields
);
739 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
741 foreach ($fields as $key => $field) {
743 isset($field['data_type']) &&
744 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
746 // ignore file upload fields
750 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
751 if ($prefixName == 'state_province' ||
$prefixName == 'country' ||
$prefixName == 'county') {
752 if (!array_key_exists($index, $stateCountryMap)) {
753 $stateCountryMap[$index] = array();
755 $stateCountryMap[$index][$prefixName] = $key;
757 if ($prefixName == "state_province") {
758 if ($profileContactType == 'onbehalf') {
759 //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
760 //as already done during Contribution registration via onBehalf's quickForm
761 $field['is_required'] = FALSE;
764 if (count($this->_submitValues
)) {
765 $locationTypeId = $field['location_type_id'];
766 if (array_key_exists("country-{$locationTypeId}", $fields) &&
767 array_key_exists("state_province-{$locationTypeId}", $fields) &&
768 !empty($this->_submitValues
["country-{$locationTypeId}"])) {
769 $field['is_required'] =
770 CRM_Core_Payment_Form
::checkRequiredStateProvince($this, "country-{$locationTypeId}");
777 if ($profileContactType) {
778 //Since we are showing honoree name separately so we are removing it from honoree profile just for display
779 $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
780 if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
781 unset($fields[$field['name']]);
784 if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
785 CRM_Core_BAO_UFGroup
::buildProfile(
788 CRM_Profile_Form
::MODE_CREATE
,
793 $this->_fields
[$profileContactType][$key] = $field;
796 unset($fields[$key]);
800 CRM_Core_BAO_UFGroup
::buildProfile(
803 CRM_Profile_Form
::MODE_CREATE
,
807 $this->_fields
[$key] = $field;
809 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
810 if ($field['add_captcha'] && !$this->_userID
) {
815 $this->assign($name, $fields);
817 CRM_Core_BAO_Address
::addStateCountryMap($stateCountryMap);
819 if ($addCaptcha && !$viewOnly) {
820 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
821 $captcha->add($this);
822 $this->assign('isCaptcha', TRUE);
829 * Check template file exists
830 * @param null $suffix
832 * @return null|string
834 function checkTemplateFileExists($suffix = NULL) {
836 $templateFile = "CRM/Contribute/Form/Contribution/{$this->_id}/{$this->_name}.{$suffix}tpl";
837 $template = CRM_Core_Form
::getTemplate();
838 if ($template->template_exists($templateFile)) {
839 return $templateFile;
846 * Use the form name to create the tpl file name
854 function getTemplateFileName() {
855 $fileName = $this->checkTemplateFileExists();
856 return $fileName ?
$fileName : parent
::getTemplateFileName();
860 * Default extra tpl file basically just replaces .tpl with .extra.tpl
861 * i.e. we dont override
869 function overrideExtraTemplateFileName() {
870 $fileName = $this->checkTemplateFileExists('extra.');
871 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
875 * Function to authenticate pledge user during online payment.
881 public function authenticatePledgeUser() {
882 //get the userChecksum and contact id
883 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
884 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
886 //get pledge status and contact id
887 $pledgeValues = array();
888 $pledgeParams = array('id' => $this->_values
['pledge_id']);
889 $returnProperties = array('contact_id', 'status_id');
890 CRM_Core_DAO
::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties);
893 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
894 $validStatus = array(array_search('Pending', $allStatus),
895 array_search('In Progress', $allStatus),
896 array_search('Overdue', $allStatus),
900 if ($this->_userID
&&
901 $this->_userID
== $pledgeValues['contact_id']
903 //check for authenticated user.
906 elseif ($userChecksum && $pledgeValues['contact_id']) {
907 //check for anonymous user.
908 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($pledgeValues['contact_id'], $userChecksum);
910 //make sure cid is same as pledge contact id
911 if ($validUser && ($pledgeValues['contact_id'] != $contactID)) {
917 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."));
920 //check for valid pledge status.
921 if (!in_array($pledgeValues['status_id'], $validStatus)) {
922 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))));
927 * In case user cancel recurring contribution,
928 * When we get the control back from payment gate way
929 * lets delete the recurring and related contribution.
932 public function cancelRecurring() {
933 $isCancel = CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject);
935 $isRecur = CRM_Utils_Request
::retrieve('isRecur', 'Boolean', CRM_Core_DAO
::$_nullObject);
936 $recurId = CRM_Utils_Request
::retrieve('recurId', 'Positive', CRM_Core_DAO
::$_nullObject);
937 //clean db for recurring contribution.
938 if ($isRecur && $recurId) {
939 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($recurId);
941 $contribId = CRM_Utils_Request
::retrieve('contribId', 'Positive', CRM_Core_DAO
::$_nullObject);
943 CRM_Contribute_BAO_Contribution
::deleteContribution($contribId);