App\Repositories\Client\ClientRepository::vat PHP Method

vat() public method

public vat ( $requestData )
    public function vat($requestData)
    {
        $vat = $requestData->input('vat');
        $country = $requestData->input('country');
        $company_name = $requestData->input('company_name');
        // Strip all other characters than numbers
        $vat = preg_replace('/[^0-9]/', '', $vat);
        function cvrApi($vat)
        {
            if (empty($vat)) {
                // Print error message
                return 'Please insert VAT';
            } else {
                // Start cURL
                $ch = curl_init();
                // Set cURL options
                curl_setopt($ch, CURLOPT_URL, 'http://cvrapi.dk/api?search=' . $vat . '&country=dk');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_USERAGENT, 'Flashpoint');
                // Parse result
                $result = curl_exec($ch);
                // Close connection when done
                curl_close($ch);
                // Return our decoded result
                return json_decode($result, 1);
            }
        }
        $result = cvrApi($vat, 'dk');
        return $result;
    }