From f6de5cca5c6c104d5c9eb11813251f93c069b169 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 7 Aug 2015 23:13:07 +0530 Subject: [PATCH 1/2] 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 8b390fab83b6..a30e26e3e287 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -264,11 +264,13 @@ public static function processConfirm( $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 8035b33f94f1..47de852da3b9 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 df84e8382ee2..934a6dedd222 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 311bd5c57f70..3ba22ea54139 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}
From 599e7e41573aed88002de79933bbb10b57081505 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Mon, 10 Aug 2015 16:01:22 +0530 Subject: [PATCH 2/2] Webtests and improvisations --- .../CRM/Contribute/Form/Contribution/Main.tpl | 17 +- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 4 + .../Member/OnlineMembershipCreateTest.php | 153 ++++++++++-------- 3 files changed, 101 insertions(+), 73 deletions(-) diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 934a6dedd222..219189c3e22b 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -480,19 +480,22 @@ function skipPaymentMethod() { var flag = false; + // If price-set is used then calculate the Total Amount if (cj('#pricevalue').length !== 0) { - currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); - flag = (currentTotal == 0) ? true : false; + currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); + flag = (currentTotal == 0) ? true : false; } + // Else quick-config w/o other-amount scenarios 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 ) { + cj('.price-set-option-content input').each( function() { + currentTotal = cj(this).is('[data-amount]') ? cj(this).attr('data-amount').replace(/[^\/\d]/g,'') : 0; + 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 ) { + cj('.price-set-option-content input, .other_amount-content input').change( function () { + currentTotal = cj(this).is('[data-amount]') ? cj(this).attr('data-amount').replace(/[^\/\d]/g,'') : (cj(this).val() ? cj(this).val() : 0); + if (currentTotal == 0 ) { flag = true; } else { flag = false; diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index dd6366b6f602..832843f3c522 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -852,6 +852,9 @@ public function webtestAddPaymentProcessor($processorName = 'Test Processor', $p elseif ($processorType == 'AuthNet') { // FIXME: we 'll need to make a new separate account for testing $processorSettings = array( + //dummy live username/password are passed to bypass processor validation on live credential + 'user_name' => '3HcY62mY', + 'password' => '69943NrwaQA92b8J', 'test_user_name' => '5ULu56ex', 'test_password' => '7ARxW575w736eF5p', ); @@ -875,6 +878,7 @@ public function webtestAddPaymentProcessor($processorName = 'Test Processor', $p } elseif ($processorType == 'PayPal_Standard') { $processorSettings = array( + 'user_name' => 'V18ki@9r5Bf.org', 'test_user_name' => 'V18ki@9r5Bf.org', ); } diff --git a/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php b/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php index 0641939c38d3..eda26ef03095 100644 --- a/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php +++ b/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php @@ -207,7 +207,7 @@ public function testOnlineMembershipCreate() { * @param $hash * @param bool $otherAmount */ - public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE) { + public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE) { //Open Live Contribution Page $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); // Select membership type 1 @@ -242,24 +242,30 @@ public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $la $this->type("postal_code-1", "94117"); $this->select("country-1", "value=1228"); $this->select("state_province-1", "value=1001"); - if (!$payLater && $amountSection) { - //Credit Card Info - $this->select("credit_card_type", "value=Visa"); - $this->type("credit_card_number", "4111111111111111"); - $this->type("cvv2", "000"); - $this->select("credit_card_exp_date[M]", "value=1"); - $this->select("credit_card_exp_date[Y]", "value=2020"); - - //Billing Info - $this->waitForElementPresent("billing_first_name"); - $this->type("billing_first_name", $firstName . "billing"); - $this->waitForElementPresent("billing_last_name"); - $this->type("billing_last_name", $lastName . "billing"); - $this->type("billing_street_address-5", "15 Main St."); - $this->type(" billing_city-5", "San Jose"); - $this->select("billing_country_id-5", "value=1228"); - $this->select("billing_state_province_id-5", "value=1004"); - $this->type("billing_postal_code-5", "94129"); + + if ($freeMembership) { + $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']"); + } + else { + if (!$payLater && $amountSection) { + //Credit Card Info + $this->select("credit_card_type", "value=Visa"); + $this->type("credit_card_number", "4111111111111111"); + $this->type("cvv2", "000"); + $this->select("credit_card_exp_date[M]", "value=1"); + $this->select("credit_card_exp_date[Y]", "value=2020"); + + //Billing Info + $this->waitForElementPresent("billing_first_name"); + $this->type("billing_first_name", $firstName . "billing"); + $this->waitForElementPresent("billing_last_name"); + $this->type("billing_last_name", $lastName . "billing"); + $this->type("billing_street_address-5", "15 Main St."); + $this->type(" billing_city-5", "San Jose"); + $this->select("billing_country_id-5", "value=1228"); + $this->select("billing_state_province_id-5", "value=1004"); + $this->type("billing_postal_code-5", "94129"); + } } $this->click("_qf_Main_upload-bottom"); $this->waitForElementPresent("_qf_Confirm_next-bottom"); @@ -409,59 +415,74 @@ public function testOnlineMembershipCreateWithZeroContribution() { $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom'); $text = "'MembershipBlock' information has been saved."; $this->waitForText('crm-notification-container', $text); - $this->click('link=Amounts'); - $this->waitForElementPresent('_qf_Amount_cancel-bottom'); - $this->click('is_monetary'); - $this->clickLink('_qf_Amount_upload_done-bottom'); - $text = "'Amount' information has been saved."; - $this->waitForText('crm-notification-container', $text); - - $firstName = 'Ma' . substr(sha1(rand()), 0, 4); - $lastName = 'An' . substr(sha1(rand()), 0, 7); - - //logout - $this->webtestLogout(); - - $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection); - // Log in using webtestLogin() method - $this->webtestLogin(); - - //Find Contribution - $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); - $this->type("sort_name", "$lastName $firstName"); - $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); - $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); - - //View Contribution Record and verify data - $expected = array( - 'From' => "{$firstName} {$lastName}", - 'Financial Type' => 'Member Dues', - 'Total Amount' => '0.00', - 'Contribution Status' => 'Completed', - 'Received Into' => 'Deposit Bank Account', - 'Source' => "Online Contribution: $contributionTitle", - 'Online Contribution Page' => $contributionTitle, + $processors = array( + 'Test Processor', + 'AuthNet', + 'PayPal', + 'PayPal_Standard', ); - $this->webtestVerifyTabularData($expected); + foreach ($processors as $processor) { + if ($processor == 'Test Processor') { + $processorName = $processor; + } + else { + $processorName = $processor . substr(sha1(rand()), 0, 7); + $this->webtestAddPaymentProcessor($processorName, $processor); + } + $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom'); + $this->assertTrue($this->isTextPresent($processorName)); + $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]"); + $this->clickLink('_qf_Amount_upload_done-bottom'); + $this->waitForText('crm-notification-container', "'Amount' information has been saved."); + + $firstName = 'Ma' . substr(sha1(rand()), 0, 4); + $lastName = 'An' . substr(sha1(rand()), 0, 7); + + //logout + $this->webtestLogout(); + + $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE); + + // Log in using webtestLogin() method + $this->webtestLogin(); + + //Find Contribution + $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); + $this->type("sort_name", "$lastName $firstName"); + $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); + $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); + + //View Contribution Record and verify data + $expected = array( + 'From' => "{$firstName} {$lastName}", + 'Financial Type' => 'Member Dues', + 'Total Amount' => '0.00', + 'Contribution Status' => 'Completed', + 'Received Into' => 'Payment Processor Account', + 'Source' => "Online Contribution: $contributionTitle", + 'Online Contribution Page' => $contributionTitle, + ); + $this->webtestVerifyTabularData($expected); - //Find Member - $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); + //Find Member + $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); - $this->type("sort_name", "$lastName $firstName"); - $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr"); - $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']"); - $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); + $this->type("sort_name", "$lastName $firstName"); + $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr"); + $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']"); + $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); - //View Membership Record - $verifyData = array( - 'Member' => $firstName . ' ' . $lastName, - 'Membership Type' => $memTypeTitle, - 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, - 'Status' => 'New', - ); + //View Membership Record + $verifyData = array( + 'Member' => $firstName . ' ' . $lastName, + 'Membership Type' => $memTypeTitle, + 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, + 'Status' => 'New', + ); - $this->webtestVerifyTabularData($verifyData); + $this->webtestVerifyTabularData($verifyData); + } } }