ria/application/helpers/zohobooks_fetch_api_helper.php

78 lines
3.0 KiB
PHP

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* InvoicePlane
*
* @author InvoicePlane Developers & Contributors
* @copyright Copyright (c) 2012 - 2017 InvoicePlane.com
* @license https://invoiceplane.com/license.txt
* @link https://invoiceplane.com
*/
function generateNewToken()
{
$ch=curl_init();
$organization_id = '776847408';
$client_id = '1000.0WMDLCXAZV5DR60IKE9P49YTYGVL6C';
$refresh_token = '1000.0fcf314cc7b7b598df6e519461bbe9b8.f77688a2254137532ae33ad5e152a064';
$client_secret = '99da3a05cfa13cf91eb6476a3c44cfa3e21b6106a8';
$redirect_uri = 'https://resicoindustries.com/RIA/';
$accesstoken = '1000.095b66fc95fc81874c1cfc7d15b0904e.10bc9956d9b9ec14cce1350ee0cf8254';
$url_getauthtoken = 'https://accounts.zoho.com/oauth/v2/token?refresh_token='.$refresh_token.'&client_id='.$client_id.'&client_secret='.$client_secret.'&redirect_uri='.$redirect_uri.'&grant_type=refresh_token';
$headers=array('Authorization:Zoho-oauthtoken '.$accesstoken,'Content-Type:application/json');
curl_setopt($ch, CURLOPT_URL, $url_getauthtoken);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
$body = '{}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res_token=curl_exec($ch);
$ress = json_decode($res_token);
return $ress->access_token;
}
function getheringInvoiceDetails($date_today , $date_yesterday , $accesstoken)
{
$ch=curl_init();
$organization_id = '776847408';
$url_org ="https://books.zoho.com/api/v3/invoices?";
$fields=array("usestate" => "true","organization_id" => $organization_id,"date_start" => $date_yesterday,"date_end" => $date_today);
$data_all = http_build_query($fields);
$headers=array('Authorization:Zoho-oauthtoken '.$accesstoken,'Content-Type:application/json');
$data_access = $url_org.$data_all;
curl_setopt($ch, CURLOPT_URL, $url_org.$data_access);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
$body = '{}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($ch);
$data['headers_new'] = $headers;
$data['data'] = curl_exec($ch);
return $data;
}
function getheringInvoiceSubDetails($invoice_id , $organization_id , $headers)
{
$ch=curl_init();
$url2 = 'https://books.zoho.com/api/v3/invoices/'.$invoice_id.'?organization_id='.$organization_id;
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
$body2 = '{}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,$body2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}