<?php
include '../config/index.php';
include '../module/index.php';
 
$data = new Database;

$con = $data->connect();

$user = new User($con);

$post = filter_var_array($_POST,FILTER_SANITIZE_FULL_SPECIAL_CHARS);

$pin    = $post['pin'];
$amount = $_SESSION['amount'];
$account_no = $_SESSION['account_tr'];
$id = $user->getByAccountNo($account_no);
$type = 'Debit';
$user_id = $_SESSION['id'];

$reference = uniqid();
$date = new DateTime();
$c = $date->format('d M y, h:i a'); // 21 Dec 22, 08:39 pm
$status = 'complete';

if($_SESSION['user_id'] != $pin){
   $_SESSION['t_error_c']  = 'incorrect pin';
   echo $data->redirect('../account/../index?pin=pin');
}else{
   echo $user->fundTransfer($amount);
   echo $user->creditTransfer($amount,$id);
   
   echo $user->createTransaction($amount,$user_id,$reference,'nill',$c,$status,$type);
   echo $user->createTransaction($amount,$id,$reference,'nill',$c,$status,'Credit');

   $_SESSION['t_error_c']  = 'Transaction complete sucessfully';
   echo $data->redirect('../account/../index?home=home');
}



?>