class-wc-payments-task-disputes.php
3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Class WC_Payments_Task_Disputes
*
* @package WooCommerce\Payments\Tasks
*/
namespace WooCommerce\Payments\Tasks;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
use WCPay\Database_Cache;
defined( 'ABSPATH' ) || exit;
/**
* WC Onboarding Task displayed if disputes awaiting response.
*
* Note: this task is separate to the Payments → Overview disputes task, which is defined in client/overview/task-list/tasks.js.
*/
class WC_Payments_Task_Disputes extends Task {
/**
* Gets the task ID.
*
* @return string
*/
public function get_id() {
return 'woocommerce_payments_disputes_task';
}
/**
* Gets the task title.
*
* @return string
*/
public function get_title() {
$dispute_count = $this->get_disputes_awaiting_response_count();
// Translators: The placeholder is the number of disputes.
return sprintf( _n( '%d disputed payment needs your response', '%d disputed payments need your response', $dispute_count, 'woocommerce-payments' ), $dispute_count );
}
/**
* Get the parent list ID.
*
* This function prior to WC 6.4.0 was abstract and so is needed for backwards compatibility.
*
* @return string
*/
public function get_parent_id() {
// WC 6.4.0 compatibility.
if ( is_callable( 'parent::get_parent_id' ) ) {
return parent::get_parent_id();
}
return 'extended';
}
/**
* Gets the task content.
*
* @return string
*/
public function get_content() {
return '';
}
/**
* Get the additional info.
*
* @return string
*/
public function get_additional_info() {
return __( 'View and respond', 'woocommerce-payments' );
}
/**
* Gets the task's action label.
*
* @return string
*/
public function get_action_label() {
return __( 'Disputes', 'woocommerce-payments' );
}
/**
* Gets the task's action URL.
*
* @return string
*/
public function get_action_url() {
return admin_url(
add_query_arg(
[
'page' => 'wc-admin',
'path' => '%2Fpayments%2Fdisputes',
'filter' => 'awaiting_response',
],
'admin.php'
)
);
}
/**
* Get the estimated time to complete the task.
*
* @return string
*/
public function get_time() {
return '';
}
/**
* Get whether the task is completed.
*
* @return bool
*/
public function is_complete() {
return false;
}
/**
* Get whether the task is visible.
*
* @return bool
*/
public function can_view() {
return $this->get_disputes_awaiting_response_count() > 0;
}
/**
* Gets the number of disputes which need a response.
*
* Because this task is initialized before WC Payments, we can only fetch from the cache (via "get()").
* The dispute status cache cannot be populated via this task. If this value hasn't been cached yet, this task won't show until it is.
*
* @return int The number of disputes which need a response.
*/
private function get_disputes_awaiting_response_count() {
$disputes_status_counts = \WC_Payments::get_database_cache()->get( Database_Cache::DISPUTE_STATUS_COUNTS_KEY );
if ( empty( $disputes_status_counts ) ) {
return 0;
}
$needs_response_statuses = [ 'needs_response', 'warning_needs_response' ];
return (int) array_sum( array_intersect_key( $disputes_status_counts, array_flip( $needs_response_statuses ) ) );
}
}