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/PayplugWoocommerce.php +194 -137 1.10.0 → 3.1.0 View file →
@@ -2,179 +2,236 @@
2 2
3 3 namespace Payplug\PayplugWoocommerce;
4 4
5 5 // Exit if accessed directly
6 -if ( ! defined( 'ABSPATH' ) ) {
7 - exit;
6 +if (!defined('ABSPATH')) {
7 + exit;
8 8 }
9 9
10 10 use Payplug\PayplugWoocommerce\Admin\Ajax;
11 11 use Payplug\PayplugWoocommerce\Admin\Metabox;
12 12 use Payplug\PayplugWoocommerce\Admin\Notices;
13 +use Payplug\PayplugWoocommerce\Admin\SetupCallback;
13 14 use Payplug\PayplugWoocommerce\Admin\WoocommerceActions;
14 -use Payplug\PayplugWoocommerce\Controller\Bancontact;
15 -use Payplug\PayplugWoocommerce\Controller\ApplePay;
16 -use Payplug\PayplugWoocommerce\Front\PayplugOney\Requests\OneyWithFees;
17 -use Payplug\PayplugWoocommerce\Front\PayplugOney\Requests\OneyWithoutFees;
15 +use Payplug\PayplugWoocommerce\Front\Oney\OneyDisplay;
16 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugAmex;
17 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugApplePay;
18 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugBancontact;
19 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugBizum;
20 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugCreditCard;
21 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugIdeal;
22 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugMybank;
23 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugOney3x;
24 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugOney3xWithoutFees;
25 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugOney4x;
26 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugOney4xWithoutFees;
27 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugSatispay;
28 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugScalapay;
29 +use Payplug\PayplugWoocommerce\Gateway\Blocks\PayplugWero;
30 +use Payplug\PayplugWoocommerce\Traits\GatewayGetter;
31 +use Payplug\PayplugWoocommerce\Traits\ServiceGetter;
18 32
19 -class PayplugWoocommerce {
33 +class PayplugWoocommerce
34 +{
35 + use ServiceGetter;
36 + use GatewayGetter;
20 37
21 - /**
22 - * @var PayplugWoocommerce
23 - */
24 - private static $instance;
38 + /**
39 + * @var PayplugWoocommerce
40 + */
41 + private static $instance;
25 42
26 - /**
27 - * PayPlug admin notices
28 - *
29 - * @var Notices
30 - */
31 - public $notices;
43 + /**
44 + * PayPlug admin notices
45 + *
46 + * @var Notices
47 + */
48 + public $notices;
32 49
33 - /**
34 - * PayPlug metabox
35 - *
36 - * @var Metabox
37 - */
38 - public $metabox;
50 + /**
51 + * PayPlug metabox
52 + *
53 + * @var Metabox
54 + */
55 + public $metabox;
39 56
40 - /**
41 - * Custom woocommerce actions
42 - *
43 - * @var WoocommerceActions
44 - */
45 - public $actions;
57 + /**
58 + * Custom woocommerce actions
59 + *
60 + * @var WoocommerceActions
61 + */
62 + public $actions;
46 63
47 - /**
48 - * @var PayplugWoocommerceRequest
49 - */
50 - public $requests;
64 + /**
65 + * @var PayplugWoocommerceRequest
66 + */
67 + public $requests;
51 68
52 - /**
53 - * Ajax actions handler
54 - *
55 - * @var Ajax
56 - */
57 - public $ajax;
69 + /**
70 + * Ajax actions handler
71 + *
72 + * @var Ajax
73 + */
74 + public $ajax;
58 75
59 - /**
60 - * Get the singleton instance.
61 - *
62 - * @return PayplugWoocommerce
63 - */
64 - public static function get_instance() {
65 - if ( is_null( self::$instance ) ) {
66 - self::$instance = new static();
67 - }
76 + /**
77 + * PayPlug Setup authentifications.
78 + *
79 + * @var SetupCallback
80 + */
81 + public $setup_callback;
68 82
69 - return self::$instance;
70 - }
83 + /**
84 + * Get the singleton instance.
85 + *
86 + * @return PayplugWoocommerce
87 + */
88 + public static function get_instance()
89 + {
90 + if (is_null(self::$instance)) {
91 + self::$instance = new static();
92 + }
71 93
72 - /**
73 - * Singleton instance can't be cloned.
74 - */
75 - private function __clone() {
76 - }
94 + return self::$instance;
95 + }
77 96
78 - /**
79 - * Singleton instance can't be serialized.
80 - */
81 - public function __wakeup() {
82 - }
97 + /**
98 + * Singleton instance can't be cloned.
99 + */
100 + private function __clone()
101 + {
102 + }
83 103
84 - /**
85 - * PayplugWoocommerce constructor.
86 - */
87 - private function __construct() {
104 + /**
105 + * Singleton instance can't be serialized.
106 + */
107 + public function __wakeup(): void
108 + {
109 + }
88 110
89 - // Bail early if WooCommerce is not activated
90 - if ( ! defined( 'WC_VERSION' ) ) {
91 - add_action( 'admin_notices', function () {
92 - ?>
111 + /**
112 + * PayplugWoocommerce constructor.
113 + */
114 + private function __construct()
115 + {
116 + // Bail early if WooCommerce is not activated
117 + if (!defined('WC_VERSION')) {
118 + add_action('admin_notices', function (): void {
119 + ?>
93 120 <div id="message" class="notice notice-error">
94 - <p><?php _e( 'PayPlug requires an active version of WooCommerce', 'payplug' ); ?></p>
121 + <p><?php _e('PayPlug requires an active version of WooCommerce', 'payplug'); ?></p>
95 122 </div>
96 123 <?php
97 - } );
124 + });
98 125
99 - return;
100 - }
126 + return;
127 + }
101 128
102 - if ( PayplugWoocommerceHelper::is_pre_30() ) {
103 - require_once PAYPLUG_GATEWAY_PLUGIN_DIR . '/woocommerce-compat.php';
104 - }
129 + $this->check_upgrade();
105 130
106 - $this->notices = new Notices();
107 - $this->metabox = new Metabox();
108 - $this->actions = new WoocommerceActions();
109 - $this->requests = new PayplugWoocommerceRequest();
110 - $this->ajax = new Ajax();
131 + if (PayplugWoocommerceHelper::is_pre_30()) {
132 + require_once PAYPLUG_GATEWAY_PLUGIN_DIR . '/woocommerce-compat.php';
133 + }
111 134
112 - if( PayplugWoocommerceHelper::show_oney_popup() ) {
113 - $this->animationHandlers();
114 - }
135 + $this->notices = new Notices();
136 + $this->metabox = new Metabox();
137 + $this->actions = new WoocommerceActions();
138 + $this->requests = new PayplugWoocommerceRequest();
139 + new Front\ApplePay();
140 + $this->ajax = new Ajax();
115 141
116 - add_action( 'woocommerce_payment_gateways', [ $this, 'register_payplug_gateway' ] );
117 - add_filter( 'plugin_action_links_' . PAYPLUG_GATEWAY_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] );
118 - }
142 + $this->setup_callback = new SetupCallback();
119 143
120 - /**
121 - * Register PayPlug gateway.
122 - *
123 - * @param $methods
124 - *
125 - * @return array
126 - */
127 - public function register_payplug_gateway( $methods ) {
128 - $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGateway';
129 - $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3x';
130 - $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4x';
131 - $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3xWithoutFees';
132 - $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4xWithoutFees';
133 - $methods[] = __NAMESPACE__ . '\\Controller\\Bancontact';
134 - $methods[] = __NAMESPACE__ . '\\Controller\\ApplePay';
135 - $methods[] = __NAMESPACE__ . '\\Controller\\AmericanExpress';
144 + if (PayplugWoocommerceHelper::show_oney_popup()) {
145 + $this->animationHandlers();
146 + }
136 147
137 - return $methods;
138 - }
148 + add_action('woocommerce_payment_gateways', [$this, 'register_payplug_gateway']);
139 149
140 - /**
141 - * Add additional action links.
142 - *
143 - * @param array $links
144 - *
145 - * @return array
146 - */
147 - public function plugin_action_links( $links = [] ) {
148 - $plugin_links = [
149 - '<a href="' . esc_url( PayplugWoocommerceHelper::get_setting_link() ) . '">' . esc_html__( 'Settings', 'payplug' ) . '</a>',
150 - ];
150 + // Registers WooCommerce Blocks integration.
151 + add_action('woocommerce_blocks_loaded', [$this, 'woocommerce_gateways_block_support']);
151 152
152 - return array_merge( $plugin_links, $links );
153 - }
153 + add_filter('plugin_action_links_' . PAYPLUG_GATEWAY_PLUGIN_BASENAME, [$this, 'plugin_action_links']);
154 + }
154 155
155 - public function animationHandlers()
156 - {
157 - $options = get_option('woocommerce_payplug_settings', []);
156 + /**
157 + * Register PayPlug gateway.
158 + *
159 + * @param $methods
160 + *
161 + * @return array
162 + */
163 + public function register_payplug_gateway($methods)
164 + {
165 + $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugCreditCard';
166 + $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3x';
167 + $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4x';
168 + $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3xWithoutFees';
169 + $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4xWithoutFees';
170 + $methods[] = __NAMESPACE__ . '\\Gateway\\Bancontact';
171 + $methods[] = __NAMESPACE__ . '\\Gateway\\AmericanExpress';
172 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Mybank';
173 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Ideal';
174 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Satispay';
175 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Wero';
176 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Bizum';
177 + $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Scalapay';
158 178
159 - //if live and don't have country setted on the option
160 - if ( !isset($options['payplug_merchant_country']) ) {
161 - $options['payplug_merchant_country'] = PayplugWoocommerceHelper::UpdateCountryOption($options);
162 - }
179 + $methods[] = __NAMESPACE__ . '\\Controller\\ApplePay';
163 180
164 - //failsafe
165 - if( empty($options['payplug_merchant_country']) ){
166 - return ;
167 - }
181 + return $methods;
182 + }
168 183
169 - if( !class_exists( "\\Payplug\\PayplugWoocommerce\\Front\\PayplugOney\\Country\\Oney" .$options['payplug_merchant_country'] )){
170 - return ;
171 - }
184 + /**
185 + * Add additional action links.
186 + *
187 + * @param array $links
188 + *
189 + * @return array
190 + */
191 + public function plugin_action_links($links = [])
192 + {
193 + $plugin_links = [
194 + '<a href="' . esc_url(PayplugWoocommerceHelper::get_setting_link()) . '">' . esc_html__('Settings', 'payplug') . '</a>',
195 + ];
172 196
197 + return array_merge($plugin_links, $links);
198 + }
173 199
174 - //check if the options has the Country setted
175 - Switch($options['oney_type']){
176 - case "without_fees" : new OneyWithoutFees();break;
177 - default: new OneyWithFees();break;
178 - }
179 - }
200 + public function animationHandlers(): void
201 + {
202 + new OneyDisplay();
203 + }
204 +
205 + /**
206 + * Registers WooCommerce Blocks integration.
207 + */
208 + public function woocommerce_gateways_block_support(): void
209 + {
210 + if (class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) {
211 + add_action(
212 + 'woocommerce_blocks_payment_method_type_registration',
213 + function (\Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry): void {
214 + $payment_method_registry->register(new PayplugCreditCard());
215 + $payment_method_registry->register(new PayplugBancontact());
216 + $payment_method_registry->register(new PayplugSatispay());
217 + $payment_method_registry->register(new PayplugAmex());
218 + $payment_method_registry->register(new PayplugIdeal());
219 + $payment_method_registry->register(new PayplugMybank());
220 + $payment_method_registry->register(new PayplugWero());
221 + $payment_method_registry->register(new PayplugBizum());
222 + $payment_method_registry->register(new PayplugScalapay());
223 + $payment_method_registry->register(new PayplugApplePay());
224 + $payment_method_registry->register(new PayplugOney3x());
225 + $payment_method_registry->register(new PayplugOney4x());
226 + $payment_method_registry->register(new PayplugOney3xWithoutFees());
227 + $payment_method_registry->register(new PayplugOney4xWithoutFees());
228 + }
229 + );
230 + }
231 + }
232 +
233 + private function check_upgrade()
234 + {
235 + return $this->get_service('upgrade')->run_upgrade();
236 + }
180 237 }