forked from buckaroo-it/WooCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuckaroo_Load_Gateways.php
317 lines (306 loc) · 9.34 KB
/
Buckaroo_Load_Gateways.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
316
317
<?php
/**
* Core class for loading gateways
* php version 7.2
*
* @category Payment_Gateways
* @package Buckaroo
* @author Buckaroo <[email protected]>
* @copyright 2021 Copyright (c) Buckaroo B.V.
* @license MIT https://tldrlegal.com/license/mit-license
* @version GIT: 2.25.0
* @link https://www.buckaroo.eu/
*/
class Buckaroo_Load_Gateways
{
protected $dir;
protected $methods = array(
//comment payment methods you do not want to use
'AfterPay' => array(
'filename' => 'gateway-buckaroo-afterpay.php',
'classname' => 'WC_Gateway_Buckaroo_AfterPay'
),
'AfterPayNew' => array(
'filename' => 'gateway-buckaroo-afterpaynew.php',
'classname' => 'WC_Gateway_Buckaroo_AfterPaynew'
),
'Applepay' => array(
'filename' => 'gateway-buckaroo-applepay.php',
'classname' => 'WC_Gateway_Buckaroo_Applepay'
),
'Bancontact / MisterCash' => array(
'filename' => 'gateway-buckaroo-mistercash.php',
'classname' => 'WC_Gateway_Buckaroo_MisterCash'
),
'Bank Transfer' => array(
'filename' => 'gateway-buckaroo-transfer.php',
'classname' => 'WC_Gateway_Buckaroo_Transfer'
),
'Belfius' => array(
'filename' => 'gateway-buckaroo-belfius.php',
'classname' => 'WC_Gateway_Buckaroo_Belfius'
),
'Billink' => array(
'filename' => 'gateway-buckaroo-billink.php',
'classname' => 'WC_Gateway_Buckaroo_Billink'
),
'Creditcards' => array(
'filename' => 'gateway-buckaroo-creditcard.php',
'classname' => 'WC_Gateway_Buckaroo_Creditcard'
),
'EPS' => array(
'filename' => 'gateway-buckaroo-eps.php',
'classname' => 'WC_Gateway_Buckaroo_EPS'
),
'Giftcards' => array(
'filename' =>
'gateway-buckaroo-giftcard.php',
'classname' => 'WC_Gateway_Buckaroo_Giftcard'
),
'Giropay' => array(
'filename' =>
'gateway-buckaroo-giropay.php',
'classname' => 'WC_Gateway_Buckaroo_Giropay'
),
'iDeal' => array(
'filename' =>
'gateway-buckaroo-ideal.php',
'classname' => 'WC_Gateway_Buckaroo_Ideal'
),
'In3' => array(
'filename' => 'gateway-buckaroo-in3.php',
'classname' => 'WC_Gateway_Buckaroo_In3'
),
'KBC' => array(
'filename' => 'gateway-buckaroo-kbc.php',
'classname' => 'WC_Gateway_Buckaroo_KBC'
),
'KlarnaPay' => array(
'filename' => 'gateway-buckaroo-klarnapay.php',
'classname' => 'WC_Gateway_Buckaroo_KlarnaPay'
),
'KlarnaPII' => array(
'filename' => 'gateway-buckaroo-klarnapii.php',
'classname' => 'WC_Gateway_Buckaroo_KlarnaPII'
),
'KlarnaKp' => array(
'filename' => 'gateway-buckaroo-klarnakp.php',
'classname' => 'WC_Gateway_Buckaroo_KlarnaKp'
),
'P24' => array(
'filename' =>
'gateway-buckaroo-p24.php',
'classname' => 'WC_Gateway_Buckaroo_P24'
),
'Payconiq' => array(
'filename' => 'gateway-buckaroo-payconiq.php',
'classname' => 'WC_Gateway_Buckaroo_Payconiq'
),
'PayPal' => array(
'filename' => 'gateway-buckaroo-paypal.php',
'classname' => 'WC_Gateway_Buckaroo_Paypal'
),
'PayPerEmail' => array(
'filename' => 'gateway-buckaroo-payperemail.php',
'classname' => 'WC_Gateway_Buckaroo_PayPerEmail'
),
'SepaDirectDebit' => array(
'filename' => 'gateway-buckaroo-sepadirectdebit.php',
'classname' => 'WC_Gateway_Buckaroo_SepaDirectDebit'
),
'Sofortbanking' => array(
'filename' => 'gateway-buckaroo-sofort.php',
'classname' => 'WC_Gateway_Buckaroo_Sofortbanking'
),
'PayByBank' => array(
'filename' => 'gateway-buckaroo-paybybank.php',
'classname' => 'WC_Gateway_Buckaroo_PayByBank'
),
'Multibanco' => array(
'filename' => 'gateway-buckaroo-multibanco.php',
'classname' => 'WC_Gateway_Buckaroo_Multibanco'
),
'MBWay' => array(
'filename' => 'gateway-buckaroo-mbway.php',
'classname' => 'WC_Gateway_Buckaroo_MBWay'
)
);
public function __construct($dir = null) {
if(is_null($dir)) {
$dir = plugin_dir_path(BK_PLUGIN_FILE);
}
$this->dir = $dir;
}
/**
* Load necesary
*
* @return void
*/
public function load()
{
$this->add_exodus();
$this->load_before();
$this->load_gateways();
$this->load_after();
$this->enable_creditcards_in_checkout();
}
/**
* Enable credicard method when set to be shown individually in checkout page
*
* @return void
*/
public function enable_creditcards_in_checkout()
{
if (!get_transient('buckaroo_credicard_updated')) {
return;
}
$gatewayNames = $this->get_creditcards_to_show();
if (!is_array($gatewayNames)) {
return;
}
foreach($gatewayNames as $name) {
$class = 'WC_Gateway_Buckaroo_'.ucfirst($name);
if (class_exists($class)) {
var_dump(class_exists($class));
(new $class())->update_option('enabled', 'yes');
}
}
delete_transient('buckaroo_credicard_updated');
}
/**
* Hook function for `woocommerce_payment_gateways` hook
*
* @param array $methods
*
* @return array
*/
public function hook_gateways_to_woocommerce($methods)
{
foreach ($this->sort_gateways_alfa($this->get_all_gateways()) as $method) {
$methods[] = $method['classname'];
}
return $methods;
}
/**
* load all gateways
*
* @return void
*/
protected function load_gateways()
{
foreach ($this->methods as $method) {
$file = $this->dir . $method['filename'];
if(file_exists($file)) {
require_once $file;
}
}
require_once $this->dir. "gateways-creditcard/gateway-buckaroo-creditcard-single.php";
foreach ($this->get_creditcard_methods() as $method) {
$file = $this->dir . $method['filename'];
if(file_exists($file)) {
require_once $file;
}
}
}
/**
* Get all gateways
*
* @return array
*/
protected function get_all_gateways()
{
return array_merge(
$this->methods,
$this->get_creditcard_methods()
);
}
/**
* Load before the gateways
*
* @return void
*/
protected function load_before()
{
//
}
/**
* Load after the gateways
*
* @return void
*/
protected function load_after()
{
require_once $this->dir . 'push-buckaroo.php';
}
/**
* Get credicard payment methods
*
* @return array
*/
protected function get_creditcard_methods()
{
$creditcardMethods = [];
foreach ($this->get_creditcards_to_show() as $creditcard) {
if (strlen(trim($creditcard)) !== 0) {
$creditcardMethods[$creditcard.'_creditcard'] = array(
'filename' => "gateways-creditcard/gateway-buckaroo-${creditcard}.php",
'classname' => 'WC_Gateway_Buckaroo_'.ucfirst($creditcard)
);
}
}
return $creditcardMethods;
}
/**
* Get creditcards to show in checkout page
*
* @return array
*/
public function get_creditcards_to_show()
{
$credit_settings = get_option('woocommerce_buckaroo_creditcard_settings', null);
if(
$credit_settings !== null &&
isset($credit_settings['creditcardmethod']) &&
$credit_settings['creditcardmethod'] === 'encrypt' &&
isset($credit_settings['show_in_checkout']) &&
is_array($credit_settings['show_in_checkout'])
) {
return $credit_settings['show_in_checkout'];
}
return [];
}
/**
* Sort payment gateway alphabetically by name
*
* @param array $gateway
*
* @return array
*/
protected function sort_gateways_alfa($gateways)
{
uksort(
$gateways,
function ($a, $b) {
return strcmp(
strtolower($a),
strtoLower($b)
);
}
);
return $gateways;
}
/**
* Load exodus class
*
* @return void
*/
private function add_exodus()
{
if (file_exists(dirname(BK_PLUGIN_FILE) . '/buckaroo-exodus.php') && !get_option('woocommerce_buckaroo_exodus')) {
$this->methods['Exodus Script'] = array(
'filename' => 'buckaroo-exodus.php',
'classname' => 'WC_Gateway_Buckaroo_Exodus',
);
}
}
}