diff --git a/includes/admin/class-wc-stripe-admin-notices.php b/includes/admin/class-wc-stripe-admin-notices.php index 525a4cadc7..7802add23b 100644 --- a/includes/admin/class-wc-stripe-admin-notices.php +++ b/includes/admin/class-wc-stripe-admin-notices.php @@ -98,10 +98,10 @@ public function admin_notices() { */ public static function display_legacy_deprecation_notice( $plugin_file ) { global $wp_list_table; - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); + $stripe_settings = WC_Stripe_Settings::get_instance(); // If Stripe is not enabled, don't show the legacy deprecation notice. - if ( ! isset( $stripe_settings['enabled'] ) || 'no' === $stripe_settings['enabled'] ) { + if ( ! $stripe_settings->get_enabled() || 'no' === $stripe_settings->get_enabled() ) { return; } diff --git a/includes/class-wc-stripe-api.php b/includes/class-wc-stripe-api.php index 3f4fd67ab1..05b8d16206 100644 --- a/includes/class-wc-stripe-api.php +++ b/includes/class-wc-stripe-api.php @@ -78,15 +78,13 @@ public static function get_secret_key() { * @param string|null $mode Optional. The mode to set the secret key for. 'live' or 'test'. Default will set the secret for the currently active mode. */ public static function set_secret_key_for_mode( $mode = null ) { - $options = WC_Stripe_Helper::get_stripe_settings(); - $secret_key = $options['secret_key'] ?? ''; - $test_secret_key = $options['test_secret_key'] ?? ''; + $stripe_settings = WC_Stripe_Settings::get_instance(); if ( ! in_array( $mode, [ 'test', 'live' ], true ) ) { $mode = WC_Stripe_Mode::is_test() ? 'test' : 'live'; } - self::set_secret_key( 'test' === $mode ? $test_secret_key : $secret_key ); + self::set_secret_key( 'test' === $mode ? $stripe_settings->get_test_secret_key() : $stripe_settings->get_secret_key() ); } /** diff --git a/includes/class-wc-stripe-helper.php b/includes/class-wc-stripe-helper.php index f3cf3b77d6..d506da520f 100644 --- a/includes/class-wc-stripe-helper.php +++ b/includes/class-wc-stripe-helper.php @@ -12,6 +12,11 @@ * @since 4.0.0 */ class WC_Stripe_Helper { + /** + * Option name for storing Stripe settings. + * + * @deprecated 9.6.0 Use WC_Stripe_Settings::SETTINGS_OPTION instead. + */ const SETTINGS_OPTION = 'woocommerce_stripe_settings'; const LEGACY_META_NAME_FEE = 'Stripe Fee'; const LEGACY_META_NAME_NET = 'Net Revenue From Stripe'; @@ -32,6 +37,8 @@ class WC_Stripe_Helper { * * @param string $method (Optional) The payment method to get the settings from. * @return array $settings The Stripe settings. + * + * @deprecated 9.6.0 Use WC_Stripe_Settings specific getters instead. */ public static function get_stripe_settings( $method = null ) { $settings = null === $method ? get_option( self::SETTINGS_OPTION, [] ) : get_option( 'woocommerce_stripe_' . $method . '_settings', [] ); diff --git a/includes/class-wc-stripe-logger.php b/includes/class-wc-stripe-logger.php index ba47fb064f..09e849aa91 100644 --- a/includes/class-wc-stripe-logger.php +++ b/includes/class-wc-stripe-logger.php @@ -98,9 +98,7 @@ public static function can_log(): bool { return false; } - $settings = WC_Stripe_Helper::get_stripe_settings(); - - if ( empty( $settings ) || ( isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) ) { + if ( 'yes' !== WC_Stripe_Settings::get_instance()->get_logging() ) { return false; } diff --git a/includes/class-wc-stripe-mode.php b/includes/class-wc-stripe-mode.php index c9d826b292..2ce6a10fcc 100644 --- a/includes/class-wc-stripe-mode.php +++ b/includes/class-wc-stripe-mode.php @@ -13,8 +13,7 @@ class WC_Stripe_Mode { * @return bool Whether the plugin is in live mode. */ public static function is_live() { - $settings = WC_Stripe_Helper::get_stripe_settings(); - return 'yes' !== ( $settings['testmode'] ?? 'no' ); + return 'yes' !== ( WC_Stripe_Settings::get_instance()->get_test_mode() ?? 'no' ); } /** @@ -23,7 +22,6 @@ public static function is_live() { * @return bool Whether the plugin is in test mode. */ public static function is_test() { - $settings = WC_Stripe_Helper::get_stripe_settings(); - return 'yes' === ( $settings['testmode'] ?? 'no' ); + return 'yes' === ( WC_Stripe_Settings::get_instance()->get_test_mode() ?? 'no' ); } } diff --git a/includes/class-wc-stripe-payment-method-configurations.php b/includes/class-wc-stripe-payment-method-configurations.php index 5fd99aa465..6b257aa14a 100644 --- a/includes/class-wc-stripe-payment-method-configurations.php +++ b/includes/class-wc-stripe-payment-method-configurations.php @@ -181,10 +181,7 @@ public static function get_upe_available_payment_method_ids() { public static function get_upe_enabled_payment_method_ids( $force_refresh = false ) { // If the payment method configurations API is not enabled, we fallback to the enabled payment methods stored in the DB. if ( ! self::is_enabled() ) { - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); - return isset( $stripe_settings['upe_checkout_experience_accepted_payments'] ) && ! empty( $stripe_settings['upe_checkout_experience_accepted_payments'] ) - ? $stripe_settings['upe_checkout_experience_accepted_payments'] - : [ WC_Stripe_Payment_Methods::CARD ]; + return WC_Stripe_Settings::get_instance()->get_upe_checkout_experience_accepted_payments(); } // Migrate payment methods from DB to Stripe PMC if needed @@ -303,17 +300,17 @@ function ( $id ) use ( $is_test_mode ) { * @return bool */ public static function is_enabled() { - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); - $connection_type_key = WC_Stripe_Mode::is_test() ? 'test_connection_type' : 'connection_type'; + $stripe_settings = WC_Stripe_Settings::get_instance(); + $connection_type = WC_Stripe_Mode::is_test() ? $stripe_settings->get_test_connection_type() : $stripe_settings->get_connection_type(); // If the account is not a Connect OAuth account, we can't use the payment method configurations API. - if ( ! isset( $stripe_settings[ $connection_type_key ] ) || 'connect' !== $stripe_settings[ $connection_type_key ] ) { + if ( 'connect' !== $connection_type ) { return false; } // If we have the pmc_enabled flag, and it is set to no, we should not use the payment method configurations API. // We only disable the PMC if the flag is set to no explicitly, an empty value means the migration has not been attempted yet. - if ( isset( $stripe_settings['pmc_enabled'] ) && 'no' === $stripe_settings['pmc_enabled'] ) { + if ( 'no' === $stripe_settings->get_pmc_enabled() ) { return false; } @@ -326,7 +323,7 @@ public static function is_enabled() { * @param bool $force_migration Whether to force the migration. */ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migration = false ) { - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); + $stripe_settings = WC_Stripe_Settings::get_instance(); // Skip if PMC is not enabled. if ( ! self::is_enabled() ) { @@ -334,7 +331,7 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr } // Skip if migration already done (pmc_enabled is set) and we are not forcing the migration. - if ( ! empty( $stripe_settings['pmc_enabled'] ) && ! $force_migration ) { + if ( $stripe_settings->get_pmc_enabled() && ! $force_migration ) { return; } @@ -344,18 +341,10 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr return; } - $enabled_payment_methods = []; - - if ( isset( $stripe_settings['upe_checkout_experience_accepted_payments'] ) && - ! empty( $stripe_settings['upe_checkout_experience_accepted_payments'] ) ) { - $enabled_payment_methods = array_merge( - $enabled_payment_methods, - $stripe_settings['upe_checkout_experience_accepted_payments'] - ); - } + $enabled_payment_methods = $stripe_settings->get_upe_checkout_experience_accepted_payments(); // Add Google Pay and Apple Pay to the list if payment_request is enabled - if ( ! empty( $stripe_settings['payment_request'] ) && 'yes' === $stripe_settings['payment_request'] ) { + if ( 'yes' === $stripe_settings->get_payment_request() ) { $enabled_payment_methods = array_merge( $enabled_payment_methods, [ WC_Stripe_Payment_Methods::GOOGLE_PAY, WC_Stripe_Payment_Methods::APPLE_PAY ] @@ -381,13 +370,12 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr } // If there is no payment method order defined, set it to the default order - if ( empty( $stripe_settings['stripe_upe_payment_method_order'] ) ) { - $stripe_settings['stripe_upe_payment_method_order'] = array_keys( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS ); + if ( empty( $stripe_settings->get_stripe_upe_payment_method_order() ) ) { + $stripe_settings->set_stripe_upe_payment_method_order( array_keys( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS ) ); } // Mark migration as complete in stripe settings - $stripe_settings['pmc_enabled'] = 'yes'; - WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); + $stripe_settings->set_pmc_enabled( 'yes' ); } /** @@ -395,8 +383,6 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr * This is called when no Payment Method Configuration is found that inherits from the WooCommerce Platform. */ private static function disable_payment_method_configuration_sync() { - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); - $stripe_settings['pmc_enabled'] = 'no'; - WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); + WC_Stripe_Settings::get_instance()->set_pmc_enabled( 'no' ); } } diff --git a/includes/class-wc-stripe-settings.php b/includes/class-wc-stripe-settings.php new file mode 100644 index 0000000000..6d7a441ead --- /dev/null +++ b/includes/class-wc-stripe-settings.php @@ -0,0 +1,308 @@ +settings = $settings; + } + + /** + * Returns the *Singleton* instance of this class. + * + * @return WC_Stripe_Settings The *Singleton* instance. + */ + public static function get_instance() { + if ( null === self::$instance ) { + self::$instance = new self(); + } + return self::$instance; + } + + /** + * Get the value of the `enabled` setting. + * + * @return string + */ + public function get_enabled() { + return $this->settings['enabled'] ?? ''; + } + + /** + * Get the value of the `logging` setting. + * + * @return string + */ + public function get_logging() { + return $this->settings['logging'] ?? ''; + } + + /** + * Get the publishable key. + * + * @return string + */ + public function get_publishable_key() { + return $this->settings['publishable_key'] ?? ''; + } + + /** + * Get the secret key. + * + * @return string + */ + public function get_secret_key() { + return $this->settings['secret_key'] ?? ''; + } + + /** + * Get the statement descriptor. + * + * @return string + */ + public function get_statement_descriptor() { + return $this->settings['statement_descriptor'] ?? ''; + } + + /** + * Get the test publishable key. + * + * @return string + */ + public function get_test_publishable_key() { + return $this->settings['test_publishable_key'] ?? ''; + } + + /** + * Get the test secret key. + * + * @return string + */ + public function get_test_secret_key() { + return $this->settings['test_secret_key'] ?? ''; + } + + /** + * Get the express checkout button type. + * + * @return string + */ + public function get_express_checkout_button_type() { + return $this->settings['payment_request_button_type'] ?? 'default'; + } + + /** + * Get the express checkout button theme. + * + * @return string + */ + public function get_express_checkout_button_theme() { + return $this->settings['payment_request_button_theme'] ?? 'dark'; + } + + /** + * Gets the button height. + * + * @return string + */ + public function get_express_checkout_button_height() { + $height = $this->settings['payment_request_button_size'] ?? 'default'; + if ( 'small' === $height ) { + return '40'; + } + + if ( 'large' === $height ) { + return '56'; + } + + return '48'; + } + + /** + * Gets the button radius. + * + * @return string + */ + public function get_express_checkout_button_radius() { + $height = $this->settings['payment_request_button_size'] ?? 'default'; + if ( 'small' === $height ) { + return '2'; + } + + if ( 'large' === $height ) { + return '6'; + } + + return '4'; + } + + /** + * Pages where the express checkout buttons should be displayed. + * + * @return array + */ + public function get_express_checkout_button_locations() { + // If the locations have not been set return the default setting. + if ( ! isset( $this->settings['payment_request_button_locations'] ) ) { + return [ 'product', 'cart' ]; + } + + // If all locations are removed through the settings UI the location config will be set to + // an empty string "". If that's the case (and if the settings are not an array for any + // other reason) we should return an empty array. + if ( ! is_array( $this->settings['payment_request_button_locations'] ) ) { + return []; + } + + return $this->settings['payment_request_button_locations']; + } + + /** + * Set the payment request button locations. + * + * @param array $value The value to set. + * @return void + */ + public function set_payment_request_button_locations( $value ) { + $this->settings['payment_request_button_locations'] = $value; + update_option( self::SETTINGS_OPTION, $this->settings ); + } + + /** + * Get the test mode setting. + * + * @return string + */ + public function get_test_mode() { + return $this->settings['test_mode'] ?? ''; + } + + /** + * Get the value of the `upe_checkout_experience_accepted_payments` setting. + * + * @return array + */ + public function get_upe_checkout_experience_accepted_payments() { + return ! empty( $this->settings['upe_checkout_experience_accepted_payments'] ) + ? $this->settings['upe_checkout_experience_accepted_payments'] + : [ WC_Stripe_Payment_Methods::CARD ]; + } + + /** + * Get the value of the `webhook_secret` setting. + * + * @return string + */ + public function get_webhook_secret() { + return $this->settings['webhook_secret'] ?? ''; + } + + /** + * Get the value of the `test_webhook_secret` setting. + * + * @return string + */ + public function get_test_webhook_secret() { + return $this->settings['test_webhook_secret'] ?? ''; + } + + /** + * Get the value of the `connection_type` setting. + * + * @return string + */ + public function get_connection_type() { + return $this->settings['connection_type'] ?? ''; + } + + /** + * Get the value of the `test_connection_type` setting. + * + * @return string + */ + public function get_test_connection_type() { + return $this->settings['test_connection_type'] ?? ''; + } + + /** + * Get the value of the `pmc_enabled` setting. + * + * @return string + */ + public function get_pmc_enabled() { + return $this->settings['pmc_enabled'] ?? ''; + } + + /** + * Set the `pmc_enabled` setting to true. + * + * @param string $value The value to set. + * @return void + */ + public function set_pmc_enabled( $value ) { + $this->settings['pmc_enabled'] = $value; + update_option( self::SETTINGS_OPTION, $this->settings ); + } + + /** + * Get the value of the `payment_request` setting. + * + * @return string + */ + public function get_payment_request() { + return $this->settings['payment_request'] ?? ''; + } + + /** + * Get the value of the `stripe_upe_payment_method_order` setting. + * + * @return array + */ + public function get_stripe_upe_payment_method_order() { + return $this->settings['stripe_upe_payment_method_order'] ?? []; + } + + /** + * Set the `stripe_upe_payment_method_order` setting. + * + * @param array $value The value to set. + * @return void + */ + public function set_stripe_upe_payment_method_order( $value ) { + $this->settings['stripe_upe_payment_method_order'] = $value; + update_option( self::SETTINGS_OPTION, $this->settings ); + } +} diff --git a/includes/class-wc-stripe-status.php b/includes/class-wc-stripe-status.php index f585aca4f7..a27124ce07 100644 --- a/includes/class-wc-stripe-status.php +++ b/includes/class-wc-stripe-status.php @@ -152,7 +152,7 @@ public function render_status_report_section() { get_button_locations(); + $express_checkout_enabled_locations = WC_Stripe_Settings::get_instance()->get_express_checkout_button_locations(); $express_checkout_enabled_locations = empty( $express_checkout_enabled_locations ) ? 'no locations enabled' : implode( ',', $express_checkout_enabled_locations ); echo esc_html__( 'Enabled', 'woocommerce-gateway-stripe' ) . ' (' . esc_html( $express_checkout_enabled_locations ) . ')'; ?> diff --git a/includes/class-wc-stripe-webhook-handler.php b/includes/class-wc-stripe-webhook-handler.php index 16b9e15cdf..4f19dbe085 100644 --- a/includes/class-wc-stripe-webhook-handler.php +++ b/includes/class-wc-stripe-webhook-handler.php @@ -57,10 +57,10 @@ class WC_Stripe_Webhook_Handler extends WC_Stripe_Payment_Gateway { */ public function __construct() { $this->retry_interval = 2; - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); + $stripe_settings = WC_Stripe_Settings::get_instance(); $this->testmode = WC_Stripe_Mode::is_test(); - $secret_key = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret'; - $this->secret = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false; + $secret = $this->testmode ? $stripe_settings->get_test_webhook_secret() : $stripe_settings->get_webhook_secret(); + $this->secret = $secret ?: false; $this->action_scheduler_service = new WC_Stripe_Action_Scheduler_Service(); diff --git a/includes/class-wc-stripe-webhook-state.php b/includes/class-wc-stripe-webhook-state.php index 3b06c8d3bb..f5c21d67db 100644 --- a/includes/class-wc-stripe-webhook-state.php +++ b/includes/class-wc-stripe-webhook-state.php @@ -42,8 +42,7 @@ class WC_Stripe_Webhook_State { public static function get_testmode() { wc_deprecated_function( __METHOD__, '8.9.0', 'WC_Stripe_Mode::is_test()' ); - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); - return ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; + return 'yes' === WC_Stripe_Settings::get_instance()->get_test_mode() ? true : false; } /** diff --git a/includes/class-wc-stripe.php b/includes/class-wc-stripe.php index 0a9174552f..c5a90ccfd0 100644 --- a/includes/class-wc-stripe.php +++ b/includes/class-wc-stripe.php @@ -119,6 +119,7 @@ public function init() { require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-feature-flags.php'; } + require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-settings.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-upe-compatibility.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-co-branded-cc-compatibility.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-exception.php'; @@ -356,10 +357,8 @@ public function install() { * @version 5.5.0 */ public function update_prb_location_settings() { - $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); - $prb_locations = isset( $stripe_settings['payment_request_button_locations'] ) - ? $stripe_settings['payment_request_button_locations'] - : []; + $stripe_settings = WC_Stripe_Settings::get_instance(); + $prb_locations = $stripe_settings->get_express_checkout_button_locations(); if ( ! empty( $stripe_settings ) && empty( $prb_locations ) ) { global $post; @@ -381,8 +380,7 @@ public function update_prb_location_settings() { $new_prb_locations[] = 'checkout'; } - $stripe_settings['payment_request_button_locations'] = $new_prb_locations; - WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); + $stripe_settings->set_payment_request_button_locations( $new_prb_locations ); } } diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-element.php b/includes/payment-methods/class-wc-stripe-express-checkout-element.php index e657f452f3..c0b6975b22 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-element.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-element.php @@ -20,7 +20,7 @@ class WC_Stripe_Express_Checkout_Element { /** * Stripe settings. * - * @var + * @var WC_Stripe_Settings */ public $stripe_settings; @@ -50,7 +50,7 @@ class WC_Stripe_Express_Checkout_Element { */ public function __construct( WC_Stripe_Express_Checkout_Ajax_Handler $express_checkout_ajax_handler, WC_Stripe_Express_Checkout_Helper $express_checkout_helper ) { self::$_this = $this; - $this->stripe_settings = WC_Stripe_Helper::get_stripe_settings(); + $this->stripe_settings = WC_Stripe_Settings::get_instance(); $this->express_checkout_helper = $express_checkout_helper; $this->express_checkout_ajax_handler = $express_checkout_ajax_handler; @@ -74,7 +74,7 @@ public function init() { } // Checks if Stripe Gateway is enabled. - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { + if ( empty( $this->stripe_settings ) || ( 'yes' !== $this->stripe_settings->get_enabled() ) ) { return; } @@ -185,7 +185,7 @@ public function javascript_params() { return [ 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), 'stripe' => [ - 'publishable_key' => WC_Stripe_Mode::is_test() ? $this->stripe_settings['test_publishable_key'] : $this->stripe_settings['publishable_key'], + 'publishable_key' => WC_Stripe_Mode::is_test() ? $this->stripe_settings->get_test_publishable_key() : $this->stripe_settings->get_publishable_key(), 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', 'locale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ), 'is_link_enabled' => $this->express_checkout_helper->is_link_enabled(), @@ -499,7 +499,7 @@ public function display_express_checkout_button_separator_html() { return; } - if ( is_checkout() && ! in_array( 'checkout', $this->express_checkout_helper->get_button_locations(), true ) ) { + if ( is_checkout() && ! in_array( 'checkout', $this->stripe_settings->get_express_checkout_button_locations(), true ) ) { return; } diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php index b0eabc7e3d..15540b7c2d 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php @@ -44,9 +44,9 @@ class WC_Stripe_Express_Checkout_Helper { */ public function __construct() { $this->gateway = WC_Stripe::get_instance()->get_main_stripe_gateway(); - $this->stripe_settings = WC_Stripe_Helper::get_stripe_settings(); + $this->stripe_settings = WC_Stripe_Settings::get_instance(); $this->testmode = WC_Stripe_Mode::is_test(); - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; + $this->total_label = $this->stripe_settings->get_statement_descriptor() ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings->get_statement_descriptor() ) : ''; $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); } @@ -103,18 +103,22 @@ public function is_account_creation_possible() { * Gets the button type. * * @return string + * + * @deprecated 9.6.0 Use WC_Stripe_Settings::get_express_checkout_button_type() instead. */ public function get_button_type() { - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; + return $this->stripe_settings->get_express_checkout_button_type(); } /** * Gets the button theme. * * @return string + * + * @deprecated 9.6.0 Use WC_Stripe_Settings::get_express_checkout_button_theme() instead. */ public function get_button_theme() { - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; + return $this->stripe_settings->get_express_checkout_button_theme(); } /** @@ -123,34 +127,18 @@ public function get_button_theme() { * @return string */ public function get_button_height() { - $height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default'; - if ( 'small' === $height ) { - return '40'; - } - - if ( 'large' === $height ) { - return '56'; - } - - return '48'; + return $this->stripe_settings->get_express_checkout_button_height(); } /** * Gets the button radius. * * @return string + * + * @deprecated 9.6.0 Use WC_Stripe_Settings::get_express_checkout_button_radius() instead. */ public function get_button_radius() { - $height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default'; - if ( 'small' === $height ) { - return '2'; - } - - if ( 'large' === $height ) { - return '6'; - } - - return '4'; + return $this->stripe_settings->get_express_checkout_button_radius(); } /** @@ -1300,12 +1288,12 @@ protected function calculate_shipping( $address = [] ) { * @return array */ public function get_button_settings() { - $button_type = $this->get_button_type(); + $button_type = $this->stripe_settings->get_express_checkout_button_type(); return [ 'type' => $button_type, - 'theme' => $this->get_button_theme(), - 'height' => $this->get_button_height(), - 'radius' => $this->get_button_radius(), + 'theme' => $this->stripe_settings->get_express_checkout_button_theme(), + 'height' => $this->stripe_settings->get_express_checkout_button_height(), + 'radius' => $this->stripe_settings->get_express_checkout_button_radius(), // Default format is en_US. 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), ]; @@ -1480,21 +1468,11 @@ public function get_login_confirmation_settings() { * Pages where the express checkout buttons should be displayed. * * @return array + * + * @deprecated 9.6.0 Use `WC_Stripe_Settings::get_express_checkout_button_locations()` instead. */ public function get_button_locations() { - // If the locations have not been set return the default setting. - if ( ! isset( $this->stripe_settings['payment_request_button_locations'] ) ) { - return [ 'product', 'cart' ]; - } - - // If all locations are removed through the settings UI the location config will be set to - // an empty string "". If that's the case (and if the settings are not an array for any - // other reason) we should return an empty array. - if ( ! is_array( $this->stripe_settings['payment_request_button_locations'] ) ) { - return []; - } - - return $this->stripe_settings['payment_request_button_locations']; + return $this->stripe_settings->get_express_checkout_button_locations(); } /** diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 9a52909df7..03cea9cba5 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -177,7 +177,7 @@ public function __construct() { $enabled_payment_methods = $this->get_upe_enabled_payment_method_ids(); $is_sofort_enabled = in_array( WC_Stripe_Payment_Methods::SOFORT, $enabled_payment_methods, true ); - $main_settings = WC_Stripe_Helper::get_stripe_settings(); + $stripe_settings = WC_Stripe_Settings::get_instance(); $this->oc_enabled = WC_Stripe_Feature_Flags::is_oc_available() && 'yes' === $this->get_option( 'optimized_checkout_element' ); $this->payment_methods = []; @@ -244,9 +244,9 @@ public function __construct() { $this->sepa_tokens_for_other_methods = 'yes' === $this->get_option( 'sepa_tokens_for_other_methods' ); $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); $this->testmode = WC_Stripe_Mode::is_test(); - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; + $this->publishable_key = $stripe_settings->get_publishable_key(); + $this->secret_key = $stripe_settings->get_secret_key(); + $this->statement_descriptor = $stripe_settings->get_statement_descriptor(); // When feature flags are enabled, title shows the count of enabled payment methods in settings page only. if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() && WC_Stripe_Feature_Flags::is_upe_preview_enabled() && isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] ) { @@ -258,8 +258,8 @@ public function __construct() { } if ( $this->testmode ) { - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; + $this->publishable_key = $stripe_settings->get_test_publishable_key(); + $this->secret_key = $stripe_settings->get_test_secret_key(); } add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] ); diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index ee330a3ea8..d41ec2e6c2 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -148,9 +148,7 @@ abstract class WC_Stripe_UPE_Payment_Method extends WC_Payment_Gateway { * Create instance of payment method */ public function __construct() { - $main_settings = WC_Stripe_Helper::get_stripe_settings(); - $is_stripe_enabled = ! empty( $main_settings['enabled'] ) && 'yes' === $main_settings['enabled']; - + $is_stripe_enabled = 'yes' === WC_Stripe_Settings::get_instance()->get_enabled(); $this->enabled = $is_stripe_enabled && in_array( static::STRIPE_ID, $this->get_upe_enabled_payment_method_ids(), true ) ? 'yes' : 'no'; // @phpstan-ignore-line (STRIPE_ID is defined in classes using this class) $this->id = WC_Gateway_Stripe::ID . '_' . static::STRIPE_ID; // @phpstan-ignore-line (STRIPE_ID is defined in classes using this class) $this->has_fields = true;