mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Show results and send email to admin. Merged from 17stable.
This commit is contained in:
parent
1f8c654979
commit
23741665cd
1 changed files with 39 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
<?php // $Id$
|
<?php // $Id$
|
||||||
|
=======
|
||||||
|
|
||||||
/// Load libraries
|
/// Load libraries
|
||||||
require_once('../../config.php');
|
require_once('../../config.php');
|
||||||
|
@ -98,66 +99,76 @@ function authorize_process_csv($filename)
|
||||||
/// Read lines
|
/// Read lines
|
||||||
$sendem = array();
|
$sendem = array();
|
||||||
$ignoredlines = '';
|
$ignoredlines = '';
|
||||||
$faultlog = '';
|
|
||||||
$imported = 0;
|
$imported = 0;
|
||||||
|
$updated = 0;
|
||||||
|
$ignored = 0;
|
||||||
while (($data = fgetcsv($handle, 8192, ",")) !== FALSE) {
|
while (($data = fgetcsv($handle, 8192, ",")) !== FALSE) {
|
||||||
if (count($data) != $numfields) {
|
if (count($data) != $numfields) {
|
||||||
continue; // ignore empty lines
|
$ignored++; // ignore empty lines
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transstatus = $data[$csvfields['Transaction Status']];
|
|
||||||
$transtype = $data[$csvfields['Transaction Type']];
|
|
||||||
$transid = $data[$csvfields['Transaction ID']];
|
$transid = $data[$csvfields['Transaction ID']];
|
||||||
$settlementdatetime = strtotime($data[$csvfields['Settlement Date/Time']]);
|
$transtype = $data[$csvfields['Transaction Type']];
|
||||||
|
$transstatus = $data[$csvfields['Transaction Status']];
|
||||||
|
$settlementdate = strtotime($data[$csvfields['Settlement Date/Time']]);
|
||||||
|
|
||||||
if ($transstatus == 'Approved Review' || $transstatus == 'Review Failed') {
|
if ($transstatus == 'Approved Review' || $transstatus == 'Review Failed') {
|
||||||
if ($order = get_record('enrol_authorize', 'transid', $transid)) {
|
if ($order = get_record('enrol_authorize', 'transid', $transid)) {
|
||||||
$order->status = ($transstatus == 'Approved Review') ? AN_STATUS_APPROVEDREVIEW : AN_STATUS_REVIEWFAILED;
|
$order->status = ($transstatus == 'Approved Review') ? AN_STATUS_APPROVEDREVIEW : AN_STATUS_REVIEWFAILED;
|
||||||
update_record('enrol_authorize', $order);
|
update_record('enrol_authorize', $order);
|
||||||
|
$updated++; // Updated order status
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want only status=Settled Successfully and type=Authorization w/ Auto Capture
|
|
||||||
if (! ($transstatus == 'Settled Successfully' && $transtype == 'Authorization w/ Auto Capture')) {
|
if (! ($transstatus == 'Settled Successfully' && $transtype == 'Authorization w/ Auto Capture')) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
|
$ignoredlines .= $transid . ": Not settled\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransactionId must match
|
// TransactionId must match
|
||||||
$order = get_record('enrol_authorize', 'transid', $transid);
|
$order = get_record('enrol_authorize', 'transid', $transid);
|
||||||
if (!$order) { // Not our business
|
if (!$order) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
|
$ignoredlines .= $transid . ": Not our business\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authorized/Captured and Settled
|
// Authorized/Captured and Settled
|
||||||
$order->status = AN_STATUS_AUTHCAPTURE;
|
$order->status = AN_STATUS_AUTHCAPTURE;
|
||||||
$order->settletime = $settlementdatetime;
|
$order->settletime = $settlementdate;
|
||||||
update_record('enrol_authorize', $order);
|
update_record('enrol_authorize', $order);
|
||||||
|
$updated++; // Updated order status and settlement date
|
||||||
|
|
||||||
if ($order->paymentmethod != AN_METHOD_ECHECK) {
|
if ($order->paymentmethod != AN_METHOD_ECHECK) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
continue; // We only interest in ECHECK
|
$ignoredlines .= $transid . ": The method must be echeck\n";
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get course and context
|
// Get course and context
|
||||||
$course = get_record('course', 'id', $order->courseid);
|
$course = get_record('course', 'id', $order->courseid);
|
||||||
if (!$course) {
|
if (!$course) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
continue; // Could not find this course
|
$ignoredlines .= $transid . ": Could not find this course: " . $order->courseid . "\n";
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||||
if (!$coursecontext) {
|
if (!$coursecontext) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
continue; // Could not find this course context
|
$ignoredlines .= $transid . ": Could not find course context: " . $order->courseid . "\n";
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user
|
// Get user
|
||||||
$user = get_record('user', 'id', $order->userid);
|
$user = get_record('user', 'id', $order->userid);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$ignoredlines .= $transid . "\n";
|
$ignored++;
|
||||||
continue; // Could not find this user
|
$ignoredlines .= $transid . ": Could not find this user: " . $order->userid . "\n";
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user wasn't enrolled, enrol now. Ignore otherwise. Because admin user might submit this file again.
|
// If user wasn't enrolled, enrol now. Ignore otherwise. Because admin user might submit this file again.
|
||||||
|
@ -176,13 +187,21 @@ function authorize_process_csv($filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$faultlog .= "Error while trying to enrol ".fullname($user)." in '$course->fullname' \n";
|
$ignoredlines .= $transid . ": Error while trying to enrol " . fullname($user) . " in '$course->fullname' \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
notice("Done... Total $imported record(s) has been imported.");
|
|
||||||
|
/// Show result
|
||||||
|
notice("<b>Done...</b><br />Imported: $imported<br />Updated: $updated<br />Ignored: $ignored");
|
||||||
|
|
||||||
|
/// Send email to admin
|
||||||
|
if (!empty($ignoredlines)) {
|
||||||
|
$admin = get_admin();
|
||||||
|
email_to_user($admin, $admin, "$SITE->fullname: Authorize.net CSV ERROR LOG", $ignoredlines);
|
||||||
|
}
|
||||||
|
|
||||||
/// Send welcome messages to users
|
/// Send welcome messages to users
|
||||||
if (!empty($sendem)) {
|
if (!empty($sendem)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue