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

188 lines 4.5 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
135 $methods[] = __NAMESPACE__ . '\\Gateway\\Bancontact';
136 $methods[] = __NAMESPACE__ . '\\Controller\\ApplePay';
137 $methods[] = __NAMESPACE__ . '\\Gateway\\AmericanExpress';
138 $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Mybank';
139 $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Giropay';
140 $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Ideal';
141 $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Sofort';
142 $methods[] = __NAMESPACE__ . '\\Gateway\\PPRO\\Satispay';
143
144 return $methods;
145 }
146
147 /**
148 * Add additional action links.
149 *
150 * @param array $links
151 *
152 * @return array
153 */
154 public function plugin_action_links( $links = [] ) {
155 $plugin_links = [
156 '<a href="' . esc_url( PayplugWoocommerceHelper::get_setting_link() ) . '">' . esc_html__( 'Settings', 'payplug' ) . '</a>',
157 ];
158
159 return array_merge( $plugin_links, $links );
160 }
161
162 public function animationHandlers()
163 {
164 $options = get_option('woocommerce_payplug_settings', []);
165
166 //if live and don't have country setted on the option
167 if ( !isset($options['payplug_merchant_country']) ) {
168 $options['payplug_merchant_country'] = PayplugWoocommerceHelper::UpdateCountryOption($options);
169 }
170
171 //failsafe
172 if( empty($options['payplug_merchant_country']) || empty($options['oney_type']) ){
173 return ;
174 }
175
176 if( !class_exists( "\\Payplug\\PayplugWoocommerce\\Front\\PayplugOney\\Country\\Oney" .$options['payplug_merchant_country'] )){
177 return ;
178 }
179
180
181 //check if the options has the Country setted
182 Switch($options['oney_type']){
183 case "without_fees" : new OneyWithoutFees();break;
184 default: new OneyWithFees();break;
185 }
186 }
187 }
188