PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.1.5
Pay with Vipps and MobilePay for WooCommerce v6.1.5
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 All 187 releases
woo-vipps / recurring / assets / js / vipps-recurring-admin.js

vipps-recurring-admin.js in Pay with Vipps and MobilePay for WooCommerce 6.1.5, at recurring/assets/js/vipps-recurring-admin.js

117 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 $('#check_charge_statuses_now').on('click', function () {
3 const $button = $(this);
4 $button.addClass('disabled');
5
6 $.post(ajaxurl, {
7 action: 'vipps_recurring_force_check_charge_statuses'
8 }).done(function (response) {
9 $button.removeClass('disabled');
10 alert(response);
11 }).fail(function (xhr, status, error) {
12 $button.removeClass('disabled');
13 alert(error);
14 });
15 })
16
17 $('.notice-vipps-recurring').on('click', '.notice-dismiss', function () {
18 const $notice = $(this).parent('.notice.is-dismissible');
19 const dismiss_url = $notice.attr('data-dismiss-url');
20
21 if (dismiss_url) {
22 $.get(dismiss_url);
23 }
24 });
25
26 if (pagenow === 'shop_order' || pagenow === 'woocommerce_page_wc-orders') {
27 $('button[data-action="capture_payment"]').click(function (e) {
28 e.preventDefault();
29
30 const button = $(this)
31
32 if (button.hasClass('disabled')) return;
33 button.attr('disabled', 'disabled');
34 button.addClass('disabled');
35
36 const { nonce } = VippsRecurringConfig;
37 const orderId = button.data('order-id')
38
39 const data = {
40 action: 'wc_vipps_recurring_order_action',
41 do: 'capture_payment',
42 orderId: orderId,
43 nonce: nonce
44 };
45
46 $.ajax(ajaxurl, {
47 method: "POST",
48 data,
49 cache: false,
50 dataType: "json",
51 timeout: 0,
52 error: function (xhr, message, error) {
53 button.removeAttr('disabled');
54 button.removeClass('disabled');
55
56 alert("Error performing Vipps/MobilePay Recurring action " + message + " " + error);
57 },
58 success: function () {
59 window.location.reload();
60 }
61 })
62 })
63 }
64
65 if (pagenow === 'woocommerce_page_wc-settings') {
66 const {currency} = window.VippsRecurringConfig
67
68 function vippsRecurringToggleInputRow(input, currentValue, showIfValue) {
69 if (currentValue !== showIfValue) {
70 input.closest('tr').hide();
71 } else {
72 input.closest('tr').show();
73 }
74 }
75
76 function toggleMobilePayReservationsWarning(brand, checked) {
77 const note = wp.i18n.__('Note: Reservations in MobilePay will be cancelled after 14 days. Remember to ship and fulfill your orders.', 'woo-vipps');
78
79 const brandInput = $('#woocommerce_vipps_recurring_brand');
80 const fieldset = brandInput.parent();
81
82 if (brand !== 'mobilepay' || checked) {
83 fieldset.find('.mobilepay-warning').remove();
84 } else {
85 fieldset.append('<div class="ui message warning notice notice-warning mobilepay-warning" style="margin-bottom: 0;"><p>' + note + '</p></div>');
86 }
87 }
88
89 function toggleVippsCurrencyWarning(brand, currency) {
90 // translators: %s is the current store currency code
91 const note = wp.i18n.sprintf(__('Note: Vipps is only available with the NOK currency. Your store currency is set to %s', 'woo-vipps'), currency);
92
93 const brandInput = $('#woocommerce_vipps_recurring_brand');
94 const fieldset = brandInput.parent();
95
96 if (brand !== 'vipps' || currency === 'NOK') {
97 fieldset.find('.vipps-currency-warning').remove();
98 } else {
99 fieldset.append('<div class="ui message warning notice notice-warning vipps-currency-warning" style="margin-bottom: 0;"><p>' + note + '</p></div>');
100 }
101 }
102
103 const brandInput = $('#woocommerce_vipps_recurring_brand');
104 const autoCaptureMobilePayInput = $('#woocommerce_vipps_recurring_auto_capture_mobilepay');
105
106 brandInput.on('change', function (event) {
107 vippsRecurringToggleInputRow(autoCaptureMobilePayInput, event.target.value, 'mobilepay');
108 toggleMobilePayReservationsWarning(event.target.value, autoCaptureMobilePayInput.is(':checked'));
109 toggleVippsCurrencyWarning(event.target.value, currency)
110 }).trigger('change');
111
112 autoCaptureMobilePayInput.on('change', function (event) {
113 toggleMobilePayReservationsWarning(brandInput.val(), event.target.checked);
114 });
115 }
116 });
117