callbackorder = $Vipps->callbackorder; return parent::init(); } // Unfortunately, we need to override all of this, because // the is_session_cookie_valid() method is *private*. On the // parent class, this checks whether or not the user is logged-in, // and if so, if this session is for the same user. But these callbacks // should not have any user privileges, so they are *not* logged in. Therefore we only // check the expiry of the cookie. IOK 2022-03-14 public function init_session_cookie() { $cookie = $this->get_session_cookie(); if ( $cookie ) { // Customer ID will be an MD5 hash id this is a guest session. $this->_customer_id = $cookie[0]; $this->_session_expiration = $cookie[1]; $this->_session_expiring = $cookie[2]; $this->_has_cookie = true; $this->_data = $this->get_session_data(); if ( ! $this->is_session_cookie_valid_ignoring_loggedinness() ) { $this->destroy_session(); $this->set_session_expiration(); } // We also won't do the logged-in update check, because we aren't logged in. // Update session if its close to expiring. if ( time() > $this->_session_expiring ) { $this->set_session_expiration(); $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); } } else { $this->set_session_expiration(); $this->_customer_id = $this->generate_customer_id(); $this->_data = $this->get_session_data(); } } // We can't override is_session_cookie_valid, which checks whether or not we are logged in. // Therefore, call this instead in init_session_cookie. IOK 2022-03-14 private function is_session_cookie_valid_ignoring_loggedinness() { // If session is expired, session cookie is invalid. if ( time() > $this->_session_expiration ) { return false; } return true; } public function get_session_cookie() { if (!$this->callbackorder) return false; $order = wc_get_order($this->callbackorder); if (empty($order) && is_wp_error($order)) { return false; } $sessionjson = $order->get_meta('_vipps_sessiondata'); if (empty($sessionjson)) return false; $sessiondata = @json_decode($sessionjson,true); if (empty($sessiondata)) return false; list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = $sessiondata; if (empty($customer_id)) return false; $this->sessiondata = $sessiondata; // If passed as an actual cookie, we would verify the cookie_hash here, but since this is // stored in the order object to which the user has no access, we don't. // (Change triggered by change of logic here for Woo.) IOK 2025-08-26 return array($customer_id, $session_expiration, $session_expiring, $cookie_hash); } public function has_session () { return !empty($this->sessiondata); } public function forget_session() { if (!$this->has_session()) return; $order = wc_get_order($this->callbackorder); if (empty($order) && is_wp_error($order)) return false; $order->delete_meta_data('_vipps_sessiondata'); wc_empty_cart(); $this->_data = array(); $this->_dirty = false; $this->_customer_id = $this->generate_customer_id(); } // This is only used for callbacks, so *never* set cookies. public function set_customer_session_cookie( $set ) { return; } }