113 lines
3.9 KiB
PHP
Executable File
113 lines
3.9 KiB
PHP
Executable File
<?php
|
|
|
|
if (! function_exists('generateNewToken')) {
|
|
function generateNewToken()
|
|
{
|
|
// Initialize cURL
|
|
$ch = curl_init();
|
|
|
|
// Zoho API credentials
|
|
$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';
|
|
|
|
// Construct URL to get the authentication token
|
|
$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';
|
|
|
|
// Set cURL options
|
|
curl_setopt($ch, CURLOPT_URL, $url_getauthtoken);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// Execute cURL request
|
|
$res_token = curl_exec($ch);
|
|
|
|
// Decode the response
|
|
$ress = json_decode($res_token);
|
|
|
|
// Return access token
|
|
return $ress->access_token;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('getheringInvoiceDetails')) {
|
|
function getheringInvoiceDetails($date_today, $date_yesterday, $accesstoken)
|
|
{
|
|
// Initialize cURL
|
|
$ch = curl_init();
|
|
|
|
// Zoho API credentials
|
|
$organization_id = '776847408';
|
|
$url_org = "https://books.zoho.com/api/v3/invoices?";
|
|
// $url_org = "https://zohoapis.com/books/v3/invoices?";
|
|
|
|
// Construct query parameters
|
|
$fields = array(
|
|
"usestate" => "true",
|
|
"organization_id" => $organization_id,
|
|
"date_start" => $date_yesterday,
|
|
"date_end" => $date_today
|
|
);
|
|
$data_all = http_build_query($fields);
|
|
|
|
// Set headers
|
|
$headers = array(
|
|
'Authorization: Zoho-oauthtoken '.$accesstoken,
|
|
'Content-Type: application/json'
|
|
);
|
|
|
|
// Construct URL
|
|
$data_access = $url_org.$data_all;
|
|
|
|
// Set cURL options
|
|
curl_setopt($ch, CURLOPT_URL, $data_access);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// Execute cURL request
|
|
$result = curl_exec($ch);
|
|
|
|
// Store headers and data
|
|
$data['headers_new'] = $headers;
|
|
$data['data'] = curl_exec($ch);
|
|
// Return data
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('getheringInvoiceSubDetails')) {
|
|
function getheringInvoiceSubDetails($invoice_id, $organization_id, $headers)
|
|
{
|
|
// Initialize cURL
|
|
$ch = curl_init();
|
|
|
|
// Construct URL for invoice sub-details
|
|
$url2 = '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;
|
|
// $url2 = 'https://zohoapis.com/books/v3/invoices/'.$invoice_id.'?organization_id='.$organization_id;
|
|
// Set cURL options
|
|
curl_setopt($ch, CURLOPT_URL, $url2);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// Execute cURL request and return response
|
|
return curl_exec($ch);
|
|
}
|
|
}
|
|
if (! function_exists('test_helper')) {
|
|
function test_helper()
|
|
{
|
|
return "Helper function called!";
|
|
}
|
|
}
|
|
|
|
?>
|