Beispiel #1
0
 /**
  * @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main|CRM_Core_Payment_ProcessorForm|CRM_Contribute_Form_UpdateBilling $form
  * @param array $processor
  *   Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
  * @param int|string $billing_profile_id
  *   Id of a profile to be passed to the processor for the processor to merge with it's required fields.
  *   (currently only implemented by manual/ pay-later processor)
  *
  * @param bool $isBackOffice
  *   Is this a backoffice form. This could affect the display of the cvn or whether some processors show,
  *   although the distinction is losing it's meaning as front end forms are used for back office and a permission
  *   for the 'enter without cvn' is probably more appropriate. Paypal std does not support another user
  *   entering details but once again the issue is not back office but 'another user'.
  *
  * @return bool
  */
 public static function buildPaymentForm(&$form, $processor, $billing_profile_id, $isBackOffice)
 {
     //if the form has address fields assign to the template so the js can decide what billing fields to show
     $profileAddressFields = $form->get('profileAddressFields');
     if (!empty($profileAddressFields)) {
         $form->assign('profileAddressFields', $profileAddressFields);
     }
     if (!empty($processor['object']) && $processor['object']->buildForm($form)) {
         return NULL;
     }
     self::setPaymentFieldsByProcessor($form, $processor, $billing_profile_id, $isBackOffice);
     self::addCommonFields($form, $form->_paymentFields);
     self::addRules($form, $form->_paymentFields);
     return !empty($form->_paymentFields);
 }
Beispiel #2
0
 /**
  * Build quickForm.
  */
 public function buildQuickForm()
 {
     CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
 }
Beispiel #3
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // build profiles first so that we can determine address fields etc
     // and then show copy address checkbox
     if (empty($this->_ccid)) {
         $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
         $this->buildCustom($this->_values['custom_post_id'], 'customPost');
         // CRM-18399: used by template to pass pre profile id as a url arg
         $this->assign('custom_pre_id', $this->_values['custom_pre_id']);
         $this->buildComponentForm($this->_id, $this);
     }
     // Build payment processor form
     CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
     $config = CRM_Core_Config::singleton();
     $contactID = $this->getContactID();
     if ($contactID) {
         $this->assign('contact_id', $contactID);
         $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
     }
     $this->applyFilter('__ALL__', 'trim');
     if (empty($this->_ccid)) {
         $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60, 'class' => 'email'), TRUE);
         $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
     } else {
         $this->addElement('hidden', "email-{$this->_bltID}", 1);
         $this->add('text', 'total_amount', ts('Total Amount'), array('readonly' => TRUE), FALSE);
     }
     $pps = array();
     //@todo - this should be replaced by a check as to whether billing fields are set
     $onlinePaymentProcessorEnabled = FALSE;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $name) {
             if ($name['billing_mode'] == 1) {
                 $onlinePaymentProcessorEnabled = TRUE;
             }
             $pps[$key] = $name['name'];
         }
     }
     if (!empty($this->_values['is_pay_later'])) {
         $pps[0] = $this->_values['pay_later_text'];
     }
     if (count($pps) > 1) {
         $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " ");
     } elseif (!empty($pps)) {
         $key = array_keys($pps);
         $key = array_pop($key);
         $this->addElement('hidden', 'payment_processor_id', $key);
         if ($key === 0) {
             $this->assign('is_pay_later', $this->_values['is_pay_later']);
             $this->assign('pay_later_text', $this->_values['pay_later_text']);
         }
     }
     $contactID = $this->getContactID();
     if ($this->getContactID() === 0) {
         $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
     }
     //build pledge block.
     $this->_useForMember = 0;
     //don't build membership block when pledge_id is passed
     if (empty($this->_values['pledge_id']) && empty($this->_ccid)) {
         $this->_separateMembershipPayment = FALSE;
         if (in_array('CiviMember', $config->enableComponents)) {
             $isTest = 0;
             if ($this->_action & CRM_Core_Action::PREVIEW) {
                 $isTest = 1;
             }
             if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) {
                 $this->_useForMember = 1;
                 $this->set('useForMember', $this->_useForMember);
             }
             $this->_separateMembershipPayment = $this->buildMembershipBlock($this->_membershipContactID, TRUE, NULL, FALSE, $isTest);
         }
         $this->set('separateMembershipPayment', $this->_separateMembershipPayment);
     }
     $this->assign('useForMember', $this->_useForMember);
     // If we configured price set for contribution page
     // we are not allow membership signup as well as any
     // other contribution amount field, CRM-5095
     if (isset($this->_priceSetId) && $this->_priceSetId) {
         $this->add('hidden', 'priceSetId', $this->_priceSetId);
         // build price set form.
         $this->set('priceSetId', $this->_priceSetId);
         if (empty($this->_ccid)) {
             CRM_Price_BAO_PriceSet::buildPriceSet($this);
         }
         if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id'])) {
             self::buildRecur($this);
         }
     }
     if ($this->_priceSetId && empty($this->_ccid)) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $this->_useForMember = 0;
             $this->set('useForMember', $this->_useForMember);
         }
     }
     //we allow premium for pledge during pledge creation only.
     if (empty($this->_values['pledge_id']) && empty($this->_ccid)) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE);
     }
     //don't build pledge block when mid is passed
     if (!$this->_mid && empty($this->_ccid)) {
         $config = CRM_Core_Config::singleton();
         if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) {
             CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this);
         }
     }
     //to create an cms user
     if (!$this->_contactID && empty($this->_ccid)) {
         $createCMSUser = FALSE;
         if ($this->_values['custom_pre_id']) {
             $profileID = $this->_values['custom_pre_id'];
             $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
         }
         if (!$createCMSUser && $this->_values['custom_post_id']) {
             if (!is_array($this->_values['custom_post_id'])) {
                 $profileIDs = array($this->_values['custom_post_id']);
             } else {
                 $profileIDs = $this->_values['custom_post_id'];
             }
             foreach ($profileIDs as $pid) {
                 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
                     $profileID = $pid;
                     $createCMSUser = TRUE;
                     break;
                 }
             }
         }
         if ($createCMSUser) {
             CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         }
     }
     if ($this->_pcpId && empty($this->_ccid)) {
         if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) {
             $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter));
             // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field.
             $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute');
             if (!empty($text)) {
                 $pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!");
             }
             $this->assign('pcpSupporterText', $pcp_supporter_text);
         }
         $prms = array('id' => $this->_pcpId);
         CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
         if ($pcpInfo['is_honor_roll']) {
             $this->assign('isHonor', TRUE);
             $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );"));
             $extraOption = array('onclick' => "return pcpAnonymous( );");
             $elements = array();
             $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
             $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
             $this->addGroup($elements, 'pcp_is_anonymous', NULL, '&nbsp;&nbsp;&nbsp;');
             $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
             $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
         }
     }
     if (empty($this->_values['fee']) && empty($this->_ccid)) {
         CRM_Core_Error::fatal(ts('This page does not have any price fields configured or you may not have permission for them. Please contact the site administrator for more details.'));
     }
     //we have to load confirm contribution button in template
     //when multiple payment processor as the user
     //can toggle with payment processor selection
     $billingModePaymentProcessors = 0;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $values) {
             if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
                 $billingModePaymentProcessors++;
             }
         }
     }
     if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
         $allAreBillingModeProcessors = TRUE;
     } else {
         $allAreBillingModeProcessors = FALSE;
     }
     if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) {
         $submitButton = array('type' => 'upload', 'name' => CRM_Utils_Array::value('is_confirm_enabled', $this->_values) ? ts('Confirm Contribution') : ts('Contribute'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE);
         // Add submit-once behavior when confirm page disabled
         if (empty($this->_values['is_confirm_enabled'])) {
             $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
         }
         //change button name for updating contribution
         if (!empty($this->_ccid)) {
             $submitButton['name'] = ts('Confirm Payment');
         }
         $this->addButtons(array($submitButton));
     }
     $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
 }
 /**
  * @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main|CRM_Core_Payment_ProcessorForm|CRM_Contribute_Form_UpdateBilling $form
  * @param array $processor
  *   Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
  * @param bool $isBillingDataOptional
  *   This manifests for 'NULL' (pay later) payment processor as the addition of billing fields to the form and.
  *   for payment processors that gather payment data on site as rendering the fields as not being required. (not entirely sure why but this
  *   is implemented for back office forms)
  *
  * @return bool
  */
 public static function buildPaymentForm(&$form, $processor, $isBillingDataOptional)
 {
     //if the form has address fields assign to the template so the js can decide what billing fields to show
     $profileAddressFields = $form->get('profileAddressFields');
     if (!empty($profileAddressFields)) {
         $form->assign('profileAddressFields', $profileAddressFields);
     }
     // $processor->buildForm appears to be an undocumented (possibly unused) option for payment processors
     // which was previously available only in some form flows
     if (!empty($form->_paymentProcessor) && !empty($form->_paymentProcessor['object']) && $form->_paymentProcessor['object']->isSupported('buildForm')) {
         $form->_paymentProcessor['object']->buildForm($form);
         return NULL;
     }
     self::setPaymentFieldsByProcessor($form, $processor, empty($isBillingDataOptional));
     self::addCommonFields($form, !$isBillingDataOptional, $form->_paymentFields);
     self::addRules($form, $form->_paymentFields);
     self::addPaypalExpressCode($form);
     return !empty($form->_paymentFields);
 }
Beispiel #5
0
 /**
  * Handle Payment Processor switching for contribution and event registration forms.
  *
  * This function is shared between contribution & event forms & this is their common class.
  *
  * However, this should be seen as an in-progress refactor, the end goal being to also align the
  * backoffice forms that action payments.
  *
  * This function overlaps assignPaymentProcessor, in a bad way.
  */
 protected function preProcessPaymentOptions()
 {
     $this->_paymentProcessorID = NULL;
     if ($this->_paymentProcessors) {
         if (!empty($this->_submitValues)) {
             $this->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $this->_submitValues);
             $this->_paymentProcessor = CRM_Utils_Array::value($this->_paymentProcessorID, $this->_paymentProcessors);
             $this->set('type', $this->_paymentProcessorID);
             $this->set('mode', $this->_mode);
             $this->set('paymentProcessor', $this->_paymentProcessor);
         } else {
             foreach ($this->_paymentProcessors as $values) {
                 if (!empty($values['is_default']) || count($this->_paymentProcessors) == 1) {
                     $this->_paymentProcessorID = $values['id'];
                     break;
                 }
             }
         }
         if ($this->_paymentProcessorID) {
             CRM_Core_Payment_ProcessorForm::preProcess($this);
         } else {
             $this->_paymentProcessor = array();
         }
         CRM_Financial_Form_Payment::addCreditCardJs();
     }
     $this->assign('paymentProcessorID', $this->_paymentProcessorID);
 }
Beispiel #6
0
 /**
  * Handle Payment Processor switching for contribution and event registration forms.
  *
  * @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register $form
  * @param bool $noFees
  */
 public static function preProcessPaymentOptions(&$form, $noFees = FALSE)
 {
     $form->_snippet = CRM_Utils_Array::value('snippet', $_GET);
     $form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
     $form->_paymentProcessorID = NULL;
     if ($form->_paymentProcessors) {
         if (!empty($form->_submitValues)) {
             $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $form->_submitValues);
             $form->_paymentProcessor = CRM_Utils_Array::value($form->_paymentProcessorID, $form->_paymentProcessors);
             $form->set('type', $form->_paymentProcessorID);
             $form->set('mode', $form->_mode);
             $form->set('paymentProcessor', $form->_paymentProcessor);
         } else {
             foreach ($form->_paymentProcessors as $values) {
                 if (!empty($values['is_default']) || count($form->_paymentProcessors) == 1) {
                     $form->_paymentProcessorID = $values['id'];
                     break;
                 }
             }
         }
         if ($form->_paymentProcessorID) {
             CRM_Core_Payment_ProcessorForm::preProcess($form);
         } else {
             $form->_paymentProcessor = array();
         }
         CRM_Financial_Form_Payment::addCreditCardJs();
     }
     $form->assign('paymentProcessorID', $form->_paymentProcessorID);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     // build profiles first so that we can determine address fields etc
     // and then show copy address checkbox
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
     $this->buildCustom($this->_values['custom_post_id'], 'customPost');
     if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
         $profileAddressFields = array();
         foreach ($this->_fields as $key => $value) {
             CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id']));
         }
         $this->set('profileAddressFields', $profileAddressFields);
     }
     // Build payment processor form
     if ($this->_ppType) {
         CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
         // Return if we are in an ajax callback
         if ($this->_snippet) {
             return;
         }
     }
     $contactID = $this->getContactID();
     $this->assign('contact_id', $contactID);
     $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
     $this->add('hidden', 'scriptFee', NULL);
     $this->add('hidden', 'scriptArray', NULL);
     $bypassPayment = $allowGroupOnWaitlist = $isAdditionalParticipants = FALSE;
     if ($this->_values['event']['is_multiple_registrations']) {
         // don't allow to add additional during confirmation if not preregistered.
         if (!$this->_allowConfirmation || $this->_additionalParticipantIds) {
             // Hardcode maximum number of additional participants here for now. May need to make this configurable per event.
             // Label is value + 1, since the code sees this is ADDITIONAL participants (in addition to "self")
             $additionalOptions = array('' => '1', 1 => '2', 2 => '3', 3 => '4', 4 => '5', 5 => '6', 6 => '7', 7 => '8', 8 => '9', 9 => '10');
             $element = $this->add('select', 'additional_participants', ts('How many people are you registering?'), $additionalOptions, NULL, array('onChange' => "allowParticipant()"));
             $isAdditionalParticipants = TRUE;
         }
     }
     //hack to allow group to register w/ waiting
     if ((CRM_Utils_Array::value('is_multiple_registrations', $this->_values['event']) || $this->_priceSetId) && !$this->_allowConfirmation && is_numeric($this->_availableRegistrations) && CRM_Utils_Array::value('has_waitlist', $this->_values['event'])) {
         $bypassPayment = TRUE;
         //case might be group become as a part of waitlist.
         //If not waitlist then they require admin approve.
         $allowGroupOnWaitlist = TRUE;
         $this->_waitlistMsg = ts("This event has only %1 space(s) left. If you continue and register more than %1 people (including yourself ), the whole group will be wait listed. Or, you can reduce the number of people you are registering to %1 to avoid being put on the waiting list.", array(1 => $this->_availableRegistrations));
         if ($this->_requireApproval) {
             $this->_requireApprovalMsg = CRM_Utils_Array::value('approval_req_text', $this->_values['event'], ts('Registration for this event requires approval. Once your registration(s) have been reviewed, you will receive an email with a link to a web page where you can complete the registration process.'));
         }
     }
     //case where only approval needed - no waitlist.
     if ($this->_requireApproval && !$this->_allowWaitlist && !$bypassPayment) {
         $this->_requireApprovalMsg = CRM_Utils_Array::value('approval_req_text', $this->_values['event'], ts('Registration for this event requires approval. Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.'));
     }
     //lets display status to primary page only.
     $this->assign('waitlistMsg', $this->_waitlistMsg);
     $this->assign('requireApprovalMsg', $this->_requireApprovalMsg);
     $this->assign('allowGroupOnWaitlist', $allowGroupOnWaitlist);
     $this->assign('isAdditionalParticipants', $isAdditionalParticipants);
     //lets get js on two different qf elements.
     $showHidePayfieldName = NULL;
     $showHidePaymentInformation = FALSE;
     if ($this->_values['event']['is_monetary']) {
         self::buildAmount($this);
     }
     $pps = array();
     //@todo this processor adding fn is another one duplicated on contribute - a shared
     // common class would make this sort of thing extractable
     $onlinePaymentProcessorEnabled = FALSE;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $name) {
             if ($name['billing_mode'] == 1) {
                 $onlinePaymentProcessorEnabled = TRUE;
             }
             $pps[$key] = $name['name'];
         }
     }
     if ($this->getContactID() === '0' && !$this->_values['event']['is_multiple_registrations']) {
         //@todo we are blocking for multiple registrations because we haven't tested
         $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
     }
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && ($this->_allowConfirmation || !$this->_requireApproval && !$this->_allowWaitlist)) {
         $pps[0] = $this->_values['event']['pay_later_text'];
     }
     if ($this->_values['event']['is_monetary']) {
         if (count($pps) > 1) {
             $this->addRadio('payment_processor', ts('Payment Method'), $pps, NULL, "&nbsp;");
         } elseif (!empty($pps)) {
             $ppKeys = array_keys($pps);
             $currentPP = array_pop($ppKeys);
             $this->addElement('hidden', 'payment_processor', $currentPP);
         }
     }
     //lets add some qf element to bypass payment validations, CRM-4320
     if ($bypassPayment) {
         $this->addElement('hidden', 'bypass_payment', NULL, array('id' => 'bypass_payment'));
     }
     $this->assign('bypassPayment', $bypassPayment);
     $this->assign('showHidePaymentInformation', $showHidePaymentInformation);
     $userID = $this->getContactID();
     if (!$userID) {
         $createCMSUser = FALSE;
         if ($this->_values['custom_pre_id']) {
             $profileID = $this->_values['custom_pre_id'];
             $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
         }
         if (!$createCMSUser && $this->_values['custom_post_id']) {
             if (!is_array($this->_values['custom_post_id'])) {
                 $profileIDs = array($this->_values['custom_post_id']);
             } else {
                 $profileIDs = $this->_values['custom_post_id'];
             }
             foreach ($profileIDs as $pid) {
                 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
                     $profileID = $pid;
                     $createCMSUser = TRUE;
                     break;
                 }
             }
         }
         if ($createCMSUser) {
             CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         }
     }
     //we have to load confirm contribution button in template
     //when multiple payment processor as the user
     //can toggle with payment processor selection
     $billingModePaymentProcessors = 0;
     if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $values) {
             if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
                 $billingModePaymentProcessors++;
             }
         }
     }
     if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
         $allAreBillingModeProcessors = TRUE;
     } else {
         $allAreBillingModeProcessors = FALSE;
     }
     if (!$allAreBillingModeProcessors || CRM_Utils_Array::value('is_pay_later', $this->_values['event']) || $bypassPayment) {
         //freeze button to avoid multiple calls.
         $js = NULL;
         if (!CRM_Utils_Array::value('is_monetary', $this->_values['event'])) {
             $js = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
         }
         $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => $js)));
     }
     $this->addFormRule(array('CRM_Event_Form_Registration_Register', 'formRule'), $this);
     // add pcp fields
     if ($this->_pcpId) {
         CRM_PCP_BAO_PCP::buildPcp($this->_pcpId, $this);
     }
 }
Beispiel #8
0
 /**
  * Handle Payment Processor switching for contribution and event registration forms.
  *
  * This function is shared between contribution & event forms & this is their common class.
  *
  * However, this should be seen as an in-progress refactor, the end goal being to also align the
  * backoffice forms that action payments.
  *
  * This function overlaps assignPaymentProcessor, in a bad way.
  */
 protected function preProcessPaymentOptions()
 {
     $this->_paymentProcessorID = NULL;
     if ($this->_paymentProcessors) {
         if (!empty($this->_submitValues)) {
             $this->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $this->_submitValues);
             $this->_paymentProcessor = CRM_Utils_Array::value($this->_paymentProcessorID, $this->_paymentProcessors);
             $this->set('type', $this->_paymentProcessorID);
             $this->set('mode', $this->_mode);
             $this->set('paymentProcessor', $this->_paymentProcessor);
         } else {
             foreach ($this->_paymentProcessors as $values) {
                 if (!empty($values['is_default']) || count($this->_paymentProcessors) == 1) {
                     $this->_paymentProcessorID = $values['id'];
                     break;
                 }
             }
         }
         if ($this->_paymentProcessorID || isset($this->_submitValues['payment_processor_id']) && $this->_submitValues['payment_processor_id'] == 0) {
             CRM_Core_Payment_ProcessorForm::preProcess($this);
         } else {
             $this->_paymentProcessor = array();
         }
         CRM_Financial_Form_Payment::addCreditCardJs();
     }
     $this->assign('paymentProcessorID', $this->_paymentProcessorID);
     // We save the fact that the profile 'billing' is required on the payment form.
     // Currently pay-later is the only 'processor' that takes notice of this - but ideally
     // 1) it would be possible to select the minimum_billing_profile_id for the contribution form
     // 2) that profile_id would be set on the payment processor
     // 3) the payment processor would return a billing form that combines these user-configured
     // minimums with the payment processor minimums. This would lead to fields like 'postal_code'
     // only being on the form if either the admin has configured it as wanted or the processor
     // requires it.
     $this->assign('billing_profile_id', CRM_Utils_Array::value('is_billing_required', $this->_values) ? 'billing' : '');
 }
Beispiel #9
0
 /**
  * Handle Payment Processor switching
  * For contribution and event registration forms
  */
 static function preProcessPaymentOptions(&$form, $noFees = FALSE)
 {
     $form->_snippet = CRM_Utils_Array::value('snippet', $_GET);
     $form->assign('snippet', $form->_snippet);
     $form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
     $form->_ppType = NULL;
     if ($form->_paymentProcessors) {
         // Fetch type during ajax request
         if (isset($_GET['type']) && $form->_snippet) {
             $form->_ppType = $_GET['type'];
         } elseif (!empty($form->_submitValues)) {
             $form->_ppType = CRM_Utils_Array::value('payment_processor', $form->_submitValues);
             $form->_paymentProcessor = CRM_Utils_Array::value($form->_ppType, $form->_paymentProcessors);
             $form->set('type', $form->_ppType);
             $form->set('mode', $form->_mode);
             $form->set('paymentProcessor', $form->_paymentProcessor);
         } else {
             foreach ($form->_paymentProcessors as $values) {
                 if (!empty($values['is_default']) || count($form->_paymentProcessors) == 1) {
                     $form->_ppType = $values['id'];
                     break;
                 }
             }
         }
         if ($form->_ppType) {
             CRM_Core_Payment_ProcessorForm::preProcess($form);
         }
         //get payPal express id and make it available to template
         foreach ($form->_paymentProcessors as $ppId => $values) {
             $payPalExpressId = $values['payment_processor_type'] == 'PayPal_Express' ? $values['id'] : 0;
             $form->assign('payPalExpressId', $payPalExpressId);
             if ($payPalExpressId) {
                 break;
             }
         }
         if (!$form->_snippet) {
             // Add JS to show icons for the accepted credit cards
             $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames();
             CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
         }
     }
     $form->assign('ppType', $form->_ppType);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_ppType) {
         return CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
     }
     $config = CRM_Core_Config::singleton();
     if (CRM_Utils_Array::value('is_for_organization', $this->_values) == 2) {
         $this->assign('onBehalfRequired', TRUE);
         $this->_onBehalfRequired = 1;
     }
     if ($this->_onbehalf) {
         $this->assign('onbehalf', TRUE);
         return CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60), TRUE);
     $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
     $this->_paymentProcessors = $this->get('paymentProcessors');
     $pps = array();
     if (!empty($this->_paymentProcessors)) {
         $pps = $this->_paymentProcessors;
         foreach ($pps as $key => &$name) {
             $pps[$key] = $name['name'];
         }
     }
     if (CRM_Utils_Array::value('is_pay_later', $this->_values)) {
         $pps[0] = $this->_values['pay_later_text'];
     }
     if (count($pps) > 1) {
         $this->addRadio('payment_processor', ts('Payment Method'), $pps, NULL, "&nbsp;", TRUE);
     } elseif (!empty($pps)) {
         $key = array_pop(array_keys($pps));
         $this->addElement('hidden', 'payment_processor', $key);
         if ($key === 0) {
             $this->assign('is_pay_later', $this->_values['is_pay_later']);
             $this->assign('pay_later_text', $this->_values['pay_later_text']);
         }
     }
     //build pledge block.
     $this->_useForMember = 0;
     //don't build membership block when pledge_id is passed
     if (!CRM_Utils_Array::value('pledge_id', $this->_values)) {
         $this->_separateMembershipPayment = FALSE;
         if (in_array('CiviMember', $config->enableComponents)) {
             $isTest = 0;
             if ($this->_action & CRM_Core_Action::PREVIEW) {
                 $isTest = 1;
             }
             if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) {
                 $this->_useForMember = 1;
                 $this->set('useForMember', $this->_useForMember);
             }
             $this->_separateMembershipPayment = CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, TRUE, NULL, FALSE, $isTest, $this->_membershipContactID);
         }
         $this->set('separateMembershipPayment', $this->_separateMembershipPayment);
     }
     $this->assign('useForMember', $this->_useForMember);
     // If we configured price set for contribution page
     // we are not allow membership signup as well as any
     // other contribution amount field, CRM-5095
     if (isset($this->_priceSetId) && $this->_priceSetId) {
         $this->add('hidden', 'priceSetId', $this->_priceSetId);
         // build price set form.
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_Set::buildPriceSet($this);
         if ($this->_values['is_monetary'] && $this->_values['is_recur'] && !CRM_Utils_Array::value('pledge_id', $this->_values)) {
             self::buildRecur($this);
         }
     } elseif (CRM_Utils_Array::value('amount_block_is_active', $this->_values) && !CRM_Utils_Array::value('pledge_id', $this->_values)) {
         $this->buildAmount($this->_separateMembershipPayment);
     }
     if ($this->_priceSetId) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $this->_useForMember = 0;
             $this->set('useForMember', $this->_useForMember);
         }
     }
     if ($this->_values['is_for_organization']) {
         $this->buildOnBehalfOrganization();
     }
     //we allow premium for pledge during pledge creation only.
     if (!CRM_Utils_Array::value('pledge_id', $this->_values)) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE);
     }
     if ($this->_values['honor_block_is_active']) {
         $this->buildHonorBlock();
     }
     //don't build pledge block when mid is passed
     if (!$this->_mid) {
         $config = CRM_Core_Config::singleton();
         if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('pledge_block_id', $this->_values)) {
             CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
     $this->buildCustom($this->_values['custom_post_id'], 'customPost');
     if (!empty($this->_fields)) {
         $profileAddressFields = array();
         foreach ($this->_fields as $key => $value) {
             CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields);
         }
         $this->set('profileAddressFields', $profileAddressFields);
     }
     //to create an cms user
     if (!$this->_userID) {
         $createCMSUser = FALSE;
         if ($this->_values['custom_pre_id']) {
             $profileID = $this->_values['custom_pre_id'];
             $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
         }
         if (!$createCMSUser && $this->_values['custom_post_id']) {
             if (!is_array($this->_values['custom_post_id'])) {
                 $profileIDs = array($this->_values['custom_post_id']);
             } else {
                 $profileIDs = $this->_values['custom_post_id'];
             }
             foreach ($profileIDs as $pid) {
                 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
                     $profileID = $pid;
                     $createCMSUser = TRUE;
                     break;
                 }
             }
         }
         if ($createCMSUser) {
             CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         }
     }
     if ($this->_pcpId) {
         if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) {
             $this->assign('pcpSupporterText', ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter)));
         }
         $this->assign('pcp', TRUE);
         $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );"));
         $extraOption = array('onclick' => "return pcpAnonymous( );");
         $elements = array();
         $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
         $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
         $this->addGroup($elements, 'pcp_is_anonymous', NULL, '&nbsp;&nbsp;&nbsp;');
         $this->_defaults['pcp_is_anonymous'] = 0;
         $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
         $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
     }
     //we have to load confirm contribution button in template
     //when multiple payment processor as the user
     //can toggle with payment processor selection
     $billingModePaymentProcessors = 0;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $values) {
             if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
                 $billingModePaymentProcessors++;
             }
         }
     }
     if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
         $allAreBillingModeProcessors = TRUE;
     } else {
         $allAreBillingModeProcessors = FALSE;
     }
     if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) {
         $this->addButtons(array(array('type' => 'upload', 'name' => ts('Confirm Contribution'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE)));
     }
     $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
 }