PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
← All changes | src/Gateway/PayplugGatewayRequirements.php +141 -159 1.10.0 → 3.1.0 View file →
@@ -4,186 +4,168 @@
4 4
5 5 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
6 6
7 7 // Exit if accessed directly
8 -use const OPENSSL_VERSION_TEXT;
9 8 use const PHP_VERSION;
10 -use function sprintf;
11 -use function var_dump;
12 -use Payplug\PayplugWoocommerce\Gateway\PayplugPermissions;
13 9
14 -if ( ! defined( 'ABSPATH' ) ) {
15 - exit;
10 +if (!defined('ABSPATH')) {
11 + exit;
16 12 }
17 13
18 -class PayplugGatewayRequirements {
14 +class PayplugGatewayRequirements
15 +{
16 + public const PHP_MIN = '5.6';
17 + public const OPENSSL_MIN = 268439567;
18 + public const OPENSSL_MIN_TEXT = 'OpenSSL 1.0.1 14 Mar 2012';
19 19
20 - const PHP_MIN = '5.6';
21 - const OPENSSL_MIN = 268439567;
22 - const OPENSSL_MIN_TEXT = 'OpenSSL 1.0.1 14 Mar 2012';
20 + /**
21 + * @var PayplugGateway
22 + */
23 + private $gateway;
23 24
24 - /**
25 - * @var PayplugGateway
26 - */
27 - private $gateway;
25 + /**
26 + * Gateway settings.
27 + *
28 + * @var array
29 + */
30 + protected $settings;
28 31
32 + /**
33 + * PayplugGatewayRequirements constructor.
34 + *
35 + * @param PayplugGateway $gateway
36 + */
37 + public function __construct(PayplugGateway $gateway)
38 + {
39 + $this->gateway = $gateway;
40 + $this->settings = PayplugWoocommerceHelper::get_payplug_options();
41 + }
29 42
30 43 /**
31 - * @var PayplugPermissions
44 + * Check if all gateway requirements are fulfilled.
45 + *
46 + * @return bool
32 47 */
33 - private $permissions;
48 + public function satisfy_requirements()
49 + {
50 + return $this->valid_php()
51 + && $this->valid_curl()
52 + && $this->valid_openssl()
53 + && $this->valid_currency()
54 + && $this->valid_account();
55 + }
34 56
35 - /**
36 - * Gateway settings.
37 - *
38 - * @var array
39 - */
40 - protected $settings;
57 + /**
58 + * @return array
59 + */
60 + public function curl_requirement()
61 + {
62 + return [
63 + 'status' => $this->valid_curl(),
64 + 'text' => __('payplug_section_status_curl', 'payplug'),
65 + ];
66 + }
41 67
42 - /**
43 - * PayplugGatewayRequirements constructor.
44 - *
45 - * @param PayplugGateway $gateway
46 - */
47 - public function __construct( PayplugGateway $gateway ) {
48 - $this->gateway = $gateway;
49 - $this->permissions = new PayplugPermissions($gateway);
50 - $this->settings = get_option( 'woocommerce_payplug_settings', [] );
51 - }
68 + /**
69 + * @return array
70 + */
71 + public function php_requirement()
72 + {
73 + return [
74 + 'status' => $this->valid_php(),
75 + 'text' => __('payplug_section_status_php', 'payplug'),
76 + ];
77 + }
52 78
53 - /**
54 - * Check if all gateway requirements are fulfilled.
55 - *
56 - * @return bool
57 - */
58 - public function satisfy_requirements() {
59 - return $this->valid_php()
60 - && $this->valid_curl()
61 - && $this->valid_openssl()
62 - && $this->valid_currency()
63 - && $this->valid_account();
64 - }
79 + /**
80 + * @return array
81 + */
82 + public function openssl_requirement()
83 + {
84 + return [
85 + 'status' => $this->valid_openssl(),
86 + 'text' => __('payplug_section_status_ssl', 'payplug'),
87 + ];
88 + }
65 89
66 - /**
67 - * @return string
68 - */
69 - public function curl_requirement() {
70 - return ( $this->valid_curl() )
71 - ? '<p class="success">' . __( 'payplug_PayplugGatewayRequirements_curl_requirement_curlinstalled', 'payplug' ) . '</p>'
72 - : '<p class="failed">' . __( 'The PHP cURL extension must be installed and activated on your server.', 'payplug' ) . '</p>';
73 - }
90 + /**
91 + * @return array
92 + */
93 + public function currency_requirement()
94 + {
95 + return [
96 + 'status' => $this->valid_currency(),
97 + 'text' => __('payplug_section_status_currency', 'payplug'),
98 + ];
99 + }
74 100
75 - /**
76 - * @return string
77 - */
78 - public function php_requirement() {
79 - return ( $this->valid_php() )
80 - ? '<p class="success">' . __( 'The PHP version on your server is valid.', 'payplug' ) . '</p>'
81 - /* translators: %s: minimum required PHP version */
82 - : '<p class="failed">' . sprintf( __( 'The PHP version on your server is not supported. Your server must run PHP %s or greater.', 'payplug' ), self::PHP_MIN ) . '</p>';
83 - }
101 + /**
102 + * @return array
103 + */
104 + public function account_requirement()
105 + {
106 + return [
107 + 'status' => $this->valid_account(),
108 + 'text' => __('payplug_section_status_account', 'payplug'),
109 + ];
110 + }
84 111
85 - /**
86 - * @return string
87 - */
88 - public function openssl_requirement() {
89 - return ( $this->valid_openssl() )
90 - ? '<p class="success">' . __( 'OpenSSL is up to date.', 'payplug' ) . '</p>'
91 - /* translators: %s: minimum required OpenSSL version */
92 - : '<p class="failed">' . sprintf( __( 'OpenSSL is not up to date. Please update to OpenSSL %s or later.', 'payplug' ), self::OPENSSL_MIN . ' ( ' . self::OPENSSL_MIN_TEXT . ' )' ) . '</p>';
93 - }
112 + /**
113 + * Check if CURL is available and support SSL
114 + *
115 + * @return bool
116 + */
117 + public function valid_curl()
118 + {
119 + if (!function_exists('curl_init') || !function_exists('curl_exec')) {
120 + return false;
121 + }
94 122
95 - /**
96 - * @return string
97 - */
98 - public function currency_requirement() {
99 - return ( $this->valid_currency() )
100 - ? '<p class="success">' . __( 'Your shop currency has been set up with Euro.', 'payplug' ) . '</p>'
101 - : '<p class="failed">' . __( 'Your shop currency must be set up with Euro.', 'payplug' ) . '</p>';
102 - }
123 + // Also Check for SSL support
124 + $curl_version = curl_version();
125 + if (!(CURL_VERSION_SSL & $curl_version['features'])) {
126 + return false;
127 + }
103 128
104 - /**
105 - * @return string
106 - */
107 - public function account_requirement() {
108 - return ( $this->valid_account() )
109 - ? '<p class="success">' . __( 'You are logged in with your PayPlug account.', 'payplug' ) . '</p>'
110 - : '<p class="failed">' . __( 'You must be logged in with your PayPlug account.', 'payplug' ) . '</p>';
111 - }
129 + return true;
130 + }
112 131
113 - /**
114 - * @return string
115 - */
116 - public function oney_requirement() {
117 - return ($this->valid_oney_check())
118 - ? '<p class="success">' . __( 'Oney is active on your store.', 'payplug' ) . '</p>'
119 - : '';
120 - }
132 + /**
133 + * Check if PHP version is equal or above the minimum supported.
134 + *
135 + * @return bool
136 + */
137 + public function valid_php()
138 + {
139 + return version_compare(PHP_VERSION, self::PHP_MIN, '>=');
140 + }
121 141
122 - /**
123 - * Check if CURL is available and support SSL
124 - *
125 - * @return bool
126 - */
127 - public function valid_curl() {
128 - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
129 - return false;
130 - }
142 + /**
143 + * Check if OPENSSL version is equal or above the minimum supported.
144 + *
145 + * @return bool
146 + */
147 + public function valid_openssl()
148 + {
149 + return OPENSSL_VERSION_NUMBER >= self::OPENSSL_MIN;
150 + }
131 151
132 - // Also Check for SSL support
133 - $curl_version = curl_version();
134 - if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) {
135 - return false;
136 - }
152 + /**
153 + * Check if the shop currency is Euro.
154 + *
155 + * @return bool
156 + */
157 + public function valid_currency()
158 + {
159 + return 'EUR' === get_woocommerce_currency();
160 + }
137 161
138 - return true;
139 - }
140 -
141 - /**
142 - * Check if PHP version is equal or above the minimum supported.
143 - *
144 - * @return bool
145 - */
146 - public function valid_php() {
147 - return version_compare( PHP_VERSION, self::PHP_MIN, '>=' );
148 - }
149 -
150 - /**
151 - * Check if OPENSSL version is equal or above the minimum supported.
152 - *
153 - * @return bool
154 - */
155 - public function valid_openssl() {
156 - return OPENSSL_VERSION_NUMBER >= self::OPENSSL_MIN;
157 - }
158 -
159 - /**
160 - * Check if the shop currency is Euro.
161 - *
162 - * @return bool
163 - */
164 - public function valid_currency() {
165 - return 'EUR' === get_woocommerce_currency();
166 - }
167 -
168 - /**
169 - * Check if the user is logged in.
170 - *
171 - * @return bool
172 - */
173 - public function valid_account() {
174 - return $this->gateway->user_logged_in();
175 - }
176 -
177 -
178 - /**
179 - * Check if the user is in live mode and has activated oney
180 - *
181 - * @return bool
182 - */
183 - public function valid_oney_check() {
184 - if (!isset($this->settings['mode']) || !isset($this->settings['oney'])) {
185 - return false;
186 - }
187 - return ("yes" === $this->settings['mode'] && "yes" === $this->settings['oney'] && $this->permissions->has_permissions(PayplugPermissions::USE_ONEY));
188 - }
162 + /**
163 + * Check if the user is logged in.
164 + *
165 + * @return bool
166 + */
167 + public function valid_account()
168 + {
169 + return $this->gateway->user_logged_in();
170 + }
189 171 }