From d64d7ee30d6dbb4568dd6dcd68ea8983959d9e86 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Oct 2023 22:57:33 +0530 Subject: [PATCH] Fix: display legacy payment gateway with v2 donation forms (#6995) --- .../settings/class-settings-gateways.php | 211 ++++++++++-------- 1 file changed, 118 insertions(+), 93 deletions(-) diff --git a/includes/admin/settings/class-settings-gateways.php b/includes/admin/settings/class-settings-gateways.php index 8da2aa0217..c8b23161de 100644 --- a/includes/admin/settings/class-settings-gateways.php +++ b/includes/admin/settings/class-settings-gateways.php @@ -1,4 +1,5 @@ id = 'gateways'; - $this->label = esc_html__( 'Payment Gateways', 'give' ); + /** + * Give_Settings_Gateways. + * + * @sine 1.8 + */ + class Give_Settings_Gateways extends Give_Settings_Page + { + /** + * Constructor. + */ + public function __construct() + { + $this->id = 'gateways'; + $this->label = esc_html__('Payment Gateways', 'give'); - $this->default_tab = 'gateways-settings'; + $this->default_tab = 'gateways-settings'; - parent::__construct(); + parent::__construct(); - // Do not use main form for this tab. - if ( give_get_current_setting_tab() === $this->id ) { + // Do not use main form for this tab. + if (give_get_current_setting_tab() === $this->id) { add_action('give_admin_field_gateway_notice', [$this, 'render_gateway_notice'], 10, 2); add_action('give_admin_field_enabled_gateways', [$this, 'render_enabled_gateways'], 10, 2); } - } - - /** - * Get settings array. - * - * @since 1.8 - * @return array - */ - public function get_settings() { - $settings = []; - $current_section = give_get_current_setting_section(); - - switch ( $current_section ) { - case 'offline-donations': - $settings = [ - // Section 3: Offline gateway. - [ - 'type' => 'title', - 'id' => 'give_title_gateway_settings_3', - ], - [ - 'name' => __( 'Collect Billing Details', 'give' ), - 'desc' => __( 'If enabled, required billing address fields are added to Offline Donation forms. These fields are not required to process the transaction, but you may have a need to collect the data. Billing address details are added to both the donation and donor record in GiveWP. ', 'give' ), - 'id' => 'give_offline_donation_enable_billing_fields', - 'type' => 'radio_inline', - 'default' => 'disabled', - 'options' => [ - 'enabled' => __( 'Enabled', 'give' ), - 'disabled' => __( 'Disabled', 'give' ), - ], - ], - [ - 'name' => __( 'Offline Donation Instructions', 'give' ), - 'desc' => __( 'The Offline Donation Instructions are a chance for you to educate the donor on how to best submit offline donations. These instructions appear directly on the form, and after submission of the form. Note: You may also customize the instructions on individual forms as needed.', 'give' ), - 'id' => 'global_offline_donation_content', - 'default' => give_get_default_offline_donation_content(), - 'type' => 'wysiwyg', - 'options' => [ - 'textarea_rows' => 6, - ], - ], - [ - 'name' => esc_html__( 'Offline Donations Settings Docs Link', 'give' ), - 'id' => 'offline_gateway_settings_docs_link', - 'url' => esc_url( 'http://docs.givewp.com/offlinegateway' ), - 'title' => __( 'Offline Gateway Settings', 'give' ), - 'type' => 'give_docs_link', - ], - [ - 'type' => 'sectionend', - 'id' => 'give_title_gateway_settings_3', - ], - ]; - break; - - case 'gateways-settings': - $settings = [ + } + + /** + * Get settings array. + * + * @since 1.8 + * @return array + */ + public function get_settings() + { + $settings = []; + $current_section = give_get_current_setting_section(); + + switch ($current_section) { + case 'offline-donations': + $settings = [ + // Section 3: Offline gateway. + [ + 'type' => 'title', + 'id' => 'give_title_gateway_settings_3', + ], + [ + 'name' => __('Collect Billing Details', 'give'), + 'desc' => __('If enabled, required billing address fields are added to Offline Donation forms. These fields are not required to process the transaction, but you may have a need to collect the data. Billing address details are added to both the donation and donor record in GiveWP. ', 'give'), + 'id' => 'give_offline_donation_enable_billing_fields', + 'type' => 'radio_inline', + 'default' => 'disabled', + 'options' => [ + 'enabled' => __('Enabled', 'give'), + 'disabled' => __('Disabled', 'give'), + ], + ], + [ + 'name' => __('Offline Donation Instructions', 'give'), + 'desc' => __('The Offline Donation Instructions are a chance for you to educate the donor on how to best submit offline donations. These instructions appear directly on the form, and after submission of the form. Note: You may also customize the instructions on individual forms as needed.', 'give'), + 'id' => 'global_offline_donation_content', + 'default' => give_get_default_offline_donation_content(), + 'type' => 'wysiwyg', + 'options' => [ + 'textarea_rows' => 6, + ], + ], + [ + 'name' => esc_html__('Offline Donations Settings Docs Link', 'give'), + 'id' => 'offline_gateway_settings_docs_link', + 'url' => esc_url('http://docs.givewp.com/offlinegateway'), + 'title' => __('Offline Gateway Settings', 'give'), + 'type' => 'give_docs_link', + ], + [ + 'type' => 'sectionend', + 'id' => 'give_title_gateway_settings_3', + ], + ]; + break; + + case 'gateways-settings': + $settings = [ // Section 1: Gateways. [ 'id' => 'give_title_gateway_settings_1', @@ -263,7 +266,7 @@ private function canAcceptCreditCard() */ public function render_gateway_notice($field, $settings) { - if ( ! $this->hasPremiumPaymentGateway() && ! $this->canAcceptCreditCard()) { + if (! $this->hasPremiumPaymentGateway() && ! $this->canAcceptCreditCard()) { ?>
@@ -323,18 +326,18 @@ public function render_gateway_notice($field, $settings)
gateways->hasPaymentGateway($key); + }, + ARRAY_FILTER_USE_BOTH + ); + + // v2 gateways are gateways that are registered with updated gateway registration API. + // These payment gateways support donation processing with v2 donation forms. + // Legacy payment gateways will display with v2 gateways. $v2Gateways = give_get_ordered_payment_gateways( - array_intersect_key($gateways, give()->gateways->getPaymentGateways(2)), - 2 + array_merge( + $legacyGateways, + array_intersect_key( + $gateways, + give()->gateways->getPaymentGateways(2) + ) + ) ); + + // v3 gateways are gateways that are registered with updated gateway registration API. + // These payment gateways support donation processing with v3 donation forms. $v3Gateways = give_get_ordered_payment_gateways( array_intersect_key($gateways, give()->gateways->getPaymentGateways(3)), 3 @@ -595,10 +620,10 @@ class="give-payment-gateway-settings-dialog__close"
- - @@ -610,7 +635,7 @@ class="give-payment-gateway-settings-dialog__content-link">