Skip to content

Commit e4e9f3c

Browse files
authored
Check for valid deadline when setting Update Business Details task (#5154)
* adds a check to the client to ensure we have a valid deadline and use a more generic message if not. * Update changelog * Fixes to the logic, and also fixed a bug discovered in the process. * Update to the logic for showing the task to use a transient * Update to make the account status data task check on every fetch of the account * Fixing accidental merge issue * Updating to use a bool rather than a string * Updating to use a bool rather than a string
1 parent 468fe02 commit e4e9f3c

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

changelog/4846-update-by-jan-1970

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: fix
3+
4+
Fix for an issue where a timestamp in the past could be displayed on the update business details task card.

client/overview/task-list/tasks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getTasks = ( {
2727

2828
const isDisputeTaskVisible = 0 < numDisputesNeedingResponse;
2929

30-
if ( accountRestrictedSoon ) {
30+
if ( accountRestrictedSoon && currentDeadline ) {
3131
accountDetailsTaskDescription = sprintf(
3232
/* translators: %s - formatted requirements current deadline (date) */
3333
__(
@@ -50,7 +50,7 @@ export const getTasks = ( {
5050

5151
return [
5252
isAccountOverviewTasksEnabled &&
53-
'yes' === showUpdateDetailsTask && {
53+
showUpdateDetailsTask && {
5454
key: 'update-business-details',
5555
level: 1,
5656
title: __(

client/overview/task-list/test/tasks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe( 'getTasks()', () => {
1414
pastDue: false,
1515
accountLink: 'http://example.com',
1616
},
17-
showUpdateDetailsTask: 'yes',
17+
showUpdateDetailsTask: true,
1818
isAccountOverviewTasksEnabled: true,
1919
} );
2020

@@ -36,7 +36,7 @@ describe( 'getTasks()', () => {
3636
pastDue: true,
3737
accountLink: 'http://example.com',
3838
},
39-
showUpdateDetailsTask: 'no',
39+
showUpdateDetailsTask: false,
4040
isAccountOverviewTasksEnabled: true,
4141
} );
4242

@@ -57,7 +57,7 @@ describe( 'getTasks()', () => {
5757
pastDue: false,
5858
accountLink: 'http://example.com',
5959
},
60-
showUpdateDetailsTask: 'yes',
60+
showUpdateDetailsTask: true,
6161
isAccountOverviewTasksEnabled: true,
6262
} );
6363

@@ -111,7 +111,7 @@ describe( 'getTasks()', () => {
111111
it( 'returns the expected keys when the account overview flag is enabled', () => {
112112
const tasks = getTasks( {
113113
isAccountOverviewTasksEnabled: true,
114-
showUpdateDetailsTask: 'yes',
114+
showUpdateDetailsTask: true,
115115
wpcomReconnectUrl: 'http://example.com',
116116
accountStatus: {},
117117
} );
@@ -126,7 +126,7 @@ describe( 'getTasks()', () => {
126126

127127
it( 'returns the expected keys when the account overview flag is disabled', () => {
128128
const tasks = getTasks( {
129-
showUpdateDetailsTask: 'yes',
129+
showUpdateDetailsTask: true,
130130
wpcomReconnectUrl: 'http://example.com',
131131
accountStatus: {},
132132
} );

includes/admin/class-wc-payments-admin.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ public function add_payments_menu_for_treatment() {
210210
);
211211

212212
$this->add_menu_notification_badge();
213-
$this->add_update_business_details_task();
214213
}
215214

216215
/**
@@ -419,7 +418,6 @@ public function add_payments_menu() {
419418
);
420419

421420
$this->add_menu_notification_badge();
422-
$this->add_update_business_details_task();
423421
$this->add_disputes_notification_badge();
424422
if ( \WC_Payments_Features::is_auth_and_capture_enabled() && $this->wcpay_gateway->get_option( 'manual_capture' ) === 'yes' ) {
425423
$this->add_transactions_notification_badge();
@@ -478,6 +476,8 @@ public function register_payments_scripts() {
478476
];
479477
}
480478

479+
$account_status_data = $this->account->get_account_status_data();
480+
481481
$wcpay_settings = [
482482
'connectUrl' => WC_Payments_Account::get_connect_url(),
483483
'connect' => [
@@ -496,11 +496,11 @@ public function register_payments_scripts() {
496496
'fraudServices' => $this->account->get_fraud_services_config(),
497497
'isJetpackConnected' => $this->payments_api_client->is_server_connected(),
498498
'isJetpackIdcActive' => Jetpack_Identity_Crisis::has_identity_crisis(),
499-
'accountStatus' => $this->account->get_account_status_data(),
499+
'accountStatus' => $account_status_data,
500500
'accountFees' => $this->account->get_fees(),
501501
'accountLoans' => $this->account->get_capital(),
502502
'accountEmail' => $this->account->get_account_email(),
503-
'showUpdateDetailsTask' => get_option( 'wcpay_show_update_business_details_task', 'no' ),
503+
'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
504504
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
505505
'additionalMethodsSetup' => [
506506
'isUpeEnabled' => WC_Payments_Features::is_upe_enabled(),
@@ -809,21 +809,24 @@ public function add_menu_notification_badge() {
809809
}
810810

811811
/**
812-
* Attempts to add a setup task to remind the user to update
813-
* their business details when the account is facing restriction.
812+
* Check whether a setup task needs to be displayed prompting the user to update
813+
* their business details.
814+
*
815+
* @param array $account_status_data An array containing the account status data.
816+
*
817+
* @return bool True if we should show the task, false otherwise.
814818
*/
815-
public function add_update_business_details_task() {
816-
if ( 'yes' === get_option( 'wcpay_show_update_business_details_task', 'no' ) ) {
817-
return;
819+
public function get_should_show_update_business_details_task( array $account_status_data ) {
820+
$status = $account_status_data['status'] ?? '';
821+
$current_deadline = $account_status_data['currentDeadline'] ?? false;
822+
$past_due = $account_status_data['pastDue'] ?? false;
823+
824+
// If the account is restricted_soon, but there's no current deadline, no action is needed.
825+
if ( ( 'restricted_soon' === $status && $current_deadline ) || ( 'restricted' === $status && $past_due ) ) {
826+
return true;
818827
}
819828

820-
$account = $this->account->get_account_status_data();
821-
$status = $account['status'] ?? '';
822-
$past_due = $account['has_overdue_requirements'] ?? false;
823-
824-
if ( 'restricted_soon' === $status || ( 'restricted' === $status && $past_due ) ) {
825-
update_option( 'wcpay_show_update_business_details_task', 'yes' );
826-
}
829+
return false;
827830
}
828831

829832
/**

includes/class-wc-payments-account.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public function get_account_status_data() {
194194
'paymentsEnabled' => $account['payments_enabled'],
195195
'deposits' => $account['deposits'] ?? [],
196196
'depositsStatus' => $account['deposits']['status'] ?? $account['deposits_status'] ?? '',
197-
'currentDeadline' => isset( $account['current_deadline'] ) ? $account['current_deadline'] : false,
198-
'pastDue' => isset( $account['has_overdue_requirements'] ) ? $account['has_overdue_requirements'] : false,
197+
'currentDeadline' => $account['current_deadline'] ?? false,
198+
'pastDue' => $account['has_overdue_requirements'] ?? false,
199199
'accountLink' => $this->get_login_url(),
200200
'hasSubmittedVatData' => $account['has_submitted_vat_data'] ?? false,
201201
];

0 commit comments

Comments
 (0)