From 7c8cc4610c3299711dcf08add25c216359573ed6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 30 Mar 2013 16:49:56 -0700 Subject: [PATCH] Load payment form without ajax --- CRM/Contribute/Form/Contribution/Main.php | 38 +++++++++++++++---- .../CRM/Contribute/Form/Contribution/Main.tpl | 13 +++++-- templates/CRM/common/paymentBlock.tpl | 12 ------ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 49267838f3..8436c828ec 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -57,6 +57,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu public $_useForMember; protected $_ppType; + protected $_snippet; /** * Function to set variables up before form is built @@ -67,16 +68,34 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu public function preProcess() { parent::preProcess(); - $this->_ppType = CRM_Utils_Array::value('type', $_GET); - $this->assign('ppType', FALSE); - if ($this->_ppType) { - $this->assign('ppType', TRUE); - return CRM_Core_Payment_ProcessorForm::preProcess($this); - } + $this->_snippet = CRM_Utils_Array::value('snippet', $_GET); + $this->assign('snippet', $this->_snippet); - //get payPal express id and make it available to template $paymentProcessors = $this->get('paymentProcessors'); + $this->assign('ppType', FALSE); + $this->_ppType = NULL; if (!empty($paymentProcessors)) { + // Fetch type during ajax request + if (isset($_GET['type']) && $this->_snippet) { + $this->_ppType = $_GET['type']; + } + // Set default payment processor + else { + foreach ($paymentProcessors as $values) { + if (!empty($values['is_default']) || count($paymentProcessors) == 1) { + $this->_ppType = $values['id']; + } + } + } + if ($this->_ppType) { + $this->assign('ppType', TRUE); + CRM_Core_Payment_ProcessorForm::preProcess($this); + if ($this->_snippet) { + return; + } + } + + //get payPal express id and make it available to template foreach ($paymentProcessors as $ppId => $values) { $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; $this->assign('payPalExpressId', $payPalExpressId); @@ -387,7 +406,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu */ public function buildQuickForm() { if ($this->_ppType) { - return CRM_Core_Payment_ProcessorForm::buildQuickForm($this); + CRM_Core_Payment_ProcessorForm::buildQuickForm($this); + if ($this->_snippet) { + return; + } } $config = CRM_Core_Config::singleton(); diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 7c560f0d53..52586d6409 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -23,7 +23,8 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $ppType} +{* Callback snippet: Load payment processor *} +{if $ppType and $snippet} {include file="CRM/Core/BillingBlock.tpl" context="front-end"} {if $is_monetary} {* Put PayPal Express button after customPost block since it's the submit button in this case. *} @@ -51,7 +52,8 @@ {/if} {/if} -{elseif $onbehalf} +{* Callback snippet: Load on-behalf profile *} +{elseif $onbehalf and $snippet} {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl} {else} {literal} @@ -294,7 +296,12 @@ {/if} -
+
+ {* If we have a payment processor, load it - otherwise it happens via ajax *} + {if $ppType} + {include file="CRM/Contribute/Form/Contribution/Main.tpl" snippet=4} + {/if} +
{include file="CRM/common/paymentBlock.tpl"}
diff --git a/templates/CRM/common/paymentBlock.tpl b/templates/CRM/common/paymentBlock.tpl index f1792d3450..a11a7f551e 100644 --- a/templates/CRM/common/paymentBlock.tpl +++ b/templates/CRM/common/paymentBlock.tpl @@ -60,18 +60,6 @@ function buildPaymentBlock( type ) { } cj( function() { - var processorTypeObj = cj('input[name="payment_processor"]'); - - if ( processorTypeObj.attr('type') == 'hidden' ) { - var processorTypeValue = processorTypeObj.val( ); - } else { - var processorTypeValue = processorTypeObj.filter(':checked').val(); - } - - if ( processorTypeValue ) { - buildPaymentBlock( processorTypeValue ); - } - cj('input[name="payment_processor"]').change( function() { buildPaymentBlock( cj(this).val() ); }); -- 2.25.1