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
This commit is contained in:
Joshua T Flowers 2020-01-17 09:11:04 +08:00 committed by GitHub
parent c3ae5ed53e
commit 69525f70df
1 changed files with 77 additions and 0 deletions

View File

@ -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 );
}
/**