Finicity API Issue - php

We are using the finicity API to get statements and transaction. We have followed below steps, but we are getting "aggregationStatusCode:185" while fetching the customer accounts [ https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts ].
To get the custommer account I am using https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts.
Then we are fetching statements for account using "https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts/['account_id']/statement?index=1; this loops for 6 times. We need 6 months statement for each account.
Then, we are fetching transaction for account using "https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts/['account_id']/transactions?fromDate=".$from."&toDate=".strtotime(date('Y-m-d'))."&limit=".$transactionLimit."&includePending=true";
We are facing the below two issues.
1. Getting timeout error, when selecting more than 2 accounts.
2. Getting "aggregationStatusCode:185" for some live accounts.
Below are the code for reference.
function get_statements(){
$FinicityAppToken=$_POST['FinicityAppToken'];
$customerId=$_POST['customerId'];
$leadId=$_POST['leadId'];
$finicityConnectUrl=$_POST['finicityConnectUrl'];
$NoOFStatements = 6;
$transactionLimit = 100;
$transactionsMonth = 1;
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts";
$response=callAPI('POST', $url,false,$FinicityAppToken);
$response = json_decode($response);
$allstatements=array();
if($response){
if(isset($response->accounts)){
$accounts = array();
$array = array();
foreach($response->accounts as $account){
if ($account->aggregationStatusCode == 0 && $account->aggregationSuccessDate != '' && $account->aggregationAttemptDate != '') {
for($i=1;$i<=$NoOFStatements;$i++) {
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts/".$account->id."/statement?index=".$i;
$stateresponse=callAPI('GET', $url,false,$FinicityAppToken);
$temp = array();
$temp['accountId'] = $account->id;
$temp['statement'] = base64_encode($stateresponse);
$statements[]=$temp;
}
$act = array();
$month = date('m') - $transactionsMonth;
$from = strtotime(date('Y').'-'.$month.'-1');
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts/".$account->id."/transactions?fromDate=".$from."&toDate=".strtotime(date('Y-m-d'))."&limit=".$transactionLimit."&includePending=true";
$data['url'] = $url;
$transactions = json_decode(callAPI('GET', $url,false,$FinicityAppToken));
$act['account']['accountNumber'] = $account->number;
unset($account->number);
$act['account']['currencySymbol'] = $account->currency;
unset($account->currency);
if(empty((array) $account->detail)) {
$account->detail = (object) transactionsDetailsEmpty();
}
$act['account'] = json_decode(json_encode($account), true);
if(isset($transactions->transactions)) {
$act['transactions'] = $transactions->transactions;
} else {
$act['transactions'] = array();
}
// echo "step";
$accounts[] = $act;
} else {
$data['success'] = 1;
$data['response']=$response ;
$data['finicityConnectUrl'] = $finicityConnectUrl;
$data['leadId'] = $leadId;
$data['FinicityAppToken'] = $FinicityAppToken;
$data['customerId'] = $customerId;
echo json_encode($data);
die();
}
$j++;
}
$array['accounts'] = $accounts;
$array['leadId'] = $leadId;
$data['accounts'] = $array;
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId;
$response=callAPI('DELETE', $url,false,$FinicityAppToken);
}
}
}

Related

unable to insert multiple array data from dynamic generated field?

I am unable to enter multiple data, it enter only single data. I have tried using for loop and then entering data, using 3 user and 2 task, there is an error previously offset.
public function add($postData)
{
// dd($postData);
$c = count($postData['user_name']);
$t = count($postData['task_name']);
for ($i = 0; $i < $c; $i++) {
$user_name = $postData['user_name'][$i];
$user_email = $postData['user_email'][$i];
$data['insert']['user_name'] = $user_name;
$data['insert']['user_email'] = $user_email;
}
for ($j = 0; $j < $t; $j++) {
$task_name = $postData['task_name'][$j];
$data['insert']['task_name'] = $task_name;
}
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
if ($result == true) {
$response['status'] = 'success';
$response['message'] = 'Project created';
} else {
$response['status'] = 'danger';
$response['message'] = DEFAULT_MESSAGE;
}
return $response;
}
As Per lack of question details attached, I am supposing that you want to insert multiple task entry with project name, description etc.
Here is updated code:
<?php
// dd($postData);
$username = $postData['username'];
$user_email = $postData['user_email'];
$task_name = $postData['task_name'];
foreach ($username as $key => $value) {
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['username'] = $value;
$data['insert']['user_email'] = $user_email[$key];
$data['insert']['task_name'] = $task_name[$key];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
}

While loop doesn't wait before displaying

In this code section, the query gets all the teachers and appends their assigned classes within the object
The weird thing is it works perfectly on local but not online, it is almost it doesn't wait for the while loop
<?php
$SID = mysqli_real_escape_string($con, htmlspecialchars($_POST["SID"], ENT_QUOTES));
$allTeachersArr = [];
$test = [];
$q = "SELECT onderwysers.*,klasse.Klas,klasse.Datum,klasse.Vak FROM `onderwysers` LEFT JOIN klasse ON onderwysers.ID = klasse.Teacher WHERE `SID` = '$SID'";
// echo $q;
$result = $con->query($q);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$subjectItem = new stdClass();
$filtered_array = [];
$isIn = false;
$var1 = $row['ID'];
$var2 = $row['Teacher'];
if (count($allTeachersArr) > 0)
foreach ($allTeachersArr as $item) {
if ($item->ID == $var1 && $item->Teacher == $var2) {
// do something
$filtered_array = $item;
$isIn = true;
}
}
if ($isIn == true) {
$notAdd = false;
// echo "updates";
$subjectItem->Klas = $row["Klas"];
$subjectItem->Datum = $row["Datum"];
$subjectItem->Vak = $row["Vak"];
foreach ($filtered_array->displaySubjects as $item) {
if ($item->Klas == $row["Klas"] && $item->Vak == $row["Vak"] && $item->Datum == $row["Datum"]) {
// do something
$filtered_array = $item;
$notAdd = true;
}
}
if ($notAdd == false) {
$temp = $filtered_array->displaySubjects;
array_push($temp, $subjectItem);
$filtered_array->displaySubjects = $temp;
}
} else {
//add new entry
$subjectItem->ID = $row["ID"];
$subjectItem->Title = $row["Title"];
$subjectItem->Name = $row["Name"];
$subjectItem->Surname = $row["Surname"];
$subjectItem->Afkorting = $row["Afkorting"];
$subjectItem->IdentityNumber = $row["IdentityNumber"];
$subjectItem->Geslag = $row["Geslag"];
$subjectItem->ContactDetails = $row["ContactDetails"];
$subjectItem->Email = $row["Email"];
$subjectItem->RegKlas = $row["RegKlas"];
$subjectItem->Status = $row["Status"];
$subjectItem->UID = $row["UID"];
$subjectItem->displaySubjects = [];
array_push($allTeachersArr, $subjectItem);
}
}
}
echo json_encode($allTeachersArr);
$con->close();
THE EXPECTED RETURNED DATA(This is local, online returns nothing)

Laravel - Import excel keep looping

Dears,
i have an excel file with 5K rows and i'm importing it to my table in the DB successfully.
But the error, when the system finish all the rows, it keeps looping and the page doesn't stop running and not redirecting to my view.
My controller:
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->select('id')->get()->toArray();
if(empty($res)) {
$polic = new policies();
$polic->cust_id = $row['custno'];
$polic->policy = '';
$polic->bord_date = $borddate;
$polic->client_id = $row['clientid'];
$polic->client_no = $row['clientno'];
$polic->client_name = $row['clientname'];
$polic->draft_no = $row['draftno'];
if ($row['status'] == '') {
$polic->status = '';
} else {
$polic->status = $row['status'];
}
$polic->due_date = $duedate;
if ($row['curno'] == 'USD') {
$polic->currency = 1;
} else {
$polic->currency = 0;
}
$polic->amount = $row['amnt'];
$polic->zone = $row['zone'];
$polic->broker_id = $row['brokercode'];
$polic->broker_name = $row['brokername'];
$polic->remarks = $row['remarks'];
$polic->phone = $row['phone'];
$polic->insured_name = $row['insname'];
// $polic->cust_id = $row['valuedate'];
$polic->address = ''; //address
if (trim($row['status']) == 'P') {
$polic->paid_at = date('Y-m-d');
}
$polic->new = 1; //address
$polic->save();
}
else {
//am updating the imported date in the DB
}
what is very strange that in my localhost is working fine, but in digitaloceans cloud, keep looping without redirecting.
Thanks for your help.
I can be because you have 5000 rows to insert and 5000 insert operation consumes lots of memory. What you can try is batch insert operation.
In your policies.php make all fields fillable
protected $fillable=['cust_id ','policy','bord_date','client_id','client_no','client_name ','draft_no','bord_date','status','due_date','currency','amount','zone','broker_id','broker_name','remarks','phone','insured_name','address','paid_at','new'];
And on your excel file import use exists rather than getting collections.
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
$data=[];
$i=0;
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->exists();
if(!$res) {
$i++;
$data[$i]['cust_id ']=$row['custno'];
$data['policy'] = '';
$data['bord_date'] = $borddate;
$data[$i]['client_id'] = $row['clientid'];
$data[$i]['client_no'] = $row['clientno'];
$data[$i]['client_name'] = $row['clientname'];
$data[$i]['draft_no'] = $row['draftno'];
if ($row['status'] == '') {
$data[$i]['status'] = '';
} else {
$data[$i]['status'] = $row['status'];
}
$data[$i]['due_date'] = $duedate;
if ($row['curno'] == 'USD') {
$data[$i]['currency'] = 1;
} else {
$data[$i]['currency'] = 0;
}
$data[$i]['amount'] = $row['amnt'];
$data[$i]['zone'] = $row['zone'];
$data[$i]['broker_id'] = $row['brokercode'];
$data[$i]['broker_name'] = $row['brokername'];
$data[$i]['remarks'] = $row['remarks'];
$data[$i]['phone'] = $row['phone'];
$data[$i]['insured_name'] = $row['insname'];
// $data[$i]['cust_id'] = $row['valuedate'];
$data[$i]['address'] = ''; //address
if (trim($row['status']) == 'P') {
$data[$i]['paid_at'] = date('Y-m-d');
}
$data[$i]['new'] = 1; //address
}
else {
//am updating the imported date in the DB
}
}
policies::insert($data);

Undefined variable: error in adding field into db

I'm getting error:Undefined variable: error
in my code:
public function add(){
$this->polls_model->rules = Pf::event()->trigger("filter","polls-adding-validation-rule",$this->polls_model->rules);
$template = null;
$template = Pf::event()->trigger("filter","polls-add-template",$template);
if ($this->request->is_post()){
$data = array();
$data["polls_question"] = $this->post->{"polls_question"};
$data["polls_pubdate"] = str_to_mysqldate($this->post->{"polls_pubdate"},$this->polls_model->elements_value["polls_pubdate"],"Y-m-d H:i:s");
$data["polls_unpubdate"] = str_to_mysqldate($this->post->{"polls_unpubdate"},$this->polls_model->elements_value["polls_unpubdate"],"Y-m-d H:i:s");
if (is_array($this->post->{"polls_status"})){
$data["polls_status"] = implode(",",$this->post->{"polls_status"});
}else{
$data["polls_status"] = $this->post->{"polls_status"};
}
$port_answer = isset($this->post->{"answer"}) ? $this->post->{"answer"} : array();
$data = Pf::event()->trigger("filter","polls-post-data",$data);
$data = Pf::event()->trigger("filter","polls-adding-post-data",$data);
$var = array();
$pollq_multiple_yes = intval($this->post->{'pollq_multiple_yes'});
$data['polls_multiple'] = 0;
if ($pollq_multiple_yes == 1) {
if(intval($this->post->{'pollq_multiple'}) > count($port_answer)){
$data['polls_multiple'] = 1;
}else{
$data['polls_multiple'] = intval($this->post->{'pollq_multiple'});
}
} else {
$data['polls_multiple'] = 1;
}
//debug($data);
Pf::database()->query('START TRANSACTION');
$inserted = $this->polls_model->insert($data);
if($inserted === false){
Pf::database()->query('ROLLBACK');
}else{
$new_id = $this->polls_model->insert_id();
$insert_meta = true;
if(count($port_answer) > 0){
$custom = array();
$int = count($port_answer);
for ($i = 0; $i < $int ; $i++) {
if(!empty($port_answer[$i])){
$custom = array(
'pollsa_qid' => $new_id,
'pollsa_answers' => e($port_answer[$i]),
);
}
$insert_meta = $this->answers_model->insert($custom);
}
if($insert_meta === false){
Pf::database()->query('ROLLBACK');
}else{
Pf::database()->query('COMMIT');
}
}
Pf::database()->query('COMMIT');
}
$errors = Pf::validator()->get_readable_errors(false);
foreach ($errors as $key => $value) {
$error[$key][0] = $errors[$key][0];
}
$this->view->errors = $error; // error here!
$var['content'] = $this->view->fetch($template);
if (count($error) > 0){// and here!!!
$var['error'] = 1;
}else{
Pf::event()->trigger("action","polls-add-successfully",$this->polls_model->insert_id(),$data);
$var['error'] = 0;
$var['url'] = admin_url($this->action.'=index&ajax=&id=&token=');
}
echo json_encode($var);
}else{
$this->view->render($template);
}
}
I edited code, added function code.
This is my add function, if I want add poll with answers.
It gives me this error to my log.
I found this tutorial Undefined Variable error in View
I've googled it but didnt find anything special what helps me out.
Initiate the variable as an array.
because if the $error is empty the compiler will see it as an array.
if not it will get an error.
$error = [];
$errors = Pf::validator()->get_readable_errors(false);
foreach ($errors as $key => $value) {
// $error[$key][0] = $errors[$key][0];
// the right way is below
// i actually dont know what you want to do but this is the right way
// but providing [0] will make it some how constant.
$error[$key] = $errors[$key]
}
$this->view->errors = $error; // error showing here!
$var['content'] = $this->view->fetch($template);
if (count($error) > 0){ // and here???
$var['error'] = 1;
}else{
Pf::event()->trigger("action","polls-add-successfully",$this->polls_model->insert_id(),$data);
$var['error'] = 0;
$var['url'] = admin_url($this->action.'=index&ajax=&id=&token=');
}

how can i create and pass value in multidimensional array in php?

I need to save some data's in php. I am trying this code
$click_free = [];
$ano = 0;
while($res_qry = mysql_fetch_array($sel_qry)){
$arr_cnt = sizeof($click_free);
if($arr_cnt != 0){
$m = 0;
for($k=0;$k<$arr_cnt;$k++)
{
if($click_free[$k][0] == $res_qry['Free_id'])
{
$click_free[$k][0] = ($click_free[$k][0]+$res_qry['Qty']);
$m=1;
}
}if($m==0){
$click_free[$arr_cnt] = [1,];
}
}else{
$click_free[0] = [$res_qry['Free_id'],$res_qry['Qty']];
}
}
But this code has many error. Please help me solve this
while($res_qry = mysql_fetch_array($sel_qry)){
$id_existed = false;
if(!empty($click_free))
foreach($click_free as $key=>$ligne)
if( $ligne[0] == $res_qry['Free_id']){
$qty = $ligne[1] + $res_qry['Qty'];
$click_free[$key] = [ $ligne[0] , $qty ];
$id_existed =true;
}
if(!$id_existed){
$click_free[] = [ $res_qry['Free_id'] , $res_qry['Qty'] ];
}
}
Finally we got a solution
while($res_qry = mysql_fetch_array($sel_qry)){
$arr_cnt = sizeof($click_free);
if($arr_cnt != 0){
$m = 0;
foreach ($click_free as $k => $v) {
if ($v['Free_id']==$res_qry['Free_id']) {
S_qty=$v['Qty']+$res_qry['Qty'];
$click_free[$k]['Qty']=$S_qty;
$m=1;
}
}
if($m==0){
$click_free[] = array("Free_id" => $res_qry['Free_id'],"Qty"=>$res_qry['Qty']);
}
}else{
$click_free[] = array("Free_id" => $res_qry['Free_id'],"Qty"=>$res_qry['Qty']);
}
}
Thanks to bfahmi, Kris Roofe, B. Desai , user3542450, dr_debug

Categories