<?php

namespace App\Tally;

class TallyConnector{


    private $curRequest;
    public static $creditorAndDebtors;

    public function connect(){
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_PORT => _env('TALLY_PORT'),
            CURLOPT_URL => _env('TALLY_CONNECTION'),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 5,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_POSTFIELDS => $this->curRequest,
            CURLOPT_HTTPHEADER => array(
                "Content-Type: application/x-www-form-urlencoded",
                "cache-control: no-cache"
            ),
        ));

        $response = curl_exec($curl);
        $response = simplexml_load_string($response);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err || !$response) {
            return false;
        } else {
            return true;
        }
    }
}
