<?php

class ANAF_API
{
    const apiURL = 'https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ws/tva';
    const ANAF_CUI_LIMIT = 500;
    public function callApi($data = NULL)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(CURLOPT_URL => self::apiURL, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => array("Cache-Control: no-cache", "Content-Type: application/json")));
        var_dump($data);
        exit;
        $response = curl_exec($curl);
        $info = curl_getinfo($curl);
        curl_close($curl);
        if (!isset($info['http_code']) || $info['http_code'] !== 200) {
            wp_die("Response status: {$info['http_code']} | Response body: {$response}");
        }
        $items = json_decode($response);
        if (json_last_error() !== JSON_ERROR_NONE) {
            wp_die("Json parse error | Response body: {$response}");
        }
        if ("SUCCESS" !== $items->message || 200 !== $items->cod) {
            throw new Exceptions\RequestFailed("Response message: {$items->message} | Response body: {$response}");
        }
        return $items->found;
    }
}