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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / Features / OnboardingTasks / Tasks / Payments.php
woocommerce / src / Admin / Features / OnboardingTasks / Tasks Last commit date
AdditionalPayments.php 1 year ago Appearance.php 2 years ago CustomizeStore.php 5 months ago ExperimentalShippingRecommendation.php 5 months ago ExtendStore.php 1 year ago GetMobileApp.php 3 years ago LaunchYourStore.php 2 years ago Marketing.php 7 months ago Payments.php 10 months ago Products.php 1 month ago ReviewShippingOptions.php 3 years ago Shipping.php 3 months ago StoreCreation.php 4 years ago StoreDetails.php 3 years ago Tax.php 1 year ago TourInAppMarketplace.php 2 years ago WooCommercePayments.php 5 months ago
Payments.php
483 lines
1 <?php
2 declare( strict_types=1 );
3
4 namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
5
6 use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
7 use Automattic\WooCommerce\Internal\Admin\Settings\Payments as SettingsPaymentsService;
8 use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\DefaultPaymentGateways;
9 use Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders;
10 use Automattic\WooCommerce\Internal\Admin\Suggestions\PaymentsExtensionSuggestions;
11 use WC_Gateway_BACS;
12 use WC_Gateway_Cheque;
13 use WC_Gateway_COD;
14
15 /**
16 * Payments Task
17 */
18 class Payments extends Task {
19
20 /**
21 * Used to cache is_complete() method result.
22 *
23 * @var null
24 */
25 private $is_complete_result = null;
26
27 /**
28 * ID.
29 *
30 * @return string
31 */
32 public function get_id() {
33 return 'payments';
34 }
35
36 /**
37 * Title.
38 *
39 * @return string
40 */
41 public function get_title() {
42 return __( 'Set up payments', 'woocommerce' );
43 }
44
45 /**
46 * Content.
47 *
48 * @return string
49 */
50 public function get_content() {
51 return __(
52 'Choose payment providers and enable payment methods at checkout.',
53 'woocommerce'
54 );
55 }
56
57 /**
58 * Time.
59 *
60 * @return string
61 */
62 public function get_time() {
63 return __( '5 minutes', 'woocommerce' );
64 }
65
66 /**
67 * Task completion.
68 *
69 * @return bool
70 */
71 public function is_complete() {
72 if ( null === $this->is_complete_result ) {
73 if ( $this->is_woopayments_active() ) {
74 // If WooPayments is active, check if it is fully onboarded with a live account.
75 $this->is_complete_result = $this->is_woopayments_onboarded() && ! $this->has_woopayments_test_account();
76 } else {
77 // If WooPayments is not active, check if there are any enabled gateways.
78 $this->is_complete_result = self::has_gateways();
79 }
80 }
81
82 return $this->is_complete_result;
83 }
84
85 /**
86 * Task visibility.
87 *
88 * @return bool
89 */
90 public function can_view() {
91 // The task is always visible.
92 return true;
93 }
94
95 /**
96 * Check if the store has any enabled gateways.
97 *
98 * @return bool
99 */
100 public static function has_gateways() {
101 $gateways = WC()->payment_gateways()->payment_gateways;
102 $enabled_gateways = array_filter(
103 $gateways,
104 function ( $gateway ) {
105 return 'yes' === $gateway->enabled;
106 }
107 );
108
109 return ! empty( $enabled_gateways );
110 }
111
112 /**
113 * Check if the task is in progress.
114 *
115 * @return bool
116 */
117 public function is_in_progress() {
118 // If the task is already complete, it's not in progress.
119 if ( $this->is_complete() ) {
120 return false;
121 }
122
123 return ( $this->has_woopayments_live_account_in_progress() || $this->has_woopayments_test_account() );
124 }
125
126 /**
127 * The task in progress label.
128 *
129 * @return string
130 */
131 public function in_progress_label() {
132 // If WooPayments live account onboarding is in progress, show "Action needed" label.
133 if ( $this->has_woopayments_live_account_in_progress() ) {
134 return esc_html__( 'Action needed', 'woocommerce' );
135 }
136
137 return esc_html__( 'Test account', 'woocommerce' );
138 }
139
140 /**
141 * The task action URL.
142 *
143 * Empty string means the JS logic will handle the task linking.
144 *
145 * @return string
146 */
147 public function get_action_url() {
148 // Link to the Payments settings page.
149 return admin_url( 'admin.php?page=wc-settings&tab=checkout&from=' . SettingsPaymentsService::FROM_PAYMENTS_TASK );
150 }
151
152 /**
153 * Additional data to be passed to the front-end JS logic.
154 *
155 * Primarily used to inform the behavior of the Payments task in the LYS context.
156 *
157 * @return array
158 */
159 public function get_additional_data() {
160 return array(
161 'wooPaymentsIsActive' => $this->is_woopayments_active(),
162 'wooPaymentsIsInstalled' => $this->is_woopayments_installed(),
163 'wooPaymentsSettingsCountryIsSupported' => $this->is_woopayments_supported_country( $this->get_payments_settings_country() ),
164 'wooPaymentsIsOnboarded' => $this->is_woopayments_onboarded(),
165 'wooPaymentsHasTestAccount' => $this->has_woopayments_test_account(),
166 'wooPaymentsHasOtherProvidersEnabled' => $this->has_providers_enabled_other_than_woopayments(),
167 'wooPaymentsHasOtherProvidersNeedSetup' => $this->has_providers_needing_setup_other_than_woopayments(),
168 'wooPaymentsHasOnlineGatewaysEnabled' => $this->has_online_gateways(),
169 );
170 }
171
172 /**
173 * Check if the WooPayments plugin is active.
174 *
175 * @return bool
176 */
177 private function is_woopayments_active(): bool {
178 return class_exists( '\WC_Payments' );
179 }
180
181 /**
182 * Check if the WooPayments plugin is installed.
183 *
184 * @return bool
185 */
186 private function is_woopayments_installed(): bool {
187 if ( $this->is_woopayments_active() ) {
188 // If it is active, it is also installed.
189 return true;
190 }
191
192 $woopayments_suggestion = $this->get_woopayments_suggestion();
193 // We should have the WooPayments suggestion, but if not, return false.
194 if ( ! $woopayments_suggestion ) {
195 return false;
196 }
197
198 // Check if the suggestion has its plugin installed.
199 if ( ! empty( $woopayments_suggestion['plugin']['status'] ) &&
200 PaymentsProviders::EXTENSION_INSTALLED === $woopayments_suggestion['plugin']['status'] ) {
201
202 return true;
203 }
204
205 return false;
206 }
207
208 /**
209 * Check if WooPayments is completely onboarded.
210 *
211 * @return bool
212 */
213 private function is_woopayments_onboarded(): bool {
214 if ( ! $this->is_woopayments_active() ) {
215 return false;
216 }
217
218 $woopayments_provider = $this->get_woopayments_provider();
219 // We should have the WooPayments provider, but if not, return false.
220 if ( ! $woopayments_provider ) {
221 return false;
222 }
223
224 // Check the provider's state to determine if it is onboarded.
225 if ( ! empty( $woopayments_provider['onboarding']['state']['completed'] ) ) {
226 return true;
227 }
228
229 return false;
230 }
231
232 /**
233 * Check if WooPayments has a live account onboarding in progress.
234 *
235 * @return bool
236 */
237 private function has_woopayments_live_account_in_progress() {
238 if ( $this->is_woopayments_onboarded() ) {
239 return false;
240 }
241
242 $woopayments_provider = $this->get_woopayments_provider();
243 // We should have the WooPayments provider, but if not, return false.
244 if ( ! $woopayments_provider ) {
245 return false;
246 }
247
248 // If we have a test account, we are not in live account onboarding.
249 if ( $this->has_woopayments_test_account() ) {
250 return false;
251 }
252
253 // Check the provider's state to determine if a live account onboarding is started.
254 if ( ! empty( $woopayments_provider['onboarding']['state']['started'] ) ) {
255 return true;
256 }
257
258 return false;
259 }
260
261 /**
262 * Check if WooPayments is onboarded and has a test [drive] account.
263 *
264 * @return bool
265 */
266 private function has_woopayments_test_account(): bool {
267 if ( ! $this->is_woopayments_onboarded() ) {
268 return false;
269 }
270
271 $woopayments_provider = $this->get_woopayments_provider();
272 // We should have the WooPayments provider, but if not, return false.
273 if ( ! $woopayments_provider ) {
274 return false;
275 }
276
277 // Check the provider's state to determine if a test [drive] account is in use.
278 if ( ! empty( $woopayments_provider['onboarding']['state']['test_drive_account'] ) ) {
279 return true;
280 }
281
282 return false;
283 }
284
285 /**
286 * Check if the store is in a WooPayments-supported geography.
287 *
288 * @param string $country_code Country code to check. If not provided, uses store base country.
289 *
290 * @return bool Whether the country is supported by WooPayments.
291 */
292 private function is_woopayments_supported_country( string $country_code ): bool {
293 if ( class_exists( '\WC_Payments_Utils' ) && is_callable( array( '\WC_Payments_Utils', 'supported_countries' ) ) ) {
294 $supported_countries = array_keys( \WC_Payments_Utils::supported_countries() );
295 return in_array( $country_code, $supported_countries, true );
296 }
297
298 // WooPayments is not installed and active, use core's list of supported countries.
299 $supported_countries = DefaultPaymentGateways::get_wcpay_countries();
300 return in_array( $country_code, $supported_countries, true );
301 }
302
303 /**
304 * Check if the store has any enabled providers other than WooPayments.
305 *
306 * @return bool
307 */
308 public function has_providers_enabled_other_than_woopayments(): bool {
309 $providers = $this->get_payments_providers();
310
311 foreach ( $providers as $provider ) {
312 // Check if the provider is enabled and is not WooPayments.
313 if (
314 ! empty( $provider['state']['enabled'] ) &&
315 ! empty( $provider['id'] ) &&
316 'woocommerce_payments' !== $provider['id']
317 ) {
318 return true;
319 }
320 }
321
322 return false;
323 }
324
325 /**
326 * Check if any non-WooPayments providers need setup.
327 *
328 * @return bool
329 */
330 private function has_providers_needing_setup_other_than_woopayments(): bool {
331 $providers = $this->get_payments_providers();
332
333 foreach ( $providers as $provider ) {
334 // Check if the provider needs setup and is not WooPayments.
335 if (
336 ! empty( $provider['state']['needs_setup'] ) &&
337 ! empty( $provider['id'] ) &&
338 'woocommerce_payments' !== $provider['id']
339 ) {
340 return true;
341 }
342 }
343
344 return false;
345 }
346
347 /**
348 * Check if the store has any enabled online gateways.
349 *
350 * @return bool
351 */
352 private function has_online_gateways(): bool {
353 $providers = $this->get_payments_providers();
354
355 foreach ( $providers as $provider ) {
356 // Check if the provider is enabled and is not an offline payment method.
357 if (
358 ! empty( $provider['state']['enabled'] ) &&
359 ! empty( $provider['id'] ) &&
360 ! in_array( $provider['id'], array( WC_Gateway_BACS::ID, WC_Gateway_Cheque::ID, WC_Gateway_COD::ID ), true )
361 ) {
362 return true;
363 }
364 }
365
366 return false;
367 }
368
369 /**
370 * Get the store's business registration country/location as it is used on the Payments Settings page.
371 *
372 * @return string The business registration country/location code.
373 */
374 private function get_payments_settings_country(): string {
375 try {
376 /**
377 * The Payments Settings [page] service.
378 *
379 * @var SettingsPaymentsService $settings_payments_service
380 */
381 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
382
383 return $settings_payments_service->get_country();
384 } catch ( \Throwable $e ) {
385 // In case of any error, return the WooCommerce base country.
386 return WC()->countries->get_base_country();
387 }
388 }
389
390 /**
391 * Get the list of payments providers as it is used on the Payments Settings page.
392 *
393 * The list can include payments extension suggestions, the same as on the Payments Settings page.
394 *
395 * @return array The list of payments providers.
396 */
397 private function get_payments_providers(): array {
398 try {
399 /**
400 * The Payments Settings [page] service.
401 *
402 * @var SettingsPaymentsService $settings_payments_service
403 */
404 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
405
406 // Get the raw list of payment providers, including suggestions, but remove shells.
407 // This way we prevent shell gateways that are (wrongly) reported as enabled from affecting the task completion.
408 return $settings_payments_service->get_payment_providers( $settings_payments_service->get_country(), false, true );
409 } catch ( \Throwable $e ) {
410 // In case of any error, return an empty array.
411 return array();
412 }
413 }
414
415 /**
416 * Get the list of payments extension suggestions as it is used on the Payments Settings page.
417 *
418 * @return array The list of payments extension suggestions.
419 */
420 private function get_payments_extension_suggestions(): array {
421 try {
422 /**
423 * The Payments Settings [page] service.
424 *
425 * @var SettingsPaymentsService $settings_payments_service
426 */
427 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
428
429 return $settings_payments_service->get_payment_extension_suggestions( $settings_payments_service->get_country() );
430 } catch ( \Throwable $e ) {
431 // In case of any error, return an empty array.
432 return array();
433 }
434 }
435
436 /**
437 * Get the WooPayments provider details from the list used on the Payments Settings page.
438 *
439 * @return array|null The WooPayments provider details or null if not found.
440 */
441 private function get_woopayments_provider(): ?array {
442 $providers = $this->get_payments_providers();
443 foreach ( $providers as $provider ) {
444 if ( ! empty( $provider['id'] ) && PaymentsProviders\WooPayments\WooPaymentsService::GATEWAY_ID === $provider['id'] ) {
445 return $provider;
446 }
447 }
448
449 return null;
450 }
451
452 /**
453 * Get the WooPayments payments extension suggestion details from the lists used on the Payments Settings page.
454 *
455 * @return array|null The WooPayments suggestion details or null if not found.
456 */
457 private function get_woopayments_suggestion(): ?array {
458 // First, check the payments providers list.
459 $providers = $this->get_payments_providers();
460 foreach ( $providers as $provider ) {
461 if ( ! empty( $provider['_type'] ) &&
462 PaymentsProviders::TYPE_SUGGESTION === $provider['_type'] &&
463 ! empty( $provider['_suggestion_id'] ) &&
464 PaymentsExtensionSuggestions::WOOPAYMENTS === $provider['_suggestion_id'] ) {
465
466 return $provider;
467 }
468 }
469
470 // If not found in the main list, check the payments extension suggestions list.
471 $suggestions = $this->get_payments_extension_suggestions();
472 foreach ( $suggestions as $suggestion ) {
473 if ( ! empty( $suggestion['id'] ) &&
474 PaymentsExtensionSuggestions::WOOPAYMENTS === $suggestion['id'] ) {
475
476 return $suggestion;
477 }
478 }
479
480 return null;
481 }
482 }
483