siddharth_application/application/helpers/zohobooks_fetch_api_helper.php
2024-05-29 03:28:17 +00:00

76 lines
3.1 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();
$refresh_token = '1000.6608673cee76166874b326b8183a38ab.5fa4b2fa427fe64c5a8700f7170e3a58';
$client_id = '1000.T9H4WV9XTGUJRB6HRDMQANB6VT04NH';
$client_secret = '91ec3fc047493706ae9c15c086741d90ef1de3cd6c';
$redirect_uri = 'https://sia.sidharthindustries.com/SIA/';
$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';
$accesstoken = '1000.095b66fc95fc81874c1cfc7d15b0904e.10bc9956d9b9ec14cce1350ee0cf8254';
$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 = '655654572';
$url_org_old ="https://books.zoho.com/api/v3/invoices?";
$url_org ="https://zohoapis.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_old = 'https://books.zoho.com/api/v3/invoices/'.$invoice_id.'?organization_id='.$organization_id;
$url2 = 'https://zohoapis.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);
}