First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
include "db.php";
|
||||
include "table.php";
|
||||
|
||||
$user_account = new Table("user_account");
|
||||
|
||||
$school_num = 435;
|
||||
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
||||
$school_record = db_fetch_assoc($results);
|
||||
date_default_timezone_set($school_record['timezone']);
|
||||
$now = time();
|
||||
$today = date("Y-m-d",$now);
|
||||
$order_payments = "";
|
||||
$snum = 0;
|
||||
|
||||
$query = "SELECT posting_time,payment_date,first_name,last_name,payer_email,mc_currency,mc_gross,mc_fee,payment_type,payment_status,pending_reason," .
|
||||
"item_name,business,receiver_email,txn_id,receipt_id,trx_num,user_num,posting_result,posting_message,record_num " .
|
||||
"FROM user_paypal_transactions " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND posting_result = 'Pending' " .
|
||||
"ORDER BY posting_time,last_name";
|
||||
$transactions = db_query($query);
|
||||
|
||||
while ($row = db_fetch_assoc($transactions)) {
|
||||
extract($row);
|
||||
|
||||
if ($payment_type != 'instant') {
|
||||
echo("$txn_id - not instant\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND payment_reference = '$txn_id'";
|
||||
$ua_entries = db_query($query);
|
||||
if (db_num_rows($ua_entries) > 0) {
|
||||
echo("$txn_id - already posted\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get payment info
|
||||
$query = "SELECT * FROM user_online_payments WHERE record_num = {$trx_num}";
|
||||
$r = db_query($query);
|
||||
$row = db_fetch_assoc($r);
|
||||
$transaction_fee = $row['transaction_fee'];
|
||||
|
||||
// Update hotlunch_orders table
|
||||
$query = "SELECT hloh.* FROM hotlunch_order_header as hloh, people as p " .
|
||||
"WHERE hloh.school_num = {$school_num} " .
|
||||
"AND ordered_by_num = p.record_num " .
|
||||
"AND p.user_num = {$user_num} " .
|
||||
"AND hloh.status NOT IN ('Paid','Complimentary','Concession')";
|
||||
$orders = db_query($query);
|
||||
|
||||
// Update paypal_payments database table
|
||||
$query = "UPDATE user_online_payments " .
|
||||
"SET status = 'Paid', payment_amount = balance_owing, reference = '{$txn_id}', trx_fee = {$mc_fee}, completed_time = $now; " .
|
||||
"WHERE record_num = $trx_num";
|
||||
db_query($query);
|
||||
|
||||
if (db_num_rows($orders) > 0) {
|
||||
$order_payments = "";
|
||||
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
|
||||
$entered_time = $now;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
|
||||
// Post transaction fee if there is one
|
||||
if ($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 ($school_num,$user_num,$snum,'$trx_time','PayPal Transaction Fee','Closed','',$transaction_fee,$transaction_fee,0,'PayPal','$txn_id',NULL,'N',$entered_time)";
|
||||
db_query($query);
|
||||
$entered_time += 1;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
}
|
||||
|
||||
$amount = $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) " .
|
||||
"VALUES ($school_num,$user_num,$snum,'$trx_time','Payment','PayPal Payment',$amount,$mc_fee,'PayPal','$txn_id','$order_payments','N',$entered_time)";
|
||||
db_query($query);
|
||||
|
||||
// Reset user transaction status
|
||||
$query = "update users set trx_status = NULL where school_num = $school_num and record_num = $user_num";
|
||||
db_query($query);
|
||||
|
||||
// Reset user can_order flag
|
||||
$query = "update users set can_order = 'Yes' where school_num = $school_num and can_order = 'Balance' and record_num = $user_num";
|
||||
db_query($query);
|
||||
|
||||
// Update user_paypal_transactions
|
||||
db_query("UPDATE user_paypal_transactions SET posting_message = 'Payment processed ok' WHERE record_num = $record_num");
|
||||
db_query("UPDATE user_paypal_transactions SET posting_result = 'Posted' WHERE trx_num = $trx_num");
|
||||
|
||||
echo("$txn_id - posted\n");
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user