From 69525f70dfd04f35accd4923b8f231db1e56d6f7 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Fri, 17 Jan 2020 09:11:04 +0800 Subject: [PATCH] Onboarding: Mark payments task complete on updating payment gateways (https://github.com/woocommerce/woocommerce-admin/pull/3579) * Mark payments task complete on Stripe settings update * Check for Paypal completion * Update payments task to complete on setting Square tokens * Update Paypal settings to check ppec settings --- .../src/Features/OnboardingTasks.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php index d8af8ff10de..4742687f6ab 100644 --- a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php +++ b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php @@ -63,6 +63,83 @@ class OnboardingTasks { add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_homepage_notice_admin_script' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_tax_notice_admin_script' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_product_import_notice_admin_script' ) ); + + // Update payment cache on payment gateways update. + add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'check_stripe_completion' ), 10, 2 ); + add_action( 'add_option_woocommerce_stripe_settings', array( $this, 'check_stripe_completion' ), 10, 2 ); + add_action( 'update_option_woocommerce_ppec_paypal_settings', array( $this, 'check_paypal_completion' ), 10, 2 ); + add_action( 'add_option_woocommerce_ppec_paypal_settings', array( $this, 'check_paypal_completion' ), 10, 2 ); + add_action( 'add_option_wc_square_refresh_tokens', array( $this, 'check_square_completion' ), 10, 2 ); + } + + /** + * Check if Square payment settings are complete. + * + * @param string $option Option name. + * @param array $value Current value. + */ + public static function check_square_completion( $option, $value ) { + if ( empty( $value ) ) { + return; + } + + self::maybe_update_payments_cache(); + } + + + /** + * Check if Paypal payment settings are complete. + * + * @param mixed $old_value Old value. + * @param array $value Current value. + */ + public static function check_paypal_completion( $old_value, $value ) { + if ( + ! isset( $value['enabled'] ) || + 'yes' !== $value['enabled'] || + ! isset( $value['api_username'] ) || + empty( $value['api_username'] ) || + ! isset( $value['api_password'] ) || + empty( $value['api_password'] ) + ) { + return; + } + + self::maybe_update_payments_cache(); + } + + /** + * Check if Stripe payment settings are complete. + * + * @param mixed $old_value Old value. + * @param array $value Current value. + */ + public static function check_stripe_completion( $old_value, $value ) { + if ( + ! isset( $value['enabled'] ) || + 'yes' !== $value['enabled'] || + ! isset( $value['publishable_key'] ) || + empty( $value['publishable_key'] ) || + ! isset( $value['secret_key'] ) || + empty( $value['secret_key'] ) + ) { + return; + } + + self::maybe_update_payments_cache(); + } + + /** + * Update the payments cache to complete if not already. + */ + public static function maybe_update_payments_cache() { + $task_list_payments = get_option( 'woocommerce_task_list_payments', array() ); + if ( isset( $task_list_payments['completed'] ) && $task_list_payments['completed'] ) { + return; + } + + $task_list_payments['completed'] = 1; + update_option( 'woocommerce_task_list_payments', $task_list_payments ); } /**