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
AdditionalPayments.php
156 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks; |
| 3 | |
| 4 | use Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders; |
| 5 | use Automattic\WooCommerce\Internal\Admin\Settings\Payments as SettingsPaymentsService; |
| 6 | |
| 7 | /** |
| 8 | * Payments Task |
| 9 | */ |
| 10 | class AdditionalPayments extends Payments { |
| 11 | |
| 12 | /** |
| 13 | * Used to cache is_complete() method result. |
| 14 | * |
| 15 | * @var null |
| 16 | */ |
| 17 | private $is_complete_result = null; |
| 18 | |
| 19 | /** |
| 20 | * Used to cache can_view() method result. |
| 21 | * |
| 22 | * @var null |
| 23 | */ |
| 24 | private $can_view_result = null; |
| 25 | |
| 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 __( |
| 43 | 'Set up additional payment options', |
| 44 | 'woocommerce' |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Content. |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | public function get_content() { |
| 54 | return __( |
| 55 | 'Choose payment providers and enable payment methods at checkout.', |
| 56 | 'woocommerce' |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Time. |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | public function get_time() { |
| 66 | return __( '2 minutes', 'woocommerce' ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Task completion. |
| 71 | * |
| 72 | * @return bool |
| 73 | */ |
| 74 | public function is_complete() { |
| 75 | if ( null === $this->is_complete_result ) { |
| 76 | $this->is_complete_result = $this->has_enabled_non_psp_payment_suggestion(); |
| 77 | } |
| 78 | |
| 79 | return $this->is_complete_result; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Task visibility. |
| 84 | * |
| 85 | * @return bool |
| 86 | */ |
| 87 | public function can_view() { |
| 88 | if ( null !== $this->can_view_result ) { |
| 89 | return $this->can_view_result; |
| 90 | } |
| 91 | |
| 92 | // Always show task if there are any gateways enabled (i.e. the Payments task is complete). |
| 93 | if ( self::has_gateways() ) { |
| 94 | $this->can_view_result = true; |
| 95 | } else { |
| 96 | $this->can_view_result = false; |
| 97 | } |
| 98 | |
| 99 | return $this->can_view_result; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Action URL. |
| 104 | * |
| 105 | * @return string |
| 106 | */ |
| 107 | public function get_action_url(): string { |
| 108 | // We auto-expand the "Other" section to show the additional payment methods. |
| 109 | return admin_url( 'admin.php?page=wc-settings&tab=checkout&other_pes_section=expanded&from=' . SettingsPaymentsService::FROM_ADDITIONAL_PAYMENTS_TASK ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Check if there are any enabled non-PSP payment suggestions. |
| 114 | * |
| 115 | * @return bool True if there are enabled non-PSP payment suggestions, false otherwise. |
| 116 | */ |
| 117 | private function has_enabled_non_psp_payment_suggestion(): bool { |
| 118 | $providers = $this->get_payment_providers(); |
| 119 | foreach ( $providers as $provider ) { |
| 120 | // Check if the provider is enabled and has a suggestion category ID that matches the ones we are interested in. |
| 121 | if ( |
| 122 | ! empty( $provider['state']['enabled'] ) && |
| 123 | ! empty( $provider['_suggestion_category_id'] ) && |
| 124 | in_array( $provider['_suggestion_category_id'], array( PaymentsProviders::CATEGORY_BNPL, PaymentsProviders::CATEGORY_EXPRESS_CHECKOUT, PaymentsProviders::CATEGORY_CRYPTO ), true ) |
| 125 | ) { |
| 126 | return true; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Get the list of payments providers as it is used on the Payments Settings page. |
| 135 | * |
| 136 | * @return array The list of payment providers. |
| 137 | */ |
| 138 | private function get_payment_providers(): array { |
| 139 | try { |
| 140 | /** |
| 141 | * The Payments Settings [page] service. |
| 142 | * |
| 143 | * @var SettingsPaymentsService $settings_payments_service |
| 144 | */ |
| 145 | $settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class ); |
| 146 | |
| 147 | $providers = $settings_payments_service->get_payment_providers( $settings_payments_service->get_country(), false ); |
| 148 | } catch ( \Throwable $e ) { |
| 149 | // In case of any error, return an empty array. |
| 150 | $providers = array(); |
| 151 | } |
| 152 | |
| 153 | return $providers; |
| 154 | } |
| 155 | } |
| 156 |