PluginProbe
PayPlug for WooCommerce (Official) / 2.10.0
PayPlug for WooCommerce (Official) v2.10.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 1.2.6 All 101 releases
payplug / src / PayplugWoocommerce.php

PayplugWoocommerce.php in PayPlug for WooCommerce (Official) 2.10.0, at src/PayplugWoocommerce.php

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