-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluem.php
2127 lines (1840 loc) · 66.8 KB
/
bluem.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Bluem ePayments, iDIN, eMandates services and integration for WooCommerce
* Version: 1.3.22
* Plugin URI: https://bluem.nl/en/
* Description: Bluem integration for WordPress and WooCommerce for Payments, eMandates, iDIN identity verification and more
* Author: Bluem Payment Services
* Author URI: https://bluem.nl
* Requires at least: 5.0
* Tested up to: 6.5
* Requires PHP: 8.0
*
* License: GPL v3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* Text Domain: bluem
*
* @package bluem-woocommerce
* @author Bluem Payment Services
*/
if (!defined('ABSPATH')) {
exit;
}
global $bluem_db_version;
$bluem_db_version = 1.5;
const BLUEM_WOOCOMMERCE_MANUAL_URL = "https://codexology.notion.site/Bluem-voor-WordPress-en-WooCommerce-Handleiding-9e2df5c5254a4b8f9cbd272fae641f5e";
require __DIR__ . '/vendor/autoload.php';
use Bluem\BluemPHP\Bluem;
use Bluem\Wordpress\Observability\BluemActivationNotifier;
if (!defined("BLUEM_LOCAL_DATE_FORMAT")) {
define("BLUEM_LOCAL_DATE_FORMAT", "Y-m-d\TH:i:s");
}
// get specific gateways and helpers
if (bluem_module_enabled('mandates')) {
include_once __DIR__ . '/bluem-mandates.php';
include_once __DIR__ . '/bluem-mandates-instant.php';
include_once __DIR__ . '/bluem-mandates-shortcode.php';
}
if (bluem_module_enabled('payments')) {
include_once __DIR__ . '/bluem-payments.php';
}
if (bluem_module_enabled('idin')) {
include_once __DIR__ . '/bluem-idin.php';
}
// database functions
require_once __DIR__ . '/bluem-db.php';
// interface and display functions
require_once __DIR__ . '/bluem-interface.php';
// integrations with external plugins
require_once __DIR__ . '/bluem-integrations.php';
// Observability
//require_once __DIR__ . '/Observability/SentryLogger.php';
/**
* Check if WooCommerce is activated
*/
if (!function_exists('bluem_is_woocommerce_activated')) {
function bluem_is_woocommerce_activated(): bool
{
$active_plugins = get_option('active_plugins');
if (in_array('woocommerce/woocommerce.php', $active_plugins)) {
return true;
}
return false;
}
}
/**
* Check if Contact Form 7 is activated
*/
if (!function_exists('bluem_is_contactform7_activated')) {
function bluem_is_contactform7_activated(): bool
{
$active_plugins = get_option('active_plugins');
if (in_array('contact-form-7/wp-contact-form-7.php', $active_plugins)) {
return true;
}
return false;
}
}
/**
* Check if Gravity Forms is activated
*/
if (!function_exists('bluem_is_gravityforms_activated')) {
function bluem_is_gravityforms_activated(): bool
{
$active_plugins = get_option('active_plugins');
return in_array('gravityforms', $active_plugins, true)
|| in_array('gravityforms/gravityforms.php', $active_plugins, true);
}
}
/**
* Check if Permalinks is enabled
*/
if (!function_exists('bluem_is_permalinks_enabled')) {
function bluem_is_permalinks_enabled(): bool
{
$structure = get_option('permalink_structure');
if (!empty($structure)) {
return true;
}
return false;
}
}
/**
* Check if WooCommerce is active
**/
if (!bluem_is_woocommerce_activated()) {
// No WooCommerce module found!
add_action('admin_notices', 'bluem_woocommerce_no_woocommerce_notice');
}
/**
* Check if Permalinks is enabled
**/
if (!bluem_is_permalinks_enabled()) {
// No WooCommerce module found!
add_action('admin_notices', 'bluem_woocommerce_no_permalinks_notice');
}
// Plug-in activation
function bluem_woocommerce_plugin_activate()
{
update_option('bluem_plugin_registration', false);
}
register_activation_hook(__FILE__, 'bluem_woocommerce_plugin_activate');
// Update CSS within in Admin
function bluem_add_admin_style()
{
wp_enqueue_style('admin-styles', plugin_dir_url(__FILE__) . '/css/admin.css');
}
add_action('admin_enqueue_scripts', 'bluem_add_admin_style');
// Update CSS within frontend
function bluem_add_front_style()
{
wp_register_style(
'bluem_woo_front_styles',
plugin_dir_url(__FILE__) . '/css/front.css'
);
wp_enqueue_style('bluem_woo_front_styles');
}
add_action('wp_enqueue_scripts', 'bluem_add_front_style');
// https://www.wpbeginner.com/wp-tutorials/how-to-add-admin-notices-in-wordpress/
function bluem_woocommerce_no_woocommerce_notice()
{
if (is_admin()) {
$bluem_options = get_option('bluem_woocommerce_options');
if (!isset($bluem_options['suppress_woo']) || $bluem_options['suppress_woo'] === "0") {
echo '<div class="notice notice-warning is-dismissible">
<p><span class="dashicons dashicons-warning"></span>';
/* translators: %s: the link to settings page */
printf(wp_kses_post('De Bluem integratie is grotendeels afhankelijk van WooCommerce - installeer en/of activeer deze plug-in. <br/>
Gebruik je geen WooCommerce? Dan kan je deze melding en WooCommerce gerelateerde functionaliteiten uitzetten bij de %s.', 'bluem'),
'<a href="' . esc_url(admin_url('admin.php?page=)bluem-settings')) . '">' . esc_html__('Instellingen', 'bluem') . '</a>');
echo '</p>
</div>';
}
}
}
function bluem_woocommerce_no_permalinks_notice()
{
if (is_admin()) {
echo '<div class="notice notice-warning is-dismissible">
<p><span class="dashicons dashicons-warning"></span>';
esc_html_e("De Bluem integratie is vanwege de routing afhankelijk van de WordPress Permalink instelling.<br>
Selecteer een optie BEHALVE \'Eenvoudig\' bij de Permalink", 'bluem');
echo '<a href="' . esc_url(admin_url('options-permalink.php')) . '">' . esc_html__('Instellingen', 'bluem') . '</a>.</p>
</div>';
}
}
/* ******** SETTINGS *********** */
/**
* Settings page initialisation
*
* @return void
*/
function bluem_woocommerce_settings_handler()
{
add_options_page(
esc_html__('Bluem', 'bluem'),
esc_html__('Bluem', 'bluem'),
'manage_options',
'bluem',
'bluem_settings_page'
);
}
//add_action( 'admin_menu', 'bluem_woocommerce_settings_handler' );
/**
* Register the necessary administrative pages in the WordPress back-end.
*
* @return void
*/
function bluem_register_menu()
{
add_menu_page(
esc_html__("Bluem", 'bluem'),
esc_html__("Bluem", 'bluem'),
"manage_options",
"bluem-admin",
"bluem_home",
plugins_url('bluem/assets/bluem/icon.png') //'dashicons-money'
);
add_submenu_page(
'bluem-admin',
esc_html__('Activatie', 'bluem'),
esc_html__('Activatie', 'bluem'),
'manage_options',
'bluem-activate',
'bluem_plugin_activation'
);
add_submenu_page(
'bluem-admin',
esc_html__('Transacties', 'bluem'),
esc_html__('Transacties', 'bluem'),
'manage_options',
'bluem-transactions',
'bluem_requests_view'
);
add_submenu_page(
'bluem-admin',
esc_html__('Instellingen', 'bluem'),
esc_html__('Instellingen', 'bluem'),
'manage_options',
'bluem-settings',
'bluem_settings_page'
);
add_submenu_page(
'bluem-admin',
esc_html__('Import / export', 'bluem'),
esc_html__('Import / export', 'bluem'),
'manage_options',
'bluem-importexport',
'bluem_admin_importexport'
);
add_submenu_page(
'bluem-admin',
esc_html__('Status', 'bluem'),
esc_html__('Status', 'bluem'),
'manage_options',
'bluem-status',
'bluem_admin_status'
);
}
add_action('admin_menu', 'bluem_register_menu', 9);
/**
* Get composer dependency version.
*/
function bluem_get_composer_dependency_version($dependency_name)
{
// Path to the composer.lock file
$composer_lock_path = plugin_dir_path(__FILE__) . 'composer.lock';
// Read and decode the contents of the composer.lock file
try {
$composer_lock = json_decode(file_get_contents($composer_lock_path), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
return false;
}
// Find the package entry by the dependency name
$package_entry = array_filter($composer_lock['packages'], function ($package) use ($dependency_name) {
return $package['name'] === $dependency_name;
});
// Retrieve the version constraint of the specified dependency
return reset($package_entry)['version'];
}
/**
* Bluem home page.
*/
function bluem_home()
{
$dependency_bluem_php_version = bluem_get_composer_dependency_version('bluem-development/bluem-php');
include_once 'views/home.php';
}
/**
* Bluem plug-in activation page.
*/
function bluem_plugin_activation()
{
$bluem_options = get_option('bluem_woocommerce_options');
$bluem_registration = get_option('bluem_woocommerce_registration');
$bluem_plugin_registration = get_option('bluem_plugin_registration');
$required_fields = [
'company_name',
'company_telephone',
'company_email',
'tech_name',
'tech_telephone',
'tech_email'
];
if (!empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate input
$is_valid = true;
foreach ($required_fields as $required_field) {
if (empty($_POST[$required_field]) || empty(sanitize_text_field(wp_unslash($_POST[$required_field])))) {
$is_valid = false;
}
}
if ($is_valid) {
if (!empty($_POST['acc_senderid'])) {
$acc_senderid = sanitize_text_field(wp_unslash($_POST['acc_senderid']));
} else {
$acc_senderid = '';
}
if (!empty($_POST['acc_testtoken'])) {
$acc_testtoken = sanitize_text_field(wp_unslash($_POST['acc_testtoken']));
} else {
$acc_testtoken = '';
}
if (!empty($_POST['acc_prodtoken'])) {
$acc_prodtoken = sanitize_text_field(wp_unslash($_POST['acc_prodtoken']));
} else {
$acc_prodtoken = '';
}
if (!empty($_POST['company_name'])) {
$company_name = sanitize_text_field(wp_unslash($_POST['company_name']));
} else {
$company_name = '';
}
if (!empty($_POST['company_telephone'])) {
$company_telephone = sanitize_text_field(wp_unslash($_POST['company_telephone']));
} else {
$company_telephone = '';
}
if (!empty($_POST['company_email'])) {
$company_email = sanitize_text_field(wp_unslash($_POST['company_email']));
} else {
$company_email = '';
}
if (!empty($_POST['tech_name'])) {
$tech_name = sanitize_text_field(wp_unslash($_POST['tech_name']));
} else {
$tech_name = '';
}
if (!empty($_POST['tech_telephone'])) {
$tech_telephone = sanitize_text_field(wp_unslash($_POST['tech_telephone']));
} else {
$tech_telephone = '';
}
if (!empty($_POST['tech_email'])) {
$tech_email = sanitize_text_field(wp_unslash($_POST['tech_email']));
} else {
$tech_email = '';
}
$bluem_options['senderID'] = $acc_senderid;
$bluem_options['test_accessToken'] = $acc_testtoken;
$bluem_options['production_accessToken'] = $acc_prodtoken;
$bluem_registration['company']['name'] = $company_name;
$bluem_registration['company']['telephone'] = $company_telephone;
$bluem_registration['company']['email'] = $company_email;
$bluem_registration['tech_contact']['name'] = $tech_name;
$bluem_registration['tech_contact']['telephone'] = $tech_telephone;
$bluem_registration['tech_contact']['email'] = $tech_email;
// Sent registration notify email
(new BluemActivationNotifier())->reportActivatedPlugin();
// Update Bluem options
update_option('bluem_woocommerce_options', $bluem_options);
// Update Bluem registration
update_option('bluem_woocommerce_registration', $bluem_registration);
// Set plugin registration as done
update_option('bluem_plugin_registration', true);
wp_redirect(
esc_url(admin_url("admin.php?page=bluem-activate"))
);
}
}
include_once 'views/activate.php';
}
function bluem_requests_view()
{
if (isset($_GET['request_id']) && $_GET['request_id'] !== "") {
if (isset($_GET['admin_action']) && $_GET['admin_action'] === "delete") {
bluem_db_delete_request_by_id(sanitize_text_field(wp_unslash($_GET['request_id'])));
wp_redirect(
esc_url(admin_url("admin.php?page=bluem-transactions"))
);
} elseif (isset($_GET['admin_action']) && $_GET['admin_action'] === "status-update") {
bluem_update_request_by_id(sanitize_text_field(wp_unslash($_GET['request_id'])));
bluem_requests_view_request();
} else {
bluem_requests_view_request();
}
} else {
bluem_requests_view_all();
}
}
function bluem_update_request_by_id($request_id)
{
global $wpdb;
$request_query = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM `" . $wpdb->prefix . "bluem_requests` WHERE `id` = %d LIMIT 1",
$request_id
)
);
if (count($request_query) == 0) {
bluem_requests_view_all();
return;
}
$request = (object)$request_query[0];
$payload = [];
if (!empty ($request->payload)) {
$payload = json_decode($request->payload, true);
}
$bluem_config = bluem_woocommerce_get_config();
$bluem_env = !empty($payload['environment']) ? $payload['environment'] : '';
// Check for environment
if (!empty ($bluem_env)) {
$bluem_config->environment = $bluem_env;
}
$bluem = new Bluem($bluem_config);
// Check for order
if (!empty($request->order_id)) {
$order = wc_get_order($request->order_id);
}
if ($request->type === 'identity') {
try {
$response = $bluem->IdentityStatus($request->transaction_id, $request->entrance_code);
if (!$response->ReceivedResponse()) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s<br>Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'identity',
'function' => 'identity_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
$statusCode = $response->GetStatusCode();
/**
* Update status in request
*/
if ($statusCode !== $request->status) {
$db_status = bluem_db_update_request(
$request->id,
[
'status' => $statusCode
]
);
}
/**
* Check for status
*/
if ($statusCode === "Success") {
$identityReport = $response->GetIdentityReport();
if (!empty($request->id)) {
$new_data = [];
$new_data['report'] = $identityReport;
if (count($new_data) > 0) {
bluem_db_put_request_payload(
$request->id,
$new_data
);
}
}
// } elseif ($statusCode === "Pending") {
// //
// } elseif ($statusCode === "Cancelled") {
// //
// } elseif ($statusCode === "Open") {
// //
// } elseif ($statusCode === "Expired") {
// //
// } elseif ($statusCode === "New") {
// //
// } else {
// //
}
} catch (Exception $e) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s<br>Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'identity',
'function' => 'identity_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
} elseif ($request->type === 'mandates') {
try {
$response = $bluem->MandateStatus($request->transaction_id, $request->entrance_code);
if (!$response->Status()) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s<br>Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'mandates',
'function' => 'mandates_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
$statusUpdateObject = $response->EMandateStatusUpdate;
$statusCode = $statusUpdateObject->EMandateStatus->Status . "";
/**
* Update status in request
*/
if ($statusCode !== $request->status) {
$db_status = bluem_db_update_request(
$request->id,
[
'status' => $statusCode
]
);
}
/**
* Check for status
*/
if ($statusCode === "Success") {
if (!empty ($order)) {
$order->update_status('processing', esc_html__('Authorization has been received', 'bluem'));
$order->add_order_note(esc_html__("Payment process completed", 'bluem'));
}
if (!empty($request->id)) {
$new_data = [];
if (isset($response->EMandateStatusUpdate->EMandateStatus->PurchaseID)) {
$new_data['purchaseID'] = $response->EMandateStatusUpdate->EMandateStatus->PurchaseID;
}
if (isset($response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport)) {
$new_data['report'] = $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport;
}
if (count($new_data) > 0) {
bluem_db_put_request_payload(
$request->id,
$new_data
);
}
}
// } elseif ($statusCode === "Pending") {
//
} elseif ($statusCode === "Cancelled") {
if (!empty ($order)) {
$order->update_status('cancelled', esc_html__('Authorization has been canceled', 'bluem'));
}
// } elseif ($statusCode === "Open") {
//
} elseif ($statusCode === "Expired") {
if (!empty ($order)) {
$order->update_status('failed', esc_html__('Authorization has expired', 'bluem'));
}
// } elseif ($statusCode === "New") {
//
} else {
if (!empty ($order)) {
$order->update_status('failed', esc_html__('Authorization failed: error or unknown status', 'bluem'));
}
}
} catch (Exception $e) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'mandates',
'function' => 'mandates_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
} elseif ($request->type === 'ideal' || $request->type === 'creditcard' || $request->type === 'paypal' || $request->type === 'sofort' || $request->type === 'cartebancaire') {
try {
$response = $bluem->PaymentStatus($request->transaction_id, $request->entrance_code);
if (!$response->Status()) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'payments',
'function' => 'payments_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
$statusUpdateObject = $response->PaymentStatusUpdate;
$statusCode = $statusUpdateObject->Status . "";
/**
* Update status in request
*/
if ($statusCode !== $request->status) {
$db_status = bluem_db_update_request(
$request->id,
[
'status' => $statusCode
]
);
}
/**
* Check for status
*/
if ($statusCode === "Success") {
if (!empty ($order)) {
$order->update_status('processing', esc_html__('Betaling is binnengekomen', 'bluem'));
$order->add_order_note(esc_html__("Betalingsproces voltooid", 'bluem'));
}
// } elseif ($statusCode === "Pending") {
//
} elseif ($statusCode === "Cancelled") {
if (!empty ($order)) {
$order->update_status('cancelled', esc_html__('Betaling is geannuleerd', 'bluem'));
}
// } elseif ($statusCode === "Open") {
//
} elseif ($statusCode === "Expired") {
if (!empty ($order)) {
$order->update_status('failed', esc_html__('Betaling is verlopen', 'bluem'));
}
// } elseif ($statusCode === "New") {
//
} else {
if (!empty ($order)) {
$order->update_status('failed', esc_html__('Betaling is gefaald: fout of onbekende status', 'bluem'));
}
}
} catch (Exception $e) {
$errormessage = printf(
/* translators: %s: error status */
esc_html__("Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status", 'bluem'),
esc_html($response->Error())
);
bluem_error_report_email(
[
'service' => 'payments',
'function' => 'payments_admin_status_update',
'message' => $errormessage
]
);
bluem_dialogs_render_prompt($errormessage);
exit;
}
}
}
function bluem_requests_view_request()
{
global $wpdb;
if (!isset($_GET['request_id'])) {
return;
}
$id = sanitize_text_field(wp_unslash($_GET['request_id']));
if (!is_numeric($id)) {
return;
}
$request_query = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM `" . $wpdb->prefix . "bluem_requests` WHERE `id` = %d LIMIT 1",
$id
)
);
if (count($request_query) == 0) {
bluem_requests_view_all();
return;
}
$request = (object)$request_query[0];
$request_author = get_user_by('id', $request->user_id);
$links = bluem_db_get_links_for_request($request->id);
$logs = bluem_db_get_logs_for_request($id);
include_once 'views/request.php';
}
function bluem_requests_view_all()
{
global $wpdb;
$_requests = $wpdb->get_results(
"SELECT *
FROM `" . $wpdb->prefix . "bluem_requests`
ORDER BY `type` , `timestamp` DESC"
);
$requests['mandates'] = [];
$requests['identity'] = [];
$requests['ideal'] = [];
$requests['creditcard'] = [];
$requests['paypal'] = [];
$requests['sofort'] = [];
$requests['cartebancaire'] = [];
// @todo Allow filtering on only one type
foreach ($_requests as $_r) {
$requests[($_r->type === 'payments' ? 'ideal' : $_r->type)][] = $_r;
}
$users_by_id = [];
$users = get_users();
foreach ($users as $user) {
$users_by_id[$user->ID] = $user;
}
include_once 'views/requests.php';
}
// @todo Deprecate this
function bluem_woocommerce_tab($default_tab = null)
{
return isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : $default_tab;
}
/**
* Settings page display
*
* @return void
*/
function bluem_settings_page()
{
// Get the active tab from the GET param
$tab = bluem_woocommerce_tab();
include_once 'views/settings.php';
}
function bluem_woocommerce_general_settings_section()
{
// Hier kan je alle belangrijke gegevens instellen rondom Bluem algemeen. <br>
wp_kses_post(__('<p><a id="tab_general"></a>
<div class="notice notice-warning inline" style="padding:10px;">
<span class="dashicons dashicons-unlock"></span>
Let op:
Je hebt een geactiveerde account nodig bij Bluem.
De gegevens die je ontvangt via e-mail kan je hieronder
en per specifiek onderdeel invullen.
</div>
</p>', 'bluem'));
echo "<p>";
wp_kses_post(__('<div class="notice notice-info inline" style="padding:10px;">
Heb je de plugin al geinstalleerd op een andere website?<br />
Gebruik dan de import / export functie om dezelfde instellingen
en voorkeuren in te laden.<br />', 'bluem'));
printf(
wp_kses_post(
/* translators: %s: url to import/export page */
__('Ga naar <a href="%s" class="">instellingen importeren of exporteren</a>.</div>', 'bluem')
),
esc_url(admin_url('admin.php?page=bluem-importexport'))
);
echo '</p>';
}
function bluem_woocommerce_register_settings()
{
$tab = bluem_woocommerce_tab();
register_setting(
'bluem_woocommerce_options',
'bluem_woocommerce_options',
'bluem_woocommerce_options_validate'
);
if (is_null($tab)) {
register_setting(
'bluem_woocommerce_options',
'bluem_woocommerce_modules_options',
'bluem_woocommerce_modules_options_validate'
);
add_settings_section(
'bluem_woocommerce_modules_section',
esc_html__('Manage components of this plugin', 'bluem'),
'bluem_woocommerce_modules_settings_section',
'bluem_woocommerce'
);
add_settings_field(
"mandates_enabled",
esc_html__("eMandates active", 'bluem'),
"bluem_woocommerce_modules_render_mandates_activation",
"bluem_woocommerce",
"bluem_woocommerce_modules_section"
);
add_settings_field(
"payments_enabled",
esc_html__("ePayments active", 'bluem'),
"bluem_woocommerce_modules_render_payments_activation",
"bluem_woocommerce",
"bluem_woocommerce_modules_section"
);
add_settings_field(
"idin_enabled",
esc_html__("iDIN active", 'bluem'),
"bluem_woocommerce_modules_render_idin_activation",
"bluem_woocommerce",
"bluem_woocommerce_modules_section"
);
add_settings_field(
"suppress_warning",
esc_html__("Warn in admin environment if plugin has not yet been set up properly", 'bluem'),
"bluem_woocommerce_modules_render_suppress_warning",
"bluem_woocommerce",
"bluem_woocommerce_modules_section"
);
add_settings_section(
'bluem_woocommerce_general_section',
'<span class="dashicons dashicons-admin-settings"></span> ' . esc_html__("General settings", 'bluem'),
'bluem_woocommerce_general_settings_section',
'bluem_woocommerce'
);
if (function_exists('bluem_woocommerce_get_core_options')) {
$general_settings = bluem_woocommerce_get_core_options();
foreach ($general_settings as $key => $ms) {
add_settings_field(
$key,
$ms['name'],
"bluem_woocommerce_settings_render_" . $key,
"bluem_woocommerce",
"bluem_woocommerce_general_section"
);
}
}
}
if (bluem_module_enabled('mandates')) {
add_settings_section(
'bluem_woocommerce_mandates_section',
'<span class="dashicons dashicons-money"></span> ' . esc_html__("eMandates settings", 'bluem'),
'bluem_woocommerce_mandates_settings_section',
'bluem_woocommerce'
);
if (function_exists('bluem_woocommerce_get_mandates_options')) {
$mandates_settings = bluem_woocommerce_get_mandates_options();
if (is_array($mandates_settings) && count($mandates_settings) > 0) {
foreach ($mandates_settings as $key => $ms) {
add_settings_field(
$key,
$ms['name'],
"bluem_woocommerce_settings_render_" . $key,
"bluem_woocommerce",
"bluem_woocommerce_mandates_section"
);
}
}
}
}
if (bluem_module_enabled('payments')) {
add_settings_section(
'bluem_woocommerce_payments_section',
'<span class="dashicons dashicons-money-alt"></span> ' . esc_html__("ePayments settings", 'bluem'),
'bluem_woocommerce_payments_settings_section',
'bluem_woocommerce'
);
if (function_exists('bluem_woocommerce_get_payments_options')) {
$payments_settings = bluem_woocommerce_get_payments_options();
if (is_array($payments_settings) && count($payments_settings) > 0) {
foreach ($payments_settings as $key => $ms) {
$key_name = "bluem_woocommerce_settings_render_" . $key;
add_settings_field(
$key,
$ms['name'],
$key_name,
"bluem_woocommerce",
"bluem_woocommerce_payments_section"
);
}
}
}
}
if (bluem_module_enabled('idin')) {
add_settings_section(
'bluem_woocommerce_idin_section',
'<span class="dashicons dashicons-admin-users"></span> ' . esc_html__("eIdentity settings", 'bluem'),