# hyperpay-gateways/5.3.0/src/App/Log.php

HyperPay Payments, version 5.3.0. 104 lines.

- Page: https://pluginprobe.com/plugins/hyperpay-gateways/5.3.0/code/src/App/Log.php
- Raw: https://pluginprobe.com/plugins/hyperpay-gateways/5.3.0/raw/src/App/Log.php
- Modified: 2025-05-20T08:43:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/hyperpay-gateways/5.3.0/code/src/App/Log.php#L10-L20`.

```php
<?php

namespace Hyperpay\Gateways\App;

if (! defined('ABSPATH')) exit;

use Hyperpay\Gateways\Main;

class Log
{

    public static function load()
    {

        $files =  get_option('hyperpay_payments_logs' , "[]");
        $files = json_decode($files, true);
        $names = \array_keys($files);

       

        $current_file =  isset($_GET['file']) ?  sanitize_text_field(wp_unslash($_GET['file'])) : array_key_last($files);


        if (empty($files)) {
            self::print_error("There is no log ");
            return;
        }

        if ($current_file && \array_key_exists($current_file , $files)) {
            $content = $files[$current_file];
        } else {
            self::print_error("Current log dose not exists");
            $content = '';
        }

        wp_enqueue_script('code-editor');
        wp_enqueue_style('code-editor');

        $content_label = esc_html__('Selected file content:', 'hyperpay-gateways');
        $url = isset($_SERVER["REQUEST_URI"]) ?  sanitize_url(wp_unslash($_SERVER["REQUEST_URI"])) : '';



        return View::render('logs.html', \compact('content_label', 'content', 'current_file', 'names', 'url'));
    }


    private static function print_error($error)
    {
?>
        <div class="notice notice-error">
            <p>
                <?php echo esc_html($error); ?>
            </p>
        </div>
<?php
    }

    private static function fileName()
    {
        $today = gmdate("Y-m-d");
        return  "hyperpay-log-$today";
    }

    public static function write($msg)
    {
        $log_file = static::fileName();
        $time = gmdate("H:i:s");
        $message = print_r($msg, true);
        $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3);
        if (isset($bt[2])) {
            $caller = $bt[2];
            $file = $caller['file'];
            $line = $caller['line'];
            $title = "[$time $file:$line]";
            $footer = print_r($bt[2]['args'], true);
        } else {
            $title = "[$time]";
            $footer = print_r($bt, true);
        }

        $selected =  get_option('hyperpay_payments_logs' , "[]");
        $selected = json_decode($selected, true);

        $selected[$log_file] = ($selected[$log_file] ?? '') . "$title\n$message\n$footer\n";


        update_option('hyperpay_payments_logs', json_encode($selected));
    }

    public static function removeExpiredLogs()
    {
        $selected =  get_option('hyperpay_payments_logs' , "[]");
        $selected = json_decode($selected, true);

        $selected = array_filter($selected, function ($key) {
            return strtotime($key) >= strtotime('-14 days');
        }, ARRAY_FILTER_USE_KEY);


        update_option('hyperpay_payments_logs', json_encode($selected));
    }
}

```
