Weak hands cannot be planted, meager skills have no foundation. Shallow wisdom is futile, how can one hope for a good name?扰扰从役倦，屑屑身事微。少壮轻年月，迟暮惜光辉。
<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace Hostinger\Reach\Api;

use Hostinger\Reach\Admin\Notices\ConnectionNotice;
use Hostinger\Reach\Setup\Encrypt;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class ApiKeyManager {
    public const CSRF_TRANSIENT            = 'hostinger_reach_csrf_token';
    public const CSRF_TRANSIENT_EXPIRATION = 500;
    public const API_KEY_NAME              = 'hostinger_reach_api_key';
    public const API_CONNECTION_TIME_NAME  = 'hostinger_reach_api_connection_time';

    public function store_token( string $token ): bool {
        add_option( self::API_CONNECTION_TIME_NAME, time() );

        return update_option( self::API_KEY_NAME, $this->encrypt_token( $token ) );
    }

    public function get_token(): string {
        return $this->decrypt_token( get_option( self::API_KEY_NAME, '' ) );
    }

    public function encrypt_token( string $token ): string {
        return Encrypt::encrypt( $token );
    }

    public function decrypt_token( string $token ): string {
        return Encrypt::decrypt( $token );
    }

    public function validate_csrf( string $csrf ): bool {
        $transient_csrf = $this->get_csrf();
        $order_id       = $this->get_order_id();
        if ( $transient_csrf && $transient_csrf === $csrf ) {
            return true;
        }

        if ( $order_id && $order_id === $csrf ) {
            return true;
        }

        return false;
    }

    public function generate_csrf(): void {
        set_transient( self::CSRF_TRANSIENT, wp_generate_password( 12, false ), self::CSRF_TRANSIENT_EXPIRATION );
    }

    public function get_csrf(): string {
        return get_transient( self::CSRF_TRANSIENT );
    }

    public function clear_csrf(): void {
        delete_transient( self::CSRF_TRANSIENT );
    }

    public function clear_token(): void {
        delete_option( self::API_KEY_NAME );
        delete_transient( ConnectionNotice::NOTICE_DISMISS_TRANSIENT );
    }

    public function is_connected(): bool {
        return ! empty( $this->get_token() );
    }

    protected function get_order_id(): string {
        $api_token_path =