<?php

    class WebServices {
        private $url;
        private $data;
        private $headers;


        public function curlPost($url, $data, $headers = null) {

            $this->url = $url;
            $this->data = $data;

            $ch = curl_init();
            $timeout = 30;
            curl_setopt($ch, CURLOPT_URL, $this->url);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            if($headers) {
                $this->headers = $headers;
                curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
            }
            $response = curl_exec($ch);
            if(curl_errno($ch)) {
                echo 'Error: ' . curl_error($ch);
            }
            curl_close($ch);
            return json_decode($response);
        }

    }

?>