| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Gateway; |
| 4 |
|
| 5 |
use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 6 |
|
| 7 |
// Exit if accessed directly |
| 8 |
use const PHP_VERSION; |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 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 |
|
| 20 |
/** |
| 21 |
* @var PayplugGateway |
| 22 |
*/ |
| 23 |
private $gateway; |
| 24 |
|
| 25 |
/** |
| 26 |
* Gateway settings. |
| 27 |
* |
| 28 |
* @var array |
| 29 |
*/ |
| 30 |
protected $settings; |
| 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 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Check if all gateway requirements are fulfilled. |
| 45 |
* |
| 46 |
* @return bool |
| 47 |
*/ |
| 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 |
} |
| 56 |
|
| 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 |
} |
| 67 |
|
| 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 |
} |
| 78 |
|
| 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 |
} |
| 89 |
|
| 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 |
} |
| 100 |
|
| 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 |
} |
| 111 |
|
| 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 |
} |
| 122 |
|
| 123 |
// Also Check for SSL support |
| 124 |
$curl_version = curl_version(); |
| 125 |
if (!(CURL_VERSION_SSL & $curl_version['features'])) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
|
| 129 |
return true; |
| 130 |
} |
| 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 |
} |
| 141 |
|
| 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 |
} |
| 151 |
|
| 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 |
} |
| 161 |
|
| 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 |
} |
| 172 |
|