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

181 lines 4.1 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
19 class PayplugWoocommerce {
20
21 /**
22 * @var PayplugWoocommerce
23 */
24 private static $instance;
25
26 /**
27 * PayPlug admin notices
28 *
29 * @var Notices
30 */
31 public $notices;
32
33 /**
34 * PayPlug metabox
35 *
36 * @var Metabox
37 */
38 public $metabox;
39
40 /**
41 * Custom woocommerce actions
42 *
43 * @var WoocommerceActions
44 */
45 public $actions;
46
47 /**
48 * @var PayplugWoocommerceRequest
49 */
50 public $requests;
51
52 /**
53 * Ajax actions handler
54 *
55 * @var Ajax
56 */
57 public $ajax;
58
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 }
68
69 return self::$instance;
70 }
71
72 /**
73 * Singleton instance can't be cloned.
74 */
75 private function __clone() {
76 }
77
78 /**
79 * Singleton instance can't be serialized.
80 */
81 public function __wakeup() {
82 }
83
84 /**
85 * PayplugWoocommerce constructor.
86 */
87 private function __construct() {
88
89 // Bail early if WooCommerce is not activated
90 if ( ! defined( 'WC_VERSION' ) ) {
91 add_action( 'admin_notices', function () {
92 ?>
93 <div id="message" class="notice notice-error">
94 <p><?php _e( 'PayPlug requires an active version of WooCommerce', 'payplug' ); ?></p>
95 </div>
96 <?php
97 } );
98
99 return;
100 }
101
102 if ( PayplugWoocommerceHelper::is_pre_30() ) {
103 require_once PAYPLUG_GATEWAY_PLUGIN_DIR . '/woocommerce-compat.php';
104 }
105
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();
111
112 if( PayplugWoocommerceHelper::show_oney_popup() ) {
113 $this->animationHandlers();
114 }
115
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 }
119
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';
136
137 return $methods;
138 }
139
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 ];
151
152 return array_merge( $plugin_links, $links );
153 }
154
155 public function animationHandlers()
156 {
157 $options = get_option('woocommerce_payplug_settings', []);
158
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 }
163
164 //failsafe
165 if( empty($options['payplug_merchant_country']) ){
166 return ;
167 }
168
169 if( !class_exists( "\\Payplug\\PayplugWoocommerce\\Front\\PayplugOney\\Country\\Oney" .$options['payplug_merchant_country'] )){
170 return ;
171 }
172
173
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 }
180 }
181