diff --git a/enrol/authorize/authorizenet.class.php b/enrol/authorize/authorizenet.class.php
index 91819642d27..08fb8e527cd 100644
--- a/enrol/authorize/authorizenet.class.php
+++ b/enrol/authorize/authorizenet.class.php
@@ -1,4 +1,31 @@
.
+
+/**
+ * Authorize enrolment plugin.
+ *
+ * This plugin allows you to set up paid courses, using authorize.net.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
@@ -27,14 +54,13 @@ class AuthorizeNet
*/
public static function getsettletime($time)
{
- global $CFG;
+ $mconfig = get_config('enrol_authorize');
- $cutoff = intval($CFG->an_cutoff);
- $mins = $cutoff % 60;
- $hrs = ($cutoff - $mins) / 60;
- $cutofftime = strtotime("$hrs:$mins", $time);
+ $cutoff_hour = intval($mconfig->an_cutoff_min);
+ $cutoff_min = intval($mconfig->an_cutoff_hour);
+ $cutofftime = strtotime("{$cutoff_hour}:{$cutoff_min}", $time);
if ($cutofftime < $time) {
- $cutofftime = strtotime("$hrs:$mins", $time + (24 * 3600));
+ $cutofftime = strtotime("{$cutoff_hour}:{$cutoff_min}", $time + (24 * 3600));
}
return $cutofftime;
}
@@ -98,22 +124,24 @@ class AuthorizeNet
static $constpd = array();
require_once($CFG->libdir.'/filelib.php');
+ $mconfig = get_config('enrol_authorize');
+
if (empty($constpd)) {
- $mconfig = get_config('enrol/authorize');
+ $mconfig = get_config('enrol_authorize');
$constpd = array(
'x_version' => '3.1',
'x_delim_data' => 'True',
'x_delim_char' => self::AN_DELIM,
'x_encap_char' => self::AN_ENCAP,
'x_relay_response' => 'FALSE',
- 'x_login' => rc4decrypt($mconfig->an_login)
+ 'x_login' => $mconfig->an_login
);
if (!empty($mconfig->an_tran_key)) {
- $constpd['x_tran_key'] = rc4decrypt($mconfig->an_tran_key);
+ $constpd['x_tran_key'] = $mconfig->an_tran_key;
}
else {
- $constpd['x_password'] = rc4decrypt($mconfig->an_password);
+ $constpd['x_password'] = $mconfig->an_password;
}
}
@@ -141,7 +169,7 @@ class AuthorizeNet
$pd = $constpd;
$pd['x_method'] = $method;
- $test = !empty($CFG->an_test);
+ $test = !empty($mconfig->an_test);
$pd['x_test_request'] = ($test ? 'TRUE' : 'FALSE');
switch ($action) {
@@ -242,8 +270,8 @@ class AuthorizeNet
}
$headers = array('Connection' => 'close');
- if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
- $headers['Referer'] = $CFG->an_referer;
+ if (! (empty($mconfig->an_referer) || $mconfig->an_referer == "http://")) {
+ $headers['Referer'] = $mconfig->an_referer;
}
@ignore_user_abort(true);
@@ -251,7 +279,7 @@ class AuthorizeNet
@set_time_limit(300);
}
- $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
+ $host = $test ? 'test.authorize.net' : 'secure.authorize.net';
$data = download_file_content("https://$host:443/gateway/transact.dll", $headers, $pd, false, 300, 60, true);
if (!$data) {
$message = "No connection to https://$host:443";
@@ -333,7 +361,7 @@ class AuthorizeNet
if ($message == '[[' . $reasonstr . ']]') {
$message = isset($response[3]) ? $response[3] : 'unknown error';
}
- if ($method == AN_METHOD_CC && !empty($CFG->an_avs) && $response[5] != "P") {
+ if ($method == AN_METHOD_CC && !empty($mconfig->an_avs) && $response[5] != "P") {
$avs = "avs" . strtolower($response[5]);
$stravs = get_string($avs, "enrol_authorize");
$message .= "
" . get_string("avsresult", "enrol_authorize", $stravs);
@@ -346,8 +374,13 @@ class AuthorizeNet
{
if (!empty($cctype)) {
$ccaccepts = get_list_of_creditcards();
+
unset($ccaccepts[$cctype]);
- set_config('an_acceptccs', implode(',', array_keys($ccaccepts)));
+ set_config("an_acceptcc_{$cctype}", 0, 'enrol_authorize');
+
+ foreach ($ccaccepts as $key=>$val) {
+ set_config("an_acceptcc_{$key}", 1, 'enrol_authorize');
+ }
message_to_admin("$message ($cctype) This is new config(an_acceptccs):", $ccaccepts);
}
break;
@@ -355,14 +388,14 @@ class AuthorizeNet
// Echecks only
case self::AN_REASON_ACHONLY:
{
- set_config('an_acceptmethods', AN_METHOD_ECHECK);
+ set_config("an_acceptmethod_".AN_METHOD_ECHECK, 1, 'enrol_authorize');
message_to_admin("$message This is new config(an_acceptmethods):", array(AN_METHOD_ECHECK));
break;
}
// Echecks aren't accepted
case self::AN_REASON_NOACH:
{
- set_config('an_acceptmethods', AN_METHOD_CC);
+ set_config("an_acceptmethod_".AN_METHOD_CC, 1, 'enrol_authorize');
message_to_admin("$message This is new config(an_acceptmethods):", array(AN_METHOD_CC));
break;
}
@@ -375,14 +408,15 @@ class AuthorizeNet
// CCD=BUSINESSCHECKING
case 'CCD':
{
- set_config('an_acceptechecktypes', 'CHECKING,SAVINGS');
+ set_config('an_acceptecheck_CHECKING', 1, 'enrol_authorize');
+ set_config('an_acceptecheck_SAVINGS', 1, 'enrol_authorize');
message_to_admin("$message This is new config(an_acceptechecktypes):", array('CHECKING','SAVINGS'));
}
break;
// WEB=CHECKING or SAVINGS
case 'WEB':
{
- set_config('an_acceptechecktypes', 'BUSINESSCHECKING');
+ set_config('an_acceptecheck_BUSINESSCHECKING', 1, 'enrol_authorize');
message_to_admin("$message This is new config(an_acceptechecktypes):", array('BUSINESSCHECKING'));
}
break;
diff --git a/enrol/authorize/db/access.php b/enrol/authorize/db/access.php
index 5ef473cca9f..38a74096daf 100644
--- a/enrol/authorize/db/access.php
+++ b/enrol/authorize/db/access.php
@@ -2,6 +2,39 @@
$capabilities = array(
+ 'enrol/authorize:config' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
+ 'enrol/authorize:manage' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'manager' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ )
+ ),
+
+ 'enrol/authorize:unenrol' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
+ 'enrol/authorize:unenrolself' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ )
+ ),
+
+
'enrol/authorize:managepayments' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'write',
diff --git a/enrol/authorize/db/install.xml b/enrol/authorize/db/install.xml
index 6ac4bd3d637..0a65b29e1b3 100644
--- a/enrol/authorize/db/install.xml
+++ b/enrol/authorize/db/install.xml
@@ -1,5 +1,5 @@
-
@@ -10,8 +10,9 @@
-
-
+
+
+
@@ -47,4 +48,4 @@
-
+
\ No newline at end of file
diff --git a/enrol/authorize/db/upgrade.php b/enrol/authorize/db/upgrade.php
index a5e9d8f4eaa..573e7fa1712 100644
--- a/enrol/authorize/db/upgrade.php
+++ b/enrol/authorize/db/upgrade.php
@@ -82,7 +82,16 @@ function xmldb_enrol_authorize_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2009042700, 'enrol', 'authorize');
}
+ // Add instanceid field to enrol_authorize table
+ if ($oldversion < 2010081203) {
+ $table = new xmldb_table('enrol_authorize');
+ $field = new xmldb_field('instanceid');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'userid');
+ $dbman->add_field($table, $field);
+ }
+ upgrade_plugin_savepoint(true, 2010081203, 'enrol', 'authorize');
+ }
+
return true;
}
-
-
diff --git a/enrol/authorize/enrol_form.php b/enrol/authorize/enrol_form.php
index 9edf25597f8..e30ea095405 100755
--- a/enrol/authorize/enrol_form.php
+++ b/enrol/authorize/enrol_form.php
@@ -1,16 +1,44 @@
.
+
+/**
+ * Authorize.Net enrol plugin implementation.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
class enrol_authorize_form extends moodleform
{
- function definition()
- {
- global $CFG, $USER;
+ protected $instance;
+
+ function definition() {
+ global $USER;
+
+ $mform = $this->_form;
+ $this->instance = $this->_customdata;
+ $plugin = enrol_get_plugin('authorize');
$paymentmethodsenabled = get_list_of_payment_methods();
$paymentmethod = optional_param('paymentmethod', $paymentmethodsenabled[0], PARAM_ALPHA);
@@ -18,30 +46,27 @@ class enrol_authorize_form extends moodleform
print_error('invalidpaymentmethod', '', '', $paymentmethod);
}
- $mform =& $this->_form;
- $course = $this->_customdata['course'];
-
- $mform->addElement('header', 'general', get_string('paymentrequired'));
$othermethodstr = $this->other_method_available($paymentmethod);
if ($othermethodstr) {
$mform->addElement('static', '', '
' . $othermethodstr . '
', '');
}
- $mform->addElement('hidden', 'id', $course->id);
+ $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
+ $mform->setDefault('id', $this->instance->courseid);
+
+ $mform->addElement('hidden', 'instanceid');
+ $mform->setType('instanceid', PARAM_INT);
+ $mform->setDefault('instanceid', $this->instance->id);
$mform->addElement('hidden', 'paymentmethod', $paymentmethod);
$mform->setType('paymentmethod', PARAM_ALPHA);
$firstlastnamestr = (AN_METHOD_CC == $paymentmethod) ? get_string('nameoncard', 'enrol_authorize') : get_string('echeckfirslasttname', 'enrol_authorize');
- $firstlastnamegrp = array();
- $firstlastnamegrp[] = &$mform->createElement('text', 'firstname', '', 'size="16"');
- $firstlastnamegrp[] = &$mform->createElement('text', 'lastname', '', 'size="16"');
- $mform->addGroup($firstlastnamegrp, 'firstlastgrp', $firstlastnamestr, ' ', false);
- $firstlastnamegrprules = array();
- $firstlastnamegrprules['firstname'][] = array(get_string('missingfirstname'), 'required', null, 'client');
- $firstlastnamegrprules['lastname'][] = array(get_string('missinglastname'), 'required', null, 'client');
- $mform->addGroupRule('firstlastgrp', $firstlastnamegrprules);
+ $mform->addElement('text', 'firstname', get_string('firstnameoncard', 'enrol_authorize'), 'size="16"');
+ $mform->addElement('text', 'lastname', get_string('lastnameoncard', 'enrol_authorize'), 'size="16"');
+ $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'client');
+ $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'client');
$mform->setType('firstname', PARAM_ALPHANUM);
$mform->setType('lastname', PARAM_ALPHANUM);
$mform->setDefault('firstname', $USER->firstname);
@@ -66,14 +91,10 @@ class enrol_authorize_form extends moodleform
for ($i = $startyear; $i < $endyear; $i++) {
$yearsmenu[$i] = $i;
}
- $ccexpiregrp = array();
- $ccexpiregrp[] = &$mform->createElement('select', 'ccexpiremm', '', $monthsmenu);
- $ccexpiregrp[] = &$mform->createElement('select', 'ccexpireyyyy', '', $yearsmenu);
- $mform->addGroup($ccexpiregrp, 'ccexpiregrp', get_string('ccexpire', 'enrol_authorize'), ' ', false);
- $ccexpiregrprules = array();
- $ccexpiregrprules['ccexpiremm'][] = array(get_string('missingccexpire', 'enrol_authorize'), 'required', null, 'client');
- $ccexpiregrprules['ccexpireyyyy'][] = array(get_string('missingccexpire', 'enrol_authorize'), 'required', null, 'client');
- $mform->addGroupRule('ccexpiregrp', $ccexpiregrprules);
+ $mform->addElement('select', 'ccexpiremm', get_string('expiremonth', 'enrol_authorize'), $monthsmenu);
+ $mform->addElement('select', 'ccexpireyyyy', get_string('expireyear', 'enrol_authorize'), $yearsmenu);
+ $mform->addRule('ccexpiremm', get_string('missingccexpiremonth', 'enrol_authorize'), 'required', null, 'client');
+ $mform->addRule('ccexpireyyyy', get_string('missingccexpireyear', 'enrol_authorize'), 'required', null, 'client');
$mform->setType('ccexpiremm', PARAM_INT);
$mform->setType('ccexpireyyyy', PARAM_INT);
$mform->setDefault('ccexpiremm', '');
@@ -91,7 +112,7 @@ class enrol_authorize_form extends moodleform
$mform->addRule('cvv', get_string('missingcvv', 'enrol_authorize'), 'required', null, 'client');
$mform->addRule('cvv', get_string('missingcvv', 'enrol_authorize'), 'numeric', null, 'client');
- if (!empty($CFG->an_authcode)) {
+ if ($plugin->get_config('an_authcode')) {
$ccauthgrp = array();
$ccauthgrp[] = &$mform->createElement('checkbox', 'haveauth', null, get_string('haveauthcode', 'enrol_authorize'));
$ccauthgrp[] = &$mform->createElement('static', 'nextline', null, '
');
@@ -105,7 +126,7 @@ class enrol_authorize_form extends moodleform
$mform->setDefault('ccauthcode', '');
}
- if (!empty($CFG->an_avs)) {
+ if ($plugin->get_config('an_avs')) {
$mform->addElement('header', '', ' ' . get_string('address'), '');
$mform->addElement('text', 'ccaddress', get_string('address'), 'size="30"');
@@ -113,14 +134,9 @@ class enrol_authorize_form extends moodleform
$mform->setDefault('ccaddress', $USER->address);
$mform->addRule('ccaddress', get_string('missingaddress', 'enrol_authorize'), 'required', null, 'client');
- $citystategrp = array();
- $citystategrp[] = &$mform->createElement('text', 'cccity', '', 'size="14"');
- $citystategrp[] = &$mform->createElement('static', 'sep', null, ' - ');
- $citystategrp[] = &$mform->createElement('text', 'ccstate', '', 'size="8"');
- $mform->addGroup($citystategrp, 'citystategrp', get_string('city') . ' - ' . get_string('state'), ' ', false);
- $citystategrprules = array();
- $citystategrprules['cccity'][] = array(get_string('missingcity'), 'required', null, 'client');
- $mform->addGroupRule('citystategrp', $citystategrprules);
+ $mform->addElement('text', 'cccity', get_string('cccity', 'enrol_authorize'), 'size="14"');
+ $mform->addElement('text', 'ccstate', get_string('ccstate', 'enrol_authorize'), 'size="8"');
+ $mform->addRule('cccity', get_string('missingcity'), 'required', null, 'client');
$mform->setType('cccity', PARAM_ALPHANUM);
$mform->setType('ccstate', PARAM_ALPHANUM);
$mform->setDefault('cccity', $USER->city);
@@ -142,9 +158,7 @@ class enrol_authorize_form extends moodleform
$mform->setType('ccountry', PARAM_ALPHA);
$mform->setDefault('cccountry', $USER->country);
}
- }
- elseif (AN_METHOD_ECHECK == $paymentmethod)
- {
+ } elseif (AN_METHOD_ECHECK == $paymentmethod) {
$mform->addElement('text', 'abacode', get_string('echeckabacode', 'enrol_authorize'), 'size="9" maxlength="9"');
$mform->setType('abacode', PARAM_ALPHANUM);
$mform->setDefault('abacode', '');
@@ -182,10 +196,9 @@ class enrol_authorize_form extends moodleform
$this->add_action_buttons(false, get_string('sendpaymentbutton', 'enrol_authorize'));
}
- function validation($data, $files)
- {
- global $CFG;
+ function validation($data, $files) {
$errors = parent::validation($data, $files);
+ $plugin = enrol_get_plugin('authorize');
if (AN_METHOD_CC == $data['paymentmethod'])
{
@@ -197,14 +210,14 @@ class enrol_authorize_form extends moodleform
$validcc = $this->validate_cc($data['cc'], $data['cctype'], $expdate);
if (!$validcc) {
if ($validcc === 0) {
- $errors['ccexpiregrp'] = get_string('ccexpired', 'enrol_authorize');
+ $errors['ccexpiremm'] = get_string('ccexpired', 'enrol_authorize');
}
else {
$errors['cc'] = get_string('ccinvalid', 'enrol_authorize');
}
}
- if (!empty($CFG->an_authcode) && !empty($data['haveauth']) && empty($data['ccauthcode'])) {
+ if ($plugin->get_config('an_authcode') && !empty($data['haveauth']) && empty($data['ccauthcode'])) {
$errors['ccauthgrp'] = get_string('missingccauthcode', 'enrol_authorize');
}
}
@@ -224,16 +237,14 @@ class enrol_authorize_form extends moodleform
private function other_method_available($currentmethod)
{
- $course = $this->_customdata['course'];
if ($currentmethod == AN_METHOD_CC) {
$otheravailable = in_array(AN_METHOD_ECHECK, get_list_of_payment_methods());
- $url = 'enrol.php?id='.$course->id.'&paymentmethod='.AN_METHOD_ECHECK;
+ $url = 'index.php?id='.$this->instance->courseid.'&paymentmethod='.AN_METHOD_ECHECK;
$stringtofetch = 'usingecheckmethod';
- }
- else {
+ } else {
$otheravailable = in_array(AN_METHOD_CC, get_list_of_payment_methods());
- $url = 'enrol.php?id='.$course->id.'&paymentmethod='.AN_METHOD_CC;
+ $url = 'index.php?id='.$this->instance->courseid.'&paymentmethod='.AN_METHOD_CC;
$stringtofetch = 'usingccmethod';
}
if ($otheravailable) {
diff --git a/enrol/authorize/import_form.php b/enrol/authorize/import_form.php
index c43123f601f..3af46d4c4f9 100644
--- a/enrol/authorize/import_form.php
+++ b/enrol/authorize/import_form.php
@@ -15,6 +15,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+/**
+ * Adds new instance of enrol_authorize to specified course
+ * or edits current instance.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
require_once($CFG->libdir.'/formslib.php');
class enrol_authorize_import_form extends moodleform {
diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php
index 3fd83a85cd1..5bdee1851a0 100644
--- a/enrol/authorize/index.php
+++ b/enrol/authorize/index.php
@@ -1,5 +1,32 @@
.
+
+/**
+ * Adds new instance of enrol_authorize to specified course
+ * or edits current instance.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
/// Load libraries
require_once('../../config.php');
require_once('const.php');
diff --git a/enrol/authorize/lang/en/enrol_authorize.php b/enrol/authorize/lang/en/enrol_authorize.php
index 0474a655fdc..edd077c0689 100644
--- a/enrol/authorize/lang/en/enrol_authorize.php
+++ b/enrol/authorize/lang/en/enrol_authorize.php
@@ -23,22 +23,32 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+$string['authorize:config'] = 'Configure Authorize.Net enrol instances';
+$string['authorize:manage'] = 'Manage enrolled users';
+$string['authorize:unenrol'] = 'Unenrol users from course';
+$string['authorize:unenrolself'] = 'Unenrol self from the course';
+$string['authorize:managepayments'] = 'Manage payments';
+$string['authorize:uploadcsv'] = 'Upload CSV file';
$string['adminacceptccs'] = 'Which credit card types will be accepted?';
$string['adminaccepts'] = 'Select payment methods allowed and their types';
-$string['adminauthcode'] = 'If an user\'s credit card cannot be captured on the internet directly, obtain authorization code over the phone from customer\'s bank.';
+$string['anauthcode'] = 'Obtain authcode';
+$string['anauthcodedesc'] = 'If a user\'s credit card cannot be captured on the internet directly, obtain authorization code over the phone from customer\'s bank.';
$string['adminauthorizeccapture'] = 'Order Review & Scheduled-Capture Settings';
$string['adminauthorizeemail'] = 'Email Sending Settings';
-$string['adminauthorizesettings'] = 'Authorize.net Merchant Account Settings';
+$string['adminauthorizesettings'] = 'Authorize.Net Merchant Account Settings';
$string['adminauthorizewide'] = 'General Settings';
-$string['adminavs'] = 'Check this if you have activated Address Verification System (AVS) in your authorize.net merchant account. This demands address fields like street, state, country and zip when user fills out payment form.';
+$string['anavs'] = 'Address Verification System';
+$string['anavsdesc'] = 'Check this if you have activated Address Verification System (AVS) in your authorize.Net merchant account. This demands address fields like street, state, country and zip when user fills out payment form.';
$string['adminconfighttps'] = 'Please ensure that you have "turned loginhttps ON" to use this plugin
in Admin >> Variables >> Security >> HTTP security.';
$string['adminconfighttpsgo'] = 'Go to the secure page to configure this plugin.';
-$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 scheduled-capture feature.
Enable \'Authorize.net plugin\' and setup cron properly; or uncheck an_review again.
If you disable scheduled-capture, 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['adminemailexpired'] = 'This is useful for \'Manual-Capture\'. Admins are notified {$a} days prior to pending orders expiring.';
+$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 scheduled-capture feature.
Enable \'Authorize.Net plugin\' and setup cron properly; or uncheck an_review again.
If you disable scheduled-capture, 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['anemailexpired'] = 'Expiry notification';
+$string['anemailexpireddesc'] = 'This is useful for \'Manual-Capture\'. Admins are notified the specified amount of days prior to pending orders expiring.';
$string['adminemailexpiredsort'] = 'When the number of pending orders expiring are sent to the teachers via email, which one is important?';
$string['adminemailexpiredsortcount'] = 'Order count';
$string['adminemailexpiredsortsum'] = 'Total amount';
-$string['adminemailexpiredteacher'] = 'If you have enabled manual-capture (see above) and teachers can manage the payments, they may also notified about pending orders expiring. This will send an email to each course teachers about the count of the pending orders to expire.';
+$string['anemailexpiredteacher'] = 'Expiry notification - Teacher';
+$string['anemailexpiredteacherdesc'] = 'If you have enabled manual-capture (see above) and teachers can manage the payments, they may also notified about pending orders expiring. This will send an email to each course teachers about the count of the pending orders to expire.';
$string['adminemailexpsetting'] = '(0=disable sending email, default=2, max=5)
(Manual capture settings for sending email: cron=enabled, an_review=checked, an_capture_day=0, an_emailexpired=1-5)';
$string['adminhelpcapturetitle'] = 'Scheduled-Capture Day';
$string['adminhelpreviewtitle'] = 'Order Review';
@@ -62,22 +72,23 @@ $string['adminneworder'] = 'Dear Admin,
{$a->url}';
$string['adminnewordersubject'] = '{$a->course}; New Pending Order: {$a->orderid}';
$string['adminpendingorders'] = 'You have disabled scheduled-capture feature.
Total {$a->count} transactions with the status of \'Authorized/Pending Capture\' are to be cancelled unless you check them.
To accept/deny payments, go to url}\'>Payment Management page.';
-$string['adminreview'] = 'Review order before processing the credit card.';
+$string['anreview'] = 'Review';
+$string['anreviewdesc'] = 'Review order before processing the credit card.';
$string['adminteachermanagepay'] = 'Teachers can manage the payments of the course.';
$string['allpendingorders'] = 'All Pending Orders';
$string['amount'] = 'Amount';
-$string['anlogin'] = 'Authorize.net: Login name';
-$string['anpassword'] = 'Authorize.net: Password';
-$string['anreferer'] = 'Define the URL referer if you have set up this in your authorize.net merchant account. This will send a line "Referer: URL" embedded in the web request.';
-$string['antestmode'] = 'Run transactions in test mode only (no money will be drawn)';
-$string['antrankey'] = 'Authorize.net: Transaction Key';
+$string['anlogin'] = 'Authorize.Net: Login name';
+$string['anpassword'] = 'Authorize.Net: Password';
+$string['anreferer'] = 'Referer';
+$string['anrefererdesc'] = 'Define the URL referer if you have set up this in your authorize.Net merchant account. This will send a line "Referer: URL" embedded in the web request.';
+$string['antestmode'] = 'Test mode';
+$string['antestmodedesc'] = 'Run transactions in test mode only (no money will be drawn)';
+$string['antrankey'] = 'Authorize.Net: Transaction Key';
$string['approvedreview'] = 'Approved Review';
$string['authcaptured'] = 'Authorized / Captured';
$string['authcode'] = 'Authorization Code';
$string['authorizedpendingcapture'] = 'Authorized / Pending Capture';
-$string['authorizeerror'] = 'Authorize.net Error: {$a}';
-$string['authorize:managepayments'] = 'Manage payments';
-$string['authorize:uploadcsv'] = 'Upload CSV file';
+$string['authorizeerror'] = 'Authorize.Net Error: {$a}';
$string['avsa'] = 'Address (street) matches, postal code does not';
$string['avsb'] = 'Address information not provided';
$string['avse'] = 'Address Verification System Error';
@@ -107,10 +118,11 @@ $string['cctype'] = 'Credit Card Type';
$string['ccvv'] = 'Card Verification';
$string['ccvvhelp'] = 'Look at the back of card (last 3 digits)';
$string['costdefaultdesc'] = 'In course settings, enter -1 to use this default cost to course cost field.';
-$string['cutofftime'] = 'Transaction Cut-Off Time. When the last transaction is picked up for settlement?';
+$string['cutofftime'] = 'Cut-off time';
+$string['cutofftimedesc'] = 'Transaction Cut-Off Time. When the last transaction is picked up for settlement?';
$string['dataentered'] = 'Data entered';
$string['delete'] = 'Destroy';
-$string['description'] = 'The Authorize.net module allows you to set up paid courses via payment providers. If the cost for any course is zero, then students are not asked to pay for entry. Two ways to set the course cost (1) a site-wide cost as a default for the whole site or (2) a course setting that you can set for each course individually. The course cost overrides the site cost.
Note: If you enter an enrolment key in the course settings, then students will also have the option to enrol using a key. This is useful if you have a mixture of paying and non-paying students.';
+$string['description'] = 'The Authorize.Net module allows you to set up paid courses via payment providers. Two ways to set the course cost (1) a site-wide cost as a default for the whole site or (2) a course setting that you can set for each course individually. The course cost overrides the site cost.';
$string['echeckabacode'] = 'Bank ABA Number';
$string['echeckaccnum'] = 'Bank Account Number';
$string['echeckacctype'] = 'Bank Account Type';
@@ -119,7 +131,7 @@ $string['echeckbusinesschecking'] = 'Business Checking';
$string['echeckfirslasttname'] = 'Bank Account Owner';
$string['echeckchecking'] = 'Checking';
$string['echecksavings'] = 'Savings';
-$string['enrolname'] = 'Authorize.net Payment Gateway';
+$string['enrolname'] = 'Authorize.Net Payment Gateway';
$string['expired'] = 'Expired';
$string['haveauthcode'] = 'I have already an authorization code';
$string['howmuch'] = 'How much?';
@@ -131,15 +143,18 @@ $string['invalidaccnum'] = 'Invalid account number';
$string['invalidacctype'] = 'Invalid account type';
$string['isbusinesschecking'] = 'Is business checking?';
$string['logindesc'] = 'This option must be ON.
Please ensure that you have turned loginhttps ON in Admin >> Variables >> Security.
Turning this on will make Moodle use a secure https connection just for the login and payment pages.';
-$string['logininfo'] = 'Login name, password and transaction key are not shown due to security precautions. There is no need to enter again if you have configured these fields before. You see a green text left of the box if some fields were already configured. If you enter these fields for the first time, the login name (*) is required and you must enter either the transaction key (#1) or the password (#2) in the appropriate box. We recommend you enter the transaction key due to security precautions. If you want to delete the current password, tick the checkbox.';
+$string['logininfo'] = 'When configuring your Authorize.Net account, the login name is required and you must enter either the transaction key or the password in the appropriate box. We recommend you enter the transaction key due to security precautions.';
$string['methodcc'] = 'Credit Card';
+$string['methodccdesc'] = 'Select Credit Card and accepted types below';
$string['methodecheck'] = 'eCheck (ACH)';
+$string['methodecheckdesc'] = 'Select eCheck and accepted types below';
$string['missingaba'] = 'Missing ABA number';
$string['missingaddress'] = 'Missing address';
$string['missingbankname'] = 'Missing bank name';
$string['missingcc'] = 'Missing card number';
$string['missingccauthcode'] = 'Missing authorization code';
-$string['missingccexpire'] = 'Missing expiration date';
+$string['missingccexpiremonth'] = 'Missing expiration month';
+$string['missingccexpireyear'] = 'Missing expiration year';
$string['missingcctype'] = 'Missing card type';
$string['missingcvv'] = 'Missing verification number';
$string['missingzip'] = 'Missing postal code';
@@ -206,7 +221,8 @@ $string['reason56'] = 'This merchant accepts eCheck (ACH) transactions only; no
$string['refund'] = 'Refund';
$string['refunded'] = 'Refunded';
$string['returns'] = 'Returns';
-$string['reviewday'] = 'Capture the credit card automatically unless a teacher or administrator review the order within {$a} days. CRON MUST BE ENABLED.
(0 day means it will disable scheduled-capture, also means teacher or admin review order manually. Transaction will be cancelled if you disable scheduled-capture or unless you review it within 30 days.)';
+$string['ancaptureday'] = 'Capture day';
+$string['ancapturedaydesc'] = 'Capture the credit card automatically unless a teacher or administrator review the order within the specified days. CRON MUST BE ENABLED.
(0 days means it will disable scheduled-capture, also means teacher or admin review order manually. Transaction will be cancelled if you disable scheduled-capture or unless you review it within 30 days.)';
$string['reviewfailed'] = 'Review Failed';
$string['reviewnotify'] = 'Your payment will be reviewed. Expect an email within a few days from your teacher.';
$string['sendpaymentbutton'] = 'Send Payment';
@@ -223,8 +239,8 @@ $string['unenrolstudent'] = 'Unenrol student?';
$string['uploadcsv'] = 'Upload a CSV file';
$string['usingccmethod'] = 'Enrol using Credit Card';
$string['usingecheckmethod'] = 'Enrol using eCheck';
-$string['verifyaccount'] = 'Verify your authorize.net merchant account';
-$string['verifyaccountresult'] = 'Verification result: {$a}';
+$string['verifyaccount'] = 'Verify your authorize.Net merchant account';
+$string['verifyaccountresult'] = 'Verification result: {$a}';
$string['void'] = 'Void';
$string['voidyes'] = 'The transaction will be cancelled. Are you sure?';
$string['welcometocoursesemail'] = 'Dear {$a->name},
@@ -238,3 +254,19 @@ You may view your payment details or edit your profile:
{$a->profileurl}';
$string['youcantdo'] = 'You can\'t do this action: {$a->action}';
$string['zipcode'] = 'Zip Code';
+$string['pluginname'] = 'Authorize';
+$string['cost'] = 'Cost';
+$string['currency'] = 'Currency';
+$string['enrolperiod'] = 'Enrolment period';
+$string['enrolstartdate'] = 'Start date';
+$string['enrolenddate'] = 'End date';
+$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date';
+$string['status'] = 'Allow Autorize.net enrolments';
+$string['nocost'] = 'There is no cost associated with enrolling in this course via Authorize.Net!';
+$string['firstnameoncard'] = 'Firstname on card';
+$string['lastnameoncard'] = 'Lastname on card';
+$string['expiremonth'] = 'Expiry month';
+$string['expireyear'] = 'Expiry year';
+$string['cccity'] = 'City';
+$string['ccstate'] = 'State';
+$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';
diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php
index 456ec94e81e..cffe4a61ea7 100644
--- a/enrol/authorize/localfuncs.php
+++ b/enrol/authorize/localfuncs.php
@@ -1,18 +1,43 @@
.
+
+/**
+ * Authorize enrolment plugin.
+ *
+ * This plugin allows you to set up paid courses, using authorize.net.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
require_once($CFG->libdir.'/eventslib.php');
-function get_course_cost($course)
-{
- global $CFG;
+function get_course_cost($plugininstance) {
+ $defaultplugin = enrol_get_plugin('authorize');
$cost = (float)0;
- $currency = (!empty($course->currency))
- ? $course->currency :( empty($CFG->enrol_currency)
- ? 'USD' : $CFG->enrol_currency );
+ $currency = (!empty($plugininstance->currency))
+ ? $plugininstance->currency :( empty($defaultplugin->currency)
+ ? 'USD' : $defaultplugin->enrol_currency );
- if (!empty($course->cost)) {
- $cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost;
+ if (!empty($plugininstance->cost)) {
+ $cost = (float)(((float)$plugininstance->cost) < 0) ? $defaultplugin->cost : $plugininstance->cost;
}
$cost = format_float($cost, 2);
@@ -24,26 +49,26 @@ function get_course_cost($course)
return $ret;
}
-function zero_cost($course) {
- $curcost = get_course_cost($course);
+function zero_cost($plugininstance) {
+ $curcost = get_course_cost($plugininstance);
return (abs($curcost['cost']) < 0.01);
}
-function prevent_double_paid($course)
-{
+function prevent_double_paid($plugininstance) {
global $CFG, $SESSION, $USER, $DB;
+ $plugin = enrol_get_plugin('authorize');
- $sql = "SELECT id FROM {enrol_authorize} WHERE userid = ? AND courseid = ? ";
- $params = array($USER->id, $course->id);
+ $sql = "SELECT id FROM {enrol_authorize} WHERE userid = ? AND courseid = ? AND instanceid = ?";
+ $params = array($USER->id, $plugininstance->courseid, $plugininstance->id);
- if (empty($CFG->an_test)) { // Real mode
- $sql .= 'AND status IN(?,?,?)';
+ if (!$plugin->get_config('an_test')) { // Real mode
+ $sql .= ' AND status IN(?,?,?)';
$params[] = AN_STATUS_AUTH;
$params[] = AN_STATUS_UNDERREVIEW;
$params[] = AN_STATUS_APPROVEDREVIEW;
}
else { // Test mode
- $sql .= 'AND status=?';
+ $sql .= ' AND status=?';
$params[] = AN_STATUS_NONE;
}
@@ -61,9 +86,8 @@ function prevent_double_paid($course)
}
}
-function get_list_of_creditcards($getall = false)
-{
- global $CFG;
+function get_list_of_creditcards($getall = false) {
+ $plugin = enrol_get_plugin('authorize');
$alltypes = array(
'mcd' => 'Master Card',
@@ -77,44 +101,61 @@ function get_list_of_creditcards($getall = false)
'enr' => 'EnRoute'
);
- if ($getall or empty($CFG->an_acceptccs)) {
+ if ($getall) {
return $alltypes;
}
$ret = array();
- $ccs = explode(',', $CFG->an_acceptccs);
- foreach ($ccs as $key) {
- $ret[$key] = $alltypes[$key];
+ foreach ($alltypes as $code=>$name) {
+ if ($plugin->get_config("an_acceptcc_{$code}")) {
+ $ret[$code] = $name;
+ }
}
+
return $ret;
}
-function get_list_of_payment_methods($getall = false)
-{
- global $CFG;
+function get_list_of_payment_methods($getall = false) {
+ $plugin = enrol_get_plugin('authorize');
+ $method_cc = $plugin->get_config('an_acceptmethod_cc');
+ $method_echeck = $plugin->get_config('an_acceptmethod_echeck');
- if ($getall || empty($CFG->an_acceptmethods)) {
+
+ if ($getall || (empty($method_cc) && empty($method_echeck))) {
return array(AN_METHOD_CC, AN_METHOD_ECHECK);
- }
- else {
- return explode(',', $CFG->an_acceptmethods);
+ } else {
+ $methods = array();
+ if ($method_cc) {
+ $methods[] = AN_METHOD_CC;
+ }
+
+ if ($method_echeck) {
+ $methods[] = AN_METHOD_ECHECK;
+ }
+
+ return $methods;
}
}
-function get_list_of_bank_account_types($getall = false)
-{
- global $CFG;
+function get_list_of_bank_account_types($getall = false) {
+ $plugin = enrol_get_plugin('authorize');
+ $alltypes = array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS');
- if ($getall || empty($CFG->an_acceptechecktypes)) {
- return array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS');
- }
- else {
- return explode(',', $CFG->an_acceptechecktypes);
+ if ($getall) {
+ return $alltypes;
+ } else {
+ $types = array();
+ foreach ($alltypes as $type) {
+ if ($plugin->get_config("an_acceptecheck_{$type}")) {
+ $types[] = $type;
+ }
+ }
+
+ return $types;
}
}
-function message_to_admin($subject, $data)
-{
+function message_to_admin($subject, $data) {
global $SITE;
$admin = get_admin();
@@ -124,6 +165,8 @@ function message_to_admin($subject, $data)
$emailmessage .= print_r($data, true);
$eventdata = new object();
$eventdata->modulename = 'moodle';
+ $eventdata->component = 'enrol_authorize';
+ $eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = "$SITE->fullname: Authorize.net ERROR";
@@ -134,8 +177,7 @@ function message_to_admin($subject, $data)
message_send($eventdata);
}
-function send_welcome_messages($orderdata)
-{
+function send_welcome_messages($orderdata) {
global $CFG, $SITE, $DB;
if (empty($orderdata)) {
@@ -191,6 +233,8 @@ function send_welcome_messages($orderdata)
$eventdata = new object();
$eventdata->modulename = 'moodle';
+ $eventdata->component = 'enrol_authorize';
+ $eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $sender;
$eventdata->userto = $user;
$eventdata->subject = get_string("enrolmentnew", '', $SITE->shortname);
@@ -207,20 +251,20 @@ function send_welcome_messages($orderdata)
}
}
-function check_curl_available()
-{
+function check_curl_available() {
return function_exists('curl_init') &&
function_exists('stream_get_wrappers') &&
in_array('https', stream_get_wrappers());
}
-function authorize_verify_account()
-{
- global $CFG, $USER, $SITE;
+function authorize_verify_account() {
+ global $USER, $SITE;
+ $plugin = enrol_get_plugin('authorize');
+
require_once('authorizenet.class.php');
- $original_antest = $CFG->an_test;
- $CFG->an_test = 1; // Test mode
+ $original_antest = $plugin->get_config('an_test');
+ $plugin->set_config('an_test', 1); // Test mode
$order = new stdClass();
$order->id = -1;
@@ -257,7 +301,9 @@ function authorize_verify_account()
else {
$ret = get_string('verifyaccountresult', 'enrol_authorize', $message);
}
- $CFG->an_test = $original_antest;
+
+ $plugin->set_config('an_test', $original_antest);
+
return $ret;
}
diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php
index 9e010ce19d4..4a3a0bd6319 100644
--- a/enrol/authorize/locallib.php
+++ b/enrol/authorize/locallib.php
@@ -1,4 +1,30 @@
.
+
+/**
+ * Authorize enrolment plugin.
+ *
+ * This plugin allows you to set up paid courses, using authorize.net.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
@@ -17,6 +43,9 @@ function authorize_print_orders($courseid, $userid) {
global $course;
global $CFG, $USER, $SITE, $DB, $OUTPUT, $PAGE;
global $strs, $authstrs;
+
+ $plugin = enrol_get_plugin('authorize');
+
require_once($CFG->libdir.'/tablelib.php');
$perpage = optional_param('perpage', 10, PARAM_INT);
@@ -132,7 +161,7 @@ function authorize_print_orders($courseid, $userid) {
switch ($status)
{
case AN_STATUS_NONE:
- if (empty($CFG->an_test)) {
+ if (!$plugin->get_config('an_test')) {
$where .= "AND (e.status != :status) ";
$params['status'] = AN_STATUS_NONE;
}
@@ -223,6 +252,9 @@ function authorize_print_order($orderid)
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
global $strs, $authstrs;
+ $plugin = enrol_get_plugin('authorize');
+ $an_test = $plugin->get_config('an_test');
+
$do = optional_param('do', '', PARAM_ALPHA);
$unenrol = optional_param('unenrol', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
@@ -269,6 +301,7 @@ function authorize_print_order($orderid)
}
$PAGE->navbar->add($authstrs->paymentmanagement, 'index.php?course='.$course->id);
$PAGE->navbar->add($authstrs->orderid . ': ' . $orderid, 'index.php');
+ $PAGE->set_course($course);
$PAGE->set_title("$course->shortname: $authstrs->paymentmanagement");
$PAGE->set_heading($authstrs->orderdetails);
$PAGE->set_cacheable(false);
@@ -302,9 +335,9 @@ function authorize_print_order($orderid)
$message = '';
$extra = NULL;
if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
- if (empty($CFG->an_test)) {
+ if (empty($an_test)) {
if (enrol_into_course($course, $user, 'authorize')) {
- if (!empty($CFG->enrol_mailstudents)) {
+ if ($plugin->get_config('enrol_mailstudents')) {
send_welcome_messages($orderid);
}
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
@@ -352,13 +385,15 @@ function authorize_print_order($orderid)
$message = '';
$success = AuthorizeNet::process($order, $message, $extra, AN_ACTION_CREDIT);
if (AN_APPROVED == $success || AN_REVIEW == $success) {
- if (empty($CFG->an_test)) {
+ if (empty($an_test)) {
if (empty($extra->id)) {
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "insert record error", 20);
}
else {
if (!empty($unenrol)) {
- role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
+ $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid));
+ $plugin->unenrol_user($pinstance, $order->userid);
+ //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
@@ -383,7 +418,9 @@ function authorize_print_order($orderid)
elseif (ORDER_DELETE == $do && in_array(ORDER_DELETE, $statusandactions->actions)) {
if ($confirm && confirm_sesskey()) {
if (!empty($unenrol)) {
- role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
+ $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid));
+ $plugin->unenrol_user($pinstance, $order->userid);
+ //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
$DB->delete_records('enrol_authorize', array('id'=>$orderid));
redirect("$CFG->wwwroot/enrol/authorize/index.php");
@@ -399,7 +436,7 @@ function authorize_print_order($orderid)
$extra = NULL;
$message = '';
if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_VOID)) {
- if (empty($CFG->an_test)) {
+ if (empty($an_test)) {
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
else {
@@ -434,9 +471,11 @@ function authorize_print_order($orderid)
$message = '';
$extra = NULL;
if (AN_APPROVED == AuthorizeNet::process($suborder, $message, $extra, AN_ACTION_VOID)) {
- if (empty($CFG->an_test)) {
+ if (empty($an_test)) {
if (!empty($unenrol)) {
- role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
+ $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid));
+ $plugin->unenrol_user($pinstance, $order->userid);
+ //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
diff --git a/enrol/authorize/uploadcsv.php b/enrol/authorize/uploadcsv.php
index 11da31fa597..3f4b4f223a2 100644
--- a/enrol/authorize/uploadcsv.php
+++ b/enrol/authorize/uploadcsv.php
@@ -1,5 +1,4 @@
.
+/**
+ * Authorize.Net enrolment plugin - support for user self unenrolment.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
/// Load libraries
require_once('../../config.php');
require_once($CFG->dirroot.'/enrol/authorize/const.php');
@@ -62,6 +71,8 @@ echo $OUTPUT->footer();
function authorize_process_csv($filename) {
global $CFG, $SITE, $DB;
+ $plugin = enrol_get_plugin('authorize');
+
/// We need these fields
$myfields = array(
'Transaction ID', // enrol_authorize.transid or enrol_authorize_refunds.transid; See: Reference Transaction ID
@@ -214,15 +225,13 @@ function authorize_process_csv($filename) {
$timestart = time();
$timeend = $timestart + $course->enrolperiod;
}
- //TODO: do some real enrolment here
- if (role_assign($role->id, $user->id, $coursecontext->id, 'enrol_authorize')) {
- $imported++;
- if (!empty($CFG->enrol_mailstudents)) {
- $sendem[] = $order->id;
- }
- }
- else {
- $ignoredlines .= $transid . ": Error while trying to enrol " . fullname($user) . " in '$course->fullname' \n";
+ // Enrol user
+ $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid));
+ $plugin->enrol_user($pinstance, $user->id, $pinstance->roleid, $timestart, $timeend);
+
+ $imported++;
+ if ($plugin->get_config('enrol_mailstudents')) {
+ $sendem[] = $order->id;
}
}
}
@@ -235,6 +244,8 @@ function authorize_process_csv($filename) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
+ $eventdata->component = 'enrol_authorize';
+ $eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = "$SITE->fullname: Authorize.net CSV ERROR LOG";
diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php
index 933bb1663fa..fbdccd0defb 100755
--- a/enrol/authorize/version.php
+++ b/enrol/authorize/version.php
@@ -1,6 +1,31 @@
.
-$plugin->version = 2009042700;
+/**
+ * Authorize.Net enrolment plugin version specification.
+ *
+ * @package enrol
+ * @subpackage authorize
+ * @copyright 2010 Eugene Venter
+ * @author Eugene Venter
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2010081203;
$plugin->requires = 2007101507;
-
-
+$plugin->cron = 180;