/** * 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); }
/** * Add the discount button immediately before the price set. * * @param CRM_Contribute_Form_Contribution_Main $form */ function _cividiscount_add_button_before_priceSet(&$form) { CRM_Core_Region::instance('price-set-1')->add(array('template' => 'CRM/CiviDiscount/discountButton.tpl', 'weight' => -1, 'type' => 'template', 'name' => 'discount_code')); $form->add('text', 'discountcode', ts('If you have a discount code, enter it here'), array('class' => 'description')); $errorMessage = $form->get('discountCodeErrorMsg'); if ($errorMessage) { $form->setElementError('discountcode', $errorMessage); } $form->set('discountCodeErrorMsg', null); $buttonName = $form->getButtonName('reload'); $form->addElement('submit', $buttonName, ts('Apply'), array('formnovalidate' => 1)); $form->assign('discountElements', array('discountcode', $buttonName)); }
/** * 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) { // Fetch type during ajax request if (isset($_GET['type']) && $form->_snippet) { $form->_paymentProcessorID = CRM_Utils_Request::retrieve('type', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, 0); } elseif (!empty($form->_submitValues)) { $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor', $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(); } //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('paymentProcessorID', $form->_paymentProcessorID); }