Settlement date.

This commit is contained in:
ethem
2005-12-22 15:24:05 +00:00
parent aac4707d05
commit 0ccf08fe1d
6 changed files with 287 additions and 183 deletions
+144 -98
View File
@@ -42,50 +42,90 @@ define('AN_ACTION_CREDIT', 0x04);
* - Also used to cancel existing transaction with a status of
* settled/refunded. Credited mistakenly, so cancel it
* and return funds to our account.
*
* @todo cut-off time
*/
define('AN_ACTION_VOID', 0x08);
define('AN_REASON_NONE', 0);
define('AN_REASON_TRAN_NOT_FOUND', 16);
/**
* Gets settlement date and time
*
* @param int $time Processed time, usually now.
* @return int Settlement date
*/
function getsettletime($time)
{
global $CFG;
$hrs = intval($CFG->an_cutoff_hour);
$mins = intval($CFG->an_cutoff_min);
$cutofftime = strtotime("$hrs:$mins", $time);
if ($cutofftime < $time) {
$cutofftime = strtotime("$hrs:$mins", $time + (24 * 3600));
}
return $cutofftime;
}
/**
* Is order settled? Status must be auth_captured or credited.
*
* @param object $order Order details
* @return bool true, if settled, false otherwise.
*/
function settled($order)
{
global $CFG;
static $timenow;
if (!isset($timenow)) {
$timenow = time();
}
return (($order->status == AN_STATUS_AUTHCAPTURE || $order->status == AN_STATUS_CREDIT)
&& $order->settletime < $timenow && $order->settletime > 0);
}
/**
* Performs an action on authorize.net
*
* @param &object $order Which transaction data will be send. See enrol_authorize table.
* @param &string $message Information about error messages.
* @param object &$order Which transaction data will be send. See enrol_authorize table.
* @param string &$message Information about error messages.
* @param int &$reason Reason subcode
* @param object &$extra Extra transaction data.
* @param int $action Which action will be performed. See AN_ACTION_*
* @param object $extra Extra transaction data.
* @param &int $reason Response reason code.
* @return bool true, transaction was successful, false otherwise.
* @author Ethem Evlice <ethem a.t evlice d.o.t com>
* @uses $CFG
* @todo cut-off time
*/
function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra = NULL)
function authorizenet_action(&$order, &$message, &$reason, &$extra, $action=AN_ACTION_NONE)
{
global $CFG;
static $conststring;
$an_test = !empty($CFG->an_test);
if (empty($conststring)) {
$consdata = array (
'x_version' => '3.1',
'x_delim_data' => 'True',
'x_delim_char' => AN_DELIM,
'x_encap_char' => AN_ENCAP,
'x_relay_response' => 'False',
'x_method' => 'CC',
'x_login' => $CFG->an_login,
'x_test_request' => $an_test ? 'TRUE' : 'FALSE'
if (!isset($conststring)) {
$consdata = array(
'x_version' => '3.1',
'x_delim_data' => 'True',
'x_delim_char' => AN_DELIM,
'x_encap_char' => AN_ENCAP,
'x_relay_response' => 'False',
'x_method' => 'CC',
'x_login' => $CFG->an_login,
'x_test_request' => $an_test ? 'TRUE' : 'FALSE'
);
$str = '';
foreach($consdata as $ky => $vl) {
$str .= $ky . '=' . urlencode($vl) . '&';
}
$str .= (!empty($CFG->an_tran_key)) ?
"x_tran_key" . "=" . urlencode($CFG->an_tran_key):
"x_password" . "=" . urlencode($CFG->an_password);
'x_tran_key=' . urlencode($CFG->an_tran_key):
'x_password=' . urlencode($CFG->an_password);
$conststring = $str;
}
@@ -97,12 +137,14 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
$message = "check order->id!";
return false;
}
elseif ($action <= AN_ACTION_NONE || $action > AN_ACTION_CREDIT) {
elseif ($action <= AN_ACTION_NONE || $action > AN_ACTION_VOID) {
$message = "no action taken!";
return false;
}
$poststring = $conststring;
$timenowsettle = getsettletime(time());
switch ($action) {
case AN_ACTION_AUTH_ONLY:
case AN_ACTION_AUTH_CAPTURE:
@@ -116,10 +158,10 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
return false;
}
$ext = (array)$extra;
$poststring .= "&" . "x_type=" . ($action==AN_ACTION_AUTH_ONLY ?
"AUTH_ONLY" : "AUTH_CAPTURE");
$poststring .= '&x_type=' . ($action==AN_ACTION_AUTH_ONLY ?
'AUTH_ONLY' : 'AUTH_CAPTURE');
foreach($ext as $k => $v) {
$poststring .= "&" . $k . "=" . urlencode($v);
$poststring .= '&' . $k . '=' . urlencode($v);
}
break;
}
@@ -130,79 +172,75 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
$message = "order->status must be AN_STATUS_AUTH!";
return false;
}
// 30 days. +1 = cut-off time
$timediff = time() - (31 * 3600 * 24);
if ($order->timecreated < $timediff) {
$timediff = $timenowsettle - (30 * 3600 * 24);
$timecreatedsettle = getsettletime($order->timecreated);
if ($timecreatedsettle < $timediff) {
$order->status = AN_STATUS_EXPIRED;
$message = "Transaction must be captured within 30 days. EXPIRED!";
return false;
}
$poststring .= "&" . "x_type=PRIOR_AUTH_CAPTURE";
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
$poststring .= '&x_type=PRIOR_AUTH_CAPTURE&x_trans_id=' . urlencode($order->transid);
break;
}
case AN_ACTION_CREDIT:
{
if ($order->status != (AN_STATUS_AUTH | AN_STATUS_CAPTURE)) {
$message = "order->status must be AN_STATUS_AUTH & AN_STATUS_CAPTURE!";
if ($order->status != AN_STATUS_AUTHCAPTURE) {
$message = "order->status must be AN_STATUS_AUTHCAPTURE!";
return false;
}
if (!settled($order)) {
$message = "Order wasn't settled, try VOID. Check Cut-Off time if it fails!";
return false;
}
// 120 days
$timediff = time() - (120 * 3600 * 24);
if ($order->timecreated < $timediff) {
$timediff = $timenowsettle - (120 * 3600 * 24);
if ($order->settletime < $timediff) {
$message = "Order can be credited within 120 days!";
return false;
}
// extra fields
if (empty($extra)) {
$message = "need extra fields for CREDIT!";
return false;
}
// up to original amount
$total = doubleval($extra->sum) + doubleval($extra->amount);
if (($extra->amount == 0) || ($total > $order->amount)) {
$message = "Can be credited up to original amount.";
return false;
}
$poststring .= "&" . "x_type=CREDIT";
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
$poststring .= "&" . "x_card_num=" . sprintf("%04d", intval($order->cclastfour));
$poststring .= "&" . "x_currency_code=" . urlencode($extra->currency);
$poststring .= "&" . "x_amount=" . urlencode($extra->amount);
$poststring .= '&x_type=CREDIT&x_trans_id=' . urlencode($order->transid);
$poststring .= '&x_card_num=' . sprintf("%04d", intval($order->cclastfour));
$poststring .= '&x_currency_code=' . urlencode($order->currency);
$poststring .= '&x_amount=' . urlencode($extra->amount);
break;
}
case AN_ACTION_VOID:
{
// only: authonly, authcapture, credit
if ($order->status != AN_STATUS_AUTH &&
$order->status != (AN_STATUS_AUTH | AN_STATUS_CAPTURE) &&
$order->status != AN_STATUS_CREDIT) {
$message = "order->status must be AUTH, AUTH_CAPTURE or CREDIT!";
return false;
}
if ($order->status == AN_STATUS_AUTH) {
// 30 days for authonly, make it expired (***********timeupdated)
$timediff = time() - (30 * 3600 * 24);
if ($order->timecreated < $timediff) {
$message = "Auth_only transaction can be voided within 30 days!";
// 30 days for authonly, make it expired (**settletime**)
$timediff = $timenowsettle - (30 * 3600 * 24);
$timecreatedsettle = getsettletime($order->timecreated);
if ($timecreatedsettle < $timediff) {
$message = "Auth_only transaction must be voided within 30 days. EXPIRED!";
$order->status = AN_STATUS_EXPIRED;
return false;
}
} elseif ($order->status == (AN_STATUS_AUTH | AN_STATUS_CAPTURE)) {
// 1 day. Cancel pending settlement.
$timediff = time() - (2 * 3600 * 24); // TO DO: Cut-off time
if ($order->timecreated < $timediff) {
$message = "Settled transaction cannot be voided. Try REFUND!";
return false;
}
} elseif ($order->status == AN_STATUS_CREDIT) {
// 120 days for credit
$timediff = time() - (120 * 3600 * 24);
if ($order->timecreated < $timediff) {
$message = "Ops! Settled transaction must be credited within 120 days!";
}
elseif ($order->status == AN_STATUS_AUTHCAPTURE || $order->status == AN_STATUS_CREDIT) {
if (settled($order)) {
$message = "Settled transaction cannot be voided. Check Cut-Off time!";
return false;
}
}
// OK.
$poststring .= "&" . "x_type=VOID";
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
else {
$message = "order->status must be AUTH, AUTH_CAPTURE or CREDIT!";
return false;
}
$poststring .= '&x_type=VOID&x_trans_id=' . urlencode($order->transid);
break;
}
default: { // ???
@@ -213,8 +251,8 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
// referer
$anrefererheader = '';
if (!(empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
}
$response = array();
@@ -225,13 +263,12 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
return false;
}
fputs($fp,
"POST " . AN_PATH . " HTTP/1.0\r\n" .
"Host: $connect_host\r\n" . $anrefererheader .
"Content-type: application/x-www-form-urlencoded\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($poststring) . "\r\n\r\n" .
$poststring . "\r\n"
fwrite($fp, "POST " . AN_PATH . " HTTP/1.0\r\n" .
"Host: $connect_host\r\n" . $anrefererheader .
"Content-type: application/x-www-form-urlencoded\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($poststring) . "\r\n\r\n" .
$poststring . "\r\n"
);
$tmpstr = '';
@@ -243,7 +280,7 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
@fclose($fp);
return false;
}
$length = trim(substr($tmpstr,strpos($tmpstr,'content-length') + 15));
$length = trim(substr($tmpstr, strpos($tmpstr,'content-length')+15));
fgets($fp, 4096);
$data = fgets($fp, $length);
@fclose($fp);
@@ -262,37 +299,46 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
$reason = intval($response[2]);
if ($response[0] == AN_APPROVED) {
$order->transid = strval($response[6]); // TransactionID.
$order->timeupdated = time();
if ($response[0] == AN_APPROVED)
{
switch ($action) {
case AN_ACTION_AUTH_ONLY:
case AN_ACTION_AUTH_CAPTURE:
$order->authcode = strval($response[4]); // Authorization or Approval code
$order->avscode = strval($response[5]); // Address Verification System code
if ($action == AN_ACTION_AUTH_ONLY) {
$order->status = AN_STATUS_AUTH;
}
else {
$order->status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
}
break;
case AN_ACTION_PRIOR_AUTH_CAPTURE:
$order->status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
break;
case AN_ACTION_CREDIT: // generates new TransactionID
$order->status = AN_STATUS_CREDIT;
break;
{
$order->transid = strval($response[6]); // TransactionID
$order->avscode = strval($response[5]); // Address Verification System code
$order->authcode = strval($response[4]); // Authorization or Approval code
if ($action == AN_ACTION_AUTH_ONLY) {
$order->status = AN_STATUS_AUTH;
// dont't update settletime
} else {
$order->status = AN_STATUS_AUTHCAPTURE;
$order->settletime = getsettletime(time());
}
break;
}
case AN_ACTION_CREDIT:
{
// Credit generates new transaction id.
// So, $extra must be updated, not $order.
$extra->status = AN_STATUS_CREDIT;
$extra->transid = strval($response[6]);
$extra->settletime = getsettletime(time());
break;
}
case AN_ACTION_VOID:
$order->status = AN_STATUS_VOID;
break;
{
$order->status = AN_STATUS_VOID;
// dont't update settletime
break;
}
default: return false;
}
return true;
}
else {
else
{
$message = isset($response[3]) ? $response[3] : 'unknown error';
return false;
}
+8
View File
@@ -13,6 +13,8 @@ if (!isset($frm->an_referer)) $frm->an_referer = 'http://';
if (!isset($frm->an_test)) $frm->an_test = '';
if (!isset($frm->an_review)) $frm->an_review = '';
if (!isset($frm->an_review_day)) $frm->an_review_day = '5';
if (!isset($frm->an_cutoff_hour)) $frm->an_cutoff_hour = '0';
if (!isset($frm->an_cutoff_min)) $frm->an_cutoff_min = '5';
?>
@@ -93,6 +95,12 @@ if (!isset($frm->an_review_day)) $frm->an_review_day = '5';
<td><?php print_string("reviewday", "enrol_authorize", $frm->an_review_day) ?></td>
</tr>
<tr valign="top">
<td align="right">an_cutoff:</td>
<td><?php print_time_selector("an_cutoff_hour","an_cutoff_min",make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min),5); ?></td>
<td><?php print_string("cutofftime", "enrol_authorize") ?></td>
</tr>
<tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizeemail", "enrol_authorize") ?></h4></td></tr>
<tr valign="top">
+18 -1
View File
@@ -1,4 +1,4 @@
<?PHP //$Id$
them<?PHP //$Id$
// MySQL commands for upgrading this enrolment module
@@ -60,6 +60,23 @@ function authorize_upgrade($oldversion=0) {
}
}
if ($oldversion < 2005122200) { // settletime
include_once("$CFG->dirroot/enrol/authorize/enrol.php");
table_column('enrol_authorize_refunds', 'refundtype', 'status', 'integer', '1', 'unsigned', '0', 'not null');
table_column('enrol_authorize_refunds', '', 'settletime', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
table_column('enrol_authorize', 'timeupdated', 'settletime', 'integer', '10', 'unsigned', '0', 'not null');
$status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
if ($settlements = get_records_select('enrol_authorize', "status='$status'", '', 'id, settletime')) {
include_once("$CFG->dirroot/enrol/authorize/action.php");
foreach ($settlements as $settlement) {
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET settletime = '" .
getsettletime($settlement->settletime) . "' WHERE id = '$settlement->id'", false);
}
}
}
return $result;
}
+18 -1
View File
@@ -58,7 +58,24 @@ function authorize_upgrade($oldversion=0) {
}
}
}
if ($oldversion < 2005122200) { // settletime
include_once("$CFG->dirroot/enrol/authorize/enrol.php");
table_column('enrol_authorize_refunds', 'refundtype', 'status', 'integer', '1', 'unsigned', '0', 'not null');
table_column('enrol_authorize_refunds', '', 'settletime', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
table_column('enrol_authorize', 'timeupdated', 'settletime', 'integer', '10', 'unsigned', '0', 'not null');
$status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
if ($settlements = get_records_select('enrol_authorize', "status='$status'", '', 'id, settletime')) {
include_once("$CFG->dirroot/enrol/authorize/action.php");
foreach ($settlements as $settlement) {
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET settletime = '" .
getsettletime($settlement->settletime) . "' WHERE id = '$settlement->id'", false);
}
}
}
return $result;
}
+98 -82
View File
@@ -23,6 +23,10 @@ define('AN_STATUS_AUTH', 0x01);
* Captured.
*/
define('AN_STATUS_CAPTURE', 0x02);
/**
* Auth_Captured.
*/
define('AN_STATUS_AUTHCAPTURE', AN_STATUS_AUTH|AN_STATUS_CAPTURE);
/**
* Refunded.
*/
@@ -183,7 +187,7 @@ class enrolment_plugin extends enrolment_base
$order->userid = $USER->id;
$order->avscode = 'P';
$order->status = AN_STATUS_NONE; // it will be changed...
$order->timeupdated = 0; // cron changes this.
$order->settletime = 0; // cron changes this.
$order->timecreated = $timenow;
$order->amount = $curcost['cost'];
$order->currency = $curcost['currency'];
@@ -216,84 +220,84 @@ class enrolment_plugin extends enrolment_base
$extra->x_invoice_num = $order->id;
$extra->x_description = $course->shortname;
$message = NULL;
$message = '';
$reason = AN_REASON_NONE;
$an_review = !empty($CFG->an_review);
$action = $an_review ? AN_ACTION_AUTH_ONLY : AN_ACTION_AUTH_CAPTURE;
$success = authorizenet_action($order, $message, $action, $extra);
$success = authorizenet_action($order, $message, $reason, $extra, $action);
if (!$success) {
$this->email_to_admin($message, $order);
$this->ccerrormsg = $message;
return;
}
if ($success) {
$SESSION->ccpaid = 1; // security check: don't duplicate payment
if ($an_review) { // review enabled, inform admin and redirect to main page the user.
$order->timeupdated = 0; //no time() - REVIEW: cron or admin will change this.
if (update_record("enrol_authorize", $order)) {
// notification: new transaction (AUTH_ONLY)
}
else {
$this->email_to_admin("Error while trying to update data. Please edit manually this record: " .
"ID=$order->id in enrol_authorize table.", $order);
}
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '60');
return;
$SESSION->ccpaid = 1; // security check: don't duplicate payment
if ($an_review) { // review enabled, inform admin and redirect to main page.
if (update_record("enrol_authorize", $order)) {
// notification: new transaction (AUTH_ONLY)
// see order details: index.php?order=$order->id
}
// credit card captured, ENROL...
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???
else {
$this->email_to_admin("Error while trying to update data. Please edit manually this record: " .
"ID=$order->id in enrol_authorize table.", $order);
}
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
return;
}
if ($course->enrolperiod) {
$timestart = $timenow;
$timeend = $timestart + $course->enrolperiod;
} else {
$timestart = $timeend = 0;
// 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???
}
if ($course->enrolperiod) {
$timestart = $timenow;
$timeend = $timestart + $course->enrolperiod;
} else {
$timestart = $timeend = 0;
}
if (enrol_student($USER->id, $course->id, $timestart, $timeend, 'authorize')) {
$teacher = get_teacher($course->id);
if (!empty($CFG->enrol_mailstudents)) {
$a->coursename = "$course->fullname";
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id";
email_to_user($USER,
$teacher,
get_string("enrolmentnew", '', $course->shortname),
get_string('welcometocoursetext', '', $a));
}
if (enrol_student($USER->id, $course->id, $timestart, $timeend, 'authorize')) {
$teacher = get_teacher($course->id);
if (!empty($CFG->enrol_mailstudents)) {
$a->coursename = "$course->fullname";
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id";
email_to_user($USER,
$teacher,
get_string("enrolmentnew", '', $course->shortname),
get_string('welcometocoursetext', '', $a));
}
if (!empty($CFG->enrol_mailteachers)) {
$a->course = "$course->fullname";
$a->user = fullname($USER);
email_to_user($teacher,
if (!empty($CFG->enrol_mailteachers)) {
$a->course = "$course->fullname";
$a->user = fullname($USER);
email_to_user($teacher,
$USER,
get_string("enrolmentnew", '', $course->shortname),
get_string('enrolmentnewuser', '', $a));
}
if (!empty($CFG->enrol_mailadmins)) {
$a->course = "$course->fullname";
$a->user = fullname($USER);
$admins = get_admins();
foreach ($admins as $admin) {
email_to_user($admin,
$USER,
get_string("enrolmentnew", '', $course->shortname),
get_string('enrolmentnewuser', '', $a));
}
if (!empty($CFG->enrol_mailadmins)) {
$a->course = "$course->fullname";
$a->user = fullname($USER);
$admins = get_admins();
foreach ($admins as $admin) {
email_to_user($admin,
$USER,
get_string("enrolmentnew", '', $course->shortname),
get_string('enrolmentnewuser', '', $a));
}
}
} else {
$this->email_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $order);
}
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
}
redirect($destination);
} else {
$this->ccerrormsg = $message;
$this->email_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $order);
}
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl; unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
}
redirect($destination);
}
@@ -447,6 +451,8 @@ class enrolment_plugin extends enrolment_base
// not required!
set_config('an_test', optional_param('an_test', '') );
set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL) );
set_config('an_cutoff_hour', optional_param('an_cutoff_hour', '0') );
set_config('an_cutoff_min', optional_param('an_cutoff_min', '5') );
// required!
// if is it OK, process next config.
@@ -552,25 +558,26 @@ class enrolment_plugin extends enrolment_base
{
global $CFG;
parent::cron();
require_once("$CFG->dirroot/enrol/authorize/action.php");
srand((double)microtime() * 10000000);
$random100 = rand(0, 100);
$timenow = time();
$timediff30 = $timenow - (30 * 3600 * 24);
$timenowsettle = getsettletime($timenow);
$timediff30 = $timenowsettle - (30 * 3600 * 24);
if ($random100 < 15) { // delete very old records: status=AN_STATUS_NONE & timecreated=-60day.
// no credit card transaction is made in status AN_STATUS_NONE.
$timediff60 = $timenow - (60 * 3600 * 24);
$timediff60 = $timenowsettle - (60 * 3600 * 24);
$select = "(status = '" .AN_STATUS_NONE. "') AND (timecreated < '$timediff60')";
if (count_records_select('enrol_authorize', $select)) {
mtrace("Deleting records in authorize table older than 60 days (status=AN_STATUS_NONE).");
delete_records_select('enrol_authorize', $select);
}
}
if ($random100 > 80) { // EXPIRED: Transactions with auth_only will be expired 30 days later.
$select = "(status = '" .AN_STATUS_AUTH. "') AND (timeupdated = '0') AND (timecreated < '$timediff30')";
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET timeupdated = '$timenow', status = '" .AN_STATUS_EXPIRE. "' WHERE $select", false);
elseif ($random100 > 80) { // EXPIRED: Transactions with auth_only will be expired 30 days later.
$select = "(status = '" .AN_STATUS_AUTH. "') AND (settletime = '0') AND (timecreated < '$timediff30')";
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET settletime = '$timenowsettle', status = '" .AN_STATUS_EXPIRE. "' WHERE $select", false);
}
if (empty($CFG->an_review) || empty($CFG->an_review_day) || $CFG->an_review_day < 1) {
@@ -579,19 +586,21 @@ class enrolment_plugin extends enrolment_base
}
// AUTO-CAPTURE: it must be captured within 30 days. Otherwise it will expired.
$timediffcnf = $timenow - (intval($CFG->an_review_day) * 3600 * 24);
$select = "(status = '" . AN_STATUS_AUTH . "') AND (timeupdated = '0') AND (timecreated < '$timediffcnf') AND (timecreated > '$timediff30')";
$timediffcnf = $timenowsettle - (intval($CFG->an_review_day) * 3600 * 24);
$select = "(status = '" . AN_STATUS_AUTH . "') AND (settletime = '0') AND (timecreated < '$timediffcnf') AND (timecreated > '$timediff30')";
if ($orders = get_records_select('enrol_authorize', $select)) {
require_once("$CFG->dirroot/enrol/authorize/action.php");
@set_time_limit(0);
$this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
$message = NULL;
@set_time_limit(0);
$faults = '';
foreach ($orders as $order) {
$success = authorizenet_action($order, $message, AN_ACTION_PRIOR_AUTH_CAPTURE);
$message = NULL;
$extra = NULL;
$reason = AN_REASON_NONE;
$success = authorizenet_action($order, $message, $reason, $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);
"ID=$order->id in enrol_authorize table.", $order);
}
$timestart = $timeend = 0;
if ($course = get_record_sql("SELECT enrolperiod FROM {$CFG->prefix}course WHERE id='$order->courseid'")) {
@@ -601,19 +610,26 @@ class enrolment_plugin extends enrolment_base
}
}
if (enrol_student($order->userid, $order->courseid, $timestart, $timeend, 'authorize')) {
$this->log .= "user($order->userid) enrolled to course($order->courseid)\n";
$this->log .= "User($order->userid) has been enrolled to course($order->courseid).\n";
}
else {
$this->email_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $order);
}
$faults .= "Error while trying to enrol ".fullname($USER)." in '$course->fullname' \n";
foreach ($order as $okey => $ovalue) {
$faults .= " $okey = $ovalue\n";
}
}
}
else { // not success
$this->log .= $message . "\n";
}
}
$this->log .= "AUTHORIZE.NET CRON FINISHED: " . userdate(time());
$adminuser = get_admin();
if (!empty($faults)) {
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON FAULTS", $faults);
}
if (!empty($CFG->enrol_mailadmins)) {
email_to_user(get_admin(), get_admin(), "AUTHORIZE.NET CRON LOG", $this->log);
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON LOG", $this->log);
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?PHP // $Id$
$module->version = 2005121200;
$module->version = 2005122200;
$module->requires = 2005072200;
?>