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 +144 -175 1.2.3 → 3.1.0 View file →
@@ -1,202 +1,171 @@
1 1 <?php
2 2
3 +namespace Payplug\PayplugWoocommerce\Gateway;
4 +
3 5 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
4 6
5 -namespace Payplug\PayplugWoocommerce\Gateway;
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;
34 -
35 - /**
36 - * Gateway settings.
37 - *
38 - * @var array
39 - */
40 - protected $settings;
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 + }
41 56
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 - }
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 + }
52 67
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 - }
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 + }
65 78
66 - /**
67 - * @return string
68 - */
69 - public function curl_requirement() {
70 - return ( $this->valid_curl() )
71 - ? '<p class="success">' . __( 'The PHP cURL extension is installed and activated on your server.', 'payplug' ) . '</p>'
72 - : '<p class="failed">' . __( 'The PHP cURL extension must be installed and activated on your server.', 'payplug' ) . '</p>';
73 - }
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 + }
74 89
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 - }
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 + }
84 100
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 - }
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 + }
94 111
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 - }
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 + }
103 122
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 - }
123 + // Also Check for SSL support
124 + $curl_version = curl_version();
125 + if (!(CURL_VERSION_SSL & $curl_version['features'])) {
126 + return false;
127 + }
112 128
113 - /**
114 - * @return string
115 - */
116 - public function oney_requirement() {
117 - return ($this->valid_oney_check()) ? ($this->valid_oney() )
118 - ? '<p class="success">' . __( 'Oney is active on your store.', 'payplug' ) . '</p>'
119 - : '<p class="failed-oney">' . __( 'Please fill in the GCSs relating to oney.', 'payplug' ) . '</p>' :
120 - '';
121 - }
129 + return true;
130 + }
122 131
123 - /**
124 - * Check if CURL is available and support SSL
125 - *
126 - * @return bool
127 - */
128 - public function valid_curl() {
129 - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
130 - return false;
131 - }
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 + }
132 141
133 - // Also Check for SSL support
134 - $curl_version = curl_version();
135 - if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) {
136 - return false;
137 - }
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 + }
138 151
139 - return true;
140 - }
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 + }
141 161
142 - /**
143 - * Check if PHP version is equal or above the minimum supported.
144 - *
145 - * @return bool
146 - */
147 - public function valid_php() {
148 - return version_compare( PHP_VERSION, self::PHP_MIN, '>=' );
149 - }
150 -
151 - /**
152 - * Check if OPENSSL version is equal or above the minimum supported.
153 - *
154 - * @return bool
155 - */
156 - public function valid_openssl() {
157 - return OPENSSL_VERSION_NUMBER >= self::OPENSSL_MIN;
158 - }
159 -
160 - /**
161 - * Check if the shop currency is Euro.
162 - *
163 - * @return bool
164 - */
165 - public function valid_currency() {
166 - return 'EUR' === get_woocommerce_currency();
167 - }
168 -
169 - /**
170 - * Check if the user is logged in.
171 - *
172 - * @return bool
173 - */
174 - public function valid_account() {
175 - return $this->gateway->user_logged_in();
176 - }
177 -
178 -
179 - /**
180 - * Check if the user is in live mode and has activated oney
181 - *
182 - * @return bool
183 - */
184 - public function valid_oney_check() {
185 - if (!isset($this->settings['mode']) || !isset($this->settings['oney'])) {
186 - return false;
187 - }
188 - return ("yes" === $this->settings['mode'] && "yes" === $this->settings['oney'] && $this->permissions->has_permissions(PayplugPermissions::USE_ONEY));
189 - }
190 -
191 - /**
192 - * Check if CGV checkbox is check
193 - *
194 - * @return bool
195 - */
196 - public function valid_oney() {
197 - if (!isset($this->settings['oneycgv'])) {
198 - return false;
199 - }
200 - return ("yes" === $this->settings['oneycgv']);
201 - }
202 -}
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 + }
171 +}