-
Notifications
You must be signed in to change notification settings - Fork 9
/
reepay-woocommerce-payment.php
executable file
·315 lines (256 loc) · 10 KB
/
reepay-woocommerce-payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
* Plugin Name: Billwerk+ Pay
* Description: Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce.
* Author: Billwerk+
* Author URI: http://billwerk.plus
* Version: 1.7.10
* Text Domain: reepay-checkout-gateway
* Domain Path: /languages
* WC requires at least: 3.0.0
* WC tested up to: 9.1.4
*
* @package Reepay\Checkout
*/
use Reepay\Checkout\Api;
use Reepay\Checkout\Api\Controller\DebugController;
use Reepay\Checkout\Api\Controller\MetaFieldsController;
use Reepay\Checkout\DIContainer;
use Reepay\Checkout\Gateways;
use Reepay\Checkout\Gateways\ReepayGateway;
use Reepay\Checkout\Plugin\LifeCycle;
use Reepay\Checkout\Plugin\Statistics;
use Reepay\Checkout\Plugin\WoocommerceExists;
use Reepay\Checkout\Plugin\WoocommerceHPOS;
defined( 'ABSPATH' ) || exit();
/**
* Main plugin class
*/
class WC_ReepayCheckout {
/**
* Class instance
*
* @var WC_ReepayCheckout
*/
private static $instance;
/**
* Settings array
*
* @var array
*/
private $settings = array();
/**
* Gateways class instance
*
* @var Gateways
*/
private $gateways = null;
/**
* Dependency injection container
*
* @var DIContainer
*/
private $di_container = null;
/**
* Constructor
*/
private function __construct() {
include_once __DIR__ . '/vendor/autoload.php';
Statistics::get_instance( $this->get_setting( 'plugin_file' ) );
new LifeCycle( $this->get_setting( 'plugin_path' ) );
new WoocommerceExists();
new WoocommerceHPOS();
new Reepay\Checkout\Functions\Main();
add_action( 'plugins_loaded', array( $this, 'include_classes' ), 0 );
load_plugin_textdomain( 'reepay-checkout-gateway', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
add_action( 'rest_api_init', array( $this, 'init_rest_api' ) );
}
/**
* Get main class instance.
*
* @return WC_ReepayCheckout
*/
public static function get_instance(): WC_ReepayCheckout {
static $instance_requested = false;
if ( true === $instance_requested && is_null( self::$instance ) ) {
$message = 'Function Billwerk+ Pay called in time of initialization main plugin class. Recursion prevented';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$message .= '<br>Stack trace for debugging:<br><pre>' . print_r( //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
true
) . '</pre>';
}
wp_die( $message );
}
$instance_requested = true;
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Get plugin or reepay checkout gateway setting
*
* @param string $name Setting key.
*
* @return string|string[]|null
*/
public function get_setting( string $name ) {
if ( empty( $this->settings ) ) {
$gateway_settings = get_option( 'woocommerce_reepay_checkout_settings' );
if ( ! is_array( $gateway_settings ) ) {
$gateway_settings = array();
}
if ( isset( $gateway_settings['private_key'] ) ) {
$gateway_settings['private_key'] = apply_filters( 'woocommerce_reepay_private_key', $gateway_settings['private_key'] );
}
if ( isset( $gateway_settings['private_key_test'] ) ) {
$gateway_settings['private_key_test'] = apply_filters( 'woocommerce_reepay_private_key_test', $gateway_settings['private_key_test'] );
}
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$plugin_data = get_plugin_data( __FILE__ );
$this->settings = array(
'plugin_version' => $plugin_data['Version'],
'plugin_file' => __FILE__,
'plugin_basename' => plugin_basename( __FILE__ ),
'plugin_url' => plugin_dir_url( __FILE__ ),
'plugin_path' => plugin_dir_path( __FILE__ ),
'templates_url' => plugin_dir_url( __FILE__ ) . 'templates/',
'templates_path' => plugin_dir_path( __FILE__ ) . 'templates/',
'css_url' => plugin_dir_url( __FILE__ ) . 'assets/dist/css/',
'css_path' => plugin_dir_path( __FILE__ ) . 'assets/dist/css/',
'js_url' => plugin_dir_url( __FILE__ ) . 'assets/dist/js/',
'js_path' => plugin_dir_path( __FILE__ ) . 'assets/dist/js/',
'images_url' => plugin_dir_url( __FILE__ ) . 'assets/images/',
'images_path' => plugin_dir_path( __FILE__ ) . 'assets/images/',
'assets_url' => plugin_dir_url( __FILE__ ) . 'assets/',
'assets_path' => plugin_dir_path( __FILE__ ) . 'assets/',
'vite_url' => plugin_dir_url( __FILE__ ) . 'assets/dist/vite/',
'vite_path' => plugin_dir_path( __FILE__ ) . 'assets/dist/vite/',
'languages_path' => plugin_dir_path( __FILE__ ) . 'languages/',
'private_key' => ! empty( $gateway_settings['private_key'] ) ? $gateway_settings['private_key'] : '',
'private_key_test' => ! empty( $gateway_settings['private_key_test'] ) ? $gateway_settings['private_key_test'] : '',
'test_mode' => ! empty( $gateway_settings['test_mode'] ) ? $gateway_settings['test_mode'] : '',
'settle' => ! empty( $gateway_settings['settle'] ) ? $gateway_settings['settle'] : array(),
'language' => ! empty( $gateway_settings['language'] ) ? $gateway_settings['language'] : '',
'debug' => ! empty( $gateway_settings['debug'] ) ? $gateway_settings['debug'] : '',
'show_meta_fields_in_orders' => ! empty( $gateway_settings['show_meta_fields_in_orders'] ) ? $gateway_settings['show_meta_fields_in_orders'] : '',
'show_meta_fields_in_users' => ! empty( $gateway_settings['show_meta_fields_in_users'] ) ? $gateway_settings['show_meta_fields_in_users'] : '',
'disable_auto_settle' => ! empty( $gateway_settings['disable_auto_settle'] ) ? $gateway_settings['disable_auto_settle'] : '',
'payment_type' => ! empty( $gateway_settings['payment_type'] ) ? $gateway_settings['payment_type'] : '',
'skip_order_lines' => ! empty( $gateway_settings['skip_order_lines'] ) ? $gateway_settings['skip_order_lines'] : '',
'enable_order_autocancel' => ! empty( $gateway_settings['enable_order_autocancel'] ) ? $gateway_settings['enable_order_autocancel'] : '',
'is_webhook_configured' => ! empty( $gateway_settings['is_webhook_configured'] ) ? $gateway_settings['is_webhook_configured'] : '',
'handle_failover' => ! empty( $gateway_settings['handle_failover'] ) ? $gateway_settings['handle_failover'] : '',
'payment_button_text' => ! empty( $gateway_settings['payment_button_text'] ) ? $gateway_settings['payment_button_text'] : '',
'enable_sync' => ! empty( $gateway_settings['enable_sync'] ) ? $gateway_settings['enable_sync'] : '',
'status_created' => ! empty( $gateway_settings['status_created'] ) ? $gateway_settings['status_created'] : '',
'status_authorized' => ! empty( $gateway_settings['status_authorized'] ) ? $gateway_settings['status_authorized'] : '',
'status_settled' => ! empty( $gateway_settings['status_settled'] ) ? $gateway_settings['status_settled'] : '',
'logo_height' => ! empty( $gateway_settings['logo_height'] ) ? $gateway_settings['logo_height'] : '',
);
}
return $this->settings[ $name ] ?? null;
}
/**
* Reset options from database. Now using only for testing purposes
*/
public function reset_settings() {
$this->settings = null;
$this->get_setting( '' );
}
/**
* Wrapper of wc_get_template function
*
* @param string $template Template name.
* @param array $args Arguments.
* @param bool $return_template Return or echo template.
*/
public function get_template( string $template, array $args = array(), bool $return_template = false ) {
if ( $return_template ) {
ob_start();
}
wc_get_template(
$template,
$args,
'',
$this->get_setting( 'templates_path' )
);
if ( $return_template ) {
return ob_get_clean();
}
return true;
}
/**
* Set logging source.
*
* @param ReepayGateway|WC_Order|string $source Source for logging.
*
* @return Api
*/
public function api( $source ): Api {
/**
* Api instance
*
* @var Api $api
*/
$api = $this->di()->get( Api::class );
$api->set_logging_source( $source );
return $api;
}
/**
* Get gateways class instance
*
* @return Gateways|null
*/
public function gateways(): ?Gateways {
return $this->gateways;
}
/**
* Get dependency injection container
*
* @return DIContainer
*/
public function di(): DIContainer {
if ( is_null( $this->di_container ) ) {
$this->di_container = new DIContainer();
}
return $this->di_container;
}
/**
* WooCommerce Loaded: load classes
*
* @return void
*/
public function include_classes() {
if ( ! WoocommerceExists::woo_activated() ) {
return;
}
new Reepay\Checkout\Admin\Main();
new Reepay\Checkout\Tokens\Main();
new Reepay\Checkout\Plugin\UpdateDB();
new Reepay\Checkout\OrderFlow\Main();
$this->gateways = new Reepay\Checkout\Gateways();
new Reepay\Checkout\Integrations\Main();
new Reepay\Checkout\Frontend\Main();
new Reepay\Checkout\Actions\Main();
}
/**
* Init rest api
*
* @return void
*/
public function init_rest_api(): void {
( new MetaFieldsController() )->register_routes();
( new DebugController() )->register_routes();
}
}
/**
* Get reepay checkout instance
*
* @return WC_ReepayCheckout
*/
function reepay(): WC_ReepayCheckout {
return WC_ReepayCheckout::get_instance();
}
reepay();