124 lines
5.0 KiB
PHP
124 lines
5.0 KiB
PHP
<?php
|
|
|
|
class SMCFINANCE
|
|
{
|
|
|
|
// 1. AUTH URL
|
|
// API URL : http://ums.devopsmcfinance.com/umsnode/ums/api/v1/auth/login
|
|
// TYPE : POST
|
|
// BODY : { "userCode": "APIEdge", "userPass": "sineUAT", "application": [ "Sales App-API" ] }
|
|
public static function SmcFinanceAuthUrl()
|
|
{
|
|
|
|
log_message('ERROR','## SMC Finance Auth Url FNS');
|
|
// echo "Token Generation/Refresh Fns";
|
|
$headers = array('Content-Type: application/json');
|
|
try{
|
|
$ch = curl_init();
|
|
$body = '{ "userCode": "APIEdge","userPass": "sineUAT", "application": [ "Sales App-API" ] }';
|
|
log_message('ERROR',"## SMC Finance Auth Url Request ".$body);
|
|
curl_setopt($ch, CURLOPT_URL, SMC_FINANCE_AUTH_URL);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
|
|
// $result = curl_exec($ch );
|
|
$result = (array)curl_exec($ch );
|
|
if(!empty($result)){
|
|
$response_decoded = json_decode($result[0]);
|
|
$token = $response_decoded->data->accessToken;
|
|
}else{
|
|
$token = null;
|
|
}
|
|
|
|
// $response_decoded = json_decode($result);
|
|
// $response = $response_decoded;
|
|
curl_close( $ch );
|
|
log_message('ERROR', "## SMC Finance Auth Url Token : " . $token);
|
|
}
|
|
catch (Exception $e) {
|
|
$token = null;
|
|
// $response->error = array($e->getMessage());
|
|
log_message('ERROR', "## Smc Finance Auth Url ERR : " . $e->getMessage());
|
|
}
|
|
return $token;
|
|
}
|
|
|
|
|
|
// 2. Refresh Token
|
|
// API URL: http://ums.devopsmcfinance.com/umsnode/ums/api/v1/auth/access-token
|
|
// TYPE : POST
|
|
// BODY : { "refreshToken": {Refresh Token} }
|
|
public static function SmcFinanceRefreshToken($token)
|
|
{
|
|
$CI =& get_instance();
|
|
// $headersData = getallheaders();
|
|
log_message('ERROR','#### SMC Finance Refresh Token FNS ');
|
|
$headers = array('Content-Type: application/json');
|
|
try{
|
|
$ch = curl_init();
|
|
$body = '{ "refreshToken":$token'.$token.' }';
|
|
log_message('ERROR',"SMC Finance Refresh Token Request ".$body);
|
|
curl_setopt($ch, CURLOPT_URL, SMC_FINANCE_REFRESH_TOKEN);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
|
|
$result = curl_exec($ch );
|
|
$response_decoded = json_decode($result);
|
|
$response = $response_decoded;
|
|
curl_close( $ch );
|
|
log_message('ERROR','#### SMC Finance Refresh Token Reponse '.$response);
|
|
}
|
|
catch (Exception $e) {
|
|
$response->error = array($e->getMessage());
|
|
log_message('ERROR','#### SMC Finance Refresh Token Err '. $e->getMessage());
|
|
}
|
|
return $response;
|
|
}
|
|
|
|
// 3. API URL
|
|
// API URL: http://devopsmcfinance.com/salesapi/salesapplication/v1/sales-lead/${salesid}/update-pd
|
|
// TYPE : PUT
|
|
// BODY : { "pdId": "MWISE-LFMP-357", "pdStatus": 1 }
|
|
public static function SmcFinanceApiUrl($applicant_id,$sales_pd_id,$sales_pd_sno,$sales_pd_status,$token)
|
|
{
|
|
log_message('ERROR',"SMC Finance Api Fns ".$token);
|
|
// 'Authorization:Zoho-oauthtoken '.$newaccesstoken,
|
|
$headers = array('Content-Type: application/json','Authorization: Bearer '.$token);
|
|
try{
|
|
$ch = curl_init();
|
|
$body = '{"pdId":"'.$sales_pd_sno.'","pdStatus":'.$sales_pd_status.',"salesLeadId":'.$applicant_id.'}';
|
|
log_message('ERROR',"SMC Finance Api Request ".$body);
|
|
// $put_url = SMC_FINANCE_API_URL.$sales_pd_id.'/update-pd';
|
|
|
|
curl_setopt($ch, CURLOPT_URL, SMC_FINANCE_UPDATE_URL);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
|
|
|
|
$result = curl_exec($ch );
|
|
$response_decoded = json_decode($result);
|
|
log_message('ERROR', "SMC Finance Api Response : ".$result);
|
|
curl_close( $ch );
|
|
}
|
|
catch (Exception $e) {
|
|
// $response->error = array($e->getMessage());
|
|
$result = array($e->getMessage());
|
|
log_message('ERROR', "SMC Finance Api ERR : " . $e->getMessage());
|
|
}
|
|
return $result;
|
|
|
|
}
|
|
|
|
} |