-
Notifications
You must be signed in to change notification settings - Fork 5
/
Vipps.class.php
4605 lines (3973 loc) · 234 KB
/
Vipps.class.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
/*
This class is for hooks and plugin managent, and is instantiated as a singleton and set globally as $Vipps. IOK 2018-02-07
For WP-specific interactions.
This file is part of the plugin Pay with Vipps and MobilePay for WooCommerce
Copyright (c) 2019 WP-Hosting AS
MIT License
Copyright (c) 2019 WP-Hosting AS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
require_once(dirname(__FILE__) . "/VippsAPIException.class.php");
class Vipps {
private static $instance = null;
/* Used to interact with other payment gateways if neccessary (for 'external payment gateways') IOK 2024-05-27 */
public static $installed_gateways = [];
/* This directory stores the files used to speed up the callbacks checking the order status. IOK 2018-05-04 */
private $callbackDirname = 'wc-vipps-status';
private $countrymap = null;
// Used to provide the order in a callback to the session handler etc. IOK 2019-10-21
public $callbackorder = 0;
// True if HPOS is being used
public $HPOSActive = null;
// used in the fake locking mechanism using transients
private $lockKey = null;
public $vippsJSConfig = array();
// IOK 2023-11-29 Vipps merging with MobilePay causes some challenges which we solve by abstraction
public static function CompanyName() {
return __("Vipps MobilePay", 'woo-vipps');
}
public static function CheckoutName($order=null) {
return "Vipps MobilePay Checkout"; // Do not translate
}
public static function ExpressCheckoutName($order=null) {
return __("Vipps Express Checkout", 'woo-vipps');
}
public static function LoginName() {
return __("Login with Vipps", 'woo-vipps');
}
public static function RecurringName() {
return __('Vipps Recurring Payments', 'woo-vipps');
}
public static function instance() {
if (!static::$instance) static::$instance = new Vipps();
return static::$instance;
}
// To simplify development, we load translations from the plugins' own .mos on development branches. IOK 2023-11-28
public static function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
$development = apply_filters('woo_vipps_use_plugin_translations', false);
if (!$development) {
return load_plugin_textdomain($domain, $deprecated, $plugin_rel_path);
}
// Available since 6.1.0 only IOK 2023-01-25
global $wp_textdomain_registry;
if ($wp_textdomain_registry) {
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
$mofile = $domain . '-' . $locale . '.mo';
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
$wp_textdomain_registry->set_custom_path( $domain, $path );
return load_textdomain( $domain, $path . '/' . $mofile, $locale );
}
}
public static function register_hooks() {
$Vipps = static::instance();
register_activation_hook(dirname(__FILE__) . "/woo-vipps.php",array($Vipps,'activate'));
register_deactivation_hook(dirname(__FILE__) . "/woo-vipps.php",array('Vipps','deactivate'));
register_uninstall_hook(dirname(__FILE__) . "/woo-vipps.php", 'Vipps::uninstall');
if (is_admin()) {
add_action('admin_init',array($Vipps,'admin_init'));
add_action('admin_menu',array($Vipps,'admin_menu'));
} else {
add_action('wp_footer', array($Vipps,'footer'));
}
add_action( 'plugins_loaded', array($Vipps,'plugins_loaded'));
add_action( 'after_setup_theme', array($Vipps,'after_setup_theme'));
add_action('init',array($Vipps,'init'));
add_action( 'woocommerce_loaded', array($Vipps,'woocommerce_loaded'));
add_filter( 'woocommerce_available_payment_gateways', array($Vipps, 'payment_gateway_filter'));
}
// Some different bits and pieces: If we are on the pay-for-order page, we cannot provide Vipps for an order that has been at Vipps. IOK 2024-05-17
public function payment_gateway_filter ($gateways) {
if (is_checkout_pay_page()) {
$orderid = absint(get_query_var( 'order-pay'));
$order = $orderid ? wc_get_order($orderid) : null;
if (is_a($order, 'WC_Order')) {
$isavipps = $order->get_meta('_vipps_init_timestamp');
// Existing override that allows repayment. IOK 2024-06-04
$allow_repayment = class_exists('\Site\Plugins\WooVipps\WooVippsPayForOrder');
$allow_repayment = $isavipps ? apply_filters('woo_vipps_allow_repayment', $allow_repayment, $order) : true;
if ($isavipps && !$allow_repayment) unset($gateways['vipps']);
}
}
return $gateways;
}
// Get the singleton WC_GatewayVipps instance
public function gateway() {
if (class_exists('WC_Payment_Gateway')) {
require_once(dirname(__FILE__) . "/WC_Gateway_Vipps.class.php");
return WC_Gateway_Vipps::instance();
} else {
$this->log(__("Error: Cannot instantiate payment gateway, because WooCommerce is not loaded! This can happen when WooCommerce updates itself; but if it didn't, please activate WooCommerce again", 'woo-vipps'), 'error');
return null;
}
}
// These are strings that should be available for translation possibly at some future point. Partly to be easier to work with translate.wordpress.org
// Other usages are to translate any dynamic strings that may come from APIs etc. IOK 2021-03-18
private function translatable_strings() {
// Nothing here right now
return false;
}
// True iff support for HPOS has been activated IOK 2022-12-07
public function useHPOS() {
if ($this->HPOSActive == null) {
// Current way of checking IOK 2023-12-19
if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil')) {
if (Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled()) {
$this->HPOSActive = true;
} else {
$this->HPOSActive = false;
}
return $this->HPOSActive;
}
// This works in the backend, so ensures we are good with the meta fields etc.
if (function_exists('wc_get_container') && // 4.4.0
function_exists('wc_get_page_screen_id') && // Part of HPOS, not yet released
class_exists("Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController") &&
wc_get_container()->get( Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() ) {
$this->HPOSActive = true;
} else {
$this->HPOSActive = false;
}
}
return $this->HPOSActive;
}
public function init () {
// Register certain scripts in wp_loaded because they will be added to the backend as well - the gutenberg checkout block
// needs these to be defined in the backend. IOK 2024-04-16
add_action('wp_loaded', array($this, 'wp_register_scripts'));
add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
// Remove the possibility of restarting failed orders etc. This will be fixed in the future. IOK 2023-05-26
add_filter('woocommerce_my_account_my_orders_actions', array($this,'woocommerce_my_account_my_orders_actions'), 10, 2);
// Used in 'compat mode' only to add products to the cart
add_filter('woocommerce_add_to_cart_redirect', array($this, 'woocommerce_add_to_cart_redirect'), 10, 1);
$this->add_shortcodes();
$this->maybe_add_vipps_badge_feature();
// Handle the asynch call to send Order Management data on payment complete - this will push order data to the users' Vipps app
add_action('admin_post_nopriv_woo_vipps_order_management', array($this, 'do_order_management'));
add_action('admin_post_woo_vipps_order_management', array($this, 'do_order_management'));
// Extra order actions on the order screen, now using ajax to be compatible with HPOS. IOK 2022-12-02
add_action('wp_ajax_woo_vipps_order_action', array($this, 'order_handle_vipps_action'));
// Activate support for Vipps Checkout, including creating the special checkout page etc. Triggered from the payment page.
add_action('wp_ajax_woo_vipps_activate_checkout_page', function () {
check_ajax_referer('woo_vipps_activate_checkout','_wpnonce');
update_option('woo_vipps_checkout_activated', true, true); // This will load Vipps Checkout functionality from now on
$this->maybe_create_vipps_pages(); // Ensure the special page exists
if (isset($_REQUEST['activate']) && $_REQUEST['activate']) {
$this->gateway()->update_option('vipps_checkout_enabled', 'yes');
} else {
$this->gateway()->update_option('vipps_checkout_enabled', 'no');
}
});
// We need a 5-minute scheduled event for the handler for missed callbacks. Using the
// action scheduler would be better, but we can't do that just yet because of backwards
// compatibility. At some point, support for older woo-versions should be dropped; then this
// should use the action scheduler instead. IOK 2021-06-21
add_filter('cron_schedules', function ($schedules) {
if(!isset($schedules["5min"])){
$schedules["5min"] = array(
'interval' => 5*60,
'display' => __('Once every 5 minutes'));
}
return $schedules;
});
// Offload work to wp-cron so it can be done in the background on sites with heavy load IOK 2020-04-01
add_action('vipps_cron_cleanup_hook', array($this, 'cron_cleanup_hook'));
// Check periodically for orders that are stuck pending with no callback IOK 2021-06-21
add_action('vipps_cron_missing_callback_hook', array($this, 'cron_check_for_missing_callbacks'));
// For the rest, we need to read the payment gateways setting, and the payment gateway may not actually
// exist at this point. This is because for it to exist, WooCommerce must have loaded, and if it hasn't, for instance
// because it is self-updating or because it has been deactivated just now or something, we won't have access to it.
// Therefore test it first. IOK 2022-12-08
$gw = $this->gateway();
// This is a developer-mode level feature because flock() is not portable. This ensures callbacks and shopreturns do not
// simultaneously update the orders, in particular not the express checkout order lines wrt shipping. IOK 2020-05-19
if ($gw && $gw->get_option('use_flock') == 'yes') {
add_filter('woo_vipps_lock_order', array($this,'flock_lock_order'));
add_action('woo_vipps_unlock_order', array($this, 'flock_unlock_order'));
}
}
// IOK 2022-12-02 This is currently used in two places: In the code that finds orders marked "to be deleted", and
// in the getOrderIdByVippsOrderId function. This is for the old-style Woo order tables, and do nothing for HPOS right now.
// This should however be replaced by its own table so it can be done more efficiently.
public static function add_wc_order_meta_key_support() {
if (did_action('woo_vipps_add_order_meta_key_support')) return;
do_action('woo_vipps_add_order_meta_key_support');
add_filter('woocommerce_order_data_store_cpt_get_orders_query', function ($query, $query_vars) {
if (isset($query_vars['meta_vipps_orderid']) && $query_vars['meta_vipps_orderid'] ) {
if (!isset($query['meta_query'])) $query['meta_query'] = array();
$query['meta_query'][] = array(
'key' => '_vipps_orderid',
'value' => $query_vars['meta_vipps_orderid']
);
}
if (isset($query_vars['meta_vipps_delendum']) && $query_vars['meta_vipps_delendum'] ) {
if (!isset($query['meta_query'])) $query['meta_query'] = array();
$query['meta_query'][] = array(
'key' => '_vipps_delendum',
'value' => 1
);
}
return $query;
}, 10, 2);
}
public function admin_init () {
$gw = $this->gateway();
require_once(dirname(__FILE__) . "/admin/settings/VippsAdminSettings.class.php");
$adminSettings = VippsAdminSettings::instance();
// Stuff for the Order screen
add_action('woocommerce_order_item_add_action_buttons', array($this, 'order_item_add_action_buttons'), 10, 1);
require_once(dirname(__FILE__) . "/VippsDismissibleAdminBanners.class.php");
VippsDismissibleAdminBanners::add();
// Styling etc
add_action('admin_head', array($this, 'admin_head'));
// Scripts
add_action('admin_enqueue_scripts', array($this,'admin_enqueue_scripts'));
// Redirect the default WooCommerce settings page to our own
add_action( 'woocommerce_settings_start', function () {
add_filter('admin_url', function ($url, $path) {
if (strpos($path, "tab=checkout§ion=vipps") === false) return $url;
$qs = parse_url($path, PHP_URL_QUERY);
if (!$qs) return $url;
$args = [];
parse_str($qs, $args);
$ok = (($args['page']??false) == 'wc-settings') && (($args['tab']??false) == 'checkout') && (($args['section']??false) == 'vipps');
if (!$ok) return $url;
return admin_url("/admin.php?page=vipps_settings_menu");
}, 10, 2);
});
// Custom product properties
// IOK 2024-01-17 temporary: The special product properties are currenlty only active for Vipps - FIXME
if (WC_Gateway_Vipps::instance()->get_payment_method_name() == "Vipps") {
add_filter('woocommerce_product_data_tabs', array($this,'woocommerce_product_data_tabs'),99);
add_action('woocommerce_product_data_panels', array($this,'woocommerce_product_data_panels'),99);
add_action('woocommerce_process_product_meta', array($this, 'process_product_meta'), 10, 2);
}
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
// Keep admin notices during redirects IOK 2018-05-07
add_action('admin_notices',array($this,'stored_admin_notices'));
// Ajax just for the backend
add_action('wp_ajax_vipps_create_shareable_link', array($this, 'ajax_vipps_create_shareable_link'));
add_action('wp_ajax_vipps_payment_details', array($this, 'ajax_vipps_payment_details'));
add_action('wp_ajax_vipps_update_admin_settings', array($adminSettings, 'ajax_vipps_update_admin_settings'));
// POST actions for the backend
add_action('admin_post_update_vipps_badge_settings', array($this, 'update_badge_settings'));
add_action('admin_post_vipps_delete_webhook', array($this, 'vipps_delete_webhook'));
add_action('admin_post_vipps_add_webhook', array($this, 'vipps_add_webhook'));
// Link to the settings page from the plugin list
add_filter( 'plugin_action_links_'.plugin_basename( plugin_dir_path( __FILE__ ) . 'woo-vipps.php'), array($this, 'plugin_action_links'));
if ($gw->enabled == 'yes' && $gw->is_test_mode()) {
$what = sprintf(__('%1$s is currently in test mode - no real transactions will occur', 'woo-vipps'), Vipps::CompanyName());
$this->add_vipps_admin_notice($what,'info', '', 'test-mode');
}
// This requires merchants using the old shipping callback filter to choose between this or the new shipping method mechanism. IOK 2020-02-17
if (has_action('woo_vipps_shipping_methods')) {
$option = $gw->get_option('newshippingcallback');
if ($option != 'old' && $option != 'new') {
$what = __('Your theme or a plugin is currently overriding the <code>\'woo_vipps_shipping_methods\'</code> filter to customize your shipping alternatives. While this works, this disables the newer Express Checkout shipping system, which is neccessary if your shipping is to include metadata. You can do this, or stop this message, from the <a href="%1$s">settings page</a>', 'woo-vipps');
$this->add_vipps_admin_notice($what,'info');
}
}
// IOK 2020-04-01 If the plugin is updated, the normal 'activate' hook may not run. Add the scheduled events if not present.
// Normal updates will not need this, but if updates are 'sideloaded', it is neccessary still. This call will only do work if the
// jobs are not scheduled. We'll ensure the action is active first time an admin logs in.
if (!defined('DOING_AJAX') || !DOING_AJAX) {
static::maybe_add_cron_event();
if (!get_option('woo-vipps-configured')) {
list($ok, $msg) = $gw->check_connection();
if (!$ok){
if ($msg) {
$this->add_vipps_admin_notice(sprintf(__("<p>%1\$s not yet correctly configured: please go to <a href='%2\$s'>the %1\$s settings</a> to complete your setup:<br> %3\$s</p>", 'woo-vipps'), Vipps::CompanyName(), admin_url('/admin.php?page=vipps_settings_menu'), $msg));
} else {
$this->add_vipps_admin_notice(sprintf(__("<p>%1\$s not yet configured: please go to <a href='%2\$s'>the %1\$s settings</a> to complete your setup!</p>", 'woo-vipps'), Vipps::CompanyName(), admin_url('/admin.php?page=vipps_settings_menu')));
}
}
}
// If we are configured, but we don't have any webhooks yet, initialize them for the epayment api. IOK 2023-12-20
// if we do have them, check them for consistency
if (get_option('woo-vipps-configured')) {
if (empty(get_option('_woo_vipps_webhooks'))) {
$gw->initialize_webhooks();
} else {
$ok = $gw->check_webhooks();
if (!$ok) $gw->initialize_webhooks();
}
}
}
}
// Runs on init, adds the Vipps badge feature if activated
public function maybe_add_vipps_badge_feature () {
$badge_options = get_option('vipps_badge_options');
if (!$badge_options || !@$badge_options['badgeon']) return false;
add_action('wp_enqueue_scripts', function () { wp_enqueue_script('vipps-onsite-messageing'); });
add_action('woocommerce_before_add_to_cart_form', function () use ($badge_options) {
global $product;
if (!is_a($product, 'WC_Product')) return;
$show = intval(@$badge_options['defaultall']);
$forthis = $product->get_meta('_vipps_show_badge', true);
$dontshow = ($forthis == 'none');
$doshow = !$dontshow && ($show || ($forthis && $forthis != 'none'));
if (!apply_filters('woo_vipps_show_vipps_badge_for_product', $doshow, $product)) {
return;
}
$attr = "";
if ($forthis != 'none' || isset($badge_options['variant'])) {
$variant = ($forthis && $forthis != 'none') ? $forthis : $badge_options['variant'];
$attr .= " variant='" . sanitize_title($variant) . "' ";
}
$lang = $this->get_customer_language();
if ($lang) {
$attr .= " language='". $lang . "' ";
}
$brand = $this->get_payment_method_name();
if ($brand) $attr .= " brand='". strtolower($brand) . "' ";
$badge = "<vipps-mobilepay-badge $attr></vipps-mobilepay-badge>";
echo apply_filters('woo_vipps_product_badge_html', $badge);
});
}
// A small interface for editing and managing the webhooks for the MSNs for this site IOK 2023-12-20
public function webhook_menu_page () {
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You don\'t have sufficient rights to access this page', 'woo-vipps'));
}
$portalurl = 'https://portal.vippsmobilepay.com';
$webhookapi = 'https://developer.vippsmobilepay.com/docs/APIs/webhooks-api/';
echo "<div class='wrap vipps-badge-settings'>\n";
echo "<h1>" . __('Webhooks', 'woo-vipps') . "</h1>\n";
echo "<p>"; printf(__('Whenever an event like a payment or a cancellation occurs on a %1$s account, you can be notified of this using a <i>webhook</i>. This is used by this plugin to get noticed of payments by users even when they do not return to your store.', 'woo-vipps'), Vipps::CompanyName()); echo "</p>";
echo "<p>"; __('To do this, the plugin will automatically add webhooks for the MSN - Merchant Serial Numbers - configured on this site', 'woo-vipps'); echo "</p>";
echo "<p>"; __('If your MSN has registered other callbacks, for instance for another website, you can manage these here - and you can also add your own hooks that will be notified of payment events to any other URL you enter.', 'woo-vipps'); echo "</p>";
echo "<p>"; printf(__('Implementing a webhook is not trivial, so you will probably need a developer for this. You can read more about what is required <a href="%1$s">here</a>. ', 'woo-vipps'), $webhookapi);
printf(__('Please note that there is normally a limit of <em><strong>5</strong> webhooks per MSN</em> - contact %1$s if you need more', 'woo-vipps'), Vipps::CompanyName());
echo "</p>";
echo "<p>"; print __('The following is a listing of your webhooks. If you have changed your website name, you may see some hooks that you do not recognize - these should be deleted', 'woo-vipps'); echo "</p>";
$keyset = $this->gateway()->get_keyset();
$allhooks = $this->gateway()->initialize_webhooks();
$localhooks = get_option('_woo_vipps_webhooks');
echo "<form method='post' action='" . admin_url("admin-post.php") . "' autocomplete='off' id=webhook_action_form>";
echo "<input type='hidden' id='webhook_id' name='webhook_id' value='' autocomplete='false'>";
echo "<input type='hidden' id='webhook_msn' name='webhook_msn' value='' autocomplete='false'>";
echo "<input type='hidden' id='webhook_url' name='webhook_url' value='' autocomplete='false'>";
echo "<input type='hidden' id='webhook_events' name='webhook_events' value='' autocomplete='false'>";
echo "<input type='hidden' id='webhook_post_action' name='action' value='' autocomplete='false'>";
wp_nonce_field('webhook_nonce', 'webhook_nonce');
echo "</form>";
foreach ($keyset as $msn => $data) {
$testmode = $data['testmode'] ?? false;
echo "<div style='margin-top: 2rem; margin-bottom: 2rem'>";
echo "<h2>";
echo sprintf(__('Merchant Serial Number %1$s', 'woo-vipps'), $msn);
if ($testmode) echo " (" . __('Test mode', 'woo-vipps') . ")";
echo "<a style='float:right; font-size:smaller' class='webhook-adder' href='javascript:void(0)' data-msn='" . esc_attr($msn) . "'>[" . __('Add a webhook to this MSN', 'woo-vipps') . "]</a>";
echo "</h2>";
$all = $allhooks[$msn] ?? [];
$thehooks = $all['webhooks'] ?? [];
$locals = $localhooks[$msn] ?? [];
echo "<table class='table webhook-table'><thead><tr><th style='text-align: left'>" . __('Webhook', 'woo-vipps') . "</th><th>" . __('Action', 'woo-vipps') . "</th>" . "</tr></thead>";
echo "<tbody>";
foreach($thehooks as $hook) {
$id = $hook['id'];
$url = $hook['url'];
$events = $hook['events'];
$local = $locals[$id] ?? false;
echo "<tr" . ($local ? " class='local' " : '') . " data-webhook-id='" . esc_attr($id) . "' data-msn='" . esc_attr($msn) . "'";
echo " data-hookdata='" . json_encode($hook) . "'>";
echo "<td>" . esc_html($url) . "</td>";
echo "<td class='actions'>";
echo "<a href='javascript:void(0)' class='webhook-viewer'>[" . __('View', 'woo-vipps') . "]</a> ";
if (!$local) {
echo " <a href='javascript:void(0)' class='webhook-deleter'>[" . __('Delete', 'woo-vipps') . "]</a>";
} else {
echo " <em>". __('Created for this site', 'woo-vipps') . "</em>";
}
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
echo "<hr>";
}
$epayment_events = [__('Created', 'woo-vipps') => 'epayments.payment.created.v1',
__('Aborted', 'woo-vipps') => 'epayments.payment.aborted.v1',
__('Expired', 'woo-vipps') => 'epayments.payment.expired.v1',
__('Cancelled', 'woo-vipps') => 'epayments.payment.cancelled.v1',
__('Captured', 'woo-vipps') => 'epayments.payment.captured.v1',
__('Refunded', 'woo-vipps') => 'epayments.payment.refunded.v1',
__('Authorized', 'woo-vipps') => 'epayments.payment.authorized.v1',
__('Terminated', 'woo-vipps') => 'epayments.payment.terminated.v1'];
$recurring_events = [ __('Agreement accepted', 'woo-vipps') =>'recurring.agreement-activated.v1',
__('Agreement rejected', 'woo-vipps') =>'recurring.agreement-rejected.v1',
__('Agreement stopped', 'woo-vipps') =>'recurring.agreement-stopped.v1',
__('Agreement expired', 'woo-vipps') =>'recurring.agreement-expired.v1',
__('Charge reserved', 'woo-vipps') =>'recurring.charge-reserved.v1',
__('Charge captured', 'woo-vipps') =>'recurring.charge-captured.v1',
__('Charge cancelled', 'woo-vipps') =>'recurring.charge-canceled.v1',
__('Charge failed', 'woo-vipps') =>'recurring.charge-failed.v1'];
$qr_events = [__('User Checked in', 'woo-vipps')=> 'user.checked-in.v1'];
$defaultevents = ['epayments.payment.authorized.v1', 'epayments.payment.aborted.v1', 'epayments.payment.expired.v1', 'epayments.payment.terminated.v1'];
?>
<dialog id='webhook_view_dialog' style='width:70%'>
<form method="dialog">
<div class='viewdata' style='margin-bottom: 3rem'>
<label>ID</label><span class='webhook_id'></span>
<label>URL</label><span class='webhook_url'></span>
<label>Events</label><div style='width:80%' class='webhook_events'></div>
</div>
<button class="button btn button-primary" type="submit" value="OK"><?php _e('OK'); ?></button>
</form>
</dialog>
<dialog id='webhook_add_dialog' style='width: 70%'>
<form method="dialog">
<h3><?php _e('Add a webhook', 'woo-vipps'); ?></h3>
<label for='dialog_webhook_msn'>MSN</label><input style='width: 50%' id='dialog_webhook_msn' required readonly type="text" name="webhook_msn" placeholder="">
<label for='dialog_webhook_url'>URL</label><input style='width: 50%' id='dialog_webhook_url' autofocus required type="url" name="webhook_url" placeholder="https://...">
<div class="events" style="margin-bottom: 2rem">
<h3>Epayment</h3>
<?php foreach($epayment_events as $label=>$event): ?>
<label for='<?php echo esc_attr($event); ?>'><?php echo esc_html($label);?>
<input <?php if (in_array($event, $defaultevents)) echo " checked " ?>
type='checkbox' name='webhook_event' value='<?php echo esc_attr($event); ?>'>
</label>
<?php endforeach; ?>
<h3>Recurring</h3>
<?php foreach($recurring_events as $label=>$event): ?>
<label for='<?php echo esc_attr($event); ?>'><?php echo esc_html($label);?>
<input <?php if (in_array($event, $defaultevents)) echo " checked " ?>
type='checkbox' name='webhook_event' value='<?php echo esc_attr($event); ?>'>
</label>
<?php endforeach; ?>
<h3>QR</h3>
<?php foreach($qr_events as $label=>$event): ?>
<label for='<?php echo esc_attr($event); ?>'><?php echo esc_html($label);?>
<input <?php if (in_array($event, $defaultevents)) echo " checked " ?>
type='checkbox' name='webhook_event' value='<?php echo esc_attr($event); ?>'>
</label>
<?php endforeach; ?>
</div>
<div class='buttonholder'>
<button class="button btn button-primary" type="submit" value="OK"><?php _e('Add this URL as a webhook', 'woo-vipps'); ?></button>
<button class="button btn" type="submit" formnovalidate value="NO"><?php _e('No, forget it', 'woo-vipps'); ?></button>
</div>
</form>
</dialog>
<style>
dialog#webhook_add_dialog::backdrop {
background-color: rgba(0.9,0.9,0.9,0.7);
}
</style>
<script>
let dialog = document.getElementById('webhook_add_dialog');
let viewdialog = document.getElementById('webhook_view_dialog');
dialog.addEventListener('close', function () {
if (dialog.returnValue =='OK') {
let msn = dialog.querySelector('input[name="webhook_msn"]').value;
let url = dialog.querySelector('input[name="webhook_url"]').value;
dialog.querySelector('input[name="webhook_url"]').value = "";
dialog.querySelector('input[name="webhook_msn"]').value = "";
let events = dialog.querySelectorAll('input[name="webhook_event"]:checked');
let eventlist = [];
let eventstring = '';
for (const ev of events.values()) {
eventlist.push(ev.value);
}
eventstring = eventlist.join(',');
if (msn && url && eventstring) {
jQuery('#webhook_msn').val(msn);
jQuery('#webhook_post_action').val('vipps_add_webhook');
jQuery('#webhook_url').val(url);
jQuery('#webhook_events').val(eventstring);
let f = jQuery('#webhook_action_form');
f.submit();
}
}
dialog.querySelector('input[name="webhook_url"]').value = "";
dialog.querySelector('input[name="webhook_msn"]').value = "";
});
let data = "";
jQuery('a.webhook-viewer').click(function (e) {
e.preventDefault();
let row= jQuery(this).closest('tr');
data = row.data('hookdata');
viewdialog.querySelector('.viewdata').querySelector('.webhook_id').innerHTML= data['id'];
viewdialog.querySelector('.viewdata').querySelector('.webhook_url').innerHTML= data['url'];
viewdialog.querySelector('.viewdata').querySelector('.webhook_events').innerHTML= data['events'].join(" ");
viewdialog.showModal();
});
jQuery('a.webhook-deleter').click(function (e) {
e.preventDefault();
let row = jQuery(this).closest('tr');
let wh = row.data('webhook-id');
let msn = row.data('msn');
let f = jQuery('#webhook_action_form');
jQuery('#webhook_id').val(wh);
jQuery('#webhook_msn').val(msn);
jQuery('#webhook_post_action').val('vipps_delete_webhook');
f.submit();
});
jQuery('a.webhook-adder').click(function (e) {
e.preventDefault();
let msn = jQuery(this).data('msn');
dialog.querySelector('input[name="webhook_url"]').value = "";
dialog.querySelector('input[name="webhook_msn"]').value = msn;
dialog.showModal();
});
</script>
<?php
echo "</div>";
}
// To be called in admin-post.php
public function vipps_delete_webhook() {
$ok = wp_verify_nonce($_REQUEST['webhook_nonce'],'webhook_nonce');
if (!$ok) {
wp_die("Wrong nonce");
}
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You don\'t have sufficient rights', 'woo-vipps'));
}
$msn = sanitize_title($_REQUEST['webhook_msn']);
$id = sanitize_title($_REQUEST['webhook_id']);
if ($msn && $id) {
$this->gateway()->api->delete_webhook($msn, $id);
}
wp_safe_redirect(admin_url("admin.php?page=vipps_webhook_menu"));
exit();
}
// To be called in admin-post.php
public function vipps_add_webhook() {
$ok = wp_verify_nonce($_REQUEST['webhook_nonce'],'webhook_nonce');
if (!$ok) {
wp_die("Wrong nonce");
}
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You don\'t have sufficient rights', 'woo-vipps'));
}
$msn = sanitize_title($_REQUEST['webhook_msn']);
$url = sanitize_url($_REQUEST['webhook_url']);
$events = [];
foreach(explode(",", $_REQUEST['webhook_events']) as $event) {
$events[] = $event;
}
if (!empty($events) && $msn && $url) {
$this->gateway()->api->register_webhook($msn, $url, $events);
}
wp_safe_redirect(admin_url("admin.php?page=vipps_webhook_menu"));
exit();
}
public function badge_menu_page () {
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You don\'t have sufficient rights to access this page', 'woo-vipps'));
}
$badge_options = get_option('vipps_badge_options');
$variants = ['white'=> __('White', 'woo-vipps'), 'grey' => __('Grey','woo-vipps'),
'filled'=> __('Filled', 'woo-vipps'), 'light'=>__('Light','woo-vipps'),
'purple'=> __('Purple', 'woo-vipps')];
?>
<script src="https://checkout.vipps.no/on-site-messaging/v1/vipps-osm.js"></script>
<div class='wrap vipps-badge-settings'>
<h1><?php echo sprintf(__('%1$s On-Site Messaging', 'woo-vipps'), Vipps::CompanyName()); ?></h1>
<h3><?php echo sprintf(__('%1$s On-Site Messaging contains <em>badges</em> in different variants that can be used to let your customers know that %1$s payment is accepted.', 'woo-vipps'), Vipps::CompanyName()); ?></h3>
<p>
<?php _e('You can configure these badges on this page, turning them on in all or some products and configure their default setup. You can also add a badge using a shortcode or a Block', 'woo-vipps'); ?>
</p>
<h2> <?php _e('Settings', 'woo-vipps'); ?></h2>
<form class="vipps-badge-settings" action="<?php echo admin_url('admin-post.php'); ?>" method="POST">
<input type="hidden" name="action" value="update_vipps_badge_settings" />
<?php wp_nonce_field( 'badgeaction', 'badgenonce'); ?>
<div>
<label for="badgeon"><?php echo sprintf(__('Turn on support for %1$s On-site Messaging badges', 'woo-vipps'), Vipps::CompanyName()); ?></label>
<input type="hidden" name="badgeon" value="0" />
<input <?php if (@$badge_options['badgeon']) echo " checked "; ?> value="1" type="checkbox" id="badgeon" name="badgeon" />
</div>
<div>
<label for="defaultall"><?php _e('Add badge to all products by default', 'woo-vipps'); ?></label>
<input type="hidden" name="defaultall" value="0" />
<input <?php if (@$badge_options['defaultall']) echo " checked "; ?> value="1" type="checkbox" id="defaultall" name="defaultall" />
<p><?php echo sprintf(__("If selected, all products will get a badge, but you can override this on the %1\$s tab on the product data page. If not, it's the other way around. You can also choose a particular variant on that page", 'woo-vipps'), Vipps::CompanyName()); ?></p>
</div>
<p id=badgeholder style="font-size:1.5rem">
<vipps-mobilepay-badge id="vipps-badge-demo"
<?php if (@$badge_options['brand']) echo ' brand="' . esc_attr(strtolower($this->get_payment_method_name())) . '" ' ?>
<?php if (@$badge_options['variant']) echo ' variant="' . esc_attr($badge_options['variant']) . '" ' ?>
></vipps-mobilepay-badge>
</p>
<div>
<label for="vippsBadgeVariant"><?php _e('Variant', 'woo-vipps'); ?></label>
<select id=vippsBadgeVariant name="variant" onChange='changeVariant()'>
<option value=""><?php _e('Choose color variant:', 'woo-vipps'); ?></option>
<?php foreach($variants as $key=>$name): ?>
<option value="<?php echo $key; ?>" <?php if (@$badge_options['variant'] == $key) echo " selected "; ?> >
<?php echo $name ; ?>
</option>
<?php endforeach; ?>
</select>
<input type="hidden" name="brand" value="<?php echo strtolower($this->get_payment_method_name())?>" />
<div>
<input class="btn button primary" type="submit" value="<?php _e('Update settings', 'woo-vipps'); ?>" />
</div>
</form>
<h2><?php _e('The Gutenberg Block', 'woo-vipps'); ?></h2>
<p><?php echo sprintf(__('If you use Gutenberg, you should be able to add a %1$s Badge block wherever you need it. It is called %1$s On-Site Messaging Badge Block.', 'woo-vipps'), Vipps::CompanyName()); ?>
<h2><?php _e('Shortcodes', 'woo-vipps'); ?> </h2>
<p><?php echo sprintf(__('If you need to add a %1$s badge on a specific page, footer, header and so on, and you cannot use the Gutenberg Block provided for this, you can either add the %1$s Badge manually (as <a href="%2$s" nofollow rel=nofollow target=_blank>documented here</a>) or you can use the shortcode.', 'woo-vipps'), Vipps::CompanyName(), "https://developer.vippsmobilepay.com/docs/knowledge-base/design-guidelines/on-site-messaging/"); ?></p>
<br><?php _e("The shortcode looks like this:", 'woo-vipps')?><br>
<pre>[vipps-mobilepay-badge variant={white|filled|light|grey|purple}<br> language={en|no|fi|dk} ] </pre><br>
<?php _e("Please refer to the documentation for the meaning of the parameters.", 'woo-vipps'); ?></br>
<?php _e("The brand will be automatically applied.", 'woo-vipps'); ?>
</p>
</div>
<script>
function changeVariant() {
let badge = document.getElementById('vipps-badge-demo');
let variantSelector = document.getElementById('vippsBadgeVariant');
let holder = document.getElementById('badgeholder');
let newbadge = badge.cloneNode();
let variant = variantSelector.options[variantSelector.selectedIndex].value
newbadge.setAttribute('variant', variant);
badge.remove();
holder.appendChild(newbadge);
}
</script>
<?php
}
public function update_badge_settings () {
$ok = wp_verify_nonce($_REQUEST['badgenonce'],'badgeaction');
if (!$ok) {
wp_die("Wrong nonce");
}
if (!current_user_can('manage_woocommerce')) {
echo json_encode(array('ok'=>0,'msg'=>__('You don\'t have sufficient rights to edit this product', 'woo-vipps')));
wp_die(__('You don\'t have sufficient rights to edit this product', 'woo-vipps'));
}
$current = get_option('vipps_badge_options');
if (isset($_POST['badgeon'])) {
$current['badgeon'] = intval($_POST['badgeon']);
}
if (isset($_POST['defaultall'])) {
$current['defaultall'] = intval($_POST['defaultall']);
}
if (isset($_POST['variant'])) {
$current['variant'] = sanitize_title($_POST['variant']);
}
update_option('vipps_badge_options', $current);
wp_safe_redirect(admin_url("admin.php?page=vipps_badge_menu"));
exit();
}
public function vipps_mobilepay_badge_shortcode($atts) {
$args = shortcode_atts( array('id'=>'', 'class'=>'', 'brand' => '', 'variant' => '','language'=>''), $atts );
$variant = in_array($args['variant'], ['orange', 'light-orange', 'grey','white', 'purple', 'filled', 'light']) ? $args['variant'] : "";
$language = in_array($args['language'], ['en','no', 'fi', 'dk']) ? $args['language'] : $this->get_customer_language();
// $amount = intval($args['amount']);
// $later = $args['vipps-senere'];
$id = sanitize_title($args['id']);
$class = sanitize_text_field($args['class']);
$attributes = [];
$attributes['brand'] = strtolower($this->get_payment_method_name());
if ($variant) $attributes['variant'] = $variant;
if ($language) $attributes['language'] = $language;
// if ($amount) $attributes['amount'] = $amount;
// if ($later) $attributes['vipps-senere'] = 1;
if ($id) $attributes['id'] = $id;
if ($class) $attributes['class'] = $class;
$badgeatts = "";
foreach($attributes as $key=>$value) $badgeatts .= " $key=\"" . esc_attr($value) . '"';
return "<vipps-mobilepay-badge $badgeatts></vipps-mobilepay-badge>";
}
// legacy vipps_badge shortcode. LP 19.11.2024
public function vipps_badge_shortcode($atts) {
$args = shortcode_atts( array('id'=>'', 'class'=>'','variant' => '','language'=>''), $atts );
$variant = in_array($args['variant'], ['orange', 'light-orange', 'grey','white', 'purple']) ? $args['variant'] : "";
$language = in_array($args['language'], ['en','no', 'dk', 'fi']) ? $args['language'] : $this->get_customer_language();
$id = sanitize_title($args['id']);
$class = sanitize_text_field($args['class']);
$attributes = [];
if ($variant) $attributes['variant'] = $variant;
if ($language) $attributes['language'] = $language;
if ($id) $attributes['id'] = $id;
if ($class) $attributes['class'] = $class;
$badgeatts = "";
foreach($attributes as $key=>$value) $badgeatts .= " $key=\"" . esc_attr($value) . '"';
return "<vipps-badge $badgeatts></vipps-badge>";
}
public function admin_menu_page () {
$flavour = sanitize_title($this->get_payment_method_name());
// The function which is hooked in to handle the output of the page must check that the user has the required capability as well. (manage_woocommerce)
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You don\'t have sufficient rights to access this page', 'woo-vipps'));
}
$recurringsettings = admin_url('/admin.php?page=wc-settings&tab=checkout§ion=vipps_recurring');
$checkoutsettings = admin_url('/admin.php?page=vipps_settings_menu');
$loginsettings = admin_url('/options-general.php?page=vipps_login_options');
$logininstall = admin_url('/plugin-install.php?s=login-with-vipps&tab=search&type=term');
$subscriptioninstall = 'https://woocommerce.com/products/woocommerce-subscriptions/';
$recurringinstall = admin_url('/plugin-install.php?s=vipps-recurring-payments-gateway-for-woocommerce&tab=search&type=term');
$logspage = admin_url('/admin.php?page=wc-status&tab=logs');
$forumpage = 'https://wordpress.org/support/plugin/woo-vipps/';
$portalurl = 'https://portal.vippsmobilepay.com';
$installed = get_plugins();
$recurringinstalled = array_key_exists('vipps-recurring-payments-gateway-for-woocommerce/woo-vipps-recurring.php',$installed);
$recurringactive = class_exists('WC_Vipps_Recurring');
$logininstalled = array_key_exists('login-with-vipps/login-with-vipps.php', $installed);
$loginactive = class_exists('ContinueWithVipps');
$slogan = __('- very, very simple', 'woo-vipps');
$gw = $this->gateway();
$configured = get_option('woo-vipps-configured', false);
$isactive = ($gw->enabled == 'yes');
$istestmode = $gw->is_test_mode();
$ischeckout = false;
if ($isactive) {
$ischeckout = ($gw->get_option('vipps_checkout_enabled') == 'yes');
}
if (WC_Gateway_Vipps::instance()->get_payment_method_name() != "Vipps"):
?>
<style>.notice.notice-vipps.test-mode { display: none; }body.wp-admin.toplevel_page_vipps_admin_menu #wpcontent {background-color: white; }</style>
<header class="vipps-admin-page-header <?php echo esc_attr($flavour); ?>" style="padding-top: 3.5rem ; line-height: 30px;">
<h1><?php echo esc_html(Vipps::CompanyName()); ?> <?php echo esc_html($slogan); ?></h1>
</header>
<div class='wrap vipps-admin-page'>
<div id="vipps_page_vipps_banners"><?php echo apply_filters('woo_vipps_vipps_page_banners', ""); ?></div>
<h1><?php echo sprintf(__("%1\$s for WordPress and WooCommerce", 'woo-vipps'), Vipps::CompanyName()); ?></h1>
<div class="pluginsection woo-vipps">
<p><?php echo sprintf(__("This plugin gives you %1\$s in WooCommerce, either as a fully fledged Checkout, or as a flexible payment method.",'woo-vipps'), WC_Gateway_Vipps::instance()->get_payment_method_name()); ?></p>
<p><?php echo sprintf(__("With Checkout, you’ll also get access to shipping addresses, shipping selection and other payment options. Currently Checkout supports %1\$s and bank transfer; VISA and MasterCard payments will be added later.",'woo-vipps'), WC_Gateway_Vipps::instance()->get_payment_method_name()); ?></p>
<p><strong><?php echo sprintf(__("NB! Checkout for MobilePay is currently in beta mode; Bank Transfer has limited availability", 'woo-vipps')); ?></strong></p>
<p><?php echo sprintf(__("Configure the plugin on its <a href='%1\$s'>settings page</a> and get your keys from the <a target='_blank' href='%2\$s'>%3\$s portal</a>.",'woo-vipps'), $checkoutsettings, $portalurl, Vipps::CompanyName());?></p>
<p><?php echo sprintf(__("If you experience problems or unexpected results, please check the 'fatal-errors' and 'woo-vipps' logs at <a href='%1\$s'>WooCommerce logs page</a>.", 'woo-vipps'), $logspage); ?></p>
<p><?php echo sprintf(__("If you need support, please use the <a href='%1\$s'>forum page</a> for the plugin. If you cannot post your question publicly, contact WP-Hosting directly at [email protected].", 'woo-vipps'), $forumpage); ?></p>
<div class="pluginstatus vipps_admin_highlighted_section <?php echo esc_attr($flavour); ?>">
<?php if ($istestmode): ?>
<p><b>
<?php echo sprintf(__('%1$s is currently in test mode - no real transactions will occur.', 'woo-vipps'), Vipps::CompanyName()); ?>
</b></p>
<?php endif; ?>
<p>
<?php if ($configured): ?>
<?php echo sprintf(__("<a href='%1\$s'>%2\$s configuration</a> is complete.", 'woo-vipps'), $checkoutsettings, Vipps::CompanyName()); ?>
<?php else: ?>
<?php echo sprintf(__("%1\$s configuration is not yet complete - you must get your keys from the %1\$s portal and enter them on the <a href='%2\$s'>settings page</a>", 'woo-vipps'), Vipps::CompanyName(), $checkoutsettings); ?>
<?php endif; ?>
</p>
<?php if ($isactive): ?>
<p>
<?php echo sprintf(__("The plugin is <b>active</b> - %1\$s is available as a payment method.", 'woo-vipps'), Vipps::CompanyName()); ?>
<?php if ($ischeckout): ?>
</p>
<p>
<?php echo sprintf(__("You are now using <b>%1\$s Checkout</b> instead of the standard WooCommerce Checkout page.", 'woo-vipps'), WC_Gateway_Vipps::instance()->get_payment_method_name()); ?>
<?php endif; ?>
</p>
<?php else:; ?>
<?php endif; ?>
</div>
</div>
</div>
<?php else: ?>
<style>.notice.notice-vipps.test-mode { display: none; }body.wp-admin.toplevel_page_vipps_admin_menu #wpcontent {background-color: white; }</style>
<header class="vipps-admin-page-header <?php echo esc_attr($flavour); ?>" style="padding-top: 3.5rem ; line-height: 30px;">
<h1><?php echo esc_html(Vipps::CompanyName()); ?> <?php echo esc_html($slogan); ?></h1>
</header>
<div class='wrap vipps-admin-page'>
<div id="vipps_page_vipps_banners"><?php echo apply_filters('woo_vipps_vipps_page_banners', ""); ?></div>
<h1><?php echo sprintf(__("%1\$s for WordPress and WooCommerce", 'woo-vipps'), Vipps::CompanyName()); ?></h1>
<p><?php echo sprintf(__("%1\$s officially supports WordPress and WooCommerce with a family of plugins implementing a payment gateway for WooCommerce, an optional complete checkout solution powered by %1\$s, a system for managing QR-codes that link to your products or landing pages, a plugin for recurring payments, and a system for passwordless logins.", 'woo-vipps'), Vipps::CompanyName());?></p>
<p><?php echo sprintf(__("To order or configure your %1\$s account that powers these plugins, log onto <a target='_blank' href='%2\$s'>the %1\$s portal</a> and use the keys and data from that to set up your plugins as needed.", 'woo-vipps'), Vipps::CompanyName(), $portalurl); ?></p>
<h1><?php echo sprintf(__("The %1\$s plugins", 'woo-vipps'), Vipps::CompanyName()); ?></h1>
<div class="pluginsection woo-vipps">
<h2><?php echo sprintf(__('Pay with %1$s for WooCommerce', 'woo-vipps' ), Vipps::CompanyName());?></h2>
<p><?php echo sprintf(__("This plugin implements a %1\$s checkout solution for WooCommerce and an alternate %1\$s hosted checkout that supports both %2\$s and credit cards. It also supports %1\$s's QR-api for creating QR-codes to your landing pages or products.", 'woo-vipps'), Vipps::CompanyName(), WC_Gateway_Vipps::instance()->get_payment_method_name()); ?></p>
<p><?php echo sprintf(__("Configure the plugin on its <a href='%1\$s'>settings page</a> and get your keys from the <a target='_blank' href='%2\$s'>%3\$s portal</a>.",'woo-vipps'), $checkoutsettings, $portalurl, Vipps::CompanyName());?></p>
<p><?php echo sprintf(__("If you experience problems or unexpected results, please check the 'fatal-errors' and 'woo-vipps' logs at <a href='%1\$s'>WooCommerce logs page</a>.", 'woo-vipps'), $logspage); ?></p>
<p><?php echo sprintf(__("If you need support, please use the <a href='%1\$s'>forum page</a> for the plugin. If you cannot post your question publicly, contact WP-Hosting directly at [email protected].", 'woo-vipps'), $forumpage); ?></p>
<div class="pluginstatus vipps_admin_highlighted_section">
<?php if ($istestmode): ?>
<p><b>
<?php echo sprintf(__('%1$s is currently in test mode - no real transactions will occur.', 'woo-vipps'), Vipps::CompanyName()); ?>
</b></p>
<?php endif; ?>
<p>
<?php if ($configured): ?>
<?php echo sprintf(__("<a href='%1\$s'>%2\$s configuration</a> is complete.", 'woo-vipps'), $checkoutsettings, Vipps::CompanyName()); ?>
<?php else: ?>
<?php echo sprintf(__("%1\$s configuration is not yet complete - you must get your keys from the %1\$s portal and enter them on the <a href='%2\$s'>settings page</a>", 'woo-vipps'), Vipps::CompanyName(), $checkoutsettings); ?>
<?php endif; ?>
</p>
<?php if ($isactive): ?>
<p>
<?php echo sprintf(__("The plugin is <b>active</b> - %1\$s is available as a payment method.", 'woo-vipps'), Vipps::CompanyName()); ?>
<?php if ($ischeckout): ?>
</p>
<p>
<?php echo sprintf(__("You are now using <b>%1\$s Checkout</b> instead of the standard WooCommerce Checkout page.", 'woo-vipps'), WC_Gateway_Vipps::instance()->get_payment_method_name()); ?>
<?php endif; ?>
</p>
<?php else:; ?>
<?php endif; ?>
</div>
</div>
<div class="pluginsection vipps-recurring">
<h2><?php echo sprintf(__( '%1$s', 'woo-vipps' ), Vipps::RecurringName());?></h2>
<p>
<?php echo sprintf(__("<a href='%1\$s' target='_blank'>%2\$s for WooCommerce</a> by <a href='%3\$s' target='_blank'>Everyday</a> is perfect for you if you run a web shop with subscription based services or other products that would benefit from subscriptions.", 'woo-vipps'), 'https://www.wordpress.org/plugins/vipps-recurring-payments-gateway-for-woocommerce/', Vipps::RecurringName(), 'https://everyday.no/'); ?>
<?php echo sprintf(__("%1\$s requires the <a href='%2\$s' target='_blank'>WooCommerce Subscriptions plugin</a>.", 'woo-vipps'), Vipps::RecurringName(), 'https://woocommerce.com/products/woocommerce-subscriptions/'); ?>
<?php do_action('vipps_page_vipps_recurring_payments_section'); ?>
<div class="pluginstatus vipps_admin_highlighted_section">
<?php if ($recurringactive): ?>
<p>
<?php echo sprintf(__("%1\$s is <b>installed and active</b>. You can configure the plugin at its <a href='%2\$s'>settings page</a>", 'woo-vipps'), Vipps::RecurringName(), $recurringsettings); ?>
</p>
<?php elseif ($recurringinstalled): ?>
<p>