HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Shop/Vies/Rules/VatNumberSoft.php
<?php

namespace App\Komma\Shop\Vies\Rules;

use App\Komma\Shop\Vies\ViesResult;
use App\Komma\Shop\Vies\ViesService;
use Illuminate\Contracts\Validation\Rule;

/**
 * Class VatNumber
 *
 * Validates a VAT number.
 * Notice that it also considers a VAT number valid if the VIES service is unavailable
 */
class VatNumberSoft implements Rule
{
    /** @var ViesService */
    private $service;

    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->service = app(ViesService::class);
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $result = $this->service->validateVatNumber($value);

        if (is_a($result, ViesResult::class)) {
            return true;
        } elseif (is_int($result)) {
            if ($result == 0) {
                return false;
            } elseif ($result == -1) {
                return true;
            } //Vat could not be validated because service was unavailable. Return valid (true) for now
        }
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return __('shop/views.not_valid');
    }
}