$this->add('text', 'total_amount', ts('Total Amount'), ['readonly' => TRUE], FALSE);
}
$pps = $this->getProcessors();
- $optAttributes = [];
- foreach ($pps as $ppKey => $ppval) {
- if ($ppKey > 0) {
- $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
- }
- else {
- $optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
- }
- }
- if (count($pps) > 1) {
- $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
- NULL, " ", FALSE, $optAttributes
- );
- }
- elseif (!empty($pps)) {
- $key = array_keys($pps);
- $key = array_pop($key);
- $this->addElement('hidden', 'payment_processor_id', $key);
- if ($key === 0) {
+ $this->addPaymentProcessorFieldsToForm();
+ if (!empty($pps) && count($pps) === 1) {
+ $ppKeys = array_keys($pps);
+ $currentPP = array_pop($ppKeys);
+ if ($currentPP === 0) {
$this->assign('is_pay_later', $this->_values['is_pay_later']);
$this->assign('pay_later_text', $this->getPayLaterLabel());
}
}
if ($this->_values['event']['is_monetary']) {
- $optAttributes = [];
- foreach ($pps as $ppKey => $ppval) {
- if ($ppKey > 0) {
- $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
- }
- else {
- $optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
- }
- }
- if (count($pps) > 1) {
- $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
- NULL, " ", FALSE, $optAttributes
- );
- }
- elseif (!empty($pps)) {
- $ppKeys = array_keys($pps);
- $currentPP = array_pop($ppKeys);
- $this->addElement('hidden', 'payment_processor_id', $currentPP);
- }
+ $this->addPaymentProcessorFieldsToForm();
}
$this->addElement('hidden', 'bypass_payment', NULL, ['id' => 'bypass_payment']);
return $pps;
}
+ /**
+ * Adds in either a set of radio buttons or hidden fields to contain the payment processors on a front end form
+ */
+ protected function addPaymentProcessorFieldsToForm() {
+ $paymentProcessors = $this->getProcessors();
+ $optAttributes = [];
+ foreach ($pamymentProcessors as $ppKey => $ppval) {
+ if ($ppKey > 0) {
+ $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
+ }
+ else {
+ $optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
+ }
+ }
+ if (count($paymentProcessors) > 1) {
+ $this->addRadio('payment_processor_id', ts('Payment Method'), $paymentProcessors,
+ NULL, " ", FALSE, $optAttributes
+ );
+ }
+ elseif (!empty($paymentProcessorss)) {
+ $ppKeys = array_keys($paymentProcessors);
+ $currentPP = array_pop($ppKeys);
+ $this->addElement('hidden', 'payment_processor_id', $currentPP);
+ }
+ }
+
}