3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
50 * The mode that we are in
58 * The contact id related to a membership
62 public $_membershipContactID;
65 * The values for the contribution db object
72 * The paymentProcessor attributes for this page
76 public $_paymentProcessor;
77 public $_paymentObject = NULL;
80 * The membership block for this page
84 public $_membershipBlock = NULL;
87 * Does this form support a separate membership payment
90 protected $_separateMembershipPayment;
92 * The default values for the form
99 * The params submitted by the form and computed by the app
106 * The fields involved in this contribution page
110 public $_fields = array();
113 * The billing location id for this contribiution page
120 * Cache the amount to make things easier
148 * The contact id of the person for whom membership is being added or renewed based on the cid in the url,
149 * checksum, or session
157 * The Membership ID for membership renewal
161 public $_membershipId;
164 * Price Set ID, if the new price set method is used
171 * Array of fields for the price set
180 * Is honor block is enabled for this contribution?
184 public $_honor_block_is_active = FALSE;
187 * Contribution mode e.g express for payment express, notify for off-site + notification back to CiviCRM
190 public $_contributeMode;
193 * Contribution page supports memberships
196 public $_useForMember;
198 public $_isBillingAddressRequiredForPayLater;
201 * Set variables up before form is built.
203 * @throws \CRM_Contribute_Exception_InactiveContributionPageException
206 public function preProcess() {
208 $config = CRM_Core_Config
::singleton();
209 $session = CRM_Core_Session
::singleton();
211 // current contribution page id
212 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
214 // seems like the session is corrupted and/or we lost the id trail
215 // lets just bump this to a regular session error and redirect user to main page
216 $this->controller
->invalidKeyRedirect();
219 // this was used prior to the cleverer this_>getContactID - unsure now
220 $this->_userID
= $session->get('userID');
222 //Check if honor block is enabled for current contribution
223 $ufJoinParams = array(
224 'module' => 'soft_credit',
225 'entity_table' => 'civicrm_contribution_page',
226 'entity_id' => $this->_id
,
228 $ufJoin = new CRM_Core_DAO_UFJoin();
229 $ufJoin->copyValues($ufJoinParams);
231 $this->_honor_block_is_active
= $ufJoin->is_active
;
233 $this->_contactID
= $this->_membershipContactID
= $this->getContactID();
235 if ($this->_contactID
) {
236 $this->_mid
= CRM_Utils_Request
::retrieve('mid', 'Positive', $this);
238 $membership = new CRM_Member_DAO_Membership();
239 $membership->id
= $this->_mid
;
241 if ($membership->find(TRUE)) {
242 $this->_defaultMemTypeId
= $membership->membership_type_id
;
243 if ($membership->contact_id
!= $this->_contactID
) {
244 $validMembership = FALSE;
245 $employers = CRM_Contact_BAO_Relationship
::getPermissionedEmployer($this->_userID
);
246 if (!empty($employers) && array_key_exists($membership->contact_id
, $employers)) {
247 $this->_membershipContactID
= $membership->contact_id
;
248 $this->assign('membershipContactID', $this->_membershipContactID
);
249 $this->assign('membershipContactName', $employers[$this->_membershipContactID
]['name']);
250 $validMembership = TRUE;
253 $membershipType = new CRM_Member_BAO_MembershipType();
254 $membershipType->id
= $membership->membership_type_id
;
255 if ($membershipType->find(TRUE)) {
256 // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
257 // Convert to commma separated list.
258 $inheritedRelTypes = implode(CRM_Utils_Array
::explodePadded($membershipType->relationship_type_id
), ',');
259 $permContacts = CRM_Contact_BAO_Relationship
::getPermissionedContacts($this->_userID
, $membershipType->relationship_type_id
);
260 if (array_key_exists($membership->contact_id
, $permContacts)) {
261 $this->_membershipContactID
= $membership->contact_id
;
262 $validMembership = TRUE;
266 if (!$validMembership) {
267 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');
272 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');
278 // we do not want to display recently viewed items, so turn off
279 $this->assign('displayRecent', FALSE);
280 // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
281 // Use Browser Print instead.
282 $this->assign('browserPrint', TRUE);
285 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
286 $this->assign('action', $this->_action
);
289 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
291 $this->_values
= $this->get('values');
292 $this->_fields
= $this->get('fields');
293 $this->_bltID
= $this->get('bltID');
294 $this->_paymentProcessor
= $this->get('paymentProcessor');
295 $this->_priceSetId
= $this->get('priceSetId');
296 $this->_priceSet
= $this->get('priceSet');
298 if (!$this->_values
) {
299 // get all the values from the dao object
300 $this->_values
= array();
301 $this->_fields
= array();
303 CRM_Contribute_BAO_ContributionPage
::setValues($this->_id
, $this->_values
);
305 if (empty($this->_values
['is_active'])) {
306 throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id
);
309 // also check for billing informatin
310 // get the billing location type
311 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
312 // CRM-8108 remove ts around Billing location type
313 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
314 $this->_bltID
= array_search('Billing', $locationTypes);
315 if (!$this->_bltID
) {
316 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
318 $this->set('bltID', $this->_bltID
);
320 // check for is_monetary status
321 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
);
322 $isPayLater = CRM_Utils_Array
::value('is_pay_later', $this->_values
);
324 //FIXME: to support multiple payment processors
326 (!$isPayLater ||
!empty($this->_values
['payment_processor']))
328 $ppID = CRM_Utils_Array
::value('payment_processor', $this->_values
);
330 CRM_Core_Error
::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
333 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
334 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds, $this->_mode
);
336 $this->set('paymentProcessors', $this->_paymentProcessors
);
338 //set default payment processor
339 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
340 foreach ($this->_paymentProcessors
as $ppId => $values) {
341 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
342 $defaultProcessorId = $ppId;
348 if (isset($defaultProcessorId)) {
349 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
350 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
353 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
354 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
355 // check selected payment processor is active
356 if (empty($eachPaymentProcessor)) {
357 CRM_Core_Error
::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
360 // ensure that processor has a valid config
361 $this->_paymentObject
= &CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
362 $error = $this->_paymentObject
->checkConfig();
363 if (!empty($error)) {
364 CRM_Core_Error
::fatal($error);
372 CRM_Price_BAO_PriceSet
::initSet($this, $this->_id
, 'civicrm_contribution_page');
374 // this avoids getting E_NOTICE errors in php
375 $setNullFields = array(
376 'amount_block_is_active',
377 'is_allow_other_amount',
380 foreach ($setNullFields as $f) {
381 if (!isset($this->_values
[$f])) {
382 $this->_values
[$f] = NULL;
386 //check if Membership Block is enabled, if Membership Fields are included in profile
387 //get membership section for this contribution page
388 $this->_membershipBlock
= CRM_Member_BAO_Membership
::getMembershipBlock($this->_id
);
389 $this->set('membershipBlock', $this->_membershipBlock
);
391 if ($this->_values
['custom_pre_id']) {
392 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_pre_id']);
395 if ($this->_values
['custom_post_id']) {
396 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($this->_values
['custom_post_id']);
399 if (((isset($postProfileType) && $postProfileType == 'Membership') ||
400 (isset($preProfileType) && $preProfileType == 'Membership')
402 !$this->_membershipBlock
['is_active']
404 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.'));
407 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::getPledgeBlock($this->_id
);
410 $this->_values
['pledge_block_id'] = CRM_Utils_Array
::value('id', $pledgeBlock);
411 $this->_values
['max_reminders'] = CRM_Utils_Array
::value('max_reminders', $pledgeBlock);
412 $this->_values
['initial_reminder_day'] = CRM_Utils_Array
::value('initial_reminder_day', $pledgeBlock);
413 $this->_values
['additional_reminder_day'] = CRM_Utils_Array
::value('additional_reminder_day', $pledgeBlock);
415 //set pledge id in values
416 $pledgeId = CRM_Utils_Request
::retrieve('pledgeId', 'Positive', $this);
418 //authenticate pledge user for pledge payment.
420 $this->_values
['pledge_id'] = $pledgeId;
422 //lets override w/ pledge campaign.
423 $this->_values
['campaign_id'] = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
427 self
::authenticatePledgeUser();
430 $this->set('values', $this->_values
);
431 $this->set('fields', $this->_fields
);
435 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
437 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'contribute', $this->_values
);
438 $this->_pcpId
= $pcp['pcpId'];
439 $this->_pcpBlock
= $pcp['pcpBlock'];
440 $this->_pcpInfo
= $pcp['pcpInfo'];
443 // Link (button) for users to create their own Personal Campaign page
444 if ($linkText = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute')) {
445 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
446 "action=add&reset=1&pageId={$this->_id}&component=contribute",
449 $this->assign('linkTextUrl', $linkTextUrl);
450 $this->assign('linkText', $linkText);
453 //set pledge block if block id is set
454 if (!empty($this->_values
['pledge_block_id'])) {
455 $this->assign('pledgeBlock', TRUE);
458 // check if one of the (amount , membership) bloks is active or not
459 $this->_membershipBlock
= $this->get('membershipBlock');
461 if (!$this->_values
['amount_block_is_active'] &&
462 !$this->_membershipBlock
['is_active'] &&
465 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.'));
468 if ($this->_values
['amount_block_is_active']) {
469 $this->set('amount_block_is_active', $this->_values
['amount_block_is_active']);
472 $this->_contributeMode
= $this->get('contributeMode');
473 $this->assign('contributeMode', $this->_contributeMode
);
475 //assigning is_monetary and is_email_receipt to template
476 $this->assign('is_monetary', $this->_values
['is_monetary']);
477 $this->assign('is_email_receipt', $this->_values
['is_email_receipt']);
478 $this->assign('bltID', $this->_bltID
);
480 //assign cancelSubscription URL to templates
481 $this->assign('cancelSubscriptionUrl',
482 CRM_Utils_Array
::value('cancelSubscriptionUrl', $this->_values
)
485 // assigning title to template in case someone wants to use it, also setting CMS page title
487 $this->assign('title', $this->_pcpInfo
['title']);
488 CRM_Utils_System
::setTitle($this->_pcpInfo
['title']);
491 $this->assign('title', $this->_values
['title']);
492 CRM_Utils_System
::setTitle($this->_values
['title']);
494 $this->_defaults
= array();
496 $this->_amount
= $this->get('amount');
499 $config = CRM_Core_Config
::singleton();
500 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
502 $config->defaultCurrency
505 //lets allow user to override campaign.
506 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
507 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
508 $this->_values
['campaign_id'] = $campID;
511 //do check for cancel recurring and clean db, CRM-7696
512 if (CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject)) {
513 self
::cancelRecurring();
516 // check if billing block is required for pay later
517 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
)) {
518 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
);
519 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
524 * Set the default values.
528 public function setDefaultValues() {
529 return $this->_defaults
;
533 * Assign the minimal set of variables to the template.
537 public function assignToTemplate() {
538 $name = CRM_Utils_Array
::value('billing_first_name', $this->_params
);
539 if (!empty($this->_params
['billing_middle_name'])) {
540 $name .= " {$this->_params['billing_middle_name']}";
542 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $this->_params
);
544 $this->assign('billingName', $name);
545 $this->set('name', $name);
547 $this->assign('paymentProcessor', $this->_paymentProcessor
);
556 $config = CRM_Core_Config
::singleton();
557 if (isset($this->_values
['is_recur']) && !empty($this->_paymentProcessor
['is_recur'])) {
558 $this->assign('is_recur_enabled', 1);
559 $vars = array_merge($vars, array(
561 'frequency_interval',
567 if (in_array('CiviPledge', $config->enableComponents
) &&
568 CRM_Utils_Array
::value('is_pledge', $this->_params
) == 1
570 $this->assign('pledge_enabled', 1);
572 $vars = array_merge($vars, array(
574 'pledge_frequency_interval',
575 'pledge_frequency_unit',
576 'pledge_installments',
580 if (isset($this->_params
['amount_other']) ||
isset($this->_params
['selectMembership'])) {
581 $this->_params
['amount_level'] = '';
584 foreach ($vars as $v) {
585 if (isset($this->_params
[$v])) {
586 if ($v == 'frequency_unit' ||
$v == 'pledge_frequency_unit') {
587 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units');
588 if (array_key_exists($this->_params
[$v], $frequencyUnits)) {
589 $this->_params
[$v] = $frequencyUnits[$this->_params
[$v]];
592 if ($v == "amount" && $this->_params
[$v] === 0) {
593 $this->_params
[$v] = CRM_Utils_Money
::format($this->_params
[$v], NULL, NULL, TRUE);
595 $this->assign($v, $this->_params
[$v]);
599 // assign the address formatted up for display
600 $addressParts = array(
601 "street_address-{$this->_bltID}",
602 "city-{$this->_bltID}",
603 "postal_code-{$this->_bltID}",
604 "state_province-{$this->_bltID}",
605 "country-{$this->_bltID}",
608 $addressFields = array();
609 foreach ($addressParts as $part) {
610 list($n, $id) = explode('-', $part);
611 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $this->_params
);
614 $this->assign('address', CRM_Utils_Address
::format($addressFields));
616 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
617 $this->assign('onBehalfName', $this->_params
['organization_name']);
618 $locTypeId = array_keys($this->_params
['onbehalf_location']['email']);
619 $this->assign('onBehalfEmail', $this->_params
['onbehalf_location']['email'][$locTypeId[0]]['email']);
623 $assignCCInfo = FALSE;
624 if ($this->_amount
> 0.0) {
625 $assignCCInfo = TRUE;
627 elseif (!empty($this->_params
['selectMembership'])) {
628 $memFee = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params
['selectMembership'], 'minimum_fee');
630 $assignCCInfo = TRUE;
634 if ($this->_contributeMode
== 'direct' && $assignCCInfo) {
635 if ($this->_paymentProcessor
&&
636 $this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
638 $this->assign('account_holder', $this->_params
['account_holder']);
639 $this->assign('bank_identification_number', $this->_params
['bank_identification_number']);
640 $this->assign('bank_name', $this->_params
['bank_name']);
641 $this->assign('bank_account_number', $this->_params
['bank_account_number']);
644 $date = CRM_Utils_Date
::format(CRM_Utils_array
::value('credit_card_exp_date', $this->_params
));
645 $date = CRM_Utils_Date
::mysqlToIso($date);
646 $this->assign('credit_card_exp_date', $date);
647 $this->assign('credit_card_number',
648 CRM_Utils_System
::mungeCreditCard(CRM_Utils_array
::value('credit_card_number', $this->_params
))
653 $this->assign('email',
654 $this->controller
->exportValue('Main', "email-{$this->_bltID}")
657 // also assign the receipt_text
658 if (isset($this->_values
['receipt_text'])) {
659 $this->assign('receipt_text', $this->_values
['receipt_text']);
664 * Add the custom fields.
667 * @param string $name
668 * @param bool $viewOnly
669 * @param null $profileContactType
670 * @param null $fieldTypes
674 public function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
676 $contactID = $this->getContactID();
678 // we don't allow conflicting fields to be
679 // configured via profile - CRM 2100
680 $fieldsToIgnore = array(
686 'non_deductible_amount' => 1,
689 'contribution_status_id' => 1,
690 'payment_instrument' => 1,
692 'financial_type' => 1,
696 if ($contactID && CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
697 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
698 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
702 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
, NULL, NULL, FALSE,
703 NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL
708 // unset any email-* fields since we already collect it, CRM-2888
709 foreach (array_keys($fields) as $fieldName) {
710 if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
711 unset($fields[$fieldName]);
715 if (array_intersect_key($fields, $fieldsToIgnore)) {
716 $fields = array_diff_key($fields, $fieldsToIgnore);
717 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
720 $fields = array_diff_assoc($fields, $this->_fields
);
722 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
724 foreach ($fields as $key => $field) {
726 isset($field['data_type']) &&
727 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
729 // ignore file upload fields
733 if ($profileContactType) {
734 //Since we are showing honoree name separately so we are removing it from honoree profile just for display
735 $honoreeNamefields = array(
743 if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
744 unset($fields[$field['name']]);
747 if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
748 CRM_Core_BAO_UFGroup
::buildProfile(
751 CRM_Profile_Form
::MODE_CREATE
,
756 $this->_fields
[$profileContactType][$key] = $field;
759 unset($fields[$key]);
763 CRM_Core_BAO_UFGroup
::buildProfile(
766 CRM_Profile_Form
::MODE_CREATE
,
770 $this->_fields
[$key] = $field;
772 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
773 if ($field['add_captcha'] && !$this->_userID
) {
778 $this->assign($name, $fields);
780 if ($addCaptcha && !$viewOnly) {
781 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
782 $captcha->add($this);
783 $this->assign('isCaptcha', TRUE);
790 * Check template file exists.
791 * @param null $suffix
793 * @return null|string
795 public function checkTemplateFileExists($suffix = NULL) {
797 $templateFile = "CRM/Contribute/Form/Contribution/{$this->_id}/{$this->_name}.{$suffix}tpl";
798 $template = CRM_Core_Form
::getTemplate();
799 if ($template->template_exists($templateFile)) {
800 return $templateFile;
807 * Use the form name to create the tpl file name.
814 public function getTemplateFileName() {
815 $fileName = $this->checkTemplateFileExists();
816 return $fileName ?
$fileName : parent
::getTemplateFileName();
820 * Default extra tpl file basically just replaces .tpl with .extra.tpl
821 * i.e. we dont override
828 public function overrideExtraTemplateFileName() {
829 $fileName = $this->checkTemplateFileExists('extra.');
830 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
834 * Authenticate pledge user during online payment.
839 public function authenticatePledgeUser() {
840 //get the userChecksum and contact id
841 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
842 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
844 //get pledge status and contact id
845 $pledgeValues = array();
846 $pledgeParams = array('id' => $this->_values
['pledge_id']);
847 $returnProperties = array('contact_id', 'status_id');
848 CRM_Core_DAO
::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties);
851 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
852 $validStatus = array(
853 array_search('Pending', $allStatus),
854 array_search('In Progress', $allStatus),
855 array_search('Overdue', $allStatus),
859 if ($this->_userID
&&
860 $this->_userID
== $pledgeValues['contact_id']
862 //check for authenticated user.
865 elseif ($userChecksum && $pledgeValues['contact_id']) {
866 //check for anonymous user.
867 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($pledgeValues['contact_id'], $userChecksum);
869 //make sure cid is same as pledge contact id
870 if ($validUser && ($pledgeValues['contact_id'] != $contactID)) {
876 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."));
879 //check for valid pledge status.
880 if (!in_array($pledgeValues['status_id'], $validStatus)) {
881 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))));
886 * In case user cancel recurring contribution,
887 * When we get the control back from payment gate way
888 * lets delete the recurring and related contribution.
891 public function cancelRecurring() {
892 $isCancel = CRM_Utils_Request
::retrieve('cancel', 'Boolean', CRM_Core_DAO
::$_nullObject);
894 $isRecur = CRM_Utils_Request
::retrieve('isRecur', 'Boolean', CRM_Core_DAO
::$_nullObject);
895 $recurId = CRM_Utils_Request
::retrieve('recurId', 'Positive', CRM_Core_DAO
::$_nullObject);
896 //clean db for recurring contribution.
897 if ($isRecur && $recurId) {
898 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($recurId);
900 $contribId = CRM_Utils_Request
::retrieve('contribId', 'Positive', CRM_Core_DAO
::$_nullObject);
902 CRM_Contribute_BAO_Contribution
::deleteContribution($contribId);