PluginProbe
PayPlug for WooCommerce (Official) / 1.2.4
PayPlug for WooCommerce (Official) v1.2.4
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 1.2.6 All 101 releases
payplug / src / Gateway / PayplugGatewayRequirements.php

PayplugGatewayRequirements.php in PayPlug for WooCommerce (Official) 1.2.4, at src/Gateway/PayplugGatewayRequirements.php

202 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Gateway;
4
5 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
6
7 // Exit if accessed directly
8 use const OPENSSL_VERSION_TEXT;
9 use const PHP_VERSION;
10 use function sprintf;
11 use function var_dump;
12 use Payplug\PayplugWoocommerce\Gateway\PayplugPermissions;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 class PayplugGatewayRequirements {
19
20 const PHP_MIN = '5.6';
21 const OPENSSL_MIN = 268439567;
22 const OPENSSL_MIN_TEXT = 'OpenSSL 1.0.1 14 Mar 2012';
23
24 /**
25 * @var PayplugGateway
26 */
27 private $gateway;
28
29
30 /**
31 * @var PayplugPermissions
32 */
33 private $permissions;
34
35 /**
36 * Gateway settings.
37 *
38 * @var array
39 */
40 protected $settings;
41
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 }
52
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 }
65
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 }
74
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 }
84
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 }
94
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 }
103
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 }
112
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 }
122
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 // Also Check for SSL support
134 $curl_version = curl_version();
135 if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) {
136 return false;
137 }
138
139 return true;
140 }
141
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 }