Onboarding: Mark payments task complete when payment configured (https://github.com/woocommerce/woocommerce-admin/pull/3576)
* Mark payments task complete when payment configured * Only mark complete when all payments configured * Only mark payments complete if all payments configured
This commit is contained in:
parent
d22774aa66
commit
761a67f18b
|
@ -92,13 +92,7 @@ class Payments extends Component {
|
|||
}
|
||||
|
||||
completeTask() {
|
||||
const { createNotice, updateOptions } = this.props;
|
||||
|
||||
updateOptions( {
|
||||
[ 'woocommerce_task_list_payments' ]: {
|
||||
completed: 1,
|
||||
},
|
||||
} );
|
||||
const { createNotice } = this.props;
|
||||
|
||||
createNotice(
|
||||
'success',
|
||||
|
@ -165,14 +159,16 @@ class Payments extends Component {
|
|||
markConfigured( method ) {
|
||||
const { options, methods, configured } = this.props;
|
||||
configured.push( method );
|
||||
const stepsLeft = difference( methods, configured );
|
||||
|
||||
this.props.updateOptions( {
|
||||
[ 'woocommerce_task_list_payments' ]: {
|
||||
...options.woocommerce_task_list_payments,
|
||||
configured,
|
||||
completed: 0 === stepsLeft.length ? 1 : 0,
|
||||
},
|
||||
} );
|
||||
|
||||
const stepsLeft = difference( methods, configured );
|
||||
if ( 0 === stepsLeft.length ) {
|
||||
this.completeTask();
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class OnboardingTasks {
|
|||
return;
|
||||
}
|
||||
|
||||
self::maybe_update_payments_cache();
|
||||
self::mark_payment_method_configured( 'square' );
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +105,7 @@ class OnboardingTasks {
|
|||
return;
|
||||
}
|
||||
|
||||
self::maybe_update_payments_cache();
|
||||
self::mark_payment_method_configured( 'paypal' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,19 +126,28 @@ class OnboardingTasks {
|
|||
return;
|
||||
}
|
||||
|
||||
self::maybe_update_payments_cache();
|
||||
self::mark_payment_method_configured( 'stripe' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the payments cache to complete if not already.
|
||||
*
|
||||
* @param string $payment_method Payment method slug.
|
||||
*/
|
||||
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;
|
||||
public static function mark_payment_method_configured( $payment_method ) {
|
||||
$task_list_payments = get_option( 'woocommerce_task_list_payments', array() );
|
||||
$payment_methods = isset( $task_list_payments['methods'] ) ? $task_list_payments['methods'] : array();
|
||||
$configured_payment_methods = isset( $task_list_payments['configured'] ) ? $task_list_payments['configured'] : array();
|
||||
|
||||
if ( ! in_array( $payment_method, $configured_payment_methods, true ) ) {
|
||||
$configured_payment_methods[] = $payment_method;
|
||||
$task_list_payments['configured'] = $configured_payment_methods;
|
||||
}
|
||||
|
||||
if ( 0 === count( array_diff( $payment_methods, $configured_payment_methods ) ) ) {
|
||||
$task_list_payments['completed'] = 1;
|
||||
}
|
||||
|
||||
$task_list_payments['completed'] = 1;
|
||||
update_option( 'woocommerce_task_list_payments', $task_list_payments );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue