| @@ -227,9 +227,9 @@ | ||
| 227 | 227 | return $enabled; |
| 228 | 228 | } |
| 229 | 229 | $is_vipps_express = (bool) $order->get_meta( '_vipps_express_checkout' ); |
| 230 | 230 | $has_billing_email = (bool) $order->get_billing_email(); |
| 231 | - if ( $is_vipps_express && ! $has_billing_email ) { | |
| 231 | + if ( $is_vipps_express) { | |
| 232 | 232 | return false; |
| 233 | 233 | } |
| 234 | 234 | return $enabled; |
| 235 | 235 | }, 10, 3); |
| @@ -2356,15 +2356,15 @@ | ||
| 2356 | 2356 | // Default should never happen, but just to ensure we are in our enumeration |
| 2357 | 2357 | return "initiated"; |
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | - // This does not normally call Vipps, so if you need to refresh status, please use callback_check_order_status first. IOK 2019-01-23 | |
| 2360 | + // This does not normally call Vipps, so if you need to refresh status, please use poll_and_check_order_status first. IOK 2019-01-23 | |
| 2361 | 2361 | public function check_payment_status($order) { |
| 2362 | 2362 | if (!$order) return 'cancelled'; |
| 2363 | 2363 | $status = $this->interpret_vipps_order_status($order->get_meta('_vipps_status')); |
| 2364 | 2364 | // This can happen if the vipps status is set from the back end for instance. IOK 2020-08-14 |
| 2365 | 2365 | if ($order->get_status() == 'pending' && $status != 'initiated') { |
| 2366 | - $this->callback_check_order_status($order); | |
| 2366 | + $this->poll_and_check_order_status($order); | |
| 2367 | 2367 | $order = wc_get_order($order->get_id()); // refresh to get the new status IOK 2021-01-20 |
| 2368 | 2368 | $status = $this->interpret_vipps_order_status($order->get_meta('_vipps_status')); |
| 2369 | 2369 | } |
| 2370 | 2370 | return $status; |
| @@ -2369,9 +2369,9 @@ | ||
| 2369 | 2369 | } |
| 2370 | 2370 | return $status; |
| 2371 | 2371 | } |
| 2372 | 2372 | |
| 2373 | - // Called by callback_check_order_status and handle_callback to handle the situation where | |
| 2373 | + // Called by poll_and_check_order_status and handle_callback to handle the situation where | |
| 2374 | 2374 | // the payment method has been set to something else *after* Vipps has gotten the order. |
| 2375 | 2375 | // This happens very rarely for people who use Vipps as an external payment method in Klarna, so |
| 2376 | 2376 | // we only do it for orders that match this. IOK 2023-02-03 |
| 2377 | 2377 | public function reset_erroneous_payment_method($order) { |
| @@ -2398,9 +2398,9 @@ | ||
| 2398 | 2398 | } |
| 2399 | 2399 | |
| 2400 | 2400 | // Check status of order at Vipps, in case the callback has been delayed or failed. |
| 2401 | 2401 | // Should only be called if in status 'pending'; it will modify the order when status changes. |
| 2402 | - public function callback_check_order_status($order, $allow_retry = true) { | |
| 2402 | + public function poll_and_check_order_status($order, $allow_retry = true) { | |
| 2403 | 2403 | global $Vipps; |
| 2404 | 2404 | $orderid = $order->get_id(); |
| 2405 | 2405 | |
| 2406 | 2406 | clean_post_cache($order->get_id()); |
| @@ -3192,9 +3192,10 @@ | ||
| 3192 | 3192 | if (is_array($shipping_table) && isset($shipping_table[$key])) { |
| 3193 | 3193 | $decoded = $is_base64 ? @base64_decode($shipping_table[$key]) : $shipping_table[$key]; |
| 3194 | 3194 | |
| 3195 | 3195 | // Ensure no shop manager has injected an evil object (that they would have had to add as a plugin) here. IOK 2026-09-18 |
| 3196 | - $shipping_rate = $decoded ? @unserialize($decoded, ['allowed_classes' => [WC_Shipping_Rate::class]]) : null; | |
| 3196 | + $allowed_classes = apply_filters('woo_vipps_express_checkout_allowed_shipping_classes', [WC_Shipping_Rate::class, \stdClass::class]); | |
| 3197 | + $shipping_rate = $decoded ? @unserialize($decoded, ['allowed_classes' => $allowed_classes]) : null; | |
| 3197 | 3198 | $shipping_rate = is_a($shipping_rate,'WC_Shipping_Rate') ? $shipping_rate : null; |
| 3198 | 3199 | |
| 3199 | 3200 | if (!$shipping_rate) { |
| 3200 | 3201 | $this->log(sprintf(__("%1\$s: Could not deserialize the chosen shipping method %2\$s for order %3\$d", 'woo-vipps'), Vipps::ExpressCheckoutName(), $method, $order->get_id()), 'error'); |
| @@ -3380,9 +3381,9 @@ | ||
| 3380 | 3381 | $shipping_rate = apply_filters('woo_vipps_express_checkout_shipping_rate',$shipping_rate,$costExTax,$tax,$method,$product); |
| 3381 | 3382 | return $shipping_rate; |
| 3382 | 3383 | } |
| 3383 | 3384 | |
| 3384 | - // Used by both callback_check_order_status and handle_callback - sets the neccessary order metadata after a successful (or not vipps transaction). IOK 2025-08-13 | |
| 3385 | + // Used by both poll_and_check_order_status and handle_callback - sets the neccessary order metadata after a successful (or not vipps transaction). IOK 2025-08-13 | |
| 3385 | 3386 | public function order_set_transaction_metadata($order, $transaction) { |
| 3386 | 3387 | // Set Vipps metadata as early as possible |
| 3387 | 3388 | $vippsstamp = strtotime($transaction['timeStamp']); |
| 3388 | 3389 | $vippsamount = $transaction['amount'] ?? ''; |
| @@ -3762,9 +3763,9 @@ | ||
| 3762 | 3763 | } |
| 3763 | 3764 | do_action('woo_vipps_payment_complete_at_shutdown', $order, $this); |
| 3764 | 3765 | } catch (Exception $e) { |
| 3765 | 3766 | // This is/should be non-critical so just log it. |
| 3766 | - $this->log(sprintf(__("Could not do all payment-complete actions on %1\$s order %2\$d: %3\$s ", 'woo-vipps'), Vipps::CompanyName(), $orderid, $e->etMessage()), "error"); | |
| 3767 | + $this->log(sprintf(__("Could not do all payment-complete actions on %1\$s order %2\$d: %3\$s ", 'woo-vipps'), Vipps::CompanyName(), $orderid, $e->getMessage()), "error"); | |
| 3767 | 3768 | } |
| 3768 | 3769 | } |
| 3769 | 3770 | |
| 3770 | 3771 | // This is run on payment complete. Per default will it only add a link to the order confirmation page, but |
| @@ -3871,9 +3872,9 @@ | ||
| 3871 | 3872 | |
| 3872 | 3873 | $contents = WC()->cart->get_cart_contents(); |
| 3873 | 3874 | $contents = apply_filters('woo_vipps_create_express_checkout_cart_contents',$contents); |
| 3874 | 3875 | try { |
| 3875 | - $cart_hash = md5(json_encode(wc_clean($contents)) . WC()->cart->total); | |
| 3876 | + $cart_hash = WC()->cart->get_cart_hash(); | |
| 3876 | 3877 | $order = new WC_Order(); |
| 3877 | 3878 | $order->set_status('pending'); |
| 3878 | 3879 | $order->set_payment_method($this); |
| 3879 | 3880 | if ($ischeckout) { |
| @@ -3884,8 +3885,9 @@ | ||
| 3884 | 3885 | } |
| 3885 | 3886 | // We use 'checkout' as the created_via key as per requests, but allow merchants to use their own. IOK 2022-09-15 |
| 3886 | 3887 | $created_via = apply_filters('woo_vipps_express_checkout_created_via', 'checkout', $order, $ischeckout); |
| 3887 | 3888 | $order->set_created_via($created_via); |
| 3889 | + $order->set_cart_hash($cart_hash); | |
| 3888 | 3890 | |
| 3889 | 3891 | $dummy = sprintf(__('Vipps Express Checkout', 'woo-vipps')); // this is so gettext will find this string. |
| 3890 | 3892 | $dummy = sprintf(__('Vipps Checkout', 'woo-vipps')); // this is so gettext will find this string. |
| 3891 | 3893 | |