<?php
/**
 * Created by PhpStorm.
 * User: Ludah
 * Date: 8/31/2017
 * Time: 5:19 PM
 */

include "../../../config/connection.php";
include "../../config/functions/func_init.php";
include "api-func.php";


if ($_SERVER['REQUEST_METHOD'] == "POST") {

    /*
     * Json Accept values(action,kiv,ksp,phoneNumber)
     *
     */
    $pKey = passwordHash($_SERVER['HTTP_PKEY'],$mySalt);
    $mPhone = html_filter($dbc,$_SERVER['HTTP_MPHONE']); // format (+233700000001)
    //$action = html_filter($dbc,$_SERVER['HTTP_ACTION']);

    $response = array();
    $request = array();

    if(api_check_header_auth($dbc,$pKey,$mPhone)) {
        $action = $_REQUEST['action'];

        if ($action == 100) {
            // get Single Transaction on main transaction table
            $phoneNum = html_filter($dbc, $_REQUEST['phoneNum']);
            $transaction_uid = html_filter($dbc, $_REQUEST['transaction_id']);
            if (!empty($phoneNum) AND !empty($transaction_uid)) {
                $data = api_get_single_transaction($dbc, $phoneNum, $transaction_uid,$mPhone);
                $customerData = get_customer_by_id($dbc, $data['senderID']);
                if ($data['id'] != '') {
                    $response['dateTime'] = $data['dateTime'];
                    $response['name'] = $customerData['fullName'];
                    $response['company'] = $customerData['companyName'];
                    $response['amount'] = $data['recipientAmount'];
                    $response['billCode'] = $data['billCode'];
                    $response['transaction_id'] = $data['transaction_uid'];
                    $response['status'] = "SUCCESS";
                    $response['status-code'] = "0";
                } else {
                    $response['status'] = "ERROR_NO_DATA_FOUND";
                    $response['status-code'] = "1";
                }

            } else {
                $response['status'] = "ERROR_EMPTY_FIELDS";
                $response['status-code'] = "1";
            }
        }elseif($action == 101){

            if(check_if_number_exist($dbc,'')) {
                $phoneNum = html_filter($dbc, $_REQUEST['phoneNum']);
                $fullName = html_filter($dbc, $_REQUEST['fullName']);
                $fullName = html_filter($dbc, $_REQUEST['fullName']);

                if (api_add_new_customer($dbc, '', '', '', 'INDIVIDUAL')) {

                }
            }
        } else {
            $response['status'] = "ERROR_ACTION";
            $response['status-code'] = "1";
        }
    }else{
        $response['status'] = "ERROR_HEARD_AUTH";
        $response['status-code'] = "1";
    }

        echo json_encode($response);




}
