diff --git a/enrol/authorize/config.html b/enrol/authorize/config.html index 80445ef22c9..7bf1120079c 100755 --- a/enrol/authorize/config.html +++ b/enrol/authorize/config.html @@ -12,7 +12,7 @@ if (!isset($frm->an_password)) $frm->an_password = ''; 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_capture_day)) $frm->an_capture_day = '5'; if (!isset($frm->an_cutoff_hour)) $frm->an_cutoff_hour = '0'; if (!isset($frm->an_cutoff_min)) $frm->an_cutoff_min = '5'; @@ -85,14 +85,16 @@ if (!isset($frm->an_cutoff_min)) $frm->an_cutoff_min = '5'; an_review: - an_review)) echo "checked=\"true\"" ?> /> + an_review)) echo "checked=\"true\"" ?> /> + - an_review_day: - - an_review_day) ?> + an_capture_day: + + + an_capture_day) ?> diff --git a/enrol/authorize/db/mysql.php b/enrol/authorize/db/mysql.php index 0027fa8b0da..a694afc450e 100755 --- a/enrol/authorize/db/mysql.php +++ b/enrol/authorize/db/mysql.php @@ -84,6 +84,13 @@ function authorize_upgrade($oldversion=0) { execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP authcode", false); } + if ($oldversion < 2006010200) { + if (isset($CFG->an_review_day)) { // rename an_review_day + set_config('an_capture_day', $CFG->an_review_day); + delete_records('config', 'name', 'an_review_day'); + } + } + return $result; } diff --git a/enrol/authorize/db/postgres7.php b/enrol/authorize/db/postgres7.php index 232a5e3fb5b..06174555836 100644 --- a/enrol/authorize/db/postgres7.php +++ b/enrol/authorize/db/postgres7.php @@ -83,6 +83,13 @@ function authorize_upgrade($oldversion=0) { execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP authcode", false); } + if ($oldversion < 2006010200) { + if (isset($CFG->an_review_day)) { // rename an_review_day + set_config('an_capture_day', $CFG->an_review_day); + delete_records('config', 'name', 'an_review_day'); + } + } + return $result; } diff --git a/enrol/authorize/enrol.html b/enrol/authorize/enrol.html index b05b86e37a5..c6dae9a7537 100755 --- a/enrol/authorize/enrol.html +++ b/enrol/authorize/enrol.html @@ -9,15 +9,15 @@
- - - - + + + + + diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index 4edeb525bca..696bee3e650 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -24,9 +24,9 @@ define('AN_STATUS_AUTH', 0x01); */ define('AN_STATUS_CAPTURE', 0x02); /** - * Auth_Captured. + * AN_STATUS_AUTH|AN_STATUS_CAPTURE. */ -define('AN_STATUS_AUTHCAPTURE', AN_STATUS_AUTH|AN_STATUS_CAPTURE); +define('AN_STATUS_AUTHCAPTURE', 0x03); /** * Refunded. */ @@ -245,10 +245,10 @@ class enrolment_plugin extends enrolment_base $a->transid = $order->transid; $a->amount = "$order->currency $order->amount"; $a->expireon = getsettletime($timenow + (30 * 3600 * 24)); - $a->captureon = getsettletime($timenow + (intval($CFG->an_review_day) * 3600 * 24)); + $a->captureon = getsettletime($timenow + (intval($CFG->an_capture_day) * 3600 * 24)); $a->course = $course->fullname; $a->user = fullname($USER); - $a->acstatus = ($CFG->an_review_day > 0) ? get_string('yes') : get_string('no'); + $a->acstatus = ($CFG->an_capture_day > 0) ? get_string('yes') : get_string('no'); $emailmessage = get_string('adminneworder', 'enrol_authorize', $a); $a->course = $course->shortname; $a->orderid = $order->id; @@ -409,6 +409,23 @@ class enrolment_plugin extends enrolment_base notify('PHP must be compiled with SSL support (--with-openssl)'); } + $ac_enabled = !empty($frm->an_review) && intval($frm->an_capture_day) > 0; + if ($ac_enabled) { // Cron must be runnig!!! Check last cron... + $mconfig = get_config('enrol/authorize'); + $lastcron = intval($mconfig->an_lastcron); + if (time() - $lastcron > 3600 * 24) { + notify(get_string('admincronsetup', 'enrol_authorize')); + } + } + else { + if ($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH)) { + $a->count = $count; + $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=" . AN_STATUS_AUTH; + $message = get_string('adminpendingorders', 'enrol_authorize', $a); + notify($message); + } + } + if (data_submitted()) { // something POSTed, Some required fields if (empty($frm->an_login)) { @@ -420,30 +437,6 @@ class enrolment_plugin extends enrolment_base if (empty($CFG->loginhttps)) { notify("\$CFG->loginhttps must be ON"); } - - // ******************* AUTOCAPTURE ******************* - if (!(empty($frm->an_review) || $frm->an_review_day < 1)) { - // ++ENABLED++ - // Cron must be runnig!!! Check last cron... - $mconfig = get_config('enrol/authorize'); - $lastcron = intval($mconfig->an_lastcron); - if (time() - $lastcron > 3600 * 24) { - // Cron must be enabled if you want to use autocapture feature. - // Setup cron or disable an_review again... - // Otherwise, transactions will be cancelled unless you review it within 30 days. - notify(get_string('cronwarning', 'admin')); - } - } else { - // --DISABLED-- - // Cron will NOT run anymore, because autocapture runs with cron. - // Transactions with AN_STATUS_AUTH will be cancelled and we can display this warning to admin! - // Admin can check (Accept|Deny) new transactions manually. - - if ($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH)) { - notify("CRON DISABLED. TRANSACTIONS WITH A STATUS OF AN_STATUS_AUTH WILL BE CANCELLED UNLESS YOU CHECK IT. TOTAL $count"); - } - } - // *************************************************** } include($CFG->dirroot.'/enrol/authorize/config.html'); @@ -491,17 +484,17 @@ class enrolment_plugin extends enrolment_base set_config('an_password', $password_val); set_config('an_tran_key', $tran_val); - // an_review & an_review_day & cron depencies... + // an_review & an_capture_day & cron depencies... $review_val = optional_param('an_review', ''); if (empty($review_val)) { // review disabled. cron is not required. AUTH_CAPTURE works. set_config('an_review', $review_val); } else { // review enabled. - $review_day_val = optional_param('an_review_day', 5, PARAM_INT); - if ($review_day_val < 0) $review_day_val = 0; - elseif ($review_day_val > 29) $review_day_val = 29; - if ($review_day_val > 0) { + $capture_day_val = optional_param('an_capture_day', 5, PARAM_INT); + if ($capture_day_val < 0) $capture_day_val = 0; + elseif ($capture_day_val > 29) $capture_day_val = 29; + if ($capture_day_val > 0) { // Cron must change an_lastcron. :)) $mconfig = get_config('enrol/authorize'); $lastcron = intval($mconfig->an_lastcron); @@ -511,7 +504,7 @@ class enrolment_plugin extends enrolment_base } } set_config('an_review', $review_val); - set_config('an_review_day', $review_day_val); + set_config('an_capture_day', $capture_day_val); } return true; @@ -607,15 +600,38 @@ class enrolment_plugin extends enrolment_base delete_records_select('enrol_authorize', $select); } - if (!empty($CFG->an_test)) { - return; // AUTOCAPTURE doesn't work in test mode. + if (empty($CFG->an_review) || !empty($CFG->an_test)) { + return; } - if (empty($CFG->an_review) || empty($CFG->an_review_day) || $CFG->an_review_day < 1) { - return; // AUTOCAPTURE disabled. admin, teacher review it manually + + if (intval($CFG->an_capture_day < 1)) { + // Admin review it manually. + // We can send email to admin about be expired transactions. + // Last 2 days (30-28=2) is good, I think. + // Send daily email. + $nextmail = intval($mconfig->an_nextmail); + if ($nextmail > $timenow) + return; // One day must be passed. + + $timediff28 = $timenowsettle - (28 * 3600 * 24); + $select = "(status = '" . AN_STATUS_AUTH . "') AND " . + "(timecreated < '$timediff28') AND (timecreated > '$timediff30')"; + if (!$count = count_records_select('enrol_authorize', $sql)) { + return; + } + + $a->pending = $count; + $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=" . AN_STATUS_AUTH; + $a->enrolurl = "$CFG->wwwroot/$CFG->admin/users.php"; + $message = get_string('pendingordersemail', 'enrol_authorize', $a); + $adminuser = get_admin(); + email_to_user($adminuser, $adminuser, "WARNING: PENDING PAYMENTS", $a); + set_config('an_nextmail', $timenow + (3600 * 24), 'enrol/authorize'); + return; } // AUTO-CAPTURE: Transaction must be captured within 30 days. Otherwise it will expired. - $timediffcnf = $timenowsettle - (intval($CFG->an_review_day) * 3600 * 24); + $timediffcnf = $timenowsettle - (intval($CFG->an_capture_day) * 3600 * 24); $sql = "SELECT E.*, C.fullname, C.enrolperiod " . "FROM {$CFG->prefix}enrol_authorize E " . "INNER JOIN {$CFG->prefix}course C ON C.id = E.courseid " . diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php index 1e41f02cb86..7bc8146b8a3 100644 --- a/enrol/authorize/index.php +++ b/enrol/authorize/index.php @@ -54,6 +54,7 @@ function authorize_orders() $perpage = 10; $userid = optional_param('user', 0, PARAM_INT); $courseid = optional_param('course', 0, PARAM_INT); + $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); $table = new flexible_table('enrol-authorize'); $table->set_attribute('width', '100%'); @@ -64,13 +65,14 @@ function authorize_orders() $table->define_columns(array('id', 'timecreated', 'userid', 'status', '')); $table->define_headers(array($authstrs->orderid, $strs->time, $strs->user, $strs->status, $strs->action)); - $table->define_baseurl($CFG->wwwroot."/enrol/authorize/index.php?course=$courseid&user=$userid"); + $table->define_baseurl($CFG->wwwroot."/enrol/authorize/index.php?course=$courseid&user=$userid&status=$status"); $table->sortable(true); $table->pageable(true); $table->setup(); - $where = "WHERE (status != '" . AN_STATUS_NONE . "') "; + if ($status > AN_STATUS_NONE) $where = "WHERE (status = '$status') "; + else $where = "WHERE (status != '" . AN_STATUS_NONE . "') "; if ($userid > 0) { $where .= "AND (userid = '" . $userid . "') "; } if ($courseid > 0) { $where .= "AND (courseid = '" . $courseid . "') "; } diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php index db1e203e97c..ee4f9b9da75 100755 --- a/enrol/authorize/version.php +++ b/enrol/authorize/version.php @@ -1,6 +1,7 @@ -version = 2005122800; -$module->requires = 2005072200; - -?> +version = 2006010200; +$module->requires = 2005072200; + +?> + diff --git a/lang/en/enrol_authorize.php b/lang/en/enrol_authorize.php index 227d50213f0..ba17ba618fa 100755 --- a/lang/en/enrol_authorize.php +++ b/lang/en/enrol_authorize.php @@ -6,6 +6,18 @@ $string['adminauthorizeccapture'] = 'Order Review & Auto-Capture Settings'; $string['adminauthorizeemail'] = 'Email Sending Settings'; $string['adminauthorizesettings'] = 'Authorize.net Settings'; $string['adminauthorizewide'] = 'Site-Wide Settings'; +$string['admincronsetup'] = 'The cron.php maintenance script has not been run for at least 24 hours.
Cron must be enabled if you want to use autocapture feature.
Setup cron or uncheck an_review again.
If you disable autocapture, transactions will be cancelled unless you review them within 30 days.
Check an_review and enter \'0\' to an_capture_day field
if you want to manually accept/deny payments within 30 days.'; +$string['adminhelpcapture'] = 'Not only I want to manually accept/deny payments. But also, use autocapture to prevent cancelling payment. What will I do? + + - Setup cron. + - Check an_review. + - Enter a number between 1 and 29 to an_capture_day field. Card will be captured and user will be enrolled to course unless you capture it within an_capture_day.'; +$string['adminhelpreview'] = 'How will I manually accept/deny payments? +- Check an_review. +- Enter \'0\' to an_capture_day field. + +How students will be enrolled to courses immediately when they entered their card number? +- Uncheck an_review.'; $string['adminneworder'] = ' Dear Admin, You have received a new pending order: @@ -25,6 +37,7 @@ $string['adminneworder'] = ' Dear Admin, Also you can accept/deny the payment to enrol the student immediately following this link: $a->url'; $string['adminnewordersubject'] = '$a->course: New Pending Order($a->orderid)'; +$string['adminpendingorders'] = 'You have disabled auto-capture feature.
Total $a->count transactions with a status of AN_STATUS_AUTH will be cancelled unless you check it.
To accept/deny payments go to url\'>Payment Management page.'; $string['adminreview'] = 'Review order before processing the credit card.'; $string['amount'] = 'Amount'; $string['anlogin'] = 'Authorize.net: Login name'; @@ -67,6 +80,17 @@ $string['notsettled'] = 'Not settled'; $string['orderid'] = 'Order ID'; $string['paymentmanagement'] = 'Payment Management'; $string['paymentpending'] = 'Your payment is pending for this course with this order number $a->orderid.'; +$string['pendingordersemail'] = ' Dear admin, + +$a->pending transactions will be expired unless you accept payment with in 2 days. + +This is a warning message, because you didn\'t enable autocapture. Means you have to accept or deny payments manually. + +To accept/deny pending payments go to: +$a->url + +To enable autocapture, means you will not receive any warning emails anymore, go to: +$a->enrolurl'; $string['refund'] = 'Refund'; $string['refunded'] = 'Refunded'; $string['returns'] = 'Returns';
: -
:
: +
: : -
: