diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 1a9573dd7326..0e1868a3ca9c 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -655,4 +655,36 @@ protected function getDefaultPaymentInstrumentId() { return key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } + /** + * Add the payment processor select to the form. + * + * @param bool $isRequired + * Is it a mandatory field. + * @param bool $isBuildRecurBlock + * True if we want to build recur on change + * @param bool $isBuildAutoRenewBlock + * True if we want to build autorenew on change. + */ + protected function addPaymentProcessorSelect($isRequired, $isBuildRecurBlock = FALSE, $isBuildAutoRenewBlock = FALSE) { + if (!$this->_mode) { + return; + } + $js = ($isBuildRecurBlock ? array('onChange' => "buildRecurBlock( this.value ); return false;") : NULL); + if ($isBuildAutoRenewBlock) { + $js = array('onChange' => "buildAutoRenew( null, this.value, '{$this->_mode}');"); + } + $element = $this->add('select', + 'payment_processor_id', + ts('Payment Processor'), + array_diff_key($this->_processors, array(0 => 1)), + $isRequired, + $js + ); + // The concept of _online is not really explained & the code is old + // @todo figure out & document. + if ($this->_online) { + $element->freeze(); + } + } + } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index eb9f61383909..5b56bd0c1aa0 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -472,7 +472,7 @@ public function buildQuickForm() { } } $allPanes = array(); - $recurJs = NULL; + //tax rate from financialType $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates())); $this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled'))); @@ -483,6 +483,8 @@ public function buildQuickForm() { $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $this->assign('invoicing', $invoicing); + $buildRecurBlock = FALSE; + // display tax amount on edit contribution page if ($invoicing && $this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) { $this->assign('totalTaxAmount', $this->_values['tax_amount']); @@ -568,10 +570,10 @@ public function buildQuickForm() { CRM_Contribute_Form_Contribution_Main::buildRecur($this); $this->setDefaults(array('is_recur' => 0)); $this->assign('buildRecurBlock', TRUE); - $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;"); } } } + $this->addPaymentProcessorSelect(FALSE, $buildRecurBlock); foreach ($paneNames as $name => $type) { $allPanes[$name] = $this->generatePane($type, $defaults); @@ -650,10 +652,8 @@ public function buildQuickForm() { $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); - $isUpdate = FALSE; $component = 'contribution'; if ($this->_id) { - $isUpdate = TRUE; $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id); if (CRM_Utils_Array::value('membership', $componentDetails)) { $component = 'membership'; @@ -708,18 +708,6 @@ public function buildQuickForm() { $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime')); $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']); - $this->add('text', 'refund_trxn_id', ts('Transaction ID for the refund payment')); - $element = $this->add('select', - 'payment_processor_id', - ts('Payment Processor'), - $this->_processors, - NULL, - $recurJs - ); - - if ($this->_online) { - $element->freeze(); - } $totalAmount = NULL; if (empty($this->_lineItems)) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index dd0244e4db21..f220463b4433 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -645,8 +645,8 @@ public function buildQuickForm() { if ($this->_mode) { // exclude events which are not monetary when credit card registration is used $eventFieldParams['api']['params']['is_monetary'] = 1; - $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } + $this->addPaymentProcessorSelect(TRUE, FALSE, FALSE); $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE); diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index d6f526fef95e..29f91b26abe7 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -176,13 +176,7 @@ public function setDefaultValues() { */ public function buildQuickForm() { - if ($this->_mode) { - $this->add('select', 'payment_processor_id', - ts('Payment Processor'), - $this->_processors, TRUE, - array('onChange' => "buildAutoRenew( null, this.value, '{$this->_mode}');") - ); - } + $this->addPaymentProcessorSelect(TRUE, FALSE, TRUE); CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, $this->getDefaultPaymentInstrumentId()); // Build the form for auto renew. This is displayed when in credit card mode or update mode. // The reason for showing it in update mode is not that clear. diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 4b0e2941755e..8d7d73fd9852 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -239,7 +239,7 @@ {ts}Date that a receipt was sent to the contributor.{/ts} - {if $contributionMode} + {if $form.payment_processor_id} {$form.payment_processor_id.label} * {$form.payment_processor_id.html} {/if}