MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/royaltuning/www/public/backoffice.royaltuning.hu/app/Helpers/UvHelper.php
<?php

namespace App\Helpers;

use App\Http\Controllers\Backend\Api\Webshippy\WebshippyController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use UtanvetEllenor\Client;

class UvHelper
{
    public static function getApiKey($source)
    {
        $apiKeys = env("UV_API_KEYS");
        return $apiKeys[$source] ?? null;
    }

    public static function getCodInfo($order)
    {
        $client = new Client(env("UV_PUBLIC_CODE"), env("UV_PRIVATE_CODE"));
        $client->email = $order->customer_email;//"dummy-success@utanvet-ellenor.hu";
        $client->countryCode = 'HU';
        $client->postalCode = $order->shipping_postcode;
        $client->phoneNumber = $order->customer_phone;
        $client->addressLine = $order->shipping_address_1;
        $client->threshold = env('UV_THRESHOLD');
        $response = $client->sendRequest();

        if (isset($response->status) && $response->status == 200) {
            return self::formatInfo($response->result);
        } elseif (isset($response->status) && $response->status == 204) {
            return "<b style='color:red'>" . __($response->result->reason) . "</b>";
        } elseif (isset($response->status) && $response->status == 404) {
            return "<b style='color:red'>" . __($response->result->reason) . "</b>";
        } else {
            return "<b style='color:red'>" .print_r($response) . "</b>";

        }
    }

    public static function formatInfo($result)
    {
        $text = "<div class='info'>";

        $text .= "<b style='color:green'>" . $result->good . " sikeres</b>,<b style='color:red'>" . $result->bad . " sikertelen</b> (kézbesítés), reputáció:" . $result->reputation . ". <br/>Sikeres kézbesítés:<b>" . 100 / ($result->good + $result->bad) * $result->good . "%</b><br/>";
        $text .= "Api válasz: <b>" . __($result->reason) . "</b>";
        $text .= "</div>";

        return $text;
    }
}