Permalink
Browse files

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

…l_plugin base class

Patch by Eugene Venter
  • Loading branch information...
Aaron Barnes
Aaron Barnes committed Aug 19, 2010
1 parent 3c873e0 commit 0609036239dcc84d1b62fb3708f7b64ceac46d3d
@@ -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,16 +270,16 @@ 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);
if (intval(ini_get('max_execution_time')) > 0) {
@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,23 +374,28 @@ 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;
}
// 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;
@@ -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',
@@ -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>
@@ -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;
}
-
-
Oops, something went wrong.

0 comments on commit 0609036

Please sign in to comment.