Commit f16f04e8 by Jansa Jose

Merge branch 'jansa'

parents 56b642b3 71f1ebd9
...@@ -6853,171 +6853,178 @@ print_r(date('H:i',$ms));exit();*/ ...@@ -6853,171 +6853,178 @@ print_r(date('H:i',$ms));exit();*/
if (isset($data['month']) && strlen($data['month']) && isset($data['year']) && strlen($data['year']) && isset($data['first_name']) && strlen($data['first_name']) && isset($data['last_name']) && strlen($data['last_name']) && isset($data['card_number']) && strlen($data['card_number']) && isset($data['cvv']) && strlen($data['cvv']) && isset($data['booking_id']) && strlen($data['booking_id'])) { if (isset($data['month']) && strlen($data['month']) && isset($data['year']) && strlen($data['year']) && isset($data['first_name']) && strlen($data['first_name']) && isset($data['last_name']) && strlen($data['last_name']) && isset($data['card_number']) && strlen($data['card_number']) && isset($data['cvv']) && strlen($data['cvv']) && isset($data['booking_id']) && strlen($data['booking_id'])) {
$authtoken = $this->Webservice_model->get_userid_frm_authtoken($headers['Auth']); $authtoken = $this->Webservice_model->get_userid_frm_authtoken($headers['Auth']);
$data['user_id'] = $authtoken->userid; $data['user_id'] = $authtoken->userid;
$get_booked_payed_data = $this->Webservice_model->get_booked_payed_data($data['booking_id']); $payed_data = $this->Webservice_model->get_booked_payed_data($data['booking_id']);
$check_markbooking = $this->Webservice_model->checkBooking($data['booking_id']); if($payed_data['status'] == 'success' && ($payed_data['is_result'] == '0' || $payed_data['is_result'] == '1')){
$booking_details = $this->Webservice_model->get_booking_details($data['booking_id']); $check_markbooking = $this->Webservice_model->checkBooking($data['booking_id']);
$patient_data = $this->Webservice_model->get_single_patient($booking_details['patient_id']); $booking_details = $this->Webservice_model->get_booking_details($data['booking_id']);
$doctor_data = $this->Webservice_model->get_single_doctor($booking_details['doctor_id']); $patient_data = $this->Webservice_model->get_single_patient($booking_details['patient_id']);
$doctor_data = $this->Webservice_model->get_single_doctor($booking_details['doctor_id']);
$time = $data['offset']; $time = $data['offset'];
$new_time = date('H:i', $time); $new_time = date('H:i', $time);
$new_time = explode(':', $new_time); $new_time = explode(':', $new_time);
$nowin_server = date("Y-m-d TH:i:s"); $nowin_server = date("Y-m-d TH:i:s");
if ($data['offset'] > 0) { if ($data['offset'] > 0) {
$nowin_server_addoffset = date('Y-m-d H:i:s', strtotime('+'.$new_time[0].' hour +'.$new_time[1].' minutes', strtotime($nowin_server))); $nowin_server_addoffset = date('Y-m-d H:i:s', strtotime('+'.$new_time[0].' hour +'.$new_time[1].' minutes', strtotime($nowin_server)));
} else { } else {
$nowin_server_addoffset = date('Y-m-d H:i:s', strtotime('-'.$new_time[0].' hour -'.$new_time[1].' minutes', strtotime($nowin_server))); $nowin_server_addoffset = date('Y-m-d H:i:s', strtotime('-'.$new_time[0].' hour -'.$new_time[1].' minutes', strtotime($nowin_server)));
} }
$payment_token = array('account_id' => $this->config->item('id'), 'method' => 'credit_card', 'test' => true, ); $payment_token = array('account_id' => $this->config->item('id'), 'method' => 'credit_card', 'test' => true, );
$payment_token['data'] = array('number' => $data['card_number'], 'verification_value' => $data['cvv'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'month' => $data['month'], 'year' => $data['year']); $payment_token['data'] = array('number' => $data['card_number'], 'verification_value' => $data['cvv'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'month' => $data['month'], 'year' => $data['year']);
$request = load_curl('https://api.iugu.com/v1/payment_token', $payment_token); $request = load_curl('https://api.iugu.com/v1/payment_token', $payment_token);
$token = json_decode($request); $token = json_decode($request);
if ($check_markbooking['count'] != 1) { if ($check_markbooking['count'] != 1) {
$res = array('status' => 'fail', 'payment_status' => '0', 'message' => 'No Booking Found'); $res = array('status' => 'fail', 'payment_status' => '0', 'message' => 'No Booking Found');
}
elseif(!empty($token->errors->number)) {
$res = array('status' => 'fail', 'payment_status' => '0', 'message' => 'Invalid Card Provided');
}
else {
if (empty($patient_data['pt_customer_id'])) {
$create_customer = array('email' => $patient_data['pt_email'], 'name' => $patient_data['pt_name'], 'cpf_cnpj' => $patient_data['pt_cpf'], 'zip_code' => $patient_data['pt_zip_code'], 'street' => $patient_data['pt_street_add'], 'number' => $patient_data['pt_number'], 'complement' => $patient_data['pt_complement']);
$request = load_curl('https://api.iugu.com/v1/customers', $create_customer);
$customer = json_decode($request);
$this->Webservice_model->update_profile($patient_data['patientid'], array('customer_id' => $customer->id));
$patient_data['pt_customer_id'] = $customer->id;
} }
elseif(!empty($token->errors->number)) {
$res = array('status' => 'fail', 'payment_status' => '0', 'message' => 'Invalid Card Provided');
}
else {
if (empty($patient_data['pt_customer_id'])) {
$create_customer = array('email' => $patient_data['pt_email'], 'name' => $patient_data['pt_name'], 'cpf_cnpj' => $patient_data['pt_cpf'], 'zip_code' => $patient_data['pt_zip_code'], 'street' => $patient_data['pt_street_add'], 'number' => $patient_data['pt_number'], 'complement' => $patient_data['pt_complement']);
$request = load_curl('https://api.iugu.com/v1/customers', $create_customer);
$customer = json_decode($request);
$this->Webservice_model->update_profile($patient_data['patientid'], array('customer_id' => $customer->id));
$patient_data['pt_customer_id'] = $customer->id;
}
$create_payment_method = array('description' => 'Booking Payment', 'token' => $token->id); $create_payment_method = array('description' => 'Booking Payment', 'token' => $token->id);
$request = load_curl('https://api.iugu.com/v1/customers/'.$patient_data['pt_customer_id'].'/payment_methods', $create_payment_method); $request = load_curl('https://api.iugu.com/v1/customers/'.$patient_data['pt_customer_id'].'/payment_methods', $create_payment_method);
$payment_method = json_decode($request); $payment_method = json_decode($request);
$create_charge = array('customer_payment_method_id' => $payment_method->id, 'customer_id' => $patient_data['pt_customer_id'], 'email' => $patient_data['pt_email']); $create_charge = array('customer_payment_method_id' => $payment_method->id, 'customer_id' => $patient_data['pt_customer_id'], 'email' => $patient_data['pt_email']);
$items = array('description' => 'Doctor Visit', 'price_cents' => $booking_details['total_sum'] * 100, 'quantity' => 1); $items = array('description' => 'Doctor Visit', 'price_cents' => $booking_details['total_sum'] * 100, 'quantity' => 1);
$create_charge['items'] = $items; $create_charge['items'] = $items;
$create_charge['payer'] = array('cpf_cnpj' => $patient_data['pt_cpf'], 'name' => $patient_data['pt_name'], 'email' => $patient_data['pt_email']); $create_charge['payer'] = array('cpf_cnpj' => $patient_data['pt_cpf'], 'name' => $patient_data['pt_name'], 'email' => $patient_data['pt_email']);
$create_charge['payer']['address'] = array('zip_code' => $patient_data['pt_zip_code'], 'street' => $patient_data['pt_street_add'], 'number' => $patient_data['pt_number'], 'complement' => $patient_data['pt_complement']); $create_charge['payer']['address'] = array('zip_code' => $patient_data['pt_zip_code'], 'street' => $patient_data['pt_street_add'], 'number' => $patient_data['pt_number'], 'complement' => $patient_data['pt_complement']);
//print_r($create_charge);die(); //print_r($create_charge);die();
$request = load_curl('https://api.iugu.com/v1/charge', $create_charge); $request = load_curl('https://api.iugu.com/v1/charge', $create_charge);
$charge = json_decode($request); $charge = json_decode($request);
if (isset($charge->success)and isset($charge->LR)and($charge->success == true)and($charge->LR == '00')) { if (isset($charge->success)and isset($charge->LR)and($charge->success == true)and($charge->LR == '00')) {
/*CODE FOR DOCTOR NOTIFICATION ON CONFIRMED CONSULTATION*/ /*CODE FOR DOCTOR NOTIFICATION ON CONFIRMED CONSULTATION*/
/*CODE FOR WALLET INSERTION*/ /*CODE FOR WALLET INSERTION*/
/*------------------------------------------------*/ /*------------------------------------------------*/
$wallet = $this->Webservice_model->get_wallet_for_doctor($booking_details['doctor_id']); $wallet = $this->Webservice_model->get_wallet_for_doctor($booking_details['doctor_id']);
if (empty($wallet)) { if (empty($wallet)) {
$wallet = array('reedem_earn' => 0, 'future_earn' => 0, 'total_earn' => 0); $wallet = array('reedem_earn' => 0, 'future_earn' => 0, 'total_earn' => 0);
} }
$earn = $booking_details['total_sum'] - (($booking_details['total_sum'] * $booking_details['ipok_fee']) / 100); $earn = $booking_details['total_sum'] - (($booking_details['total_sum'] * $booking_details['ipok_fee']) / 100);
$wallet['future_earn'] = $wallet['future_earn'] + $earn; $wallet['future_earn'] = $wallet['future_earn'] + $earn;
$wallet['total_earn'] = $wallet['total_earn'] + $earn; $wallet['total_earn'] = $wallet['total_earn'] + $earn;
$this->Webservice_model->update_wallet($booking_details['doctor_id'], $wallet); $this->Webservice_model->update_wallet($booking_details['doctor_id'], $wallet);
if ($booking_details['booking_status'] == 0) { if ($booking_details['booking_status'] == 0) {
/*------------------------------------------------*/ /*------------------------------------------------*/
/*CODE FOR SENTING WAITING LIST NOTIFICATION FOR PAID VISIT - PATIENT NOTIFICATION*/ /*CODE FOR SENTING WAITING LIST NOTIFICATION FOR PAID VISIT - PATIENT NOTIFICATION*/
$text_pat = 'Your appointment was scheduled in the system as waiting, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', doctor '.$doctor_data['dr_name']; $text_pat = 'Your appointment was scheduled in the system as waiting, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', doctor '.$doctor_data['dr_name'];
$notification_pat = array('patient_id' => $booking_details['patient_id'], 'type' => 0, 'message' => $text_pat, 'read_status' => 0, 'time' => strtotime($nowin_server), 'booking_id' => $_POST['booking_id']); $notification_pat = array('patient_id' => $booking_details['patient_id'], 'type' => 0, 'message' => $text_pat, 'read_status' => 0, 'time' => strtotime($nowin_server), 'booking_id' => $_POST['booking_id']);
$patient_insert_id = $this->Webservice_model->insert_notification_patient($notification_pat); $patient_insert_id = $this->Webservice_model->insert_notification_patient($notification_pat);
$fcm_user = $this->Webservice_model->get_patient_fcm($booking_details['patient_id']); $fcm_user = $this->Webservice_model->get_patient_fcm($booking_details['patient_id']);
if (!empty($fcm_user['fcm_token'])) { if (!empty($fcm_user['fcm_token'])) {
$pat_push_obj['id'] = $patient_insert_id; $pat_push_obj['id'] = $patient_insert_id;
$pat_push_obj['type'] = "Waiting List"; $pat_push_obj['type'] = "Waiting List";
$pat_push_obj['booking_id'] = $_POST['booking_id']; $pat_push_obj['booking_id'] = $_POST['booking_id'];
$pat_push_obj['booking_date'] = $booking_details['date']; $pat_push_obj['booking_date'] = $booking_details['date'];
$pat_push_obj['doctor_id'] = $booking_details['doctor_id']; $pat_push_obj['doctor_id'] = $booking_details['doctor_id'];
$pat_push_obj['doctor_name'] = $doctor_data['dr_name']; $pat_push_obj['doctor_name'] = $doctor_data['dr_name'];
$pat_push_obj['doctor_specialization'] = $doctor_data['dr_specialization']; $pat_push_obj['doctor_specialization'] = $doctor_data['dr_specialization'];
$pat_push_obj['message'] = $text_pat; $pat_push_obj['message'] = $text_pat;
$pat_push_obj['time'] = strtotime($nowin_server); $pat_push_obj['time'] = strtotime($nowin_server);
$pat_push_obj['to'] = $fcm_user['fcm_token']; $pat_push_obj['to'] = $fcm_user['fcm_token'];
$user_type = '1'; //patient push $user_type = '1'; //patient push
$push_status = $this->Webservice_model->push_sent($pat_push_obj, $user_type); $push_status = $this->Webservice_model->push_sent($pat_push_obj, $user_type);
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
} else { } else {
/*CODE FOR SENTING NOTIFICATION - DOCTOR NOTIFICATION*/ /*CODE FOR SENTING NOTIFICATION - DOCTOR NOTIFICATION*/
/*------------------------------------------------*/ /*------------------------------------------------*/
$text = 'A new appointment was scheduled in the system, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', patient '.$patient_data['pt_name']; $text = 'A new appointment was scheduled in the system, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', patient '.$patient_data['pt_name'];
$notification = array('doctor_id' => $booking_details['doctor_id'], 'type' => 2, 'message' => $text, 'read_status' => 0, 'time' => strtotime($nowin_server)); $notification = array('doctor_id' => $booking_details['doctor_id'], 'type' => 2, 'message' => $text, 'read_status' => 0, 'time' => strtotime($nowin_server));
$doctor_insert_id = $this->Webservice_model->insert_notification_doctor($notification); $doctor_insert_id = $this->Webservice_model->insert_notification_doctor($notification);
$fcm_doctor = $this->Webservice_model->get_doctor_fcm($booking_details['doctor_id']); $fcm_doctor = $this->Webservice_model->get_doctor_fcm($booking_details['doctor_id']);
if (!empty($fcm_doctor['fcm_token'])) { if (!empty($fcm_doctor['fcm_token'])) {
$doc_push_obj['id'] = $doctor_insert_id; $doc_push_obj['id'] = $doctor_insert_id;
$doc_push_obj['type'] = "New Consultation"; $doc_push_obj['type'] = "New Consultation";
$doc_push_obj['message'] = $text; $doc_push_obj['message'] = $text;
$doc_push_obj['read_status'] = false; $doc_push_obj['read_status'] = false;
$doc_push_obj['to'] = $fcm_doctor['fcm_token']; $doc_push_obj['to'] = $fcm_doctor['fcm_token'];
$user_type = '2'; $user_type = '2';
$push_status = $this->Webservice_model->push_sent($doc_push_obj, $user_type); $push_status = $this->Webservice_model->push_sent($doc_push_obj, $user_type);
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
/*CODE FOR SENTING NOTIFICATION - PATIENT NOTIFICATION*/ /*CODE FOR SENTING NOTIFICATION - PATIENT NOTIFICATION*/
/*------------------------------------------------*/ /*------------------------------------------------*/
$text_pat = 'Your appointment was scheduled in the system, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', doctor '.$doctor_data['dr_name']; $text_pat = 'Your appointment was scheduled in the system, on '.date('d.m.Y', $booking_details['time_start']).' at '.date('H:i a', $booking_details['time_start']).', doctor '.$doctor_data['dr_name'];
$notification_pat = array('patient_id' => $booking_details['patient_id'], 'type' => 0, 'message' => $text_pat, 'read_status' => 0, 'time' => strtotime($nowin_server), 'booking_id' => $data['booking_id']); $notification_pat = array('patient_id' => $booking_details['patient_id'], 'type' => 0, 'message' => $text_pat, 'read_status' => 0, 'time' => strtotime($nowin_server), 'booking_id' => $data['booking_id']);
$patient_insert_id = $this->Webservice_model->insert_notification_patient($notification_pat); $patient_insert_id = $this->Webservice_model->insert_notification_patient($notification_pat);
$fcm_user = $this->Webservice_model->get_patient_fcm($booking_details['patient_id']); $fcm_user = $this->Webservice_model->get_patient_fcm($booking_details['patient_id']);
if (!empty($fcm_user['fcm_token'])) { if (!empty($fcm_user['fcm_token'])) {
$pat_push_obj['id'] = $patient_insert_id; $pat_push_obj['id'] = $patient_insert_id;
$pat_push_obj['type'] = "Consultation Confirmation"; $pat_push_obj['type'] = "Consultation Confirmation";
$pat_push_obj['booking_id'] = $data['booking_id']; $pat_push_obj['booking_id'] = $data['booking_id'];
$pat_push_obj['booking_date'] = $booking_details['date']; $pat_push_obj['booking_date'] = $booking_details['date'];
$pat_push_obj['doctor_id'] = $booking_details['doctor_id']; $pat_push_obj['doctor_id'] = $booking_details['doctor_id'];
$pat_push_obj['doctor_name'] = $doctor_data['dr_name']; $pat_push_obj['doctor_name'] = $doctor_data['dr_name'];
$pat_push_obj['doctor_specialization'] = $doctor_data['dr_specialization']; $pat_push_obj['doctor_specialization'] = $doctor_data['dr_specialization'];
$pat_push_obj['message'] = $text_pat; $pat_push_obj['message'] = $text_pat;
$pat_push_obj['time'] = strtotime($nowin_server); $pat_push_obj['time'] = strtotime($nowin_server);
$pat_push_obj['to'] = $fcm_user['fcm_token']; $pat_push_obj['to'] = $fcm_user['fcm_token'];
$user_type = '1'; //patient push $user_type = '1'; //patient push
$push_status = $this->Webservice_model->push_sent($pat_push_obj, $user_type); $push_status = $this->Webservice_model->push_sent($pat_push_obj, $user_type);
}
/*------------------------------------------------*/
} }
/*------------------------------------------------*/ $result = $this->Webservice_model->set_payment_status($data['booking_id']);
}
$result = $this->Webservice_model->set_payment_status($data['booking_id']);
//$res = array('status' => 'success', 'payment_status' => '1', 'message' => 'payment success', 'booking_date' => date('d/m/Y', $check_markbooking['booking_date']), 'booking_slot' => $check_markbooking['booking_slot']); //$res = array('status' => 'success', 'payment_status' => '1', 'message' => 'payment success', 'booking_date' => date('d/m/Y', $check_markbooking['booking_date']), 'booking_slot' => $check_markbooking['booking_slot']);
$res = array('status' => 'success', 'data' =>array('booking_id'=>$data['booking_id'])); $res = array('status' => 'success', 'data' =>array('booking_id'=>$data['booking_id']));
} else { } else {
// $res = array('status' => 'fail', 'payment_status'=>'0','message'=>$charge->message); // $res = array('status' => 'fail', 'payment_status'=>'0','message'=>$charge->message);
$res = array('status' => 'error', 'payment_status' => '0', 'message' => $charge->errors); $res = array('status' => 'error', 'payment_status' => '0', 'message' => $charge->errors);
}
} }
}else{
$res = array(
"status" => "error",
"error" => "error",
"message" => $payed_data['message']);
} }
} else { } else {
$res = array( $res = array(
......
...@@ -3865,22 +3865,28 @@ class Webservice_model extends CI_Model { ...@@ -3865,22 +3865,28 @@ class Webservice_model extends CI_Model {
$this->db->update('tbl_booking', $update); $this->db->update('tbl_booking', $update);
} }
// public function get_booked_payed_data($id){ public function get_booked_payed_data($id){
// $booked_data = $this->db->get_where('tbl_booking',array('id'=>$id))->row_array(); $booked_data = $this->db->get_where('tbl_booking',array('id'=>$id))->row_array();
// if($booked_data){ if($booked_data){
// $check = $this->db->get_where('tbl_booking',array('doctor_id'=>$booked_data['doctor_id'],'clinic_id'=>$booked_data['clinic_id'],'date'=>$booked_data['date'],'time'=>$booked_data['time'],'payment_status'=>'1')); $check = $this->db->get_where('tbl_booking',array('doctor_id'=>$booked_data['doctor_id'],'clinic_id'=>$booked_data['clinic_id'],'date'=>$booked_data['date'],'time'=>$booked_data['time'],'payment_status'=>'1'));
// if($check->num_rows() <= '0'){ if($check->num_rows() <= '0'){
// $is_result = 0; $is_result = 0;
// }else if($check->num_rows() == '1'){ $res = array('status'=>'success','is_result'=>$is_result);
// $is_result = 1; }else if($check->num_rows() == '1'){
// }else if($check->num_rows() >= '1'){ $is_result = 1;
// $is_result = 2; $this->db->update('tbl_booking',array('booking_status'=>'0'),array('id'=>$id));
// } $res = array('status'=>'success','is_result'=>$is_result);
}else if($check->num_rows() >= '1'){
// return $is_result; $is_result = 2;
$this->db->update('tbl_booking',array('booking_status'=>'4'),array('id'=>$id));
// } $res = array('status'=>'error','is_result'=>$is_result,'message'=>'
// } Selected Doctor Not Available');
}
}else{
$res = array('status'=>'error','message'=>'No Booking Found');
}
return $res;
}
/*function push_sent($fcm_data,$type) { /*function push_sent($fcm_data,$type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment