From 707657f5c67d8ed9c04d7b071716ec4311bb1bcd Mon Sep 17 00:00:00 2001 From: Paul Ryley Date: Tue, 15 Sep 2015 13:24:28 +0700 Subject: [PATCH 1/4] Re: #249 Allow to modify the `give_require_billing_address` filtered value. --- includes/gateways/manual.php | 16 +++++++++--- includes/gateways/offline-donations.php | 33 +++++++++++++++++++++++-- includes/gateways/paypal-standard.php | 22 ++++++++++++++++- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/includes/gateways/manual.php b/includes/gateways/manual.php index dc256e910a..bc9d66b40e 100644 --- a/includes/gateways/manual.php +++ b/includes/gateways/manual.php @@ -18,17 +18,25 @@ add_action( 'give_manual_cc_form', '__return_false' ); /** - * Manual Gateway does not need a CC form validation, so remove it. + * Manual Gateway does not need CC billing address validation, so remove it. * * @since 1.0 + * + * @param bool $bool + * * @return void */ -add_filter( 'give_require_billing_address', 'give_manual_no_cc_validation' ); +function give_manual_do_billing_address_validation( $bool ) { -function give_manual_no_cc_validation() { - return false; + if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'manual' ) { + $bool = false; + } + + return $bool; } +add_filter( 'give_require_billing_address', 'give_manual_do_billing_address_validation' ); + /** * Processes the purchase data and uses the Manual Payment gateway to record * the transaction in the Purchase History diff --git a/includes/gateways/offline-donations.php b/includes/gateways/offline-donations.php index 862d7a1e4d..038f79baa6 100644 --- a/includes/gateways/offline-donations.php +++ b/includes/gateways/offline-donations.php @@ -6,7 +6,7 @@ * @subpackage Gateways * @copyright Copyright (c) 2015, WordImpress * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License - * @since 1.0 + * @since 1.1 */ @@ -46,6 +46,35 @@ function give_offline_disable_abandoned_orders() { add_action( 'plugins_loaded', 'give_offline_disable_abandoned_orders' ); +/** + * Require CC billing validation if offline billing info is enabled for the form. + * + * @since 1.1 + * + * @param bool $bool + * + * @return void + */ +function give_offline_do_billing_address_validation( $bool ) { + + if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'offline' ) { + + $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : false; + + $post_offline_cc_fields = $form_id ? get_post_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ) : false; + $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); + + if ( ! ( $global_offline_cc_fields == 'on' || $post_offline_cc_fields == 'on' ) ) { + $bool = false; + } + } + + return $bool; +} + +add_filter( 'give_require_billing_address', 'give_offline_do_billing_address_validation' ); + + /** * Add our payment instructions to the checkout * @@ -365,4 +394,4 @@ function give_get_default_offline_donation_email_content() { return apply_filters( 'give_default_offline_donation_content', $default_text ); -} \ No newline at end of file +} diff --git a/includes/gateways/paypal-standard.php b/includes/gateways/paypal-standard.php index ba75485eab..410adbe259 100644 --- a/includes/gateways/paypal-standard.php +++ b/includes/gateways/paypal-standard.php @@ -6,7 +6,7 @@ * @subpackage Gateways * @copyright Copyright (c) 2015, WordImpress * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License - * @since 1.0 + * @since 1.1 */ if ( ! defined( 'ABSPATH' ) ) { @@ -23,6 +23,26 @@ */ add_action( 'give_paypal_cc_form', '__return_false' ); +/** + * PayPal Standard Gateway does not need CC billing address validation, so remove it. + * + * @since 1.1 + * + * @param bool $bool + * + * @return void + */ +function give_paypal_do_billing_address_validation( $bool ) { + + if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'paypal' ) { + $bool = false; + } + + return $bool; +} + +add_filter( 'give_require_billing_address', 'give_paypal_do_billing_address_validation' ); + /** * Process PayPal Purchase * From 051d3a2abdae8a53551a64695da37bea2e89eed0 Mon Sep 17 00:00:00 2001 From: Paul Ryley Date: Tue, 15 Sep 2015 16:36:20 +0700 Subject: [PATCH 2/4] Remove flot plugin assertions The flot plugins are enqueued in `class-give-graph.php` and not via the `admin_enqueue_scripts` hook. --- tests/tests-scripts.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/tests-scripts.php b/tests/tests-scripts.php index 609d1a37ec..a9c39882f8 100644 --- a/tests/tests-scripts.php +++ b/tests/tests-scripts.php @@ -127,8 +127,6 @@ public function test_load_admin_scripts() { $this->assertTrue( wp_script_is( 'give-admin-scripts', 'enqueued' ) ); $this->assertTrue( wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ); $this->assertTrue( wp_script_is( 'jquery-flot', 'enqueued' ) ); - $this->assertTrue( wp_script_is( 'jquery-flot-orderbars', 'enqueued' ) ); - $this->assertTrue( wp_script_is( 'jquery-flot-time', 'enqueued' ) ); $this->assertTrue( wp_script_is( 'thickbox', 'enqueued' ) ); //Forms CPT Script From ed40ceb7e68a2bbd54809b8e2ed77762f03844f2 Mon Sep 17 00:00:00 2001 From: Paul Ryley Date: Wed, 16 Sep 2015 12:52:56 +0700 Subject: [PATCH 3/4] Fixes: #249 - Require billing address validation if $_POST contains the 'billing_country' field. - Verify that the offline form customization option is enabled when checking whether or not to show the billing fields. --- includes/gateways/manual.php | 20 --------------- includes/gateways/offline-donations.php | 34 ++----------------------- includes/gateways/paypal-standard.php | 22 +--------------- includes/process-purchase.php | 22 ++++++++++++++-- 4 files changed, 23 insertions(+), 75 deletions(-) diff --git a/includes/gateways/manual.php b/includes/gateways/manual.php index bc9d66b40e..8c44f2dfc2 100644 --- a/includes/gateways/manual.php +++ b/includes/gateways/manual.php @@ -17,26 +17,6 @@ */ add_action( 'give_manual_cc_form', '__return_false' ); -/** - * Manual Gateway does not need CC billing address validation, so remove it. - * - * @since 1.0 - * - * @param bool $bool - * - * @return void - */ -function give_manual_do_billing_address_validation( $bool ) { - - if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'manual' ) { - $bool = false; - } - - return $bool; -} - -add_filter( 'give_require_billing_address', 'give_manual_do_billing_address_validation' ); - /** * Processes the purchase data and uses the Manual Payment gateway to record * the transaction in the Purchase History diff --git a/includes/gateways/offline-donations.php b/includes/gateways/offline-donations.php index 038f79baa6..8dccd19fdd 100644 --- a/includes/gateways/offline-donations.php +++ b/includes/gateways/offline-donations.php @@ -6,10 +6,9 @@ * @subpackage Gateways * @copyright Copyright (c) 2015, WordImpress * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License - * @since 1.1 + * @since 1.0 */ - /** * Register the payment gateway * @@ -46,35 +45,6 @@ function give_offline_disable_abandoned_orders() { add_action( 'plugins_loaded', 'give_offline_disable_abandoned_orders' ); -/** - * Require CC billing validation if offline billing info is enabled for the form. - * - * @since 1.1 - * - * @param bool $bool - * - * @return void - */ -function give_offline_do_billing_address_validation( $bool ) { - - if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'offline' ) { - - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : false; - - $post_offline_cc_fields = $form_id ? get_post_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ) : false; - $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); - - if ( ! ( $global_offline_cc_fields == 'on' || $post_offline_cc_fields == 'on' ) ) { - $bool = false; - } - } - - return $bool; -} - -add_filter( 'give_require_billing_address', 'give_offline_do_billing_address_validation' ); - - /** * Add our payment instructions to the checkout * @@ -99,7 +69,7 @@ function give_offline_payment_cc_form( $form_id ) { $post_offline_cc_fields = get_post_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ); $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); - if ( $global_offline_cc_fields == 'on' || $post_offline_cc_fields == 'on' ) { + if ( $global_offline_cc_fields == 'on' || ( $post_offline_customization_option == 'yes' && $post_offline_cc_fields == 'on' ) ) { add_action( 'give_before_offline_info_fields', 'give_default_cc_address_fields' ); } diff --git a/includes/gateways/paypal-standard.php b/includes/gateways/paypal-standard.php index 410adbe259..ba75485eab 100644 --- a/includes/gateways/paypal-standard.php +++ b/includes/gateways/paypal-standard.php @@ -6,7 +6,7 @@ * @subpackage Gateways * @copyright Copyright (c) 2015, WordImpress * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License - * @since 1.1 + * @since 1.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -23,26 +23,6 @@ */ add_action( 'give_paypal_cc_form', '__return_false' ); -/** - * PayPal Standard Gateway does not need CC billing address validation, so remove it. - * - * @since 1.1 - * - * @param bool $bool - * - * @return void - */ -function give_paypal_do_billing_address_validation( $bool ) { - - if ( isset( $_POST['give-gateway'] ) && $_POST['give-gateway'] == 'paypal' ) { - $bool = false; - } - - return $bool; -} - -add_filter( 'give_require_billing_address', 'give_paypal_do_billing_address_validation' ); - /** * Process PayPal Purchase * diff --git a/includes/process-purchase.php b/includes/process-purchase.php index df56379d7b..4a8876f120 100644 --- a/includes/process-purchase.php +++ b/includes/process-purchase.php @@ -272,7 +272,7 @@ function give_purchase_form_required_fields() { ); // Let payment gateways and other extensions determine if address fields should be required - $require_address = apply_filters( 'give_require_billing_address', true ); + $require_address = give_require_billing_address(); if ( $require_address ) { $required_fields['card_zip'] = array( @@ -297,6 +297,24 @@ function give_purchase_form_required_fields() { } +/** + * Check if the Billing Address is required + * + * @param int $form_id + * + * @return bool + */ +function give_require_billing_address() { + + $return = false; + + if ( isset( $_POST['billing_country'] ) ) { + $return = true; + } + + return apply_filters( 'give_require_billing_address', $return ); +} + /** * Purchase Form Validate Logged In User * @@ -993,4 +1011,4 @@ function give_check_purchase_email( $valid_data, $posted ) { } } -add_action( 'give_checkout_error_checks', 'give_check_purchase_email', 10, 2 ); \ No newline at end of file +add_action( 'give_checkout_error_checks', 'give_check_purchase_email', 10, 2 ); From 2a7dc098b1e6c0070e19267fa7936f68b0460a45 Mon Sep 17 00:00:00 2001 From: Paul Ryley Date: Wed, 16 Sep 2015 12:55:43 +0700 Subject: [PATCH 4/4] bump file version --- includes/process-purchase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/process-purchase.php b/includes/process-purchase.php index 4a8876f120..829f9befcd 100644 --- a/includes/process-purchase.php +++ b/includes/process-purchase.php @@ -6,7 +6,7 @@ * @subpackage Functions * @copyright Copyright (c) 2015, WordImpress * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License - * @since 1.0 + * @since 1.0.1 */ // Exit if accessed directly @@ -300,8 +300,7 @@ function give_purchase_form_required_fields() { /** * Check if the Billing Address is required * - * @param int $form_id - * + * @since 1.0.1 * @return bool */ function give_require_billing_address() {