Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enrol/authorize: MDL-22777 upgrade enrol/authorize plugin to new enro…

…l_plugin base class

Patch by Eugene Venter
  • Loading branch information...
commit 0609036239dcc84d1b62fb3708f7b64ceac46d3d 1 parent 3c873e0
@srynot4sale srynot4sale authored
View
74 enrol/authorize/authorizenet.class.php
@@ -1,4 +1,31 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
$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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
}
$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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
@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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
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 .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs);
@@ -346,8 +374,13 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
{
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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
// 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 @@ public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NO
// 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;
View
33 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',
View
9 enrol/authorize/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="enrol/authorize/db" VERSION="20080927" COMMENT="XMLDB file for Moodle enrol/authorize"
+<XMLDB PATH="enrol/authorize/db" VERSION="20100812" COMMENT="XMLDB file for Moodle enrol/authorize"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -10,8 +10,9 @@
<FIELD NAME="paymentmethod" TYPE="char" LENGTH="6" NOTNULL="true" DEFAULT="cc" SEQUENCE="false" PREVIOUS="id" NEXT="refundinfo"/>
<FIELD NAME="refundinfo" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="paymentmethod" NEXT="ccname"/>
<FIELD NAME="ccname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="refundinfo" NEXT="courseid"/>
- <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="ccname" NEXT="userid"/>
- <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid" NEXT="transid"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="ccname" NEXT="instanceid"/>
+ <FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid" NEXT="userid"/>
+ <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="instanceid" NEXT="transid"/>
<FIELD NAME="transid" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="status"/>
<FIELD NAME="status" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="transid" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="status" NEXT="settletime"/>
@@ -47,4 +48,4 @@
</INDEXES>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
13 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;
}
-
-
View
111 enrol/authorize/enrol_form.php
@@ -1,16 +1,44 @@
<?php
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
-}
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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 @@ function definition()
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', '', '<div class="mdl-right">' . $othermethodstr . '</div>', '');
}
- $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, '&nbsp;', 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 @@ function definition()
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'), '&nbsp;', 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 @@ function definition()
$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, '<br />');
@@ -105,7 +126,7 @@ function definition()
$mform->setDefault('ccauthcode', '');
}
- if (!empty($CFG->an_avs)) {
+ if ($plugin->get_config('an_avs')) {
$mform->addElement('header', '', '&nbsp;&nbsp;' . get_string('address'), '');
$mform->addElement('text', 'ccaddress', get_string('address'), 'size="30"');
@@ -113,14 +134,9 @@ function definition()
$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'), '&nbsp;', 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 @@ function definition()
$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 @@ function definition()
$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 @@ function validation($data, $files)
$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 @@ function validation($data, $files)
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.'&amp;paymentmethod='.AN_METHOD_ECHECK;
+ $url = 'index.php?id='.$this->instance->courseid.'&amp;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.'&amp;paymentmethod='.AN_METHOD_CC;
+ $url = 'index.php?id='.$this->instance->courseid.'&amp;paymentmethod='.AN_METHOD_CC;
$stringtofetch = 'usingccmethod';
}
if ($otheravailable) {
View
12 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 <http://www.gnu.org/licenses/>.
+/**
+ * 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 {
View
27 enrol/authorize/index.php
@@ -1,5 +1,32 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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');
View
78 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 &amp; 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 "<a href="{$a->url}">turned loginhttps ON</a>" to use this plugin<br />in Admin >> Variables >> Security >> HTTP security.';
$string['adminconfighttpsgo'] = 'Go to the <a href="{$a->url}">secure page</a> to configure this plugin.';
-$string['admincronsetup'] = 'The cron.php maintenance script has not been run for at least 24 hours.<br />Cron must be enabled if you want to use scheduled-capture feature.<br /><b>Enable</b> \'Authorize.net plugin\' and <b>setup cron</b> properly; or <b>uncheck an_review</b> again.<br />If you disable scheduled-capture, transactions will be cancelled unless you review them within 30 days.<br />Check <b>an_review</b> and enter <b>\'0\' to an_capture_day</b> field<br />if you want to <b>manually</b> accept/deny payments within 30 days.';
-$string['adminemailexpired'] = 'This is useful for \'Manual-Capture\'. Admins are notified <b>{$a}</b> days prior to pending orders expiring.';
+$string['admincronsetup'] = 'The cron.php maintenance script has not been run for at least 24 hours.<br />Cron must be enabled if you want to use scheduled-capture feature.<br /><b>Enable</b> \'Authorize.Net plugin\' and <b>setup cron</b> properly; or <b>uncheck an_review</b> again.<br />If you disable scheduled-capture, transactions will be cancelled unless you review them within 30 days.<br />Check <b>an_review</b> and enter <b>\'0\' to an_capture_day</b> field<br />if you want to <b>manually</b> 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)<br />(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 @@
{$a->url}';
$string['adminnewordersubject'] = '{$a->course}; New Pending Order: {$a->orderid}';
$string['adminpendingorders'] = 'You have disabled scheduled-capture feature.<br />Total {$a->count} transactions with the status of \'Authorized/Pending Capture\' are to be cancelled unless you check them.<br />To accept/deny payments, go to <a href=\'{$a->url}\'>Payment Management</a> 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['ccvv'] = 'Card Verification';
$string['ccvvhelp'] = 'Look at the back of card (last 3 digits)';
$string['costdefaultdesc'] = '<strong>In course settings, enter -1</strong> 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.<br /><br /><b>Note:</b> 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['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['invalidacctype'] = 'Invalid account type';
$string['isbusinesschecking'] = 'Is business checking?';
$string['logindesc'] = 'This option must be ON. <br /><br />Please ensure that you have turned <a href="{$a->url}">loginhttps ON</a> in Admin >> Variables >> Security.<br /><br />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 <strong>either</strong> the transaction key (#1) <strong>or</strong> 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 <strong>either</strong> the transaction key <strong>or</strong> 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['refund'] = 'Refund';
$string['refunded'] = 'Refunded';
$string['returns'] = 'Returns';
-$string['reviewday'] = 'Capture the credit card automatically unless a teacher or administrator review the order within <b>{$a}</b> days. CRON MUST BE ENABLED.<br />(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.<br />(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['uploadcsv'] = 'Upload a CSV file';
$string['usingccmethod'] = 'Enrol using <a href="{$a->url}"><strong>Credit Card</strong></a>';
$string['usingecheckmethod'] = 'Enrol using <a href="{$a->url}"><strong>eCheck</strong></a>';
-$string['verifyaccount'] = 'Verify your authorize.net merchant account';
-$string['verifyaccountresult'] = 'Verification result: {$a}';
+$string['verifyaccount'] = 'Verify your authorize.Net merchant account';
+$string['verifyaccountresult'] = '<b>Verification result:</b> {$a}';
$string['void'] = 'Void';
$string['voidyes'] = 'The transaction will be cancelled. Are you sure?';
$string['welcometocoursesemail'] = 'Dear {$a->name},
@@ -238,3 +254,19 @@
{$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}"?';
View
148 enrol/authorize/localfuncs.php
@@ -1,18 +1,43 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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;
}
View
57 enrol/authorize/locallib.php
@@ -1,4 +1,30 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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");
}
View
31 enrol/authorize/uploadcsv.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,6 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+/**
+ * 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 @@
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";
View
29 enrol/authorize/version.php
@@ -1,6 +1,31 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-$plugin->version = 2009042700;
-$plugin->requires = 2007101507;
+/**
+ * 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;
Please sign in to comment.
Something went wrong with that request. Please try again.