| @@ -54,11 +54,8 @@ | ||
| 54 | 54 | |
| 55 | 55 | // True if HPOS is being used |
| 56 | 56 | public $HPOSActive = null; |
| 57 | 57 | |
| 58 | - // used in the fake locking mechanism using transients | |
| 59 | - private $lockKey = null; | |
| 60 | - | |
| 61 | 58 | public $vippsJSConfig = array(); |
| 62 | 59 | |
| 63 | 60 | public $button_options_version = '2.0'; |
| 64 | 61 | public $button_options_express_version = '2.0'; |
| @@ -270,15 +267,8 @@ | ||
| 270 | 267 | // because it is self-updating or because it has been deactivated just now or something, we won't have access to it. |
| 271 | 268 | // Therefore test it first. IOK 2022-12-08 |
| 272 | 269 | $gw = $this->gateway(); |
| 273 | 270 | |
| 274 | - // This is a developer-mode level feature because flock() is not portable. This ensures callbacks and shopreturns do not | |
| 275 | - // simultaneously update the orders, in particular not the express checkout order lines wrt shipping. IOK 2020-05-19 | |
| 276 | - if ($gw && $gw->get_option('use_flock') == 'yes') { | |
| 277 | - add_filter('woo_vipps_lock_order', array($this,'flock_lock_order')); | |
| 278 | - add_action('woo_vipps_unlock_order', array($this, 'flock_unlock_order')); | |
| 279 | - } | |
| 280 | - | |
| 281 | 271 | // Set default button options, migrating any older setup IOK 2026-07-15 |
| 282 | 272 | $this->init_button_options(); |
| 283 | 273 | |
| 284 | 274 | /* |
| @@ -1101,8 +1091,10 @@ | ||
| 1101 | 1091 | // Don't support these login verbs. LP 2026-06-04 |
| 1102 | 1092 | if (in_array($attrs['verb'], ['login', 'register'])) $attrs['verb'] = 'buy'; |
| 1103 | 1093 | // Looks like button and badge web components now use 'da' instead of 'dk' for danish. LP 2026-08-11 |
| 1104 | 1094 | if ('dk' === $attrs['language']) $attrs['language'] = 'da'; |
| 1095 | + // Fix swedish too. LP 2026-10-06 | |
| 1096 | + if ('se' === $attrs['language']) $attrs['language'] = 'sv'; | |
| 1105 | 1097 | |
| 1106 | 1098 | $escaped_attrs = []; |
| 1107 | 1099 | foreach($attrs as $k => $v) { |
| 1108 | 1100 | $escaped_attrs[$k] = esc_attr($v); |
| @@ -1957,9 +1949,9 @@ | ||
| 1957 | 1949 | public function express_checkout_section_html() { |
| 1958 | 1950 | $payment_method = $this->get_payment_method_name(); |
| 1959 | 1951 | $header_text = __('Express Checkout', 'woo-vipps'); |
| 1960 | 1952 | $header = "<legend class='express-header'>$header_text</legend>"; |
| 1961 | - $div_classes = "legacy-checkout vipps-express-checkout $payment_method"; | |
| 1953 | + $div_classes = "legacy-checkout express $payment_method"; | |
| 1962 | 1954 | echo "<fieldset class='$div_classes'>$header"; |
| 1963 | 1955 | $this->checkout_express_checkout_button_html(); |
| 1964 | 1956 | echo '</fieldset>'; |
| 1965 | 1957 | } |
| @@ -2576,82 +2568,9 @@ | ||
| 2576 | 2568 | if ($ok) return $callbackdir; |
| 2577 | 2569 | return null; |
| 2578 | 2570 | } |
| 2579 | 2571 | |
| 2580 | - // Unfortunately, we cannot do any form of portable locking, and we may get callbacks from Vipps arriving at the same moment as we check the status at Vipps, | |
| 2581 | - // which in the very worst case, for Express Checkout orders, may lead to a double shipping line. Changing this to a queue system is non-trivial, because some of | |
| 2582 | - // the operations done when modifying the order actually requires the customers session to be active. This operation will make conflicts a litte less probable | |
| 2583 | - // by implementing something that isn't quite a lock, and the filter may be used to implement proper locking, using e.g. flock, where this can be used | |
| 2584 | - // (non-distributed environments using unix on standard filesystems. IOK 2020-05-15 | |
| 2585 | - // Returns true if lock succeeds, or false. | |
| 2586 | - public function lockOrder($order) { | |
| 2587 | - $orderid = $order->get_id(); | |
| 2588 | - if (has_filter('woo_vipps_lock_order')) { | |
| 2589 | - $ok = apply_filters('woo_vipps_lock_order', $order); | |
| 2590 | - if (!$ok) return false; | |
| 2591 | - } else { | |
| 2592 | - if(get_transient('order_lock_'.$orderid)) return false; | |
| 2593 | - $this->lockKey = uniqid(); | |
| 2594 | - set_transient('order_lock_' . $orderid, $this->lockKey, 30); | |
| 2595 | - } | |
| 2596 | - add_action('shutdown', function () use ($order) { global $Vipps; $Vipps->unlockOrder($order); }); | |
| 2597 | - return true; | |
| 2598 | - } | |
| 2599 | - // If the order is locked, it means it is in the process of being finalized, so for instance, we do *not* want to abandon it | |
| 2600 | - // in checkout. | |
| 2601 | - public function isLocked ($order) { | |
| 2602 | - $orderid = $order->get_id(); | |
| 2603 | - $locked = get_transient('order_lock_'.$orderid); | |
| 2604 | - return apply_filters('woo_vipps_order_locked', $locked, $order); | |
| 2605 | - } | |
| 2606 | - public function unlockOrder($order) { | |
| 2607 | - $orderid = $order->get_id(); | |
| 2608 | - if (has_action('woo_vipps_unlock_order')) { | |
| 2609 | - do_action('woo_vipps_unlock_order', $order); | |
| 2610 | - } else { | |
| 2611 | - if(get_transient('order_lock_'.$orderid) == $this->lockKey) { | |
| 2612 | - delete_transient('order_lock_'.$orderid); | |
| 2613 | - } | |
| 2614 | - } | |
| 2615 | - } | |
| 2616 | 2572 | |
| 2617 | - // Functions using flock() and files to lock orders. This is only guaranteed to work on certain setups, ie, non-distributed setups | |
| 2618 | - // using Unix with normal filesystems (not NFS). | |
| 2619 | - public function flock_lock_order($order) { | |
| 2620 | - global $_orderlocks; | |
| 2621 | - if (!$_orderlocks) $_orderlocks = array(); | |
| 2622 | - $dir = $this->callbackDir(); | |
| 2623 | - if (!$dir) { | |
| 2624 | - $this->log(__("Cannot use flock() to lock orders: cannot create or write to directory", "woo-vipps"), 'error'); | |
| 2625 | - return true; | |
| 2626 | - } | |
| 2627 | - $fname = '.ht-vipps-lock-'.md5($order->get_order_key() . $order->get_meta('_vipps_transaction')); | |
| 2628 | - $path = $dir . DIRECTORY_SEPARATOR . $fname; | |
| 2629 | - touch($path); | |
| 2630 | - if (!is_writable($path)) { | |
| 2631 | - $this->log(__("Cannot use flock() to lock orders: cannot create lockfiles ", "woo-vipps"), 'error'); | |
| 2632 | - return true; | |
| 2633 | - } | |
| 2634 | - $handle = fopen($path, 'w+'); | |
| 2635 | - if (flock($handle, LOCK_EX | LOCK_NB)) { | |
| 2636 | - $_orderlocks[$order->get_id()] = array($handle,$path); | |
| 2637 | - return true; | |
| 2638 | - } | |
| 2639 | - return false; | |
| 2640 | - } | |
| 2641 | - public function flock_unlock_order($order) { | |
| 2642 | - $orderid=$order->get_id(); | |
| 2643 | - global $_orderlocks; | |
| 2644 | - if (!$_orderlocks) return; | |
| 2645 | - if (!isset($_orderlocks[$orderid])) return; | |
| 2646 | - list($handle, $path) = $_orderlocks[$orderid]; | |
| 2647 | - unset($_orderlocks[$orderid]); | |
| 2648 | - flock($handle, LOCK_UN); | |
| 2649 | - fclose($handle); | |
| 2650 | - @unlink($path); | |
| 2651 | - } | |
| 2652 | - | |
| 2653 | - | |
| 2654 | 2573 | // Because the prefix used to create the Vipps order id is editable |
| 2655 | 2574 | // by the user, we will store that as a meta and use this for callbacks etc. |
| 2656 | 2575 | // IOK 2023-01-23 this function is no longer used, and kept only for backwards compatibility with |
| 2657 | 2576 | // debug filters and similar. |
| @@ -3002,10 +2921,15 @@ | ||
| 3002 | 2921 | $this->vippsJSConfig['vippslocale'] = get_locale(); |
| 3003 | 2922 | $this->vippsJSConfig['vippsexpressbuttonurl'] = $this->get_payment_method_name(); |
| 3004 | 2923 | $this->vippsJSConfig['paymentMethodSlug'] = sanitize_title($this->get_payment_method_name()); |
| 3005 | 2924 | $this->vippsJSConfig['paymentMethodName'] = $this->get_payment_method_name(); |
| 3006 | - | |
| 2925 | + $wc_lang = $this->get_html_button_attrs_for_context()['language']; | |
| 2926 | + if ('store' === $wc_lang) $wc_lang = $this->get_customer_language(); | |
| 2927 | + // Looks like button and badge web components now use 'da' instead of 'dk' for danish. LP 2026-08-11 | |
| 2928 | + if ('dk' === $wc_lang) $wc_lang = 'da'; | |
| 2929 | + $this->vippsJSConfig['webcomponentLanguage'] = $wc_lang; | |
| 3007 | 2930 | |
| 2931 | + | |
| 3008 | 2932 | // If the site supports Gutenberg Blocks, support the Checkout block IOK 2020-08-10 |
| 3009 | 2933 | if (class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) { |
| 3010 | 2934 | // Ensure gateways are loaded at this point IOK 2026-05-27 |
| 3011 | 2935 | require_once(dirname(__FILE__) . '/WC_Gateway_VippsCard.class.php'); |
| @@ -3877,9 +3801,9 @@ | ||
| 3877 | 3801 | $shipping_method = $methodclass ? new $methodclass($rate->get_instance_id()) : null; |
| 3878 | 3802 | |
| 3879 | 3803 | $tax = $rate->get_shipping_tax() ?: 0; |
| 3880 | 3804 | $cost = $rate->get_cost() ?: 0; |
| 3881 | - $label = $rate->get_label(); | |
| 3805 | + $label = html_entity_decode($rate->get_label()); | |
| 3882 | 3806 | |
| 3883 | 3807 | if ($cost == 0 && ($methodid != 'local_pickup' && $methodid != 'pickup_location')) { |
| 3884 | 3808 | $has_free_shipping = true; |
| 3885 | 3809 | } |
| @@ -3905,9 +3829,9 @@ | ||
| 3905 | 3829 | $shippingcostB = sprintf("%.2F",wc_format_decimal($cost, '') + wc_format_decimal($tax,'')); |
| 3906 | 3830 | $shippingcost = max($shippingcostA, $shippingcostB); |
| 3907 | 3831 | |
| 3908 | 3832 | $vippsmethod['shippingCost'] = $shippingcost; |
| 3909 | - $vippsmethod['shippingMethod'] = $rate->get_label(); | |
| 3833 | + $vippsmethod['shippingMethod'] = html_entity_decode($rate->get_label()); | |
| 3910 | 3834 | $vippsmethod['shippingMethodId'] = $key; |
| 3911 | 3835 | $vippsmethods[]=$vippsmethod; |
| 3912 | 3836 | |
| 3913 | 3837 | // Metadata and settings stored for later use for Checkout |
| @@ -4252,9 +4176,9 @@ | ||
| 4252 | 4176 | $tax = $rate->get_shipping_tax() ?: 0; |
| 4253 | 4177 | $cost = $rate->get_cost() ?: 0; |
| 4254 | 4178 | |
| 4255 | 4179 | $method['shippingCost'] = sprintf("%.2F",wc_format_decimal($cost+$tax,'')); |
| 4256 | - $method['shippingMethod'] = $rate->get_label(); | |
| 4180 | + $method['shippingMethod'] = html_entity_decode($rate->get_label()); | |
| 4257 | 4181 | // We may not really need the tax stashed here, but just to be sure. |
| 4258 | 4182 | $method['shippingMethodId'] = $rate->get_id() . ";" . $tax; |
| 4259 | 4183 | $methods[]= $method; |
| 4260 | 4184 | |