From: Eileen McNaughton Date: Wed, 27 May 2015 22:26:56 +0000 (+1200) Subject: CRM-16555 call extracted form snippet not overloaded form snippet. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e02d7e961a53ad1d854c897ca7d31a2860bd5b77;p=civicrm-core.git CRM-16555 call extracted form snippet not overloaded form snippet. The payment form snippet has been extracted so it can be called from anywhere, use this & remove the over-loaded snippet note the change of field name is to align front end & back-end but still an issue as back-end is select & front end is radio CRM-16555 last may have been too agressive CRM-16555 test fixes x --- diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 2231fecd5b..487ee06759 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -767,6 +767,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP if ($this->_online) { $element->freeze(); } + $totalAmount = NULL; if (empty($this->_lineItems)) { $buildPriceSet = FALSE; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index a74688cc2c..bab7659e91 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -730,7 +730,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr public function postProcess() { $contactID = $this->getContactID(); $isPayLater = $this->_params['is_pay_later']; - if (isset($this->_params['payment_processor']) && $this->_params['payment_processor'] == 0) { + if (isset($this->_params['payment_processor_id']) && $this->_params['payment_processor_id'] == 0) { $this->_params['is_pay_later'] = $isPayLater = TRUE; } // add a description field at the very beginning @@ -2046,8 +2046,10 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $form->_values['fee'] = $priceSetFields['fields']; $form->_priceSetId = $priceSetID; $form->setFormAmountFields($priceSetID); - if (!empty($params['payment_processor'])) { - $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor'])); + if (!empty($params['payment_processor_id'])) { + $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array( + 'id' => $params['payment_processor_id'], + )); if ($form->_paymentProcessor['billing_mode'] == 1) { $form->_contributeMode = 'direct'; } @@ -2056,7 +2058,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } else { - $form->_params['payment_processor'] = 0; + $form->_params['payment_processor_id'] = 0; } $priceFields = $priceFields[$priceSetID]['fields']; CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution'); @@ -2077,7 +2079,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr */ public static function getFormParams($id, array $params) { if (!isset($params['is_pay_later'])) { - if (!empty($params['payment_processor'])) { + if (!empty($params['payment_processor_id'])) { $params['is_pay_later'] = 0; } else { diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index b5951826d3..52dc3f6adc 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -347,7 +347,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $pid => $value) { if (!empty($value['is_default'])) { - $this->_defaults['payment_processor'] = $pid; + $this->_defaults['payment_processor_id'] = $pid; } } } @@ -375,7 +375,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu // Build payment processor form if (empty($_GET['onbehalf'])) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); - // Return if we are in an ajax callback + // Return if we are in an ajax - this is probably redundant now as + // processor does not call this form for a snippet anymore - but unsure about + // cdType if ($this->_snippet) { return; } @@ -420,14 +422,14 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } if (count($pps) > 1) { - $this->addRadio('payment_processor', ts('Payment Method'), $pps, + $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " ", TRUE ); } elseif (!empty($pps)) { $key = array_keys($pps); $key = array_pop($key); - $this->addElement('hidden', 'payment_processor', $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']); @@ -961,7 +963,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } if (!empty($fields['is_recur']) && - CRM_Utils_Array::value('payment_processor', $fields) == 0 + CRM_Utils_Array::value('payment_processor_id', $fields) == 0 ) { $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.'); } @@ -1049,7 +1051,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } // also return if paylater mode - if (CRM_Utils_Array::value('payment_processor', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater == 0) { + if (CRM_Utils_Array::value('payment_processor_id', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater == 0) { return empty($errors) ? TRUE : $errors; } @@ -1063,7 +1065,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if (!empty($self->_paymentFields)) { CRM_Core_Form::validateMandatoryFields($self->_paymentFields, $fields, $errors); } - CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor'], $fields, $errors, $self); + CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, $self); foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) { @@ -1179,7 +1181,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if (($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params)) || - (!empty($params['payment_processor']) && $params['payment_processor'] == 0) + (!empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0) ) { $params['is_pay_later'] = 1; } @@ -1386,13 +1388,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $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); - } - // Remember type during form post - elseif (!empty($form->_submitValues)) { - $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor', $form->_submitValues); + 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); diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 33fc16c1de..b1533d351e 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -199,7 +199,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $pid => $value) { if (!empty($value['is_default'])) { - $this->_defaults['payment_processor'] = $pid; + $this->_defaults['payment_processor_id'] = $pid; } } } @@ -442,14 +442,14 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { if ($this->_values['event']['is_monetary']) { if (count($pps) > 1) { - $this->addRadio('payment_processor', ts('Payment Method'), $pps, + $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " " ); } elseif (!empty($pps)) { $ppKeys = array_keys($pps); $currentPP = array_pop($ppKeys); - $this->addElement('hidden', 'payment_processor', $currentPP); + $this->addElement('hidden', 'payment_processor_id', $currentPP); } } @@ -894,8 +894,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } if ($self->_values['event']['is_monetary']) { - if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset($fields['payment_processor'])) { - $errors['payment_processor'] = ts('Please select a Payment Method'); + if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset + ($fields['payment_processor_id'])) { + $errors['payment_processor_id'] = ts('Please select a Payment Method'); } // return if this is express mode if ($self->_paymentProcessor && @@ -992,7 +993,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $params['is_primary'] = 1; if ($this->_values['event']['is_pay_later'] - && (!array_key_exists('hidden_processor', $params) || $params['payment_processor'] == 0) + && (!array_key_exists('hidden_processor', $params) || $params['payment_processor_id'] == 0) ) { $params['is_pay_later'] = 1; } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index e90b8354bc..5729787547 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -80,7 +80,7 @@ {$form.contact_id.html} {/if} {if $contributionMode} - {$form.payment_processor_id.label} * {$form.payment_processor_id.html} + {$form.payment_processor_id.label} * {$form.payment_processor_id.html} {/if} {$form.financial_type_id.label}{$form.financial_type_id.html}  @@ -214,6 +214,7 @@ +
{* Billing Pane is the only billing pane currently *} {foreach from=$billingPanes key=paneName item=paneValue} @@ -227,6 +228,8 @@
{/foreach}
+ + {include file="CRM/common/paymentBlock.tpl"}
diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index df84e8382e..c86835de9a 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -27,36 +27,6 @@ {if $snippet and !empty($isOnBehalfCallback)} {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end"} -{* Callback snippet: Load payment processor *} -{elseif $snippet} -{include file="CRM/Core/BillingBlock.tpl"} - {if $is_monetary} - {* Put PayPal Express button after customPost block since it's the submit button in this case. *} - {if $paymentProcessor.payment_processor_type EQ 'PayPal_Express'} -
- {assign var=expressButtonName value='_qf_Main_upload_express'} -
- {ts}Checkout with PayPal{/ts} -
-
-
- {ts}Click the PayPal button to continue.{/ts} -
-
-
-
-
- {$form.$expressButtonName.html} Checkout securely. Pay without sharing your financial information. -
-
-
-
-
-
- {/if} - {/if} - -{* Main Form *} {else} {literal} {/literal} diff --git a/templates/CRM/common/paymentBlock.tpl b/templates/CRM/common/paymentBlock.tpl index e3c883f319..4131f829a2 100644 --- a/templates/CRM/common/paymentBlock.tpl +++ b/templates/CRM/common/paymentBlock.tpl @@ -36,7 +36,7 @@ function buildPaymentBlock(type) { } {/literal}{/if}{literal} - var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type; + var dataUrl = {/literal}"{crmURL p='civicrm/payment/form' h=0 q='snippet=4&processor_id='}"{literal} + type; {/literal} {if $urlPathVar} @@ -47,9 +47,6 @@ function buildPaymentBlock(type) { dataUrl = dataUrl + '&id=' + '{$contributionPageID}' {/if} - {if $qfKey} - dataUrl = dataUrl + '&qfKey=' + '{$qfKey}' - {/if} {literal} var response = cj.ajax({ @@ -63,7 +60,7 @@ function buildPaymentBlock(type) { CRM.$(function($) { $('.crm-group.payment_options-group').show(); - $('input[name="payment_processor"]').change( function() { + $('#payment_processor_id').change( function() { buildPaymentBlock( $(this).val() ); }); }); diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 2051df4ee9..a2157cb7a4 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -236,7 +236,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruff', 'selectMembership' => $this->_ids['membership_type'], - 'payment_processor' => 1, + 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), @@ -279,7 +279,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Gruff', 'email' => 'billy@goat.gruff', 'selectMembership' => $this->_ids['membership_type'], - 'payment_processor' => 1, + 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), @@ -341,7 +341,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'billing_last_name' => 'Gruff', 'email' => 'billy@goat.gruff', 'selectMembership' => $this->_ids['membership_type'], - 'payment_processor' => 1, + 'payment_processor_id' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),