| @@ -1,149 +1,171 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Payplug\PayplugWoocommerce\Gateway; |
| 4 | 4 | |
| 5 | +use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; | |
| 6 | + | |
| 5 | 7 | // Exit if accessed directly |
| 6 | -use const OPENSSL_VERSION_TEXT; | |
| 7 | 8 | use const PHP_VERSION; |
| 8 | -use function sprintf; | |
| 9 | -use function var_dump; | |
| 10 | 9 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | - exit; | |
| 10 | +if (!defined('ABSPATH')) { | |
| 11 | + exit; | |
| 13 | 12 | } |
| 14 | 13 | |
| 15 | -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'; | |
| 16 | 19 | |
| 17 | - const PHP_MIN = '5.6'; | |
| 18 | - const OPENSSL_MIN = 268439567; | |
| 19 | - const OPENSSL_MIN_TEXT = 'OpenSSL 1.0.1 14 Mar 2012'; | |
| 20 | + /** | |
| 21 | + * @var PayplugGateway | |
| 22 | + */ | |
| 23 | + private $gateway; | |
| 20 | 24 | |
| 21 | - /** | |
| 22 | - * @var PayplugGateway | |
| 23 | - */ | |
| 24 | - private $gateway; | |
| 25 | + /** | |
| 26 | + * Gateway settings. | |
| 27 | + * | |
| 28 | + * @var array | |
| 29 | + */ | |
| 30 | + protected $settings; | |
| 25 | 31 | |
| 26 | - /** | |
| 27 | - * PayplugGatewayRequirements constructor. | |
| 28 | - * | |
| 29 | - * @param PayplugGateway $gateway | |
| 30 | - */ | |
| 31 | - public function __construct( PayplugGateway $gateway ) { | |
| 32 | - $this->gateway = $gateway; | |
| 33 | - } | |
| 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 | + } | |
| 34 | 42 | |
| 35 | - /** | |
| 36 | - * Check if all gateway requirements are fulfilled. | |
| 37 | - * | |
| 38 | - * @return bool | |
| 39 | - */ | |
| 40 | - public function satisfy_requirements() { | |
| 41 | - return $this->valid_php() | |
| 42 | - && $this->valid_curl() | |
| 43 | - && $this->valid_openssl() | |
| 44 | - && $this->valid_currency() | |
| 45 | - && $this->valid_account(); | |
| 46 | - } | |
| 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 | + } | |
| 47 | 56 | |
| 48 | - /** | |
| 49 | - * @return string | |
| 50 | - */ | |
| 51 | - public function curl_requirement() { | |
| 52 | - return ( $this->valid_curl() ) | |
| 53 | - ? '<p class="success">' . __( 'The PHP cURL extension is installed and activated on your server.', 'payplug' ) . '</p>' | |
| 54 | - : '<p class="failed">' . __( 'The PHP cURL extension must be installed and activated on your server.', 'payplug' ) . '</p>'; | |
| 55 | - } | |
| 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 | + } | |
| 56 | 67 | |
| 57 | - /** | |
| 58 | - * @return string | |
| 59 | - */ | |
| 60 | - public function php_requirement() { | |
| 61 | - return ( $this->valid_php() ) | |
| 62 | - ? '<p class="success">' . __( 'The PHP version on your server is valid.', 'payplug' ) . '</p>' | |
| 63 | - /* translators: %s: minimum required PHP version */ | |
| 64 | - : '<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>'; | |
| 65 | - } | |
| 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 | + } | |
| 66 | 78 | |
| 67 | - /** | |
| 68 | - * @return string | |
| 69 | - */ | |
| 70 | - public function openssl_requirement() { | |
| 71 | - return ( $this->valid_openssl() ) | |
| 72 | - ? '<p class="success">' . __( 'OpenSSL is up to date.', 'payplug' ) . '</p>' | |
| 73 | - /* translators: %s: minimum required OpenSSL version */ | |
| 74 | - : '<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>'; | |
| 75 | - } | |
| 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 | + } | |
| 76 | 89 | |
| 77 | - /** | |
| 78 | - * @return string | |
| 79 | - */ | |
| 80 | - public function currency_requirement() { | |
| 81 | - return ( $this->valid_currency() ) | |
| 82 | - ? '<p class="success">' . __( 'Your shop currency has been set up with Euro.', 'payplug' ) . '</p>' | |
| 83 | - : '<p class="failed">' . __( 'Your shop currency must be set up with Euro.', 'payplug' ) . '</p>'; | |
| 84 | - } | |
| 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 | + } | |
| 85 | 100 | |
| 86 | - /** | |
| 87 | - * @return string | |
| 88 | - */ | |
| 89 | - public function account_requirement() { | |
| 90 | - return ( $this->valid_account() ) | |
| 91 | - ? '<p class="success">' . __( 'You are logged in with your PayPlug account.', 'payplug' ) . '</p>' | |
| 92 | - : '<p class="failed">' . __( 'You must be logged in with your PayPlug account.', 'payplug' ) . '</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 | - * Check if CURL is available and support SSL | |
| 97 | - * | |
| 98 | - * @return bool | |
| 99 | - */ | |
| 100 | - public function valid_curl() { | |
| 101 | - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) { | |
| 102 | - return false; | |
| 103 | - } | |
| 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 | + } | |
| 104 | 122 | |
| 105 | - // Also Check for SSL support | |
| 106 | - $curl_version = curl_version(); | |
| 107 | - if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) { | |
| 108 | - return false; | |
| 109 | - } | |
| 123 | + // Also Check for SSL support | |
| 124 | + $curl_version = curl_version(); | |
| 125 | + if (!(CURL_VERSION_SSL & $curl_version['features'])) { | |
| 126 | + return false; | |
| 127 | + } | |
| 110 | 128 | |
| 111 | - return true; | |
| 112 | - } | |
| 129 | + return true; | |
| 130 | + } | |
| 113 | 131 | |
| 114 | - /** | |
| 115 | - * Check if PHP version is equal or above the minimum supported. | |
| 116 | - * | |
| 117 | - * @return bool | |
| 118 | - */ | |
| 119 | - public function valid_php() { | |
| 120 | - return version_compare( PHP_VERSION, self::PHP_MIN, '>=' ); | |
| 121 | - } | |
| 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 | + } | |
| 122 | 141 | |
| 123 | - /** | |
| 124 | - * Check if OPENSSL version is equal or above the minimum supported. | |
| 125 | - * | |
| 126 | - * @return bool | |
| 127 | - */ | |
| 128 | - public function valid_openssl() { | |
| 129 | - return OPENSSL_VERSION_NUMBER >= self::OPENSSL_MIN; | |
| 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 | - /** | |
| 133 | - * Check if the shop currency is Euro. | |
| 134 | - * | |
| 135 | - * @return bool | |
| 136 | - */ | |
| 137 | - public function valid_currency() { | |
| 138 | - return 'EUR' === get_woocommerce_currency(); | |
| 139 | - } | |
| 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 | + } | |
| 140 | 161 | |
| 141 | - /** | |
| 142 | - * Check if the user is logged in. | |
| 143 | - * | |
| 144 | - * @return bool | |
| 145 | - */ | |
| 146 | - public function valid_account() { | |
| 147 | - return $this->gateway->user_logged_in(); | |
| 148 | - } | |
| 149 | -} | |
| 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 | +} | |