class-wc-payments-features.php
5.71 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* Class WC_Payments_Features
*
* @package WooCommerce\Payments
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* WC Payments Features class
*/
class WC_Payments_Features {
const UPE_FLAG_NAME = '_wcpay_feature_upe';
const WCPAY_SUBSCRIPTIONS_FLAG_NAME = '_wcpay_feature_subscriptions';
const WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_express_checkout';
const AUTH_AND_CAPTURE_FLAG_NAME = '_wcpay_feature_auth_and_capture';
/**
* Checks whether the UPE gateway is enabled
*
* @return bool
*/
public static function is_upe_enabled() {
return '1' === get_option( self::UPE_FLAG_NAME, '0' );
}
/**
* Checks whether the UPE gateway is enabled
*
* @return bool
*/
public static function did_merchant_disable_upe() {
return 'disabled' === get_option( self::UPE_FLAG_NAME, '0' );
}
/**
* Checks whether the UPE settings redesign is enabled
*
* @return bool
*/
public static function is_upe_settings_preview_enabled() {
return '1' === get_option( '_wcpay_feature_upe_settings_preview', '1' );
}
/**
* Checks whether the customer Multi-Currency feature is enabled
*
* @return bool
*/
public static function is_customer_multi_currency_enabled() {
return '1' === get_option( '_wcpay_feature_customer_multi_currency', '1' );
}
/**
* Returns if the encryption libraries are loaded and the encrypt method exists.
*
* @return bool
*/
public static function is_client_secret_encryption_eligible() {
return extension_loaded( 'openssl' ) && function_exists( 'openssl_encrypt' );
}
/**
* Checks whether the client secret encryption feature is enabled.
*
* @return bool
*/
public static function is_client_secret_encryption_enabled() {
$enabled = '1' === get_option( '_wcpay_feature_client_secret_encryption', '0' );
// Check if it can be enabled when it's enabled, it needs openssl to operate.
if ( $enabled && ! self::is_client_secret_encryption_eligible() ) {
update_option( '_wcpay_feature_client_secret_encryption', '0' );
$enabled = false;
}
return $enabled;
}
/**
* Checks whether Account Overview page is enabled
*
* @return bool
*/
public static function is_account_overview_task_list_enabled() {
return get_option( '_wcpay_feature_account_overview_task_list', '1' );
}
/**
* Checks whether WCPay Subscriptions is enabled.
*
* @return bool
*/
public static function is_wcpay_subscriptions_enabled() {
$enabled = get_option( self::WCPAY_SUBSCRIPTIONS_FLAG_NAME, null );
// Enable the feature by default for stores that are eligible.
if ( null === $enabled && function_exists( 'wc_get_base_location' ) && self::is_wcpay_subscriptions_eligible() ) {
$enabled = '1';
update_option( self::WCPAY_SUBSCRIPTIONS_FLAG_NAME, $enabled );
}
return apply_filters( 'wcpay_is_wcpay_subscriptions_enabled', '1' === $enabled );
}
/**
* Returns whether WCPay Subscriptions is eligible, based on the stores base country.
*
* @return bool
*/
public static function is_wcpay_subscriptions_eligible() {
$store_base_location = wc_get_base_location();
return ! empty( $store_base_location['country'] ) && 'US' === $store_base_location['country'];
}
/**
* Checks whether platform checkout is enabled.
*
* @return bool
*/
public static function is_platform_checkout_eligible() {
// read directly from cache, ignore cache expiration check.
$account = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY, true );
return is_array( $account ) && ( $account['platform_checkout_eligible'] ?? false );
}
/**
* Checks whether documents section is enabled.
*
* @return bool
*/
public static function is_documents_section_enabled() {
$account = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY );
$is_documents_enabled = is_array( $account ) && ( $account['is_documents_enabled'] ?? false );
return '1' === get_option( '_wcpay_feature_documents', $is_documents_enabled ? '1' : '0' );
}
/**
* Checks whether custom deposit schedules are enabled.
*
* @return bool
*/
public static function is_custom_deposit_schedules_enabled() {
return '1' === get_option( '_wcpay_feature_custom_deposit_schedules', '1' );
}
/**
* Checks whether WooPay Express Checkout is enabled.
*
* @return bool
*/
public static function is_woopay_express_checkout_enabled() {
// Confirm platform checkout eligibility as well.
return '1' === get_option( self::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' ) && self::is_platform_checkout_eligible();
}
/**
* Checks whether Auth & Capture (uncaptured transactions tab, capture from payment details page) is enabled.
*
* @return bool
*/
public static function is_auth_and_capture_enabled() {
return '1' === get_option( self::AUTH_AND_CAPTURE_FLAG_NAME, '1' );
}
/**
* Returns feature flags as an array suitable for display on the front-end.
*
* @return bool[]
*/
public static function to_array() {
return array_filter(
[
'upe' => self::is_upe_enabled(),
'upeSettingsPreview' => self::is_upe_settings_preview_enabled(),
'multiCurrency' => self::is_customer_multi_currency_enabled(),
'accountOverviewTaskList' => self::is_account_overview_task_list_enabled(),
'platformCheckout' => self::is_platform_checkout_eligible(),
'documents' => self::is_documents_section_enabled(),
'customDepositSchedules' => self::is_custom_deposit_schedules_enabled(),
'clientSecretEncryption' => self::is_client_secret_encryption_enabled(),
'woopayExpressCheckout' => self::is_woopay_express_checkout_enabled(),
'isAuthAndCaptureEnabled' => self::is_auth_and_capture_enabled(),
]
);
}
}