Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.144.23.138
<?php
ini_set('max_execution_time', 300);
ini_set("memory_limit","500M");
header("Content-Type: text/html");
require_once("PaytmChecksum.php");
function downloadSettlement($aobj_context)
{
$univcode = $aobj_context->mobj_data["univcode"];
$req = $aobj_context->req_body;
$type = $req['data']['type'];
$banktype = $req['data']['banktype'];
$fdate = $req['data']['fdate'];
$tdate = $req['data']['tdate'];
if($type == 'adm')
{
$cnd = "and ifnull(FENTTYPE,'') in('REGN','adm')";
}else
{
$cnd = "and ifnull(FENTTYPE,'') not in('REGN','adm')";
}
$aobj_context->pobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$query = "select distinct d.funivcode, d.fdbname, d.funivname, m.fkey,
m.fmid,m.fworkingid
from maspg m inner join dbname d
on d.funivcode = m.funivcode
where m.fbank = '{$banktype}' and ifnull(fsuspend,'') <> 'T'
and d.funivcode = '{$univcode}'
$cnd";
$result9 = $aobj_context->mobj_db->GetRow($query);
if(!$result9)
{
$arr['msg'] = 'Account Details Not Found';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
return;
}
$key = $result9['fkey'];
$mid = $result9['fmid'];
$dbname = $result9['fdbname'];
if($banktype == 'Paytm')
{
$response = apiResponse($mid, 1, 1, $key,$fdate,$tdate);
$res = json_decode($response, true);
$res_list = $res['settlementListResponse'];
$total_count = $res_list['totalCount'];
$max = ceil($total_count / 500);
for ($x = 1; $x <=$max ; $x++)
{
$response = apiResponse($mid, $x, 500, $key,$fdate,$tdate);
$res = json_decode($response, true);
$res_list = $res['settlementListResponse'];
$settle_list = $res_list['settlementTransactionList'];
$insert_value = '';
$provider = 'Paytm';
foreach ($settle_list as $row)
{
$date = "date_format(str_to_date('".$row['UTRPROCESSEDTIME']."', '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d %H:%i:%s')";
$insert_value =$insert_value."('".$provider."', '".$row['MERCUNQREFVAL']."', '".$row['CUSTID']."', '".$row['TXNID']."', '".$row['SETTLEDAMOUNT']."', '".$row['UTR']."', '".$row['ORDERID']."', ".$date.'),';
//die();
}
$final_value = rtrim($insert_value, ",");
$insert_data = "insert ignore into recon_new (fprovider, fappno, fregno, ftranid, famount, futr, forderid, futdate) values " . $final_value;
//var_dump($insert_data);
$result = $aobj_context->pobj_db->Execute($insert_data);
}
}else if($banktype == 'Razorpay')
{
$key = $result9['fkey'];
$secret = $result9['fworkingid'];
$fdate_date = explode('/', $fdate);
$year = $fdate_date[2];
$month = $fdate_date[1];
$url = "https://api.razorpay.com/v1/settlements/recon/combined?year=".$year."&month=".$month."&count=1000";
// var_dump($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, $key . ':' . $secret);
$response = curl_exec($ch);
$res = json_decode($response, true);
$settle_list = $res['items'];
$insert_value = '';
$provider = 'Razorpay';
foreach ($settle_list as $row){
$user = json_decode($row['notes']);
$date = "date_format(str_to_date('".gmdate("Y-m-d H:i:s", $row['settled_at'])."', '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d %H:%i:%s')";
$final_amount = $row['credit'] /100;
$insert_value =$insert_value."('".$provider."', '".$user->appno."', '".$user->regno."', '".$row['entity_id']."', '".$final_amount."', '".$row['settlement_utr']."', '".$row['order_id']."', ".$date.'),';
$final_value = rtrim($insert_value, ",");
}
$insert_data = "insert ignore into recon_new (fprovider, fappno, fregno, ftranid, famount, futr, forderid, futdate) values " . $final_value;
$result = $aobj_context->pobj_db->Execute($insert_data);
}
if ($result) {
$update_appcandsum = "update recon_new a, appcandsum b
set a.fappdate = b.fdate,
a.fdegree = b.fdegree,
a.fcollcode = b.fcollcode,
a.fyear = b.fyear,
a.fmode = b.fexamtype,
a.fappfor = 'Exam Application'
where a.fregno = b.fregno
and a.fappno = b.appno
and ifnull(fappdate,'') = ''";
$result1 = $aobj_context->pobj_db->Execute($update_appcandsum);
$update_res_stud = "update recon_new a, res_stud b
set a.fappdate = b.fappdate,
a.fdegree = b.fdegree,
a.fcollcode = b.fcollcode,
a.fyear = b.fyear,
a.fmode = b.fexamtype,
a.fappfor = 'RV / RT / PC Application'
where a.fregno = b.fregno
and a.fappno = b.appno
and ifnull(a.fappdate,'') = ''";
$result2 = $aobj_context->pobj_db->Execute($update_res_stud);
$update_res_stud = "update recon_new a, servtran b
set a.fappdate = b.fappdate,
a.fdegree = b.fdegree,
a.fcollcode = b.fcollcode,
a.fappfor = 'Online Service',
a.fname = b.fname
where a.fregno = b.fregno
and a.fappno = b.fappno
and ifnull(a.fappdate,'') = ''";
$result2 = $aobj_context->pobj_db->Execute($update_res_stud);
$update_res_stud = "update recon_new a, dctran b
set a.fappdate = b.FREGDATE,
a.fappfor = 'Convocation Application',
a.fname = b.fname
where a.fregno = b.fregno
and a.fappno = b.fappno
and ifnull(a.fappdate,'') = ''";
$result2 = $aobj_context->pobj_db->Execute($update_res_stud);
$update_student = "update recon_new a, student s
set a.fname = s.fname,
a.fcollcode = s.fcollcode,
a.fdegree = s.fdegree
where a.fregno = s.fregno
and ifnull(a.fname,'') = ''";
$result3 = $aobj_context->pobj_db->Execute($update_student);
$update_student = "update recon_new a, studhist s
set a.fname = s.fname,
a.fcollcode = s.fcollcode,
a.fdegree = s.fdegree
where a.fregno = s.fregno
and ifnull(a.fname,'') = ''";
$result3 = $aobj_context->pobj_db->Execute($update_student);
$delete_query = "delete from recon_new where ifnull(futr,'') = ''";
$result4 = $aobj_context->pobj_db->Execute($delete_query);
$arr['msg'] = 'Details Download';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
return;
} else {
$arr['msg'] = 'No Deatils Found';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
return;
}
}
function apiResponse($mid, $pageNum, $pageSize, $key,$fdate,$tdate){
$fdate_date = explode('/', $fdate);
$fdate = $fdate_date[2].'-'.$fdate_date[1].'-'.$fdate_date[0];
$tdate_date = explode('/', $tdate);
$tdate = $tdate_date[2].'-'.$tdate_date[1].'-'.$tdate_date[0];
$todayDate = date('Y-m-d',strtotime($tdate));
$prevDate = date('Y-m-d',strtotime($fdate));
/* initialize an array */
$paytmParams = array();
// var_dump(date("Y-m-d"));
$paytmParams = array(
"MID" => $mid,
"utrProcessedStartTime" => $prevDate,
"utrProcessedEndTime" => $todayDate,
"pageNum"=>$pageNum,
"pageSize"=>$pageSize
);
$paytmChecksum = PaytmChecksum::generateSignature($paytmParams, $key);
/* head parameters */
$paytmParams = array(
/* put generated checksum value here */
"MID" => $mid,
"utrProcessedStartTime" => $prevDate,
"utrProcessedEndTime" => $todayDate,
"pageNum"=>$pageNum,
"pageSize"=>$pageSize,
"checksumHash" => $paytmChecksum
);
$post_data = json_encode($paytmParams);
//var_dump($post_data);
$url = "https://securegw.paytm.in/merchant-settlement-service/settlement/list";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
return $response;
}
?>
|