First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
+316
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
exit();
|
||||
|
||||
$noSession = 1;
|
||||
require("db.php");
|
||||
include("include/school-functions.php");
|
||||
include("include/logging-functions.php");
|
||||
include("include/date-time.php");
|
||||
include("table.php");
|
||||
|
||||
$moduleName = "maPayment.php";
|
||||
// startLog($moduleName);
|
||||
|
||||
|
||||
// start capturing output
|
||||
function saveOutput($contents) {
|
||||
global $ltime, $school_num;
|
||||
|
||||
$f = fopen("/m/data1/app.hotlunches.net/maPayment.log", "w");
|
||||
fwrite($f, $contents);
|
||||
fclose($f);
|
||||
|
||||
$f = fopen("/m/data1/app.hotlunches.net/maPayment.trx.log", "a");
|
||||
fwrite($f, $contents);
|
||||
fclose($f);
|
||||
|
||||
$f = fopen("/m/data1/app.hotlunches.net/logs/ma/ma.$school_num.$ltime", "w");
|
||||
fwrite($f, $contents);
|
||||
fclose($f);
|
||||
|
||||
return nl2br(htmlentities($contents));
|
||||
}
|
||||
|
||||
|
||||
// Set time values for posting
|
||||
date_default_timezone_set("Canada/Pacific");
|
||||
$posting_time = date("Y-m-d H:i:s",$now);
|
||||
$ltime = date("Y-m-d.H.i.s",$now);
|
||||
|
||||
|
||||
// output date and POST-ed values for logging
|
||||
$contents = (date('r') . "\n\n");
|
||||
$x = $_GET;
|
||||
$contents .= print_r($x, TRUE);
|
||||
$contents .= "\n\n";
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Process parameters to script
|
||||
//
|
||||
$responsetext = $_GET['responsetext'];
|
||||
// if (strlen($responsetext) == 0 || $responsetext != 'SUCCESS') exit();
|
||||
|
||||
$trx_result = $responsetext;
|
||||
$trxMsg = $school_record['merchant_account_thanks_message'];
|
||||
if (strlen($trxMsg) == 0) $trxMsg = getLanguageText('TEXT-THANK-YOU-FOR-PAYMENT');
|
||||
|
||||
|
||||
// Get info
|
||||
$user_num = intval($_GET['merchant_defined_field_1']);
|
||||
$trx_num = intval($_GET['merchant_defined_field_2']);
|
||||
$trxNum = $trx_num;
|
||||
|
||||
// Use the posted transaction number value to get the post values from DB
|
||||
$query = "SELECT * FROM user_online_payments WHERE record_num = $trx_num AND user_num = $user_num";
|
||||
$r = db_query($query);
|
||||
if (db_num_rows($r) > 0) {
|
||||
extract(db_fetch_assoc($r), EXTR_PREFIX_ALL, 'PMTS');
|
||||
$school_num = $PMTS_school_num;
|
||||
}
|
||||
|
||||
|
||||
// Parse returned values
|
||||
$trx_result = $trxResult;
|
||||
$trx_msg = $trxMsg;
|
||||
$response = $_GET['response'];
|
||||
$responsetext = $_GET['responsetext'];
|
||||
$authcode = $_GET['authcode'];
|
||||
$avsresponse = $_GET['avsresponse'];
|
||||
$transactionid = $_GET['transactionid'];
|
||||
$orderid = $_GET['orderid'];
|
||||
$amount = $_GET['amount'];
|
||||
$first_name = $_GET['first_name'];
|
||||
$last_name = $_GET['last_name'];
|
||||
$address_1 = $_GET['address_1'];
|
||||
$address_2 = $_GET['address_2'];
|
||||
$city = $_GET['city'];
|
||||
$state = $_GET['state'];
|
||||
$country = $_GET['country'];
|
||||
$phone = $_GET['phone'];
|
||||
$postal_code = $_GET['postal_code'];
|
||||
$email = $_GET['email'];
|
||||
$referrer_url = $_GET['referrer_url'];
|
||||
|
||||
|
||||
// Create entry in user_merchant_account_transactions table
|
||||
$table = new Table('user_merchant_account_transactions');
|
||||
$trxSQL = $table->BuildInsert();
|
||||
db_query($trxSQL);
|
||||
$contents .= "$query\n";
|
||||
$trxID = db_insert_id();
|
||||
$contents .= "Insert ID: $trxID\n\n";
|
||||
|
||||
|
||||
// Check if this entry is in the user_merchant_account_transactions table
|
||||
$query = "SELECT * FROM user_merchant_account_transactions " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND trx_num = $trx_num " .
|
||||
"AND trx_result = '$trx_result' " .
|
||||
"AND authcode = '$authcode' " .
|
||||
"AND record_num != $trxID";
|
||||
$r = db_query($query);
|
||||
if (db_num_rows($r) > 0) {
|
||||
$error_message = "Duplicate Posting - Transaction Has Already Been Processed: $trx_num";
|
||||
$contents .= "$error_message\n\n";
|
||||
saveOutput($contents);
|
||||
header("Location: /?error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load school information from the database
|
||||
$r = db_query("SELECT * FROM schools WHERE record_num = {$school_num}");
|
||||
if (db_num_rows($r) != 1) {
|
||||
$error_message = "Invalid school.";
|
||||
db_query("UPDATE user_merchant_account_transactions SET posting_result = 'Error', posting_message = 'Invalid school' WHERE record_num = $trxID");
|
||||
$contents .= "$error_message\n\n";
|
||||
saveOutput($contents);
|
||||
header("Location: /?error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
} else {
|
||||
extract(db_fetch_assoc($r), EXTR_PREFIX_ALL, 's');
|
||||
}
|
||||
|
||||
|
||||
// Update online_payments database table
|
||||
$query = "UPDATE user_online_payments " .
|
||||
"SET status = 'Paid', payment_amount = balance_owing, reference = '{$transactionid}', trx_fee = 0, completed_time = $now " .
|
||||
"WHERE record_num = $trxNum";
|
||||
db_query($query);
|
||||
|
||||
|
||||
// Get largest unpaid order to use schedule number for posting
|
||||
$query = "SELECT hloh.schedule_num,hloh.record_num AS order_num, hloh.order_total - hloh.amount_paid AS balance 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') " .
|
||||
"ORDER BY balance DESC " .
|
||||
"LIMIT 0,1";
|
||||
// writeLog("query: $query\n");
|
||||
$r = db_query($query);
|
||||
$row = db_fetch_assoc($r);
|
||||
$snum = $row['schedule_num'];
|
||||
$onum = $row['order_num'];
|
||||
|
||||
|
||||
|
||||
// Post transaction to the user_account
|
||||
date_default_timezone_set(mapTimeZone($s_timezone));
|
||||
$entered_time = $now;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
$schedule_num = $snum;
|
||||
|
||||
|
||||
// Post payment discount if there is one
|
||||
if ($PMTS_payment_discount != 0) {
|
||||
$trxRecord = array();
|
||||
$trxRecord['school_num'] = $school_num;
|
||||
$trxRecord['user_num'] = $user_num;
|
||||
$trxRecord['schedule_num'] = $schedule_num;
|
||||
$trxRecord['transaction_datetime'] = $trx_time;
|
||||
$trxRecord['transaction_type'] = 'Generated Credit';
|
||||
$trxRecord['note'] = 'Payment Discount';
|
||||
$trxRecord['transaction_amount'] = abs($PMTS_payment_discount) * -1;
|
||||
$trxRecord['amount_paid'] = 0;
|
||||
$trxRecord['transaction_fee'] = 0;
|
||||
$trxRecord['payment_method'] = '';
|
||||
$trxRecord['payment_reference'] = $transactionid;
|
||||
$trxRecord['order_payments'] = '';
|
||||
|
||||
postTransaction($trxRecord);
|
||||
$entered_time += 1;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
}
|
||||
|
||||
|
||||
// Post transaction fee if there is one
|
||||
if ($PMTS_transaction_fee != 0) {
|
||||
$trxRecord = array();
|
||||
$trxRecord['school_num'] = $school_num;
|
||||
$trxRecord['user_num'] = $user_num;
|
||||
$trxRecord['schedule_num'] = $schedule_num;
|
||||
$trxRecord['transaction_datetime'] = $trx_time;
|
||||
$trxRecord['transaction_type'] = 'Credit Card Transaction Fee';
|
||||
$trxRecord['note'] = '';
|
||||
$trxRecord['transaction_amount'] = abs($PMTS_transaction_fee);
|
||||
$trxRecord['amount_paid'] = 0;
|
||||
$trxRecord['transaction_fee'] = 0;
|
||||
$trxRecord['payment_method'] = '';
|
||||
$trxRecord['payment_reference'] = $transactionid;
|
||||
$trxRecord['order_payments'] = '';
|
||||
|
||||
postTransaction($trxRecord);
|
||||
$entered_time += 1;
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set amount to a negative amount as it is a credit to the account
|
||||
$amount = $amount * -1;
|
||||
$trxRecord = array();
|
||||
$trxRecord['school_num'] = $school_num;
|
||||
$trxRecord['user_num'] = $user_num;
|
||||
$trxRecord['schedule_num'] = $schedule_num;
|
||||
$trxRecord['transaction_datetime'] = $trx_time;
|
||||
$trxRecord['transaction_type'] = 'Payment';
|
||||
$trxRecord['note'] = 'On-Line Payment';
|
||||
$trxRecord['transaction_amount'] = $amount;
|
||||
$trxRecord['amount_paid'] = 0;
|
||||
$trxRecord['transaction_fee'] = 0;
|
||||
$trxRecord['payment_method'] = 'Credit Card';
|
||||
$trxRecord['payment_reference'] = $transactionid;
|
||||
$trxRecord['order_payments'] = $order_payments;
|
||||
|
||||
$ptrx_num = postCredit($trxRecord);
|
||||
|
||||
// Close all transactions
|
||||
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE school_num = $school_num AND user_num = $user_num";
|
||||
db_query($query);
|
||||
|
||||
// Update all orders to set amount paid
|
||||
$query = "UPDATE user_account SET amount_paid = transaction_amount WHERE school_num = $school_num AND user_num = $user_num AND transaction_amount > 0";
|
||||
db_query($query);
|
||||
|
||||
|
||||
// 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);
|
||||
$contents .= "$query\n";
|
||||
$contents .= "Orders Found: " . db_num_rows($orders) . "\n";
|
||||
|
||||
$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 = $ototal - $opaid;
|
||||
if (strlen($order_payments) > 0) $order_payments .= "|";
|
||||
$order_payments .= "{" . $onum . ":" . $amt . "}";
|
||||
$payment_amt = abs($amt);
|
||||
$snum = sprintf("%0d",intval($snum));
|
||||
|
||||
// Save transaction details
|
||||
$query = "INSERT INTO user_account_detail (school_num,user_num,transaction_num,posted_to_transaction,posted_amount,posted_schedule,entered_time,deleted) " .
|
||||
"VALUES ($school_num, $user_num, $ptrx_num, $onum, $payment_amt, $snum, $now, 'N')";
|
||||
db_query($query);
|
||||
|
||||
$query = "UPDATE hotlunch_order_header " .
|
||||
"SET amount_paid = order_total, " .
|
||||
"status = 'Paid', " .
|
||||
"paid_date = '$today', " .
|
||||
"payment_method = 'On-Line Payment' " .
|
||||
"WHERE record_num = {$onum}";
|
||||
db_query($query);
|
||||
|
||||
$contents .= " - Order Paid: $onum\n";
|
||||
}
|
||||
|
||||
$query = "UPDATE user_account SET order_payments = '$order_payments' WHERE record_num = $ptrx_num";
|
||||
db_query($query);
|
||||
}
|
||||
|
||||
$contents .= "\n";
|
||||
|
||||
|
||||
// Make activity_log entry
|
||||
$username = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
|
||||
$activity = "On-Line Payment";
|
||||
$additional_info = "TRX ID: $trx_num\nAmount: " . number_format(abs($amount),2) . "\n";
|
||||
$curr_time = $now;
|
||||
$activity_datetime = date("Y-m-d H:i:s",$curr_time);
|
||||
$uid = db_escape_string($username);
|
||||
$query = "insert into activity_log (school_num,userid,user_ip,activity_time,activity_datetime,activity,information) " .
|
||||
"values($school_num,'$uid','0.0.0.0',$curr_time,'$activity_datetime','$activity','$additional_info')";
|
||||
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_merchant_account_transactions
|
||||
db_query("UPDATE user_merchant_account_transactions SET posting_message = 'Payment processed ok', posting_result = 'Posted' WHERE record_num = $trxID");
|
||||
$contents .= "Payment processed ok\n\n\n";
|
||||
|
||||
adjustUserAccountDetails($user_num,$school_num);
|
||||
|
||||
saveOutput($contents);
|
||||
header("Location: /?tnum=$ptrx_num&unum=$user_num&rcpt_link=Y&form_message=" . urlencode($trxMsg));
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user