Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CloverApi
- {
- var $sandbox_url;
- var $production_url;
- var $isSandbox;
- function __construct(){
- $this->sandbox_url = "https://apisandbox.dev.clover.com";
- $this->production_url = "https://api.clover.com";
- $this->isSandbox = true;
- }
- public function getURL(){
- if($this->isSandbox){
- return $this->sandbox_url;
- }else{
- return $this->production_url;
- }
- }
- /* Exchanging an auth code for an access token */
- public function GetAccessToken($client_id, $client_secret, $code) {
- //sandbox.dev.clover.com
- $url = 'https://sandbox.dev.clover.com/oauth/token';
- if(!$this->isSandbox){
- $url = 'https://www.clover.com/oauth/token';
- }
- $curlPost = 'client_id=' . $client_id . '&client_secret=' . $client_secret . '&code='. $code;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
- $data = json_decode(curl_exec($ch), true); //echo "<pre>";var_dump($data);
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to receive access token');
- return $data;
- }
- public function GetUser($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/current/employees/current';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get user info');
- return $data;
- }
- /* Get the list of orders */
- public function GetOrders($merchant_id, $access_token, $filter, $execution_count) {
- $limit = 1000;
- $offset = ($execution_count - 1)*$limit;
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/orders?limit='.$limit;
- for($i=0; $i<sizeof($filter); $i++)
- $url .= '&filter=' . urlencode($filter[$i]);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($_SESSION);print_r($data);echo '</pre>';exit;
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get orders');
- $myData = array();
- for($i=0; $i<sizeof($data['elements']); $i++) {
- $d = $data['elements'][$i];
- $temp['title'] = $d['title'];
- $temp['id'] = $d['id'];
- $temp['total'] = $d['total'];
- $temp['date'] = date("d-M-y",$d['clientCreatedTime']/1000);
- $temp['note'] = array();
- if(isset($d['note']))
- $temp['note'] = explode('&',$d['note']);
- $myData[] = $temp;
- }
- return $myData;
- }
- public function GetOrdersAll($merchant_id, $access_token, $filter, $execution_count) {
- $limit = 1000;
- $offset = ($execution_count - 1)*$limit;
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/orders?';
- for($i=0; $i<sizeof($filter); $i++)
- $url .= '&filter=' . urlencode($filter[$i]);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch));//echo '<pre>';print_r($_SESSION);print_r($data);echo '</pre>';exit;
- return $data;
- }
- /* Get the list of employees */
- public function GetEmployees($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/employees?limit=1000';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get employees');
- /*$employees = [];
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++)
- $employees[$data['elements'][$i]['id']] = $data['elements'][$i]['name'];
- }*/
- return $data['elements'];
- }
- /* Get the list of Inventory Category */
- public function GetCategory($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/categories?limit=1000';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';exit;
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get employees');
- $categories = [];
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++)
- $categories[$data['elements'][$i]['id']] = $data['elements'][$i]['name'];
- }
- return $categories;
- }
- public function GetOrderTypesCategories($merchant_id,$access_token){
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/order_type_categories?limit=1000';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get order types');
- $order_types = [];
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++)
- $order_types[$data['elements'][$i]['id']] = $data['elements'][$i]['label'];
- }
- return $order_types;
- }
- /* Get the list of order types */
- public function GetOrderTypes($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/order_types?limit=1000';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get order types');
- $order_types = [];
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++)
- $order_types[$data['elements'][$i]['id']] = $data['elements'][$i]['label'];
- }
- return $order_types;
- }
- /* Get merchant name */
- public function GetMerchantName($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';exit;
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get merchant name');
- return $data['name'];
- }
- /* Get merchant timezone */
- public function GetMerchantTimezone($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/properties';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get merchant timezone');
- return $data['timezone'];
- }
- public function GetPaymentTypes($merchant_id, $access_token) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/tenders';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get merchant timezone');
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++)
- $payment_types[$data['elements'][$i]['id']] = $data['elements'][$i]['label'];
- }
- return $payment_types;
- }
- private function GetAllPayment($merchant_id, $access_token, $filterPayment) {
- $url = $this->getURL().'/v3/merchants/' . $merchant_id . '/payments';
- for($i=0; $i<sizeof($filter); $i++)
- $url .= '&filter=' . urlencode($filter[$i]);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = json_decode(curl_exec($ch), true);//echo '<pre>';print_r($data);echo '</pre>';
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200)
- throw new Exception('Error : Failed to get merchant timezone');
- $Payments = [];
- if(sizeof($data['elements']) > 0) {
- for($i=0; $i<sizeof($data['elements']); $i++) {
- $payment = new stdClass();
- $payment->orderid = $data['elements'][$i]['order']['id'];
- $payment->tenderid = $data['elements'][$i]['tender']['id'];
- array_push($Payments, $payment);
- }
- }
- return $Payments;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement