* Update record as soon as possible. If update/insert record fails email to admin to have update manually.

* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
   This is last change to ignore request for user.
 * Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
   Now, these are static:
   get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
 * Some mtrace cleanup. Removed default new line.

This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable. :)
This commit is contained in:
ethem
2006-07-24 11:42:17 +00:00
parent 905fdcaa31
commit 644600315c
5 changed files with 181 additions and 190 deletions
+38 -22
View File
@@ -15,8 +15,8 @@ require_once('const.php');
/**
* Gets settlement date and time
*
* @param int $time Processed time, usually now.
* @return int Settlement date
* @param int $time Time processed, usually now.
* @return int Settlement date and time
*/
function authorize_getsettletime($time)
{
@@ -54,10 +54,6 @@ function authorize_expired(&$order)
{
static $timediff30;
if (empty($timediff30)) {
$timediff30 = authorize_getsettletime(time()) - (30 * 24 * 3600);
}
if ($order->status == AN_STATUS_EXPIRE) {
return true;
}
@@ -65,24 +61,27 @@ function authorize_expired(&$order)
return false;
}
$exp = (authorize_getsettletime($order->timecreated) < $timediff30);
if (empty($timediff30)) {
$timediff30 = authorize_getsettletime(time()) - (30 * 24 * 3600);
}
if ($exp) {
$isexpired = (authorize_getsettletime($order->timecreated) < $timediff30);
if ($isexpired) {
$order->status = AN_STATUS_EXPIRE;
update_record('enrol_authorize', $order);
}
return $exp;
return $isexpired;
}
/**
* Performs an action on authorize.net
* Performs an action on authorize.net and updates/inserts records. If record update fails,
* sends email to admin.
*
* @param object &$order Which transaction data will be sent. See enrol_authorize table.
* @param string &$message Information about error messages.
* @param object &$extra Extra transaction data.
* @param string &$message Information about error message if this function returns false.
* @param object &$extra Extra data that used for refunding and credit card information.
* @param int $action Which action will be performed. See AN_ACTION_*
* @return bool true, transaction was successful, false otherwise.
* @return bool true Transaction was successful, false otherwise. Use $message for reason.
* @author Ethem Evlice <ethem a.t evlice d.o.t com>
* @uses $CFG
*/
@@ -117,12 +116,12 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$action = intval($action);
if (empty($order) || empty($order->id)) {
if (empty($order) or empty($order->id)) {
$message = "Check order->id!";
return false;
}
elseif ($action <= AN_ACTION_NONE || $action > AN_ACTION_VOID) {
$message = "No action taken!";
elseif ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
$message = "Invalid action!";
return false;
}
@@ -180,11 +179,10 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
return false;
}
if (empty($extra)) {
$message = "need extra fields for CREDIT!";
$message = "Need extra fields to REFUND!";
return false;
}
$total = floatval($extra->sum) + floatval($extra->amount);
unset($extra->sum); // this is not used in refunds table.
if (($extra->amount == 0) || ($total > $order->amount)) {
$message = "Can be credited up to original amount.";
return false;
@@ -211,7 +209,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
}
}
else {
$message = "Order status must be authorized, auth/captured or refunded!";
$message = "Order status must be authorized/pending capture or captured-refunded/pending settlement!";
return false;
}
$poststring .= '&x_type=VOID&x_trans_id=' . urlencode($order->transid);
@@ -219,7 +217,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
}
default: {
$message = "Missing action? $action";
$message = "Invalid action: $action";
return false;
}
}
@@ -236,6 +234,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
return false;
}
@ignore_user_abort(true); // this is critical section
fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" .
"Host: $host\r\n" . $referer .
"Content-type: application/x-www-form-urlencoded\r\n" .
@@ -289,6 +288,10 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$order->status = AN_STATUS_AUTHCAPTURE;
$order->settletime = authorize_getsettletime(time());
}
if (! update_record('enrol_authorize', $order)) {
enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
"in table enrol_authorize. Please edit manually this record: ID=$order->id.", $order);
}
break;
}
case AN_ACTION_CREDIT:
@@ -298,12 +301,25 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$extra->status = AN_STATUS_CREDIT;
$extra->transid = $transid;
$extra->settletime = authorize_getsettletime(time());
unset($extra->sum); // this is not used in refunds table.
if (! $extra->id = insert_record('enrol_authorize_refunds', $extra)) {
enrolment_plugin_authorize::email_to_admin("Error while trying to insert data " .
"into table enrol_authorize_refunds. Please add manually this record:", $extra);
}
break;
}
case AN_ACTION_VOID:
{
$order->status = AN_STATUS_VOID;
$tableupdate = 'enrol_authorize';
if ($order->status == AN_STATUS_CREDIT) {
$tableupdate = 'enrol_authorize_refunds';
}
// dont't update settletime
$order->status = AN_STATUS_VOID;
if (! update_record($tableupdate, $order)) {
enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
"in table $tableupdate. Please edit manually this record: ID=$order->id.", $order);
}
break;
}
default: return false;
+2 -2
View File
@@ -31,7 +31,7 @@ if (!isset($frm->an_cutoff_hour)) {
}
if (!isset($frm->acceptccs)) {
$frm->acceptccs = array_keys(get_list_of_creditcards());
$frm->acceptccs = array_keys(enrolment_plugin_authorize::get_list_of_creditcards());
$CFG->an_acceptccs = implode(',', $frm->acceptccs);
}
@@ -127,7 +127,7 @@ if (!isset($frm->acceptccs)) {
<tr valign="top">
<td align="right">an_acceptccs:</td>
<td><?php
$allccs = get_list_of_creditcards(true);
$allccs = enrolment_plugin_authorize::get_list_of_creditcards(true);
foreach ($allccs as $key => $val) {
print_checkbox('acceptccs[]', $key, stristr($CFG->an_acceptccs, $key) !== false, $val); echo "<br />\n";
}
+3 -3
View File
@@ -1,6 +1,6 @@
<?php // $Id$
$this->prevent_double_paid($course);
enrolment_plugin_authorize::prevent_double_paid($course);
$formvars = array('password', 'ccaddress', 'cccity', 'ccstate', 'cccountry', 'cczip',
'ccfirstname', 'cclastname', 'cc', 'ccexpiremm', 'ccexpireyyyy', 'cctype', 'cvv');
@@ -10,7 +10,7 @@ foreach ($formvars as $var) {
}
}
$curcost = $this->get_course_cost($course);
$curcost = enrolment_plugin_authorize::get_course_cost($course);
$userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname;
$userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname;
$useraddress = empty($form->ccaddress) ? $USER->address : $form->ccaddress;
@@ -60,7 +60,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
<tr>
<td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
<td align="left"><?php
choose_from_menu(get_list_of_creditcards(), 'cctype', $form->cctype);
choose_from_menu(enrolment_plugin_authorize::get_list_of_creditcards(), 'cctype', $form->cctype);
if (!empty($this->ccerrors['cctype'])) { formerr($this->ccerrors['cctype']); }
?>
</td>
+136 -150
View File
@@ -3,42 +3,6 @@
require_once($CFG->dirroot.'/enrol/enrol.class.php');
require_once($CFG->dirroot.'/enrol/authorize/const.php');
/**
* get_list_of_creditcards
*
* @param bool $getall
* @return array
*/
function get_list_of_creditcards($getall = false)
{
global $CFG;
$alltypes = array(
'mcd' => 'Master Card',
'vis' => 'Visa',
'amx' => 'American Express',
'dsc' => 'Discover',
'dnc' => 'Diners Club',
'jcb' => 'JCB',
'swi' => 'Switch',
'dlt' => 'Delta',
'enr' => 'EnRoute'
);
if ($getall || empty($CFG->an_acceptccs)) {
return $alltypes;
}
$ret = array();
$ccs = explode(',', $CFG->an_acceptccs);
foreach ($ccs as $key) {
$ret[$key] = $alltypes[$key];
}
return $ret;
}
/**
* enrolment_plugin_authorize
*
@@ -100,7 +64,7 @@ class enrolment_plugin_authorize
function print_entry($course) {
global $CFG, $USER, $form;
$zerocost = $this->zero_cost($course);
$zerocost = enrolment_plugin_authorize::zero_cost($course);
if ($zerocost) {
$manual = enrolment_factory::factory('manual');
if (!empty($this->errormsg)) {
@@ -110,8 +74,6 @@ class enrolment_plugin_authorize
return;
}
httpsrequired();
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
if (empty($CFG->loginhttps)) {
error(get_string('httpsrequired', 'enrol_authorize'));
@@ -122,6 +84,8 @@ class enrolment_plugin_authorize
}
}
httpsrequired();
$strcourses = get_string('courses');
$strloginto = get_string('loginto', '', $course->shortname);
@@ -132,17 +96,18 @@ class enrolment_plugin_authorize
print_heading(get_string('choosemethod', 'enrol_authorize'), 'center');
}
print_simple_box_start('center');
if (isguest()) {
$curcost = $this->get_course_cost($course);
echo '<div align="center"><p>'.get_string('paymentrequired').'</p>';
$curcost = enrolment_plugin_authorize::get_course_cost($course);
echo '<div align="center">';
echo '<p>'.get_string('paymentrequired').'</p>';
echo '<p><b>'.get_string('cost').": $curcost[currency] $curcost[cost]".'</b></p>';
echo '<p><a href="'.$CFG->httpswwwroot.'/login/">'.get_string('loginsite').'</a></p>';
echo '</div>';
} else {
print_simple_box_start('center');
include($CFG->dirroot.'/enrol/authorize/enrol.html');
print_simple_box_end();
}
print_simple_box_end();
if ($course->password) {
$password = '';
@@ -162,7 +127,8 @@ class enrolment_plugin_authorize
* @access public
*/
function check_entry($form, $course) {
if ($this->zero_cost($course) or (!empty($course->password) and !empty($form->password))) {
if (enrolment_plugin_authorize::zero_cost($course) or
(!empty($course->password) and !empty($form->password))) {
$manual = enrolment_factory::factory('manual');
$manual->check_entry($form, $course);
if (!empty($manual->errormsg)) {
@@ -187,10 +153,10 @@ class enrolment_plugin_authorize
global $CFG, $USER, $SESSION;
require_once('authorizenetlib.php');
$this->prevent_double_paid($course);
enrolment_plugin_authorize::prevent_double_paid($course);
$useripno = getremoteaddr();
$curcost = $this->get_course_cost($course);
$curcost = enrolment_plugin_authorize::get_course_cost($course);
$exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy;
// NEW ORDER
@@ -208,7 +174,7 @@ class enrolment_plugin_authorize
$order->currency = $curcost['currency'];
$order->id = insert_record("enrol_authorize", $order);
if (!$order->id) {
$this->email_to_admin("Error while trying to insert new data", $order);
enrolment_plugin_authorize::email_to_admin("Error while trying to insert new data", $order);
$this->ccerrors['header'] = "Insert record error. Admin has been notified!";
return;
}
@@ -242,7 +208,7 @@ class enrolment_plugin_authorize
$action = $an_review ? AN_ACTION_AUTH_ONLY : AN_ACTION_AUTH_CAPTURE;
$success = authorize_action($order, $message, $extra, $action);
if (!$success) {
$this->email_to_admin($message, $order);
enrolment_plugin_authorize::email_to_admin($message, $order);
$this->ccerrors['header'] = $message;
return;
}
@@ -261,43 +227,31 @@ class enrolment_plugin_authorize
return;
}
if ($an_review) { // review enabled, inform admin and redirect to main page.
if (update_record("enrol_authorize", $order)) {
$a = new stdClass;
$a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$order->id";
$a->orderid = $order->id;
$a->transid = $order->transid;
$a->amount = "$order->currency $order->amount";
$a->expireon = userdate(authorize_getsettletime($timenow + (30 * 3600 * 24)));
$a->captureon = userdate(authorize_getsettletime($timenow + (intval($CFG->an_capture_day) * 3600 * 24)));
$a->course = $course->fullname;
$a->user = fullname($USER);
$a->acstatus = ($CFG->an_capture_day > 0) ? get_string('yes') : get_string('no');
$emailmessage = get_string('adminneworder', 'enrol_authorize', $a);
$a = new stdClass;
$a->course = $course->shortname;
$a->orderid = $order->id;
$emailsubject = get_string('adminnewordersubject', 'enrol_authorize', $a);
$admins = get_admins();
foreach ($admins as $admin) {
email_to_user($admin, $USER, $emailsubject, $emailmessage);
}
}
else {
$this->email_to_admin("Error while trying to update data. Please edit manually this record: " .
"ID=$order->id in enrol_authorize table.", $order);
if ($an_review) { // review enabled, inform admin and redirect user to main page.
$a = new stdClass;
$a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$order->id";
$a->orderid = $order->id;
$a->transid = $order->transid;
$a->amount = "$order->currency $order->amount";
$a->expireon = userdate(authorize_getsettletime($timenow + (30 * 3600 * 24)));
$a->captureon = userdate(authorize_getsettletime($timenow + (intval($CFG->an_capture_day) * 3600 * 24)));
$a->course = $course->fullname;
$a->user = fullname($USER);
$a->acstatus = ($CFG->an_capture_day > 0) ? get_string('yes') : get_string('no');
$emailmessage = get_string('adminneworder', 'enrol_authorize', $a);
$a = new stdClass;
$a->course = $course->shortname;
$a->orderid = $order->id;
$emailsubject = get_string('adminnewordersubject', 'enrol_authorize', $a);
$admins = get_admins();
foreach ($admins as $admin) {
email_to_user($admin, $USER, $emailsubject, $emailmessage);
}
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
return;
}
// credit card captured, ENROL student...
if (!update_record("enrol_authorize", $order)) {
$this->email_to_admin("Error while trying to update data. Please edit manually this record: " .
"ID=$order->id in enrol_authorize table.", $order);
// no error occured??? enrol student??? return??? Database busy???
}
// Credit card captured, ENROL student now...
if ($course->enrolperiod) {
$timestart = $timenow;
$timeend = $timestart + $course->enrolperiod;
@@ -338,7 +292,8 @@ class enrolment_plugin_authorize
}
}
} else {
$this->email_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $order);
enrolment_plugin_authorize::email_to_admin("Error while trying to enrol " .
fullname($USER) . " in '$course->fullname'", $order);
}
if ($SESSION->wantsurl) {
@@ -387,7 +342,8 @@ class enrolment_plugin_authorize
$this->ccerrors['cvv'] = get_string('missingcvv', 'enrol_authorize');
}
if (empty($form->cctype) || !in_array($form->cctype, array_keys(get_list_of_creditcards()))) {
if (empty($form->cctype) or
!in_array($form->cctype, array_keys(enrolment_plugin_authorize::get_list_of_creditcards()))) {
$this->ccerrors['cctype'] = get_string('missingcctype', 'enrol_authorize');
}
@@ -414,45 +370,6 @@ class enrolment_plugin_authorize
return true;
}
/**
* zero_cost
*
* @param unknown_type $course
* @return number
* @access private
*/
function zero_cost($course) {
$curcost = $this->get_course_cost($course);
return (abs($curcost['cost']) < 0.01);
}
/**
* get_course_cost
*
* @param object $course
* @return array
* @access private
*/
function get_course_cost($course)
{
global $CFG;
$cost = (float)0;
$currency = (!empty($course->currency))
? $course->currency :( empty($CFG->enrol_currency)
? 'USD' : $CFG->enrol_currency );
if (!empty($course->cost)) {
$cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost;
}
$cost = format_float($cost, 2);
$ret = array('cost' => $cost, 'currency' => $currency);
return $ret;
}
/**
* Gets access icons.
@@ -465,7 +382,7 @@ class enrolment_plugin_authorize
$manual = enrolment_factory::factory('manual');
$str = $manual->get_access_icons($course);
$curcost = $this->get_course_cost($course);
$curcost = enrolment_plugin_authorize::get_course_cost($course);
if (abs($curcost['cost']) > 0.00) {
$strrequirespayment = get_string("requirespayment");
@@ -498,7 +415,7 @@ class enrolment_plugin_authorize
{
global $CFG;
if (!$this->check_openssl_loaded()) {
if (! enrolment_plugin_authorize::check_openssl_loaded()) {
notify('PHP must be compiled with SSL support (--with-openssl)');
}
@@ -561,7 +478,9 @@ class enrolment_plugin_authorize
set_config('an_teachermanagepay', optional_param('an_teachermanagepay', 0, PARAM_BOOL));
set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL));
$acceptccs = optional_param('acceptccs', array_keys(get_list_of_creditcards()), PARAM_ALPHA);
$acceptccs = optional_param('acceptccs',
array_keys(enrolment_plugin_authorize::get_list_of_creditcards()),
PARAM_ALPHA);
set_config('an_acceptccs', implode(',', $acceptccs));
$cutoff_hour = optional_param('an_cutoff_hour', 0, PARAM_INT);
@@ -597,7 +516,7 @@ class enrolment_plugin_authorize
$passwordval = optional_param('an_password', '');
if ((empty($CFG->loginhttps) and substr($CFG->wwwroot, 0, 5) !== 'https') ||
!$this->check_openssl_loaded() ||
!enrolment_plugin_authorize::check_openssl_loaded() ||
empty($loginval) ||
(empty($tranval) and empty($passwordval))) {
return false;
@@ -610,13 +529,51 @@ class enrolment_plugin_authorize
return true;
}
/**
* zero_cost (static method)
*
* @param unknown_type $course
* @return number
* @static
*/
function zero_cost($course) {
$curcost = enrolment_plugin_authorize::get_course_cost($course);
return (abs($curcost['cost']) < 0.01);
}
/**
* email_to_admin
* get_course_cost (static method)
*
* @param object $course
* @return array
* @static
*/
function get_course_cost($course)
{
global $CFG;
$cost = (float)0;
$currency = (!empty($course->currency))
? $course->currency :( empty($CFG->enrol_currency)
? 'USD' : $CFG->enrol_currency );
if (!empty($course->cost)) {
$cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost;
}
$cost = format_float($cost, 2);
$ret = array('cost' => $cost, 'currency' => $currency);
return $ret;
}
/**
* email_to_admin (static method)
*
* @param string $subject
* @param mixed $data
* @access private
* @static
*/
function email_to_admin($subject, $data)
{
@@ -625,19 +582,16 @@ class enrolment_plugin_authorize
$admin = get_admin();
$data = (array)$data;
$message = "$SITE->fullname: Transaction failed.\n\n$subject\n\n";
foreach ($data as $key => $value) {
$message .= "$key => $value\n";
}
email_to_user($admin, $admin, "Authorize.net ERROR: ".$subject, $message);
$message = "$SITE->fullname: Transaction failed.\n\n$subject\n\n";
$message .= print_r($data, true);
email_to_user($admin, $admin, "$SITE->fullname: Authorize.net ERROR", $message);
}
/**
* prevent_double_paid
* prevent_double_paid (static method)
*
* @param object $course
* @access private
* @static
*/
function prevent_double_paid($course)
{
@@ -659,17 +613,51 @@ class enrolment_plugin_authorize
}
}
/**
* check_openssl_loaded
* check_openssl_loaded (static method)
*
* @return bool
* @access private
* @static
*/
function check_openssl_loaded() {
return extension_loaded('openssl');
}
/**
* get_list_of_creditcards (static method)
*
* @param bool $getall
* @return array
* @static
*/
function get_list_of_creditcards($getall = false)
{
global $CFG;
$alltypes = array(
'mcd' => 'Master Card',
'vis' => 'Visa',
'amx' => 'American Express',
'dsc' => 'Discover',
'dnc' => 'Diners Club',
'jcb' => 'JCB',
'swi' => 'Switch',
'dlt' => 'Delta',
'enr' => 'EnRoute'
);
if ($getall or empty($CFG->an_acceptccs)) {
return $alltypes;
}
$ret = array();
$ccs = explode(',', $CFG->an_acceptccs);
foreach ($ccs as $key) {
$ret[$key] = $alltypes[$key];
}
return $ret;
}
/**
* This function is run by admin/cron.php every time if admin has enabled this plugin.
@@ -698,17 +686,17 @@ class enrolment_plugin_authorize
if (intval($mconfig->an_dailysettlement) < $settlementtime) {
set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
mtrace(" daily cron: some cleanups and sending email to admins the count of pending orders expiring", "...");
mtrace(" daily cron; some cleanups and sending email to admins the count of pending orders expiring", ": ");
$this->cron_daily();
mtrace("done", "\n");
mtrace("done");
}
mtrace(" scheduled capture", ": ");
if (empty($CFG->an_review) or
(!empty($CFG->an_test)) or
(intval($CFG->an_capture_day) < 1) or
(!$this->check_openssl_loaded())) {
mtrace("disabled", "\n");
(!enrolment_plugin_authorize::check_openssl_loaded())) {
mtrace("disabled");
return; // order review disabled or test mode or manual capture or openssl wasn't loaded.
}
@@ -720,7 +708,7 @@ class enrolment_plugin_authorize
" AND (E.timecreated < '$timediffcnf') AND (E.timecreated > '$timediff30')";
if (!$orders = get_records_sql($sql)) {
mtrace("no pending orders", "\n");
mtrace("no pending orders");
return;
}
@@ -730,11 +718,11 @@ class enrolment_plugin_authorize
$ordercount = count((array)$orders);
if (($ordercount * $eachconn) + intval($mconfig->an_lastcron) > $timenow) {
mtrace("blocked", "\n");
mtrace("blocked");
return;
}
mtrace($ordercount ." orders are processing", "\n");
mtrace(" $ordercount orders are being processed now", ": ");
$faults = '';
$sendem = array();
@@ -747,10 +735,6 @@ class enrolment_plugin_authorize
$extra = NULL;
$success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE);
if ($success) {
if (!update_record("enrol_authorize", $order)) {
$this->email_to_admin("Error while trying to update data. Please edit manually this record: " .
"ID=$order->id in enrol_authorize table.", $order);
}
$timestart = $timeend = 0;
if ($order->enrolperiod) {
$timestart = $timenow;
@@ -775,6 +759,8 @@ class enrolment_plugin_authorize
}
}
mtrace("processed");
$timenow = time();
$elapsed = $timenow - $elapsed;
$eachconn = ceil($elapsed / $ordercount);
@@ -821,7 +807,7 @@ class enrolment_plugin_authorize
$emailmessage);
$i = $j;
}
mtrace("sent", "\n");
mtrace("sent");
}
/**
+2 -13
View File
@@ -5,6 +5,7 @@ if (!defined('MOODLE_INTERNAL')) {
}
require_once('const.php');
require_once('enrol.php');
require_once('authorizenetlib.php');
define('ORDER_CAPTURE', 'capture');
@@ -224,7 +225,6 @@ function authorize_print_order_details($orderno)
$message = '';
$extra = NULL;
$success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE);
update_record("enrol_authorize", $order); // May be expired.
if (!$success) {
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
}
@@ -301,17 +301,8 @@ function authorize_print_order_details($orderno)
$success = authorize_action($order, $message, $extra, AN_ACTION_CREDIT);
if ($success) {
if (empty($CFG->an_test)) {
$extra->id = insert_record("enrol_authorize_refunds", $extra);
if (empty($extra->id)) {
$emailsubject = "Authorize.net: insert record error";
$emailmessage = "Error while trying to insert new data to enrol_authorize_refunds table:\n";
$data = (array)$extra;
foreach ($data as $key => $value) {
$emailmessage .= "$key => $value\n";
}
$adminuser = get_admin();
email_to_user($adminuser, $adminuser, $emailsubject, $emailmessage);
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", $emailmessage);
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", 'insert record error');
}
else {
if (!empty($unenrol)) {
@@ -353,7 +344,6 @@ function authorize_print_order_details($orderno)
$extra = NULL;
$message = '';
$success = authorize_action($order, $message, $extra, AN_ACTION_VOID);
update_record("enrol_authorize", $order); // May be expired.
if ($success) {
if (empty($CFG->an_test)) {
redirect("index.php?order=$orderno");
@@ -395,7 +385,6 @@ function authorize_print_order_details($orderno)
$message = '';
$extra = NULL;
$success = authorize_action($suborder, $message, $extra, AN_ACTION_VOID);
update_record("enrol_authorize_refunds", $suborder); // May be expired.
if ($success) {
if (empty($CFG->an_test)) {
if (!empty($unenrol)) {