<?php
require_once("./includes/initialize.php");
require_once("./includes/config.php");

error_reporting(0);
define('INCLUDE_CHECK', true);
session_start();

// test
//require ('classes/config.php');
if ($_SESSION['txn_ref'] == "") {
    header("location: payment_method.php");
}
//	echo $_SESSION['txn_ref'];
$sql = mysql_query("SELECT * FROM acceptance_tranzact WHERE txt_ref='$_SESSION[txn_ref]' AND status='UNPAID' LIMIT 0,1");


$siteRedirectUrl = GATEWAY;
$siteRedirectName = GATEWAYSHORT;
if (mysql_num_rows($sql) > 0) {

    $srows = mysql_fetch_array($sql);

    $fullname = $srows['surname'] . " " . $srows['othernames'];
    $courses = $srows['department'];
    $email = $srows['email'];
    $phone = $srows['phone'];
    $level = $srows['level'];
    $fno = $srows['formno'];
    $txn_ref = $srows['txt_ref'];
//$amount_fetch = preg_replace("/\.?0*$/", '', $srows['amount']);
    $amount_fetch = $srows['amount'];
//$overhead = preg_replace("/\.?0*$/", '', $srows['overhead']);
    $overhead = ($srows['overhead']);
    $txn_fee = preg_replace("/\.?0*$/", '', $srows['txt_fees']); //not txt_fee
//$amount = $amount_fetch + $overhead + $txn_fee;
    $amounts = $amount_fetch * 100;

    $amount = ($amount_fetch + $overhead + $txn_fee) * 100; //correct correct
//$overheads = $overhead * 100;
    $faculty = $srows['faculty'];
    $session = $srows['session'];

    if ($overhead == "0") {
        $overheads = ($overhead * 100) and $ict_overheads = 0 * 100;
    }
    if ($overhead != "0") {
        //$overheads = (($overhead - 150) * 100) and $ict_overheads = 150 * 100;

        $overhead1 = (($overhead - 200) * 100);
        $to_interswitch = $overhead1;

        $overhead2 = (($overhead - 300) * 100);
        $to_omoluabi = $overhead2; //wrong
        //echo "Omoluabi ".$to_omoluabi;
    }
    $_SESSION['email'] = $email;
    $_SESSION['surname'] = $fullname;
    $_SESSION['amt4hash'] = $amount;
    $product_id = PRODID;
    $pay_item_id = 101;
    $cur = CUR;
    $mackey = MACKEY;
    $ash_codes = ($txn_ref . $product_id . $pay_item_id . $amount . "$siteRedirectUrl" . $mackey);

    $ash_code = hash('sha512', $ash_codes);
//echo "Session Details:";	print_r($_SESSION);
    ?>

    <h1>Payment Verification</h1>
    <div class="">
        <code>You can Copy/Print this Transaction Number for future reference</code> <br/><br/>
        <p class="btn btn-primary">Your Transaction Reference No:</p> <span
                class="btn btn-warning"><?php echo $txn_ref ?></span><br/><br/>
        <div class="well" style="background:#FFF">


            <table class="table table-bordered table-hover">
                <tr>
                    <td align="right"><strong>Full Name:</strong></td>
                    <td><?php echo $fullname ?></td>
                    <td align="right"><strong>FormNo/MatricNo:</strong></td>
                    <td><?php echo $fno ?></td>
                </tr>
                <tr>
                    <td align="right"><strong>Faculty:</strong></td>
                    <td><?php echo $faculty ?></td>
                    <td align="right"><strong>Department:</strong></td>
                    <td><?php echo $courses ?></td>
                </tr>
                <tr>
                    <td align="right"><strong>Level:</strong></td>
                    <td><?php echo $level ?></td>
                    <td align="right"><strong>Phone:</strong></td>
                    <td><?php echo $phone ?></td>
                </tr>
                <tr>
                <tr>
                    <td align="right"><strong>Email:</strong></td>
                    <td width="814"><?php echo $email ?></td>
                    <td align="right"><strong>Session:</strong></td>
                    <td width="814"><?php echo $session ?></td>
                </tr>
                <tr>
                    <td colspan="4"><h1>Total Amount: <?php echo number_format($amount / 100, 2) ?></h1>
                    </td>
                </tr>
            </table>
            <p><strong>NOTE</strong>: The Total Amount of
                <strike>N</strike><?php echo number_format($amount / 100, 2) ?> will be
                deducted from your account. Thanks</p>
        </div>
        <!--<form name="form1" action= "https://webpay.interswitchng.com/paydirect/pay" method="post">-->
        <?php

        $string_to_interswitch = "<form name='form1' action= 'https://sandbox.interswitchng.com/webpay/pay' method='post'>
<input name='product_id' type='hidden' value='$product_id' />
                    <input name='cust_id' type='hidden' value='$fno' />
                    <input name='cust_name' type='hidden' value='$fullname' />
                    <input name='pay_item_id' type='hidden' value='$pay_item_id' />
                    <input name='pay_item_name' type='hidden' value='OSCOTECH Payment' />
                    <input name='amount' type='hidden' value='$amount' />
                    <input name='currency' type='hidden' value='$cur' />
                    <input name='site_redirect_url' type='hidden' value='$siteRedirectUrl'/>
                    <input name='site_name' type='hidden' value='$siteRedirectName' />

                    <input name='txn_ref' type='hidden' value='" . $_SESSION['txn_ref'] . "' />
                    <input name='hash' type='hidden' value='$ash_code' />
<input name='payment_params' type='hidden' value='college_split'/>
<input name='xml_data' type='hidden' value=" . '"' . " <payment_item_detail>
        <item_details detail_ref";
        $string_to_interswitch .= "='" . trim($_SESSION["txn_ref"]) . "' college='OSCOTECH' 
                    department='$courses' faculty='$faculty'> <item_detail item_id='1' item_name='overhead fees' item_amt='" . ($overhead * 100) . "'
                     bank_id='76' acct_num='0213965027' />
					<item_detail item_id='2' item_name='Acceptance fees' item_amt='" . ($overhead * 100) . "'
					 bank_id='76' acct_num='0213965027' />
					</item_details>
					</payment_item_detail>" . '"' . " />
                    <a href='dashboard.php?type=acceptance' class='pointer' >
                    <button class='btn btn-default pointer' onclick='javascript(void)' type='button'>
                    Back
</button>
                    
                    </a>
                    <button class='btn btn-danger pointer' type='submit'>
                    Pay Now
</button>
<button class='btn btn-success pointer' type='button'>
Print
</button>
              
              
              
                    </form>";



        echo($string_to_interswitch);


        echo(' <div>
                    <div class="row">
                        <div class="col-md-3 col-lg-3 col-sm-3 col-xs-3">
                            <img src="./images/inter.jpg" class="img-responsive bankImg" alt="">
                        </div>
                        <div class="col-md-3 col-lg-3 col-sm-3 col-xs-3">
                            <img src="./images/mc.jpg" class="img-responsive bankImg bankFix" alt="">

                        </div>
                        <div class="col-md-3 col-lg-3 col-sm-3 col-xs-3">
                            <img src="./images/visa.png" class="img-responsive bankImg" alt="">

                        </div>
                        <div class="col-md-3 col-lg-3 col-sm-3 col-xs-3">
                            <img src="./images/verve.jpg" class="img-responsive bankImg" alt="">

                        </div>
                    </div>
                </div>');

        ?>
    </div>
    <!--    //this last two important for the menu (for now)-->
    </div> </div>
    <?php
} else {
    die("Unable to get transaction from database");
}

?>
