First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
+136
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$templatePageTitle = getLanguageText('TEXT-PP-POST');
|
||||
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team'))) {
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
header("Location: /?error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$trxID = $_GET['trx_num'];
|
||||
$results = db_query("SELECT * FROM user_paypal_transactions WHERE record_num = $trxID");
|
||||
$row = db_fetch_array($results);
|
||||
extract($row,EXTR_PREFIX_ALL,'p');
|
||||
|
||||
$p_user_num = intval($p_user_num);
|
||||
if ($p_user_num == 0 && is_numeric($p_transaction_subject)) {
|
||||
$p_transaction_subject = intval($p_transaction_subject);
|
||||
$p_user_num = intval(db_getVal("SELECT user_num FROM user_online_payments WHERE school_num = $school_num AND record_num = $p_transaction_subject"));
|
||||
}
|
||||
|
||||
if ($p_user_num == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-UNABLE-TO-POST-TRX');
|
||||
header("Location: /?error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
// Update hotlunch_orders table
|
||||
$query = "SELECT hloh.* FROM hotlunch_order_header as hloh, people as p " .
|
||||
"WHERE hloh.school_num = {$p_school_num} " .
|
||||
"AND ordered_by_num = p.record_num " .
|
||||
"AND p.user_num = {$p_user_num} " .
|
||||
"AND hloh.status NOT IN ('Paid','Complimentary','Concession')";
|
||||
$orders = db_query($query);
|
||||
|
||||
echo("<br>\n<br>\n");
|
||||
echo("<p>Orders Found: " . db_num_rows($orders) . "</p>\n");
|
||||
|
||||
echo("<p>Payment validated ok - updating database</p>\n");
|
||||
|
||||
// Update paypal_payments database table
|
||||
$now = time();
|
||||
$p_mc_fee = floatval($p_mc_fee);
|
||||
$query = "UPDATE user_online_payments " .
|
||||
"SET status = 'Paid', payment_amount = balance_owing, reference = '{$p_txn_id}', trx_fee = {$p_mc_fee}, completed_time = $now " .
|
||||
"WHERE record_num = $trxID";
|
||||
db_query($query);
|
||||
|
||||
$today = date("Y-m-d",$now);
|
||||
$order_payments = "";
|
||||
$snum = 0;
|
||||
if (db_num_rows($orders) > 0) {
|
||||
while ($row = db_fetch_array($orders)) {
|
||||
$onum = $row['record_num'];
|
||||
$ototal = $row['order_total'];
|
||||
$opaid = $row['amount_paid'];
|
||||
$snum = $row['schedule_num'];
|
||||
$amt = number_format($ototal - $opaid,2);
|
||||
if (strlen($order_payments) > 0) $order_payments .= "|";
|
||||
$order_payments .= "{" . $onum . ":" . $amt . "}";
|
||||
|
||||
$query = "UPDATE hotlunch_order_header " .
|
||||
"SET amount_paid = order_total, " .
|
||||
"status = 'Paid', " .
|
||||
"paid_date = '$today', " .
|
||||
"payment_method = 'PayPal' " .
|
||||
"WHERE record_num = {$onum}";
|
||||
db_query($query);
|
||||
}
|
||||
}
|
||||
|
||||
// Post transaction to the user_account
|
||||
date_default_timezone_set($school_record['timezone']);
|
||||
$trx_time = date("Y-m-d H:i:s",$now);
|
||||
$entered_time = $now;
|
||||
|
||||
// Post transaction fee if there is one
|
||||
if (isset($p_transaction_fee) && $p_transaction_fee != 0) {
|
||||
if ($p_transaction_fee > 0) {
|
||||
$query = "INSERT INTO user_account " .
|
||||
"(school_num,user_num,schedule_num,transaction_datetime,transaction_type,transaction_status,note,transaction_amount,amount_paid,transaction_fee,payment_method,payment_reference,order_payments,deleted,entered_time) " .
|
||||
"VALUES ($p_school_num,$p_user_num,$snum,'$trx_time','PayPal Transaction Fee','Closed','',$p_transaction_fee,$p_transaction_fee,0,'PayPal','$p_txn_id',NULL,'N',$entered_time)";
|
||||
}
|
||||
else {
|
||||
$query = "INSERT INTO user_account " .
|
||||
"(school_num,user_num,schedule_num,transaction_datetime,transaction_type,transaction_status,note,transaction_amount,amount_paid,transaction_fee,payment_method,payment_reference,order_payments,deleted,entered_time) " .
|
||||
"VALUES ($p_school_num,$p_user_num,$snum,'$trx_time','PayPal Transaction Credit','Closed','',$p_transaction_fee,$p_transaction_fee,0,'PayPal','$p_txn_id',NULL,'N',$entered_time)";
|
||||
}
|
||||
pp_query($query);
|
||||
$entered_time += 1;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
}
|
||||
|
||||
$amount = $p_mc_gross * -1;
|
||||
$query = "INSERT INTO user_account " .
|
||||
"(school_num,user_num,schedule_num,transaction_datetime,transaction_type,note,transaction_amount,transaction_fee,payment_method,payment_reference,order_payments,deleted,entered_time,transaction_status) " .
|
||||
"VALUES ($p_school_num,$p_user_num,$snum,'$trx_time','Payment','PayPal Payment',$amount,$p_mc_fee,'PayPal','$p_txn_id','$order_payments','N',$entered_time,'Closed')";
|
||||
db_query($query);
|
||||
|
||||
// Make activity_log entry
|
||||
$username = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $p_user_num");
|
||||
$activity = "PayPal Payment";
|
||||
$additional_info = "TRX ID: $p_txn_id\nAmount: " . number_format(abs($amount),2) . "\n";
|
||||
$curr_time = $now;
|
||||
$activity_datetime = date("Y-m-d H:i:s",$curr_time);
|
||||
$query = "insert into activity_log (school_num,userid,user_ip,activity_time,activity_datetime,activity,information) " .
|
||||
"values($p_school_num,'$username','0.0.0.0',$curr_time,'$activity_datetime','$activity','$additional_info')";
|
||||
db_query($query);
|
||||
|
||||
$query = "update users set trx_status = NULL where school_num = $p_school_num and record_num = $p_user_num";
|
||||
db_query($query);
|
||||
|
||||
// Update user_paypal_transactions
|
||||
db_query("UPDATE user_paypal_transactions SET posting_message = 'Payment processed ok' WHERE record_num = $trxID");
|
||||
db_query("UPDATE user_paypal_transactions SET posting_result = 'Posted' WHERE record_num = $trxID");
|
||||
echo("<p>Payment processed and posted ok</p>\n");
|
||||
|
||||
echo("<p><b>[<a href='?action=paypal-log-errors'>" . getLanguageText('TEXT-PAYPAL-ERROR-LOG') . "</a>]</b></p>\n");
|
||||
|
||||
header("Location: ?action=paypal-log-errors");
|
||||
exit();
|
||||
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user