2006-08-30 10:29:10 +00:00
|
|
|
<?php // $Id$
|
2005-05-13 09:05:39 +00:00
|
|
|
|
2006-06-01 07:47:22 +00:00
|
|
|
require_once($CFG->dirroot.'/enrol/enrol.class.php');
|
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/const.php');
|
2006-09-02 11:49:02 +00:00
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
|
2005-05-13 09:05:39 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
/**
|
2006-09-02 11:49:02 +00:00
|
|
|
* Authorize.net Payment Gateway plugin
|
2005-12-09 12:00:28 +00:00
|
|
|
*/
|
2006-03-13 16:47:44 +00:00
|
|
|
class enrolment_plugin_authorize
|
2005-12-09 12:00:28 +00:00
|
|
|
{
|
2005-11-21 07:33:04 +00:00
|
|
|
|
2005-12-14 15:47:37 +00:00
|
|
|
/**
|
|
|
|
* Cron log.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $log;
|
|
|
|
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
2006-10-16 09:39:08 +00:00
|
|
|
* Presents registration forms.
|
2005-11-21 07:33:04 +00:00
|
|
|
*
|
|
|
|
* @param object $course Course info
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
2005-11-21 07:33:04 +00:00
|
|
|
*/
|
2006-06-29 09:49:36 +00:00
|
|
|
function print_entry($course) {
|
2005-11-21 07:33:04 +00:00
|
|
|
global $CFG, $USER, $form;
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
$zerocost = zero_cost($course);
|
2006-06-29 19:07:28 +00:00
|
|
|
if ($zerocost) {
|
|
|
|
$manual = enrolment_factory::factory('manual');
|
|
|
|
if (!empty($this->errormsg)) {
|
|
|
|
$manual->errormsg = $this->errormsg;
|
|
|
|
}
|
|
|
|
$manual->print_entry($course);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-15 20:44:49 +00:00
|
|
|
prevent_double_paid($course);
|
2006-09-22 15:31:04 +00:00
|
|
|
httpsrequired();
|
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
|
2005-11-21 07:33:04 +00:00
|
|
|
if (empty($CFG->loginhttps)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
error(get_string('httpsrequired', 'enrol_authorize'));
|
2005-11-21 07:33:04 +00:00
|
|
|
} else {
|
2006-01-19 14:57:23 +00:00
|
|
|
$wwwsroot = str_replace('http:','https:', $CFG->wwwroot);
|
|
|
|
redirect("$wwwsroot/course/enrol.php?id=$course->id");
|
2005-11-21 07:33:04 +00:00
|
|
|
exit;
|
|
|
|
}
|
2005-08-03 10:11:16 +00:00
|
|
|
}
|
2005-07-13 20:26:16 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$strcourses = get_string('courses');
|
|
|
|
$strloginto = get_string('loginto', '', $course->shortname);
|
2005-07-13 20:26:16 +00:00
|
|
|
|
2006-08-30 14:06:40 +00:00
|
|
|
print_header($strloginto,
|
|
|
|
$course->fullname,
|
|
|
|
"<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
|
2006-01-19 14:57:23 +00:00
|
|
|
print_course($course, '80%');
|
2005-05-13 09:05:39 +00:00
|
|
|
|
2006-06-29 19:07:28 +00:00
|
|
|
if ($course->password) {
|
2006-06-29 09:49:36 +00:00
|
|
|
print_heading(get_string('choosemethod', 'enrol_authorize'), 'center');
|
2005-11-21 07:33:04 +00:00
|
|
|
}
|
2005-05-13 09:05:39 +00:00
|
|
|
|
2006-11-15 20:44:49 +00:00
|
|
|
print_simple_box_start('center', '80%');
|
2006-12-18 19:21:10 +00:00
|
|
|
if ($USER->username == 'guest') { // only real guest user, not for users with guest role
|
2006-09-02 11:49:02 +00:00
|
|
|
$curcost = get_course_cost($course);
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
echo '<div align="center">';
|
|
|
|
echo '<p>'.get_string('paymentrequired').'</p>';
|
2006-06-29 09:49:36 +00:00
|
|
|
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>';
|
2006-11-15 20:44:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/enrol_form.php');
|
2007-02-05 13:51:27 +00:00
|
|
|
$frmenrol = new enrol_authorize_form('enrol.php', compact('course'));
|
2007-01-12 18:52:09 +00:00
|
|
|
if ($frmenrol->get_data()) {
|
2006-11-17 08:49:08 +00:00
|
|
|
$authorizeerror = '';
|
2006-11-15 20:44:49 +00:00
|
|
|
switch ($form->paymentmethod) {
|
|
|
|
case AN_METHOD_CC:
|
2006-11-17 08:49:08 +00:00
|
|
|
$authorizeerror = $this->cc_submit($form, $course);
|
|
|
|
break;
|
2006-11-15 20:44:49 +00:00
|
|
|
|
|
|
|
case AN_METHOD_ECHECK:
|
2006-11-17 08:49:08 +00:00
|
|
|
$authorizeerror = $this->echeck_submit($form, $course);
|
|
|
|
break;
|
2006-11-15 20:44:49 +00:00
|
|
|
}
|
2006-11-17 08:49:08 +00:00
|
|
|
if (!empty($authorizeerror)) {
|
|
|
|
error($authorizeerror);
|
2006-11-16 12:23:40 +00:00
|
|
|
}
|
2006-11-15 20:44:49 +00:00
|
|
|
}
|
2006-11-17 08:49:08 +00:00
|
|
|
$frmenrol->display();
|
2006-06-29 09:49:36 +00:00
|
|
|
}
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
print_simple_box_end();
|
2006-06-29 09:49:36 +00:00
|
|
|
|
|
|
|
if ($course->password) {
|
|
|
|
$password = '';
|
2006-06-29 15:03:54 +00:00
|
|
|
$teacher = get_teacher($course->id);
|
2006-06-29 09:49:36 +00:00
|
|
|
include($CFG->dirroot.'/enrol/manual/enrol.html');
|
|
|
|
}
|
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
print_footer();
|
2005-08-01 14:34:30 +00:00
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
|
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
2006-10-16 09:39:08 +00:00
|
|
|
* Validates registration forms and enrols student to course.
|
2005-11-21 07:33:04 +00:00
|
|
|
*
|
|
|
|
* @param object $form Form parameters
|
|
|
|
* @param object $course Course info
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
2005-11-21 07:33:04 +00:00
|
|
|
*/
|
2006-08-30 14:06:40 +00:00
|
|
|
function check_entry($form, $course)
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
2006-09-04 07:09:44 +00:00
|
|
|
if (zero_cost($course) || (!empty($course->password) && !empty($form->enrol) && $form->enrol == 'manual')) {
|
2006-03-09 05:03:41 +00:00
|
|
|
$manual = enrolment_factory::factory('manual');
|
|
|
|
$manual->check_entry($form, $course);
|
2006-06-29 19:07:28 +00:00
|
|
|
if (!empty($manual->errormsg)) {
|
2006-06-29 09:49:36 +00:00
|
|
|
$this->errormsg = $manual->errormsg;
|
|
|
|
}
|
2006-08-30 14:06:40 +00:00
|
|
|
}
|
2005-05-16 22:22:31 +00:00
|
|
|
}
|
2005-05-26 13:22:01 +00:00
|
|
|
|
2006-09-02 15:05:10 +00:00
|
|
|
|
2006-11-15 20:44:49 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
2006-10-16 09:39:08 +00:00
|
|
|
* The user submitted credit card form.
|
2005-11-21 07:33:04 +00:00
|
|
|
*
|
|
|
|
* @param object $form Form parameters
|
|
|
|
* @param object $course Course info
|
|
|
|
* @access private
|
|
|
|
*/
|
2005-12-09 12:00:28 +00:00
|
|
|
function cc_submit($form, $course)
|
|
|
|
{
|
2005-11-21 07:33:04 +00:00
|
|
|
global $CFG, $USER, $SESSION;
|
2006-06-01 07:47:22 +00:00
|
|
|
require_once('authorizenetlib.php');
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
prevent_double_paid($course);
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-01-27 13:34:42 +00:00
|
|
|
$useripno = getremoteaddr();
|
2006-09-02 11:49:02 +00:00
|
|
|
$curcost = get_course_cost($course);
|
2006-01-27 13:34:42 +00:00
|
|
|
$exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy;
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-08-31 18:24:37 +00:00
|
|
|
// NEW CC ORDER
|
2005-12-09 12:00:28 +00:00
|
|
|
$timenow = time();
|
|
|
|
$order = new stdClass();
|
2006-08-31 18:24:37 +00:00
|
|
|
$order->paymentmethod = AN_METHOD_CC;
|
2006-11-17 16:06:46 +00:00
|
|
|
$order->refundinfo = substr($form->cc, -4);
|
2006-11-15 20:44:49 +00:00
|
|
|
$order->ccname = $form->firstname . " " . $form->lastname;
|
2005-12-09 12:00:28 +00:00
|
|
|
$order->courseid = $course->id;
|
|
|
|
$order->userid = $USER->id;
|
|
|
|
$order->status = AN_STATUS_NONE; // it will be changed...
|
2005-12-22 15:24:05 +00:00
|
|
|
$order->settletime = 0; // cron changes this.
|
2006-01-05 14:30:49 +00:00
|
|
|
$order->transid = 0; // Transaction Id
|
2005-12-09 12:00:28 +00:00
|
|
|
$order->timecreated = $timenow;
|
2005-12-12 17:42:05 +00:00
|
|
|
$order->amount = $curcost['cost'];
|
|
|
|
$order->currency = $curcost['currency'];
|
2005-12-09 12:00:28 +00:00
|
|
|
$order->id = insert_record("enrol_authorize", $order);
|
|
|
|
if (!$order->id) {
|
2006-09-02 11:49:02 +00:00
|
|
|
email_to_admin("Error while trying to insert new data", $order);
|
2006-11-17 08:49:08 +00:00
|
|
|
return "Insert record error. Admin has been notified!";
|
2005-11-21 14:09:52 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
$extra = new stdClass();
|
|
|
|
$extra->x_card_num = $form->cc;
|
|
|
|
$extra->x_card_code = $form->cvv;
|
2006-01-05 16:28:34 +00:00
|
|
|
$extra->x_exp_date = $exp_date;
|
2005-12-09 12:00:28 +00:00
|
|
|
$extra->x_currency_code = $curcost['currency'];
|
|
|
|
$extra->x_amount = $curcost['cost'];
|
2006-11-15 20:44:49 +00:00
|
|
|
$extra->x_first_name = $form->firstname;
|
|
|
|
$extra->x_last_name = $form->lastname;
|
2006-01-27 09:16:01 +00:00
|
|
|
$extra->x_country = $form->cccountry;
|
|
|
|
$extra->x_address = $form->ccaddress;
|
|
|
|
$extra->x_state = $form->ccstate;
|
|
|
|
$extra->x_city = $form->cccity;
|
|
|
|
$extra->x_zip = $form->cczip;
|
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
$extra->x_invoice_num = $order->id;
|
|
|
|
$extra->x_description = $course->shortname;
|
2006-01-27 09:16:01 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$extra->x_cust_id = $USER->id;
|
|
|
|
$extra->x_email = $USER->email;
|
2006-01-27 09:16:01 +00:00
|
|
|
$extra->x_customer_ip = $useripno;
|
2006-01-19 14:57:23 +00:00
|
|
|
$extra->x_email_customer = empty($CFG->enrol_mailstudents) ? 'FALSE' : 'TRUE';
|
2006-01-27 09:16:01 +00:00
|
|
|
$extra->x_phone = '';
|
|
|
|
$extra->x_fax = '';
|
2005-12-12 17:32:00 +00:00
|
|
|
|
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
|
|
|
$revieworder = false;
|
|
|
|
$action = AN_ACTION_AUTH_CAPTURE;
|
|
|
|
|
|
|
|
if (!empty($CFG->an_authcode) && !empty($form->ccauthcode)) {
|
|
|
|
$action = AN_ACTION_CAPTURE_ONLY;
|
|
|
|
$extra->x_auth_code = $form->ccauthcode;
|
|
|
|
}
|
|
|
|
elseif (!empty($CFG->an_review)) {
|
|
|
|
$revieworder = true;
|
|
|
|
$action = AN_ACTION_AUTH_ONLY;
|
|
|
|
}
|
|
|
|
|
2005-12-22 15:24:05 +00:00
|
|
|
$message = '';
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED != authorize_action($order, $message, $extra, $action, $form->cctype)) {
|
2006-09-02 11:49:02 +00:00
|
|
|
email_to_admin($message, $order);
|
2006-11-17 08:49:08 +00:00
|
|
|
return $message;
|
2005-12-22 15:24:05 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$SESSION->ccpaid = 1; // security check: don't duplicate payment
|
2006-01-20 16:04:52 +00:00
|
|
|
if ($order->transid == 0) { // TEST MODE
|
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
|
|
|
if ($revieworder) {
|
2006-01-05 14:30:49 +00:00
|
|
|
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
|
|
|
|
}
|
|
|
|
else {
|
2006-09-22 13:33:37 +00:00
|
|
|
enrol_into_course($course, $USER, 'manual');
|
2006-01-05 14:30:49 +00:00
|
|
|
redirect("$CFG->wwwroot/course/view.php?id=$course->id");
|
|
|
|
}
|
2005-12-26 19:21:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-03 11:20:13 +00:00
|
|
|
if ($revieworder) { // review enabled, inform payment managers and redirect the user who have paid to main page.
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$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);
|
2006-11-03 12:09:00 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
if ($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments')) {
|
|
|
|
foreach ($paymentmanagers as $paymentmanager) {
|
|
|
|
email_to_user($paymentmanager, $USER, $emailsubject, $emailmessage);
|
2006-08-29 14:30:11 +00:00
|
|
|
}
|
2005-11-21 07:33:04 +00:00
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
|
|
|
|
return;
|
|
|
|
}
|
2005-05-13 09:05:39 +00:00
|
|
|
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
// Credit card captured, ENROL student now...
|
2006-09-22 13:33:37 +00:00
|
|
|
if (enrol_into_course($course, $USER, 'manual')) {
|
2006-10-16 09:39:08 +00:00
|
|
|
if (!empty($CFG->enrol_mailstudents)) {
|
|
|
|
send_welcome_messages($order->id);
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
if (!empty($CFG->enrol_mailteachers)) {
|
2006-11-03 11:20:13 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
$paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
|
|
|
|
$paymentmanager = array_shift($paymentmanagers);
|
2006-06-01 07:47:22 +00:00
|
|
|
$a = new stdClass;
|
2005-12-22 15:24:05 +00:00
|
|
|
$a->course = "$course->fullname";
|
|
|
|
$a->user = fullname($USER);
|
2006-11-03 11:20:13 +00:00
|
|
|
email_to_user($paymentmanager,
|
2005-12-22 15:24:05 +00:00
|
|
|
$USER,
|
|
|
|
get_string("enrolmentnew", '', $course->shortname),
|
|
|
|
get_string('enrolmentnewuser', '', $a));
|
|
|
|
}
|
|
|
|
if (!empty($CFG->enrol_mailadmins)) {
|
2006-06-01 07:47:22 +00:00
|
|
|
$a = new stdClass;
|
2005-12-22 15:24:05 +00:00
|
|
|
$a->course = "$course->fullname";
|
|
|
|
$a->user = fullname($USER);
|
|
|
|
$admins = get_admins();
|
|
|
|
foreach ($admins as $admin) {
|
|
|
|
email_to_user($admin,
|
2005-11-24 13:07:35 +00:00
|
|
|
$USER,
|
|
|
|
get_string("enrolmentnew", '', $course->shortname),
|
|
|
|
get_string('enrolmentnewuser', '', $a));
|
2005-11-21 07:33:04 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
} else {
|
2006-11-03 11:20:13 +00:00
|
|
|
email_to_admin("Error while trying to enrol " . fullname($USER) . " in '$course->fullname'", $order);
|
2005-12-22 15:24:05 +00:00
|
|
|
}
|
2005-11-21 14:09:52 +00:00
|
|
|
|
2005-12-22 15:24:05 +00:00
|
|
|
if ($SESSION->wantsurl) {
|
|
|
|
$destination = $SESSION->wantsurl; unset($SESSION->wantsurl);
|
2005-11-21 14:09:52 +00:00
|
|
|
} else {
|
2005-12-22 15:24:05 +00:00
|
|
|
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
|
2005-11-21 14:09:52 +00:00
|
|
|
}
|
2006-11-03 11:20:13 +00:00
|
|
|
load_all_capabilities();
|
|
|
|
redirect($destination, get_string('paymentthanks', 'moodle', $course->fullname), 10);
|
2005-11-21 07:33:04 +00:00
|
|
|
}
|
2005-07-16 15:15:41 +00:00
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The user submitted echeck form.
|
|
|
|
*
|
|
|
|
* @param object $form Form parameters
|
|
|
|
* @param object $course Course info
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-08-30 14:06:40 +00:00
|
|
|
function echeck_submit($form, $course)
|
|
|
|
{
|
|
|
|
global $CFG, $USER, $SESSION;
|
|
|
|
require_once('authorizenetlib.php');
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
prevent_double_paid($course);
|
2006-08-30 18:59:53 +00:00
|
|
|
|
|
|
|
$useripno = getremoteaddr();
|
2006-09-02 11:49:02 +00:00
|
|
|
$curcost = get_course_cost($course);
|
2006-11-17 08:21:11 +00:00
|
|
|
$isbusinesschecking = ($form->acctype == 'BUSINESSCHECKING');
|
2006-08-30 18:59:53 +00:00
|
|
|
|
2006-08-31 18:24:37 +00:00
|
|
|
// NEW ECHECK ORDER
|
|
|
|
$timenow = time();
|
|
|
|
$order = new stdClass();
|
|
|
|
$order->paymentmethod = AN_METHOD_ECHECK;
|
2006-11-17 16:06:46 +00:00
|
|
|
$order->refundinfo = $isbusinesschecking ? 1 : 0;
|
2006-08-31 18:24:37 +00:00
|
|
|
$order->ccname = $form->firstname . ' ' . $form->lastname;
|
|
|
|
$order->courseid = $course->id;
|
|
|
|
$order->userid = $USER->id;
|
|
|
|
$order->status = AN_STATUS_NONE; // it will be changed...
|
|
|
|
$order->settletime = 0; // cron changes this.
|
|
|
|
$order->transid = 0; // Transaction Id
|
|
|
|
$order->timecreated = $timenow;
|
|
|
|
$order->amount = $curcost['cost'];
|
|
|
|
$order->currency = $curcost['currency'];
|
|
|
|
$order->id = insert_record("enrol_authorize", $order);
|
|
|
|
if (!$order->id) {
|
2006-09-02 11:49:02 +00:00
|
|
|
email_to_admin("Error while trying to insert new data", $order);
|
2006-11-17 08:49:08 +00:00
|
|
|
return "Insert record error. Admin has been notified!";
|
2006-08-31 18:24:37 +00:00
|
|
|
}
|
2006-08-30 18:59:53 +00:00
|
|
|
|
2006-09-01 15:18:22 +00:00
|
|
|
$extra = new stdClass();
|
|
|
|
$extra->x_bank_aba_code = $form->abacode;
|
|
|
|
$extra->x_bank_acct_num = $form->accnum;
|
|
|
|
$extra->x_bank_acct_type = $form->acctype;
|
2006-11-17 08:21:11 +00:00
|
|
|
$extra->x_echeck_type = $isbusinesschecking ? 'CCD' : 'WEB';
|
2006-09-01 15:18:22 +00:00
|
|
|
$extra->x_bank_name = $form->bankname;
|
|
|
|
$extra->x_currency_code = $curcost['currency'];
|
|
|
|
$extra->x_amount = $curcost['cost'];
|
|
|
|
$extra->x_first_name = $form->firstname;
|
|
|
|
$extra->x_last_name = $form->lastname;
|
|
|
|
$extra->x_country = $USER->country;
|
|
|
|
$extra->x_address = $USER->address;
|
|
|
|
$extra->x_city = $USER->city;
|
|
|
|
$extra->x_state = '';
|
|
|
|
$extra->x_zip = '';
|
|
|
|
|
|
|
|
$extra->x_invoice_num = $order->id;
|
|
|
|
$extra->x_description = $course->shortname;
|
|
|
|
|
|
|
|
$extra->x_cust_id = $USER->id;
|
|
|
|
$extra->x_email = $USER->email;
|
|
|
|
$extra->x_customer_ip = $useripno;
|
|
|
|
$extra->x_email_customer = empty($CFG->enrol_mailstudents) ? 'FALSE' : 'TRUE';
|
|
|
|
$extra->x_phone = '';
|
|
|
|
$extra->x_fax = '';
|
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
$message = '';
|
|
|
|
if (AN_REVIEW != authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) {
|
2006-09-02 11:49:02 +00:00
|
|
|
email_to_admin($message, $order);
|
2006-11-17 08:49:08 +00:00
|
|
|
return $message;
|
2006-09-01 15:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$SESSION->ccpaid = 1; // security check: don't duplicate payment
|
2006-10-16 09:39:08 +00:00
|
|
|
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
|
2006-08-30 14:06:40 +00:00
|
|
|
}
|
|
|
|
|
2005-05-16 22:22:31 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
|
|
|
* Gets access icons.
|
|
|
|
*
|
|
|
|
* @param object $course
|
|
|
|
* @return string
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
2005-11-21 07:33:04 +00:00
|
|
|
*/
|
|
|
|
function get_access_icons($course) {
|
|
|
|
|
2006-03-09 05:03:41 +00:00
|
|
|
$manual = enrolment_factory::factory('manual');
|
|
|
|
$str = $manual->get_access_icons($course);
|
2006-09-02 11:49:02 +00:00
|
|
|
$curcost = get_course_cost($course);
|
2005-11-21 07:33:04 +00:00
|
|
|
|
|
|
|
if (abs($curcost['cost']) > 0.00) {
|
|
|
|
$strrequirespayment = get_string("requirespayment");
|
|
|
|
$strcost = get_string("cost");
|
|
|
|
$currency = $curcost['currency'];
|
|
|
|
|
|
|
|
switch ($currency) {
|
|
|
|
case 'USD': $currency = 'US$'; break;
|
|
|
|
case 'CAD': $currency = 'C$'; break;
|
|
|
|
case 'EUR': $currency = '€'; break;
|
|
|
|
case 'GBP': $currency = '£'; break;
|
|
|
|
case 'JPY': $currency = '¥'; break;
|
|
|
|
}
|
2005-08-01 14:34:30 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
$str .= '<div class="cost" title="'.$strrequirespayment.'">'.$strcost.': ';
|
|
|
|
$str .= $currency . ' ' . $curcost['cost'].'</div>';
|
2005-08-01 14:34:30 +00:00
|
|
|
}
|
2005-05-16 22:22:31 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
return $str;
|
2005-05-16 22:22:31 +00:00
|
|
|
}
|
2005-08-01 14:34:30 +00:00
|
|
|
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
|
|
|
* Shows config form & errors
|
|
|
|
*
|
|
|
|
* @param object $frm
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
2005-11-21 07:33:04 +00:00
|
|
|
*/
|
2005-12-09 12:00:28 +00:00
|
|
|
function config_form($frm)
|
|
|
|
{
|
2005-11-21 07:33:04 +00:00
|
|
|
global $CFG;
|
2006-11-29 11:05:56 +00:00
|
|
|
$mconfig = get_config('enrol/authorize');
|
2005-11-21 07:33:04 +00:00
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
if (! check_openssl_loaded()) {
|
2005-11-21 07:33:04 +00:00
|
|
|
notify('PHP must be compiled with SSL support (--with-openssl)');
|
|
|
|
}
|
2005-05-25 16:27:53 +00:00
|
|
|
|
2006-05-30 08:32:43 +00:00
|
|
|
if (empty($CFG->loginhttps) and substr($CFG->wwwroot, 0, 5) !== 'https') {
|
2006-11-01 12:36:19 +00:00
|
|
|
$a = new stdClass;
|
|
|
|
$a->url = "$CFG->wwwroot/$CFG->admin/settings.php?section=httpsecurity";
|
|
|
|
notice(get_string('adminconfighttps', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
elseif (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
|
|
|
|
$wwwsroot = qualified_me();
|
|
|
|
$wwwsroot = str_replace('http:', 'https:', $wwwsroot);
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->url = $wwwsroot;
|
|
|
|
notice(get_string('adminconfighttpsgo', 'enrol_authorize', $a));
|
2006-01-03 10:23:28 +00:00
|
|
|
}
|
2006-01-19 14:57:23 +00:00
|
|
|
|
|
|
|
if (!empty($frm->an_review)) {
|
|
|
|
$captureday = intval($frm->an_capture_day);
|
|
|
|
$emailexpired = intval($frm->an_emailexpired);
|
|
|
|
if ($captureday > 0 || $emailexpired > 0) {
|
|
|
|
if ((time() - intval($mconfig->an_lastcron) > 3600 * 24)) {
|
|
|
|
notify(get_string('admincronsetup', 'enrol_authorize'));
|
|
|
|
}
|
2006-01-03 10:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
if ($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH)) {
|
2006-06-01 07:47:22 +00:00
|
|
|
$a = new stdClass;
|
2006-01-19 14:57:23 +00:00
|
|
|
$a->count = $count;
|
|
|
|
$a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH;
|
|
|
|
notify(get_string('adminpendingorders', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
if (data_submitted()) {
|
2006-11-29 11:05:56 +00:00
|
|
|
if (empty($mconfig->an_login)) {
|
2005-11-21 07:33:04 +00:00
|
|
|
notify("an_login required");
|
|
|
|
}
|
2006-11-29 11:05:56 +00:00
|
|
|
if (empty($mconfig->an_tran_key) && empty($mconfig->an_password)) {
|
2005-11-21 07:33:04 +00:00
|
|
|
notify("an_tran_key or an_password required");
|
|
|
|
}
|
2005-07-13 20:26:16 +00:00
|
|
|
}
|
2005-05-16 22:22:31 +00:00
|
|
|
|
2006-11-15 07:39:04 +00:00
|
|
|
include($CFG->dirroot.'/enrol/authorize/config_form.php');
|
2005-05-25 16:27:53 +00:00
|
|
|
}
|
2005-08-03 10:11:16 +00:00
|
|
|
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-11-21 07:33:04 +00:00
|
|
|
/**
|
|
|
|
* process_config
|
|
|
|
*
|
|
|
|
* @param object $config
|
|
|
|
* @return bool true if it will be saved.
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
2005-11-21 07:33:04 +00:00
|
|
|
*/
|
2005-12-09 12:00:28 +00:00
|
|
|
function process_config($config)
|
|
|
|
{
|
2005-11-21 07:33:04 +00:00
|
|
|
global $CFG;
|
2006-11-29 11:05:56 +00:00
|
|
|
$mconfig = get_config('enrol/authorize');
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-02-01 13:30:45 +00:00
|
|
|
// site settings
|
2006-07-25 17:38:32 +00:00
|
|
|
if (($cost = optional_param('enrol_cost', 5, PARAM_INT)) > 0) {
|
|
|
|
set_config('enrol_cost', $cost);
|
|
|
|
}
|
2006-01-19 14:57:23 +00:00
|
|
|
set_config('enrol_currency', optional_param('enrol_currency', 'USD', PARAM_ALPHA));
|
2006-06-01 07:47:22 +00:00
|
|
|
set_config('enrol_mailstudents', optional_param('enrol_mailstudents', 0, PARAM_BOOL));
|
|
|
|
set_config('enrol_mailteachers', optional_param('enrol_mailteachers', 0, PARAM_BOOL));
|
|
|
|
set_config('enrol_mailadmins', optional_param('enrol_mailadmins', 0, PARAM_BOOL));
|
2006-05-05 18:16:45 +00:00
|
|
|
|
2006-02-01 13:30:45 +00:00
|
|
|
// optional authorize.net settings
|
2006-06-01 07:47:22 +00:00
|
|
|
set_config('an_avs', optional_param('an_avs', 0, PARAM_BOOL));
|
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
|
|
|
set_config('an_authcode', optional_param('an_authcode', 0, PARAM_BOOL));
|
2006-06-01 07:47:22 +00:00
|
|
|
set_config('an_test', optional_param('an_test', 0, PARAM_BOOL));
|
2006-01-19 14:57:23 +00:00
|
|
|
set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL));
|
2006-02-01 13:03:13 +00:00
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
$acceptmethods = optional_param('acceptmethods', get_list_of_payment_methods(), PARAM_ALPHA);
|
2006-08-30 10:29:10 +00:00
|
|
|
set_config('an_acceptmethods', implode(',', $acceptmethods));
|
2006-09-02 11:49:02 +00:00
|
|
|
$acceptccs = optional_param('acceptccs', array_keys(get_list_of_creditcards()), PARAM_ALPHA);
|
2006-06-01 07:47:22 +00:00
|
|
|
set_config('an_acceptccs', implode(',', $acceptccs));
|
2006-09-04 12:09:30 +00:00
|
|
|
$acceptechecktypes = optional_param('acceptechecktypes', get_list_of_bank_account_types(), PARAM_ALPHA);
|
|
|
|
set_config('an_acceptechecktypes', implode(',', $acceptechecktypes));
|
2006-06-01 07:47:22 +00:00
|
|
|
|
2006-02-01 13:03:13 +00:00
|
|
|
$cutoff_hour = optional_param('an_cutoff_hour', 0, PARAM_INT);
|
|
|
|
$cutoff_min = optional_param('an_cutoff_min', 5, PARAM_INT);
|
|
|
|
set_config('an_cutoff', $cutoff_hour * 60 + $cutoff_min);
|
2006-01-19 14:57:23 +00:00
|
|
|
|
2006-02-01 13:30:45 +00:00
|
|
|
// cron depencies
|
2006-06-01 07:47:22 +00:00
|
|
|
$reviewval = optional_param('an_review', 0, PARAM_BOOL);
|
2006-01-19 14:57:23 +00:00
|
|
|
$captureday = optional_param('an_capture_day', 5, PARAM_INT);
|
|
|
|
$emailexpired = optional_param('an_emailexpired', 2, PARAM_INT);
|
2006-06-14 11:53:50 +00:00
|
|
|
$emailexpiredteacher = optional_param('an_emailexpiredteacher', 0, PARAM_BOOL);
|
2006-06-15 12:55:39 +00:00
|
|
|
$sorttype = optional_param('an_sorttype', 'ttl', PARAM_ALPHA);
|
2006-01-19 14:57:23 +00:00
|
|
|
|
|
|
|
$captureday = ($captureday > 29) ? 29 : (($captureday < 0) ? 0 : $captureday);
|
|
|
|
$emailexpired = ($emailexpired > 5) ? 5 : (($emailexpired < 0) ? 0 : $emailexpired);
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
if (!empty($reviewval) && ($captureday > 0 || $emailexpired > 0)) {
|
|
|
|
if (time() - intval($mconfig->an_lastcron) > 3600 * 24) {
|
|
|
|
return false;
|
|
|
|
}
|
2005-07-18 16:42:30 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
set_config('an_review', $reviewval);
|
|
|
|
set_config('an_capture_day', $captureday);
|
|
|
|
set_config('an_emailexpired', $emailexpired);
|
2006-06-14 11:53:50 +00:00
|
|
|
set_config('an_emailexpiredteacher', $emailexpiredteacher);
|
2006-06-15 12:55:39 +00:00
|
|
|
set_config('an_sorttype', $sorttype);
|
2006-01-19 14:57:23 +00:00
|
|
|
|
2006-07-31 12:45:34 +00:00
|
|
|
// https and openssl library is required
|
|
|
|
if ((substr($CFG->wwwroot, 0, 5) !== 'https' and empty($CFG->loginhttps)) or
|
2006-09-02 11:49:02 +00:00
|
|
|
!check_openssl_loaded()) {
|
2006-07-31 12:45:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-11-29 11:05:56 +00:00
|
|
|
// REQUIRED fields;
|
|
|
|
// an_login
|
2006-01-19 14:57:23 +00:00
|
|
|
$loginval = optional_param('an_login', '');
|
2006-11-29 11:05:56 +00:00
|
|
|
if (empty($loginval) && empty($mconfig->an_login)) {
|
2006-08-30 14:16:45 +00:00
|
|
|
return false;
|
2006-07-31 12:45:34 +00:00
|
|
|
}
|
2006-11-29 11:05:56 +00:00
|
|
|
$loginval = !empty($loginval) ? rc4encrypt($loginval) : strval($mconfig->an_login);
|
|
|
|
set_config('an_login', $loginval, 'enrol/authorize');
|
2006-07-31 12:45:34 +00:00
|
|
|
|
2006-11-29 11:05:56 +00:00
|
|
|
// an_tran_key, an_password
|
2006-01-19 14:57:23 +00:00
|
|
|
$tranval = optional_param('an_tran_key', '');
|
2006-11-29 11:05:56 +00:00
|
|
|
$tranval = !empty($tranval) ? rc4encrypt($tranval) : (isset($mconfig->an_tran_key)?$mconfig->an_tran_key:'');
|
2006-01-19 14:57:23 +00:00
|
|
|
$passwordval = optional_param('an_password', '');
|
2006-11-29 11:05:56 +00:00
|
|
|
$passwordval = !empty($passwordval) ? rc4encrypt($passwordval) :(isset($mconfig->an_password)?$mconfig->an_password:'');
|
|
|
|
$deletecurrent = optional_param('delete_current', '0', PARAM_BOOL);
|
|
|
|
if (!empty($deletecurrent) and !empty($tranval)) {
|
|
|
|
unset_config('an_password', 'enrol/authorize');
|
|
|
|
$passwordval = '';
|
2006-07-31 12:45:34 +00:00
|
|
|
}
|
2006-11-29 11:05:56 +00:00
|
|
|
elseif (!empty($passwordval)) {
|
|
|
|
set_config('an_password', $passwordval, 'enrol/authorize');
|
2006-07-31 12:45:34 +00:00
|
|
|
}
|
2006-11-29 11:05:56 +00:00
|
|
|
if (empty($tranval) and empty($passwordval)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-11-29 11:05:56 +00:00
|
|
|
if (!empty($tranval)) {
|
|
|
|
set_config('an_tran_key', $tranval, 'enrol/authorize');
|
|
|
|
}
|
2006-01-19 14:57:23 +00:00
|
|
|
|
2005-11-24 13:07:35 +00:00
|
|
|
return true;
|
2005-05-25 16:27:53 +00:00
|
|
|
}
|
2005-05-13 09:05:39 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
/**
|
2006-06-29 12:44:01 +00:00
|
|
|
* This function is run by admin/cron.php every time if admin has enabled this plugin.
|
|
|
|
*
|
|
|
|
* Everyday at settlement time (default is 00:05), it cleans up some tables
|
|
|
|
* and sends email to admin/teachers about pending orders expiring if manual-capture has enabled.
|
|
|
|
*
|
|
|
|
* If admin set up 'Order review' and 'Capture day', it captures credits cards and enrols students.
|
|
|
|
*
|
2005-12-09 12:00:28 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function cron()
|
|
|
|
{
|
2006-10-16 09:39:08 +00:00
|
|
|
global $CFG;
|
2006-06-01 07:47:22 +00:00
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/authorizenetlib.php');
|
2005-12-09 12:00:28 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$oneday = 86400;
|
2005-11-21 14:09:52 +00:00
|
|
|
$timenow = time();
|
2006-07-10 10:17:23 +00:00
|
|
|
$settlementtime = authorize_getsettletime($timenow);
|
2006-06-20 17:22:00 +00:00
|
|
|
$timediff30 = $settlementtime - (30 * $oneday);
|
2006-01-19 14:57:23 +00:00
|
|
|
$mconfig = get_config('enrol/authorize');
|
|
|
|
set_config('an_lastcron', $timenow, 'enrol/authorize');
|
2005-12-26 19:21:37 +00:00
|
|
|
|
2006-07-06 13:41:55 +00:00
|
|
|
mtrace("Processing authorize cron...");
|
|
|
|
|
2006-06-20 17:22:00 +00:00
|
|
|
if (intval($mconfig->an_dailysettlement) < $settlementtime) {
|
|
|
|
set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace(" daily cron; some cleanups and sending email to admins the count of pending orders expiring", ": ");
|
2006-07-06 12:01:24 +00:00
|
|
|
$this->cron_daily();
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace("done");
|
2006-01-19 14:57:23 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 13:41:55 +00:00
|
|
|
mtrace(" scheduled capture", ": ");
|
2006-07-06 12:01:24 +00:00
|
|
|
if (empty($CFG->an_review) or
|
|
|
|
(!empty($CFG->an_test)) or
|
|
|
|
(intval($CFG->an_capture_day) < 1) or
|
2006-09-02 11:49:02 +00:00
|
|
|
(!check_openssl_loaded())) {
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace("disabled");
|
2006-07-06 12:01:24 +00:00
|
|
|
return; // order review disabled or test mode or manual capture or openssl wasn't loaded.
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
2005-08-24 14:59:42 +00:00
|
|
|
|
2006-06-20 17:22:00 +00:00
|
|
|
$timediffcnf = $settlementtime - (intval($CFG->an_capture_day) * $oneday);
|
2006-09-22 14:04:11 +00:00
|
|
|
$sql = "SELECT * FROM {$CFG->prefix}enrol_authorize
|
|
|
|
WHERE (status = '" .AN_STATUS_AUTH. "')
|
|
|
|
AND (timecreated < '$timediffcnf')
|
2006-09-22 16:19:53 +00:00
|
|
|
AND (timecreated > '$timediff30')
|
|
|
|
ORDER BY courseid";
|
2005-12-28 16:53:23 +00:00
|
|
|
|
|
|
|
if (!$orders = get_records_sql($sql)) {
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace("no pending orders");
|
2005-12-26 19:21:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$eachconn = intval($mconfig->an_eachconnsecs);
|
|
|
|
if (empty($eachconn)) $eachconn = 3;
|
|
|
|
elseif ($eachconn > 60) $eachconn = 60;
|
|
|
|
|
2005-12-26 19:21:37 +00:00
|
|
|
$ordercount = count((array)$orders);
|
2006-01-19 14:57:23 +00:00
|
|
|
if (($ordercount * $eachconn) + intval($mconfig->an_lastcron) > $timenow) {
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace("blocked");
|
2006-01-19 14:57:23 +00:00
|
|
|
return;
|
2005-12-26 19:21:37 +00:00
|
|
|
}
|
|
|
|
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace(" $ordercount orders are being processed now", ": ");
|
2006-07-06 13:41:55 +00:00
|
|
|
|
2005-12-26 19:21:37 +00:00
|
|
|
$faults = '';
|
2006-01-02 09:45:07 +00:00
|
|
|
$sendem = array();
|
2005-12-26 19:21:37 +00:00
|
|
|
$elapsed = time();
|
|
|
|
@set_time_limit(0);
|
|
|
|
$this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
|
2006-03-09 11:35:54 +00:00
|
|
|
|
2006-09-22 16:19:53 +00:00
|
|
|
$lastcourseid = 0;
|
2005-12-26 19:21:37 +00:00
|
|
|
foreach ($orders as $order) {
|
|
|
|
$message = '';
|
|
|
|
$extra = NULL;
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
|
2006-09-22 16:19:53 +00:00
|
|
|
if ($lastcourseid != $order->courseid) {
|
|
|
|
$lastcourseid = $order->courseid;
|
|
|
|
$course = get_record('course', 'id', $lastcourseid);
|
|
|
|
$role = get_default_course_role($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $lastcourseid);
|
|
|
|
}
|
2006-09-22 14:04:11 +00:00
|
|
|
$timestart = $timeend = 0;
|
|
|
|
if ($course->enrolperiod) {
|
|
|
|
$timestart = $timenow;
|
|
|
|
$timeend = $order->settletime + $course->enrolperiod;
|
|
|
|
}
|
2006-09-22 16:19:53 +00:00
|
|
|
$user = get_record('user', 'id', $order->userid);
|
Last commit for enrol_student().
enrol_student($order->userid, $order->courseid, $timestart, $timeend, 'manual')
to
role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, 'manual'))
2006-09-22 13:50:10 +00:00
|
|
|
if (role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, 'manual')) {
|
2006-09-22 14:04:11 +00:00
|
|
|
$this->log .= "User($user->id) has been enrolled to course($course->id).\n";
|
2006-01-19 14:57:23 +00:00
|
|
|
if (!empty($CFG->enrol_mailstudents)) {
|
|
|
|
$sendem[] = $order->id;
|
|
|
|
}
|
2005-12-26 19:21:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-09-22 14:04:11 +00:00
|
|
|
$faults .= "Error while trying to enrol ".fullname($user)." in '$course->fullname' \n";
|
2005-12-26 19:21:37 +00:00
|
|
|
foreach ($order as $okey => $ovalue) {
|
|
|
|
$faults .= " $okey = $ovalue\n";
|
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-19 14:57:23 +00:00
|
|
|
else {
|
2006-07-10 10:17:23 +00:00
|
|
|
$this->log .= "Error, Order# $order->id: " . $message . "\n";
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 19:21:37 +00:00
|
|
|
|
* 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; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
mtrace("processed");
|
|
|
|
|
2005-12-26 19:21:37 +00:00
|
|
|
$timenow = time();
|
|
|
|
$elapsed = $timenow - $elapsed;
|
2006-01-19 14:57:23 +00:00
|
|
|
$eachconn = ceil($elapsed / $ordercount);
|
|
|
|
set_config('an_eachconnsecs', $eachconn, 'enrol/authorize');
|
2005-12-26 19:21:37 +00:00
|
|
|
|
|
|
|
$this->log .= "AUTHORIZE.NET CRON FINISHED: " . userdate($timenow);
|
|
|
|
|
|
|
|
$adminuser = get_admin();
|
|
|
|
if (!empty($faults)) {
|
|
|
|
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON FAULTS", $faults);
|
|
|
|
}
|
|
|
|
if (!empty($CFG->enrol_mailadmins)) {
|
|
|
|
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON LOG", $this->log);
|
|
|
|
}
|
2006-07-06 12:01:24 +00:00
|
|
|
|
|
|
|
// Send emails to students about which courses have enrolled.
|
2006-10-16 09:39:08 +00:00
|
|
|
if (!empty($sendem)) {
|
|
|
|
mtrace(" sending welcome messages to students", ": ");
|
|
|
|
send_welcome_messages($sendem);
|
|
|
|
mtrace("sent");
|
2006-01-02 09:45:07 +00:00
|
|
|
}
|
2006-07-06 12:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Daily cron. It executes at settlement time (default is 00:05).
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function cron_daily()
|
|
|
|
{
|
|
|
|
global $CFG, $SITE;
|
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/authorizenetlib.php');
|
|
|
|
|
|
|
|
$oneday = 86400;
|
|
|
|
$timenow = time();
|
2006-11-20 14:48:16 +00:00
|
|
|
$onepass = $timenow - $oneday;
|
2006-07-10 10:17:23 +00:00
|
|
|
$settlementtime = authorize_getsettletime($timenow);
|
2006-07-06 12:01:24 +00:00
|
|
|
$timediff30 = $settlementtime - (30 * $oneday);
|
|
|
|
|
|
|
|
// Delete orders that no transaction was made.
|
|
|
|
$select = "(status='".AN_STATUS_NONE."') AND (timecreated<'$timediff30')";
|
|
|
|
delete_records_select('enrol_authorize', $select);
|
|
|
|
|
|
|
|
// Pending orders are expired with in 30 days.
|
|
|
|
$select = "(status='".AN_STATUS_AUTH."') AND (timecreated<'$timediff30')";
|
|
|
|
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='".AN_STATUS_EXPIRE."' WHERE $select", false);
|
|
|
|
|
|
|
|
// Delete expired orders 60 days later.
|
|
|
|
$timediff60 = $settlementtime - (60 * $oneday);
|
|
|
|
$select = "(status='".AN_STATUS_EXPIRE."') AND (timecreated<'$timediff60')";
|
|
|
|
delete_records_select('enrol_authorize', $select);
|
|
|
|
|
2006-11-20 14:48:16 +00:00
|
|
|
// XXX TODO SEND EMAIL to 'enrol/authorize:uploadcsv'
|
|
|
|
// get_users_by_capability() does not handling user level resolving
|
|
|
|
// After user resolving, get_admin() to get_users_by_capability()
|
|
|
|
$adminuser = get_admin();
|
|
|
|
$select = "status IN(".AN_STATUS_UNDERREVIEW.",".AN_STATUS_APPROVEDREVIEW.") " .
|
|
|
|
"AND (timecreated<'$onepass') AND (timecreated>'$timediff60')";
|
|
|
|
$count = count_records_select('enrol_authorize', $select);
|
|
|
|
if ($count) {
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->count = $count;
|
|
|
|
$a->course = $SITE->shortname;
|
|
|
|
$subject = get_string('pendingechecksubject', 'enrol_authorize', $a);
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->count = $count;
|
|
|
|
$a->url = $CFG->wwwroot.'/enrol/authorize/uploadcsv.php';
|
|
|
|
$message = get_string('pendingecheckemail', 'enrol_authorize', $a);
|
|
|
|
@email_to_user($adminuser, $adminuser, $subject, $message);
|
|
|
|
}
|
2006-10-16 09:39:08 +00:00
|
|
|
|
2006-07-06 12:01:24 +00:00
|
|
|
// Daily warning email for pending orders expiring.
|
|
|
|
if (empty($CFG->an_emailexpired)) {
|
|
|
|
return; // not enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pending orders count will be expired.
|
|
|
|
$timediffem = $settlementtime - ((30 - intval($CFG->an_emailexpired)) * $oneday);
|
|
|
|
$select = "(status='". AN_STATUS_AUTH ."') AND (timecreated<'$timediffem') AND (timecreated>'$timediff30')";
|
|
|
|
$count = count_records_select('enrol_authorize', $select);
|
|
|
|
if (!$count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email to admin
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->pending = $count;
|
|
|
|
$a->days = $CFG->an_emailexpired;
|
|
|
|
$a->course = $SITE->shortname;
|
|
|
|
$subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->pending = $count;
|
|
|
|
$a->days = $CFG->an_emailexpired;
|
|
|
|
$a->course = $SITE->fullname;
|
2006-11-02 13:34:52 +00:00
|
|
|
$a->enrolurl = "$CFG->wwwroot/$CFG->admin/enrol_config.php?enrol=authorize";
|
2006-07-06 12:01:24 +00:00
|
|
|
$a->url = $CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH;
|
|
|
|
$message = get_string('pendingordersemail', 'enrol_authorize', $a);
|
|
|
|
email_to_user($adminuser, $adminuser, $subject, $message);
|
|
|
|
|
|
|
|
// Email to teachers
|
2006-08-14 15:06:11 +00:00
|
|
|
if (empty($CFG->an_emailexpiredteacher)) {
|
|
|
|
return; // email feature disabled for teachers.
|
2006-07-06 12:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sorttype = empty($CFG->an_sorttype) ? 'ttl' : $CFG->an_sorttype;
|
2006-10-16 09:39:08 +00:00
|
|
|
$sql = "SELECT e.courseid, e.currency, c.fullname, c.shortname,
|
|
|
|
COUNT(e.courseid) AS cnt, SUM(e.amount) as ttl
|
|
|
|
FROM {$CFG->prefix}enrol_authorize e
|
|
|
|
INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid
|
|
|
|
WHERE (e.status = ". AN_STATUS_AUTH .")
|
|
|
|
AND (e.timecreated < $timediffem)
|
|
|
|
AND (e.timecreated > $timediff30)
|
|
|
|
GROUP BY e.courseid
|
|
|
|
ORDER BY $sorttype DESC";
|
2006-07-06 12:01:24 +00:00
|
|
|
|
|
|
|
$courseinfos = get_records_sql($sql);
|
|
|
|
foreach($courseinfos as $courseinfo) {
|
|
|
|
$lastcourse = $courseinfo->courseid;
|
2006-08-29 13:59:35 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $lastcourse);
|
|
|
|
if ($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments')) {
|
2006-07-06 12:01:24 +00:00
|
|
|
$a = new stdClass;
|
|
|
|
$a->course = $courseinfo->shortname;
|
|
|
|
$a->pending = $courseinfo->cnt;
|
|
|
|
$a->days = $CFG->an_emailexpired;
|
|
|
|
$subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->course = $courseinfo->fullname;
|
|
|
|
$a->pending = $courseinfo->cnt;
|
|
|
|
$a->currency = $courseinfo->currency;
|
|
|
|
$a->sumcost = $courseinfo->ttl;
|
|
|
|
$a->days = $CFG->an_emailexpired;
|
2006-08-29 13:59:35 +00:00
|
|
|
$a->url = $CFG->wwwroot.'/enrol/authorize/index.php?course='.$lastcourse.'&status='.AN_STATUS_AUTH;
|
2006-07-06 12:01:24 +00:00
|
|
|
$message = get_string('pendingordersemailteacher', 'enrol_authorize', $a);
|
2006-08-29 13:59:35 +00:00
|
|
|
foreach ($paymentmanagers as $paymentmanager) {
|
|
|
|
email_to_user($paymentmanager, $adminuser, $subject, $message);
|
2006-07-06 12:01:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-02 09:45:07 +00:00
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|