PluginProbe
PayPlug for WooCommerce (Official) / 2.4.1
PayPlug for WooCommerce (Official) v2.4.1
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.4.1, at src/PayplugWoocommerce.php

182 lines 4.2 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\Bancontact;
15 use Payplug\PayplugWoocommerce\Controller\ApplePay;
16 use Payplug\PayplugWoocommerce\Front\PayplugOney\Requests\OneyWithFees;
17 use Payplug\PayplugWoocommerce\Front\PayplugOney\Requests\OneyWithoutFees;
18 use Payplug\PayplugWoocommerce\Gateway\PayplugGateway;
19
20 class PayplugWoocommerce {
21
22 /**
23 * @var PayplugWoocommerce
24 */
25 private static $instance;
26
27 /**
28 * PayPlug admin notices
29 *
30 * @var Notices
31 */
32 public $notices;
33
34 /**
35 * PayPlug metabox
36 *
37 * @var Metabox
38 */
39 public $metabox;
40
41 /**
42 * Custom woocommerce actions
43 *
44 * @var WoocommerceActions
45 */
46 public $actions;
47
48 /**
49 * @var PayplugWoocommerceRequest
50 */
51 public $requests;
52
53 /**
54 * Ajax actions handler
55 *
56 * @var Ajax
57 */
58 public $ajax;
59
60 /**
61 * Get the singleton instance.
62 *
63 * @return PayplugWoocommerce
64 */
65 public static function get_instance() {
66 if ( is_null( self::$instance ) ) {
67 self::$instance = new static();
68 }
69
70 return self::$instance;
71 }
72
73 /**
74 * Singleton instance can't be cloned.
75 */
76 private function __clone() {
77 }
78
79 /**
80 * Singleton instance can't be serialized.
81 */
82 public function __wakeup() {
83 }
84
85 /**
86 * PayplugWoocommerce constructor.
87 */
88 private function __construct() {
89
90 // Bail early if WooCommerce is not activated
91 if ( ! defined( 'WC_VERSION' ) ) {
92 add_action( 'admin_notices', function () {
93 ?>
94 <div id="message" class="notice notice-error">
95 <p><?php _e( 'PayPlug requires an active version of WooCommerce', 'payplug' ); ?></p>
96 </div>
97 <?php
98 } );
99
100 return;
101 }
102
103 if ( PayplugWoocommerceHelper::is_pre_30() ) {
104 require_once PAYPLUG_GATEWAY_PLUGIN_DIR . '/woocommerce-compat.php';
105 }
106
107 $this->notices = new Notices();
108 $this->metabox = new Metabox();
109 $this->actions = new WoocommerceActions();
110 $this->requests = new PayplugWoocommerceRequest();
111 $this->ajax = new Ajax();
112
113 if( PayplugWoocommerceHelper::show_oney_popup() ) {
114 $this->animationHandlers();
115 }
116
117 add_action( 'woocommerce_payment_gateways', [ $this, 'register_payplug_gateway' ] );
118 add_filter( 'plugin_action_links_' . PAYPLUG_GATEWAY_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] );
119 }
120
121 /**
122 * Register PayPlug gateway.
123 *
124 * @param $methods
125 *
126 * @return array
127 */
128 public function register_payplug_gateway( $methods ) {
129 $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGateway';
130 $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3x';
131 $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4x';
132 $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney3xWithoutFees';
133 $methods[] = __NAMESPACE__ . '\\Gateway\\PayplugGatewayOney4xWithoutFees';
134 $methods[] = __NAMESPACE__ . '\\Controller\\Bancontact';
135 $methods[] = __NAMESPACE__ . '\\Controller\\ApplePay';
136 $methods[] = __NAMESPACE__ . '\\Controller\\AmericanExpress';
137
138 return $methods;
139 }
140
141 /**
142 * Add additional action links.
143 *
144 * @param array $links
145 *
146 * @return array
147 */
148 public function plugin_action_links( $links = [] ) {
149 $plugin_links = [
150 '<a href="' . esc_url( PayplugWoocommerceHelper::get_setting_link() ) . '">' . esc_html__( 'Settings', 'payplug' ) . '</a>',
151 ];
152
153 return array_merge( $plugin_links, $links );
154 }
155
156 public function animationHandlers()
157 {
158 $options = get_option('woocommerce_payplug_settings', []);
159
160 //if live and don't have country setted on the option
161 if ( !isset($options['payplug_merchant_country']) ) {
162 $options['payplug_merchant_country'] = PayplugWoocommerceHelper::UpdateCountryOption($options);
163 }
164
165 //failsafe
166 if( empty($options['payplug_merchant_country']) || empty($options['oney_type']) ){
167 return ;
168 }
169
170 if( !class_exists( "\\Payplug\\PayplugWoocommerce\\Front\\PayplugOney\\Country\\Oney" .$options['payplug_merchant_country'] )){
171 return ;
172 }
173
174
175 //check if the options has the Country setted
176 Switch($options['oney_type']){
177 case "without_fees" : new OneyWithoutFees();break;
178 default: new OneyWithFees();break;
179 }
180 }
181 }
182