From f6de5cca5c6c104d5c9eb11813251f93c069b169 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 7 Aug 2015 23:13:07 +0530 Subject: [PATCH] CRM-14536 fix - Free Membership still submits to payment processor https://issues.civicrm.org/jira/browse/CRM-14536 --- CRM/Contribute/BAO/Contribution/Utils.php | 12 +++-- .../Contribute/Form/Contribution/Confirm.tpl | 2 +- .../CRM/Contribute/Form/Contribution/Main.tpl | 48 +++++++++++-------- .../Contribute/Form/Contribution/ThankYou.tpl | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 8b390fab83..a30e26e3e2 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -264,11 +264,13 @@ class CRM_Contribute_BAO_Contribution_Utils { $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id; } } - if (is_object($payment)) { - $result = $payment->doDirectPayment($paymentParams); - } - else { - CRM_Core_Error::fatal($paymentObjError); + if ($form->_amount > 0.0) { + if (is_object($payment)) { + $result = $payment->doDirectPayment($paymentParams); + } + else { + CRM_Core_Error::fatal($paymentObjError); + } } } diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 8035b33f94..47de852da3 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -54,7 +54,7 @@ {include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="confirmContribution"} - {if $amount GT 0 OR $minimum_fee GT 0 OR ( $priceSetID and $lineItem ) } + {if $amount GTE 0 OR $minimum_fee GTE 0 OR ( $priceSetID and $lineItem ) }
{if !$useForMember}
diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index df84e8382e..934a6dedd2 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -418,7 +418,7 @@ {/if} {literal} - function toggleConfirmButton() { + function toggleConfirmButton(flag) { var payPalExpressId = "{/literal}{$payPalExpressId}{literal}"; var elementObj = cj('input[name="payment_processor"]'); if ( elementObj.attr('type') == 'hidden' ) { @@ -428,20 +428,24 @@ var processorTypeId = elementObj.filter(':checked').val(); } - if (payPalExpressId !=0 && payPalExpressId == processorTypeId) { + if (payPalExpressId !=0 && payPalExpressId == processorTypeId && flag === false) { cj("#crm-submit-buttons").hide(); + cj("#paypalExpress").show(); } else { cj("#crm-submit-buttons").show(); + if (flag === true) { + cj("#paypalExpress").hide(); + } } } cj('input[name="payment_processor"]').change( function() { - toggleConfirmButton(); + toggleConfirmButton(false); }); CRM.$(function($) { - toggleConfirmButton(); + toggleConfirmButton(false); enableHonorType(); showRecurHelp(); skipPaymentMethod(); @@ -466,8 +470,6 @@ payment_options.hide(); payment_processor.hide(); payment_information.hide(); - // also unset selected payment methods - cj('input[name="payment_processor"]').removeProp('checked'); } else { payment_options.show(); @@ -478,20 +480,28 @@ function skipPaymentMethod() { var flag = false; - cj('.price-set-option-content input').each( function(){ - currentTotal = cj(this).attr('data-amount').replace(/[^\/\d]/g,''); - if( cj(this).is(':checked') && currentTotal == 0 ) { + if (cj('#pricevalue').length !== 0) { + currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); + flag = (currentTotal == 0) ? true : false; + } + else { + cj('.price-set-option-content input').each( function(){ + currentTotal = cj(this).attr('data-amount').replace(/[^\/\d]/g,''); + if( cj(this).is(':checked') && currentTotal == 0 ) { flag = true; - } - }); - cj('.price-set-option-content input').change( function () { - if (cj(this).attr('data-amount').replace(/[^\/\d]/g,'') == 0 ) { - flag = true; - } else { - flag = false; - } - showHidePayment(flag); - }); + } + }); + cj('.price-set-option-content input').change( function () { + if (cj(this).attr('data-amount').replace(/[^\/\d]/g,'') == 0 ) { + flag = true; + } else { + flag = false; + } + toggleConfirmButton(flag); + showHidePayment(flag); + }); + } + toggleConfirmButton(flag); showHidePayment(flag); } diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index 311bd5c57f..3ba22ea541 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -90,7 +90,7 @@ {include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="thankContribution"} - {if $amount GT 0 OR $minimum_fee GT 0 OR ( $priceSetID and $lineItem ) } + {if $amount GTE 0 OR $minimum_fee GTE 0 OR ( $priceSetID and $lineItem ) }
{if !$useForMember}
-- 2.25.1