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.2.0 10.0.1 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3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.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 2 weeks ago ExperimentalShippingRecommendation.php 2 weeks ago ExtendStore.php 1 year ago GetMobileApp.php 3 years ago LaunchYourStore.php 2 weeks ago Marketing.php 2 weeks ago Payments.php 2 weeks ago Products.php 2 weeks ago ReviewShippingOptions.php 4 years ago Shipping.php 2 weeks ago StoreCreation.php 4 years ago StoreDetails.php 2 weeks ago Tax.php 2 weeks ago TourInAppMarketplace.php 2 years ago WooCommercePayments.php 2 weeks ago
Payments.php
501 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 * Contextual image URL.
38 *
39 * @return string
40 */
41 public function get_image_url() {
42 return WC()->plugin_url() . '/assets/images/task_list/payment-illustration.svg';
43 }
44
45 /**
46 * Alt text for the contextual image.
47 *
48 * @return string
49 */
50 public function get_image_alt() {
51 return __( 'Payment illustration', 'woocommerce' );
52 }
53
54 /**
55 * Title.
56 *
57 * @return string
58 */
59 public function get_title() {
60 return __( 'Set up payments', 'woocommerce' );
61 }
62
63 /**
64 * Content.
65 *
66 * @return string
67 */
68 public function get_content() {
69 return __(
70 'Choose payment providers and enable payment methods at checkout.',
71 'woocommerce'
72 );
73 }
74
75 /**
76 * Time.
77 *
78 * @return string
79 */
80 public function get_time() {
81 return __( '5 minutes', 'woocommerce' );
82 }
83
84 /**
85 * Task completion.
86 *
87 * @return bool
88 */
89 public function is_complete() {
90 if ( null === $this->is_complete_result ) {
91 if ( $this->is_woopayments_active() ) {
92 // If WooPayments is active, check if it is fully onboarded with a live account.
93 $this->is_complete_result = $this->is_woopayments_onboarded() && ! $this->has_woopayments_test_account();
94 } else {
95 // If WooPayments is not active, check if there are any enabled gateways.
96 $this->is_complete_result = self::has_gateways();
97 }
98 }
99
100 return $this->is_complete_result;
101 }
102
103 /**
104 * Task visibility.
105 *
106 * @return bool
107 */
108 public function can_view() {
109 // The task is always visible.
110 return true;
111 }
112
113 /**
114 * Check if the store has any enabled gateways.
115 *
116 * @return bool
117 */
118 public static function has_gateways() {
119 $gateways = WC()->payment_gateways()->payment_gateways;
120 $enabled_gateways = array_filter(
121 $gateways,
122 function ( $gateway ) {
123 return 'yes' === $gateway->enabled;
124 }
125 );
126
127 return ! empty( $enabled_gateways );
128 }
129
130 /**
131 * Check if the task is in progress.
132 *
133 * @return bool
134 */
135 public function is_in_progress() {
136 // If the task is already complete, it's not in progress.
137 if ( $this->is_complete() ) {
138 return false;
139 }
140
141 return ( $this->has_woopayments_live_account_in_progress() || $this->has_woopayments_test_account() );
142 }
143
144 /**
145 * The task in progress label.
146 *
147 * @return string
148 */
149 public function in_progress_label() {
150 // If WooPayments live account onboarding is in progress, show "Action needed" label.
151 if ( $this->has_woopayments_live_account_in_progress() ) {
152 return esc_html__( 'Action needed', 'woocommerce' );
153 }
154
155 return esc_html__( 'Test account', 'woocommerce' );
156 }
157
158 /**
159 * The task action URL.
160 *
161 * Empty string means the JS logic will handle the task linking.
162 *
163 * @return string
164 */
165 public function get_action_url() {
166 // Link to the Payments settings page.
167 return admin_url( 'admin.php?page=wc-settings&tab=checkout&from=' . SettingsPaymentsService::FROM_PAYMENTS_TASK );
168 }
169
170 /**
171 * Additional data to be passed to the front-end JS logic.
172 *
173 * Primarily used to inform the behavior of the Payments task in the LYS context.
174 *
175 * @return array
176 */
177 public function get_additional_data() {
178 return array(
179 'wooPaymentsIsActive' => $this->is_woopayments_active(),
180 'wooPaymentsIsInstalled' => $this->is_woopayments_installed(),
181 'wooPaymentsSettingsCountryIsSupported' => $this->is_woopayments_supported_country( $this->get_payments_settings_country() ),
182 'wooPaymentsIsOnboarded' => $this->is_woopayments_onboarded(),
183 'wooPaymentsHasTestAccount' => $this->has_woopayments_test_account(),
184 'wooPaymentsHasOtherProvidersEnabled' => $this->has_providers_enabled_other_than_woopayments(),
185 'wooPaymentsHasOtherProvidersNeedSetup' => $this->has_providers_needing_setup_other_than_woopayments(),
186 'wooPaymentsHasOnlineGatewaysEnabled' => $this->has_online_gateways(),
187 );
188 }
189
190 /**
191 * Check if the WooPayments plugin is active.
192 *
193 * @return bool
194 */
195 private function is_woopayments_active(): bool {
196 return class_exists( '\WC_Payments' );
197 }
198
199 /**
200 * Check if the WooPayments plugin is installed.
201 *
202 * @return bool
203 */
204 private function is_woopayments_installed(): bool {
205 if ( $this->is_woopayments_active() ) {
206 // If it is active, it is also installed.
207 return true;
208 }
209
210 $woopayments_suggestion = $this->get_woopayments_suggestion();
211 // We should have the WooPayments suggestion, but if not, return false.
212 if ( ! $woopayments_suggestion ) {
213 return false;
214 }
215
216 // Check if the suggestion has its plugin installed.
217 if ( ! empty( $woopayments_suggestion['plugin']['status'] ) &&
218 PaymentsProviders::EXTENSION_INSTALLED === $woopayments_suggestion['plugin']['status'] ) {
219
220 return true;
221 }
222
223 return false;
224 }
225
226 /**
227 * Check if WooPayments is completely onboarded.
228 *
229 * @return bool
230 */
231 private function is_woopayments_onboarded(): bool {
232 if ( ! $this->is_woopayments_active() ) {
233 return false;
234 }
235
236 $woopayments_provider = $this->get_woopayments_provider();
237 // We should have the WooPayments provider, but if not, return false.
238 if ( ! $woopayments_provider ) {
239 return false;
240 }
241
242 // Check the provider's state to determine if it is onboarded.
243 if ( ! empty( $woopayments_provider['onboarding']['state']['completed'] ) ) {
244 return true;
245 }
246
247 return false;
248 }
249
250 /**
251 * Check if WooPayments has a live account onboarding in progress.
252 *
253 * @return bool
254 */
255 private function has_woopayments_live_account_in_progress() {
256 if ( $this->is_woopayments_onboarded() ) {
257 return false;
258 }
259
260 $woopayments_provider = $this->get_woopayments_provider();
261 // We should have the WooPayments provider, but if not, return false.
262 if ( ! $woopayments_provider ) {
263 return false;
264 }
265
266 // If we have a test account, we are not in live account onboarding.
267 if ( $this->has_woopayments_test_account() ) {
268 return false;
269 }
270
271 // Check the provider's state to determine if a live account onboarding is started.
272 if ( ! empty( $woopayments_provider['onboarding']['state']['started'] ) ) {
273 return true;
274 }
275
276 return false;
277 }
278
279 /**
280 * Check if WooPayments is onboarded and has a test [drive] account.
281 *
282 * @return bool
283 */
284 private function has_woopayments_test_account(): bool {
285 if ( ! $this->is_woopayments_onboarded() ) {
286 return false;
287 }
288
289 $woopayments_provider = $this->get_woopayments_provider();
290 // We should have the WooPayments provider, but if not, return false.
291 if ( ! $woopayments_provider ) {
292 return false;
293 }
294
295 // Check the provider's state to determine if a test [drive] account is in use.
296 if ( ! empty( $woopayments_provider['onboarding']['state']['test_drive_account'] ) ) {
297 return true;
298 }
299
300 return false;
301 }
302
303 /**
304 * Check if the store is in a WooPayments-supported geography.
305 *
306 * @param string $country_code Country code to check. If not provided, uses store base country.
307 *
308 * @return bool Whether the country is supported by WooPayments.
309 */
310 private function is_woopayments_supported_country( string $country_code ): bool {
311 if ( class_exists( '\WC_Payments_Utils' ) && is_callable( array( '\WC_Payments_Utils', 'supported_countries' ) ) ) {
312 $supported_countries = array_keys( \WC_Payments_Utils::supported_countries() );
313 return in_array( $country_code, $supported_countries, true );
314 }
315
316 // WooPayments is not installed and active, use core's list of supported countries.
317 $supported_countries = DefaultPaymentGateways::get_wcpay_countries();
318 return in_array( $country_code, $supported_countries, true );
319 }
320
321 /**
322 * Check if the store has any enabled providers other than WooPayments.
323 *
324 * @return bool
325 */
326 public function has_providers_enabled_other_than_woopayments(): bool {
327 $providers = $this->get_payments_providers();
328
329 foreach ( $providers as $provider ) {
330 // Check if the provider is enabled and is not WooPayments.
331 if (
332 ! empty( $provider['state']['enabled'] ) &&
333 ! empty( $provider['id'] ) &&
334 'woocommerce_payments' !== $provider['id']
335 ) {
336 return true;
337 }
338 }
339
340 return false;
341 }
342
343 /**
344 * Check if any non-WooPayments providers need setup.
345 *
346 * @return bool
347 */
348 private function has_providers_needing_setup_other_than_woopayments(): bool {
349 $providers = $this->get_payments_providers();
350
351 foreach ( $providers as $provider ) {
352 // Check if the provider needs setup and is not WooPayments.
353 if (
354 ! empty( $provider['state']['needs_setup'] ) &&
355 ! empty( $provider['id'] ) &&
356 'woocommerce_payments' !== $provider['id']
357 ) {
358 return true;
359 }
360 }
361
362 return false;
363 }
364
365 /**
366 * Check if the store has any enabled online gateways.
367 *
368 * @return bool
369 */
370 private function has_online_gateways(): bool {
371 $providers = $this->get_payments_providers();
372
373 foreach ( $providers as $provider ) {
374 // Check if the provider is enabled and is not an offline payment method.
375 if (
376 ! empty( $provider['state']['enabled'] ) &&
377 ! empty( $provider['id'] ) &&
378 ! in_array( $provider['id'], array( WC_Gateway_BACS::ID, WC_Gateway_Cheque::ID, WC_Gateway_COD::ID ), true )
379 ) {
380 return true;
381 }
382 }
383
384 return false;
385 }
386
387 /**
388 * Get the store's business registration country/location as it is used on the Payments Settings page.
389 *
390 * @return string The business registration country/location code.
391 */
392 private function get_payments_settings_country(): string {
393 try {
394 /**
395 * The Payments Settings [page] service.
396 *
397 * @var SettingsPaymentsService $settings_payments_service
398 */
399 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
400
401 return $settings_payments_service->get_country();
402 } catch ( \Throwable $e ) {
403 // In case of any error, return the WooCommerce base country.
404 return WC()->countries->get_base_country();
405 }
406 }
407
408 /**
409 * Get the list of payments providers as it is used on the Payments Settings page.
410 *
411 * The list can include payments extension suggestions, the same as on the Payments Settings page.
412 *
413 * @return array The list of payments providers.
414 */
415 private function get_payments_providers(): array {
416 try {
417 /**
418 * The Payments Settings [page] service.
419 *
420 * @var SettingsPaymentsService $settings_payments_service
421 */
422 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
423
424 // Get the raw list of payment providers, including suggestions, but remove shells.
425 // This way we prevent shell gateways that are (wrongly) reported as enabled from affecting the task completion.
426 return $settings_payments_service->get_payment_providers( $settings_payments_service->get_country(), false, true );
427 } catch ( \Throwable $e ) {
428 // In case of any error, return an empty array.
429 return array();
430 }
431 }
432
433 /**
434 * Get the list of payments extension suggestions as it is used on the Payments Settings page.
435 *
436 * @return array The list of payments extension suggestions.
437 */
438 private function get_payments_extension_suggestions(): array {
439 try {
440 /**
441 * The Payments Settings [page] service.
442 *
443 * @var SettingsPaymentsService $settings_payments_service
444 */
445 $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
446
447 return $settings_payments_service->get_payment_extension_suggestions( $settings_payments_service->get_country() );
448 } catch ( \Throwable $e ) {
449 // In case of any error, return an empty array.
450 return array();
451 }
452 }
453
454 /**
455 * Get the WooPayments provider details from the list used on the Payments Settings page.
456 *
457 * @return array|null The WooPayments provider details or null if not found.
458 */
459 private function get_woopayments_provider(): ?array {
460 $providers = $this->get_payments_providers();
461 foreach ( $providers as $provider ) {
462 if ( ! empty( $provider['id'] ) && PaymentsProviders\WooPayments\WooPaymentsService::GATEWAY_ID === $provider['id'] ) {
463 return $provider;
464 }
465 }
466
467 return null;
468 }
469
470 /**
471 * Get the WooPayments payments extension suggestion details from the lists used on the Payments Settings page.
472 *
473 * @return array|null The WooPayments suggestion details or null if not found.
474 */
475 private function get_woopayments_suggestion(): ?array {
476 // First, check the payments providers list.
477 $providers = $this->get_payments_providers();
478 foreach ( $providers as $provider ) {
479 if ( ! empty( $provider['_type'] ) &&
480 PaymentsProviders::TYPE_SUGGESTION === $provider['_type'] &&
481 ! empty( $provider['_suggestion_id'] ) &&
482 PaymentsExtensionSuggestions::WOOPAYMENTS === $provider['_suggestion_id'] ) {
483
484 return $provider;
485 }
486 }
487
488 // If not found in the main list, check the payments extension suggestions list.
489 $suggestions = $this->get_payments_extension_suggestions();
490 foreach ( $suggestions as $suggestion ) {
491 if ( ! empty( $suggestion['id'] ) &&
492 PaymentsExtensionSuggestions::WOOPAYMENTS === $suggestion['id'] ) {
493
494 return $suggestion;
495 }
496 }
497
498 return null;
499 }
500 }
501