PluginProbe
PayPlug for WooCommerce (Official) / 1.2.11
PayPlug for WooCommerce (Official) v1.2.11
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.11, at src/Gateway/PayplugGatewayRequirements.php

189 lines 4.7 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())
118 ? '<p class="success">' . __( 'Oney is active on your store.', 'payplug' ) . '</p>'
119 : '';
120 }
121
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 }
131
132 // Also Check for SSL support
133 $curl_version = curl_version();
134 if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) {
135 return false;
136 }
137
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 }
189 }