From 75bb06e0aa02f37d77505be36b864bb7fe9d588b Mon Sep 17 00:00:00 2001 From: ethem Date: Wed, 30 Aug 2006 14:06:40 +0000 Subject: [PATCH] Some UI changes. --- enrol/authorize/authorizenetlib.php | 15 ++-- enrol/authorize/config.html | 117 +++++++++++++--------------- enrol/authorize/const.php | 6 +- enrol/authorize/enrol.html | 30 ++++--- enrol/authorize/enrol.php | 111 +++++++++++++++++++------- 5 files changed, 170 insertions(+), 109 deletions(-) diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index bdf5684001..38ffc7795e 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.php @@ -82,7 +82,7 @@ function authorize_expired(&$order) * @param string &$message Information about error message if this function returns false. * @param object &$extra Extra data that used for refunding and credit card information. * @param int $action Which action will be performed. See AN_ACTION_* - * @param int $method Transaction method. AN_METHOD_CC or AN_METHOD_ECHECK + * @param string $method Transaction method. AN_METHOD_CC or AN_METHOD_ECHECK * @return bool true Transaction was successful, false otherwise. Use $message for reason. * @author Ethem Evlice * @uses $CFG @@ -92,8 +92,6 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ global $CFG; static $conststring; - $test = !empty($CFG->an_test); - if (!isset($conststring)) { $constdata = array( 'x_version' => '3.1', @@ -124,10 +122,11 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ $method = AN_METHOD_CC; } elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) { - $message = "Missing method: $method"; + $message = "Invalid method: $method"; return false; } + $action = intval($action); if ($method == AN_METHOD_ECHECK) { if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) { $message = "Please perform AUTH_CAPTURE or CREDIT for echecks"; @@ -135,16 +134,16 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ } } - $action = intval($action); if ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) { $message = "Invalid action!"; return false; } $poststring = $conststring; - $poststring .= '&x_method=' . ($method==AN_METHOD_CC ? 'CC' : 'ECHECK'); + $poststring .= '&x_method=' . $method; + + $test = !empty($CFG->an_test); $poststring .= '&x_test_request=' . ($test ? 'TRUE' : 'FALSE'); - $timenowsettle = getsettletime(time()); switch ($action) { case AN_ACTION_AUTH_ONLY: @@ -362,7 +361,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ if ($message == '[[' . $reason . ']]') { $message = isset($response[3]) ? $response[3] : 'unknown error'; } - if (!empty($CFG->an_avs) and $method == AN_METHOD_CC) { + if ($method == AN_METHOD_CC and !empty($CFG->an_avs)) { $avs = "avs" . strtolower($response[5]); $stravs = get_string($avs, "enrol_authorize"); $message .= "
" . get_string("avsresult", "enrol_authorize", $stravs); diff --git a/enrol/authorize/config.html b/enrol/authorize/config.html index a6f696ca6f..7c8ad4db21 100755 --- a/enrol/authorize/config.html +++ b/enrol/authorize/config.html @@ -31,13 +31,8 @@ if (!isset($frm->an_cutoff_hour)) { } if (!isset($frm->acceptmethods)) { - if (empty($CFG->an_acceptmethods)) { - $frm->acceptmethods = array('cc'); - $CFG->an_acceptmethods = implode(',', $frm->acceptmethods); - } - else { - $frm->acceptmethods = explode(',', $CFG->an_acceptmethods); - } + $frm->acceptmethods = enrolment_plugin_authorize::get_list_of_payment_methods(); + $CFG->an_acceptmethods = implode(',', $frm->acceptmethods); } if (!isset($frm->acceptccs)) { @@ -50,99 +45,100 @@ if (!isset($frm->acceptccs)) { - + - + - - + - - wwwroot, 0, 5) !== 'https') { /* https && loginhttps */ ?> - + echo (empty($CFG->loginhttps) ? "off" : "on"); + $a->url = "$CFG->wwwroot/$CFG->admin/config.php#configsectionsecurity"; + echo '
'; print_string("logindesc", "enrol_authorize", $a); + ?> + - + - - + - + - - + - - + - - + - - + - - + - - + - - + - + ?>
@@ -152,41 +148,40 @@ if (!isset($frm->acceptccs)) { foreach ($allccs as $key => $val) { print_checkbox('acceptccs[]', $key, stristr($CFG->an_acceptccs, $key) !== false, $val); echo "
\n"; } - ?> - + ?>
- + - +
+ - +
+ an_capture_day) ?> - + - - - - + @@ -194,26 +189,26 @@ if (!isset($frm->acceptccs)) { - + choose_from_menu($sorts, "an_sorttype", $frm->an_sorttype, "","", "") ?>
+ - - + - - + - - +

enrol_cost:.
+ .
enrol_currency:enrol_currency, "","", "") ?> + enrol_currency, "","", "") ?>
+
loginhttps:loginhttps) ? "off" : "on") ?> url = "$CFG->wwwroot/$CFG->admin/config.php#configsectionsecurity"; - print_string("logindesc", "enrol_authorize", $a) - ?>

an_login:
+
# # 
an_tran_key:#1#1
+
an_password:#2
()
#2
+
()
delete_current:delete_current)) ?>

delete_current)) ?>
+

an_referer:
+
an_cutoff:an_cutoff_hour,$frm->an_cutoff_min),5); ?>an_cutoff_hour,$frm->an_cutoff_min),5); ?>
+
an_avs:an_avs)) ?>an_avs)) ?>
+
an_test:an_test)) ?>an_test)) ?>
+
an_acceptmethods: an_acceptmethods, $key) !== false, $key); echo "
\n"; + $allpaymentmethods = enrolment_plugin_authorize::get_list_of_payment_methods(true); + $paymentmethodsenabled = enrolment_plugin_authorize::get_list_of_payment_methods(); + foreach ($allpaymentmethods as $key) { + print_checkbox('acceptmethods[]', $key, in_array($key, $paymentmethodsenabled), get_string('method'.strtolower($key),'enrol_authorize')); echo "
\n"; } - ?>

+

-

an_review: an_review)) ?> -
an_capture_day: - an_capture_day) ?>

an_emailexpired:an_emailexpired) ?>
+

+ an_emailexpired) ?>
an_emailexpiredteacher:an_emailexpiredteacher)) ?>an_emailexpiredteacher)) ?>
+
get_string('adminemailexpiredsortsum', 'enrol_authorize'), 'cnt' => get_string('adminemailexpiredsortcount', 'enrol_authorize')); - choose_from_menu($sorts, "an_sorttype", $frm->an_sorttype, "","", "") ?>
enrol_mailstudents:enrol_mailstudents)) ?>enrol_mailstudents)) ?>
+
enrol_mailteachers:enrol_mailteachers)) ?>enrol_mailteachers)) ?>
+
enrol_mailadmins:enrol_mailadmins)) ?>enrol_mailadmins)) ?>
+
diff --git a/enrol/authorize/const.php b/enrol/authorize/const.php index 74f8591a76..4396fca8db 100644 --- a/enrol/authorize/const.php +++ b/enrol/authorize/const.php @@ -6,8 +6,8 @@ * Credit Card (CC) * ECheck (ECHECK) */ -define('AN_METHOD_CC', 1); -define('AN_METHOD_ECHECK', 2); +define('AN_METHOD_CC', 'CC'); +define('AN_METHOD_ECHECK', 'ECHECK'); /**#@-*/ /**#@+ @@ -47,7 +47,7 @@ define('AN_STATUS_TEST', 0x80); /**#@-*/ /**#@+ - * Actions used in authorizenet_action function. + * Actions used in authorize_action function. * * NONE: No action. Function always returns false. * AUTH_ONLY: Used to authorize only, don't capture. diff --git a/enrol/authorize/enrol.html b/enrol/authorize/enrol.html index 11386cf750..d023c63584 100755 --- a/enrol/authorize/enrol.html +++ b/enrol/authorize/enrol.html @@ -19,7 +19,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry; ?> -

ccerrors['header'])) { formerr($this->ccerrors['header']); } ?>

+

authorizeerrors['header'])) { formerr($this->authorizeerrors['header']); } ?>

@@ -30,16 +30,26 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
+ + + + + + authorizeerrors['cc'])) { formerr($this->authorizeerrors['cc']); } ?> + authorizeerrors['ccfirstlast'])) { formerr($this->authorizeerrors['ccfirstlast']); } ?> @@ -54,14 +64,14 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry; $years[$i] = $i; } choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy); - if (!empty($this->ccerrors['ccexpire'])) { formerr($this->ccerrors['ccexpire']); } + if (!empty($this->authorizeerrors['ccexpire'])) { formerr($this->authorizeerrors['ccexpire']); } ?> @@ -69,24 +79,24 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry; + authorizeerrors['cvv'])) { formerr($this->authorizeerrors['cvv']); } ?>an_avs)) { /* Address Verification System */ ?> + authorizeerrors['ccaddress'])) { formerr($this->authorizeerrors['ccaddress']); } ?> + authorizeerrors['cccity'])) { formerr($this->authorizeerrors['cccity']); } ?> + authorizeerrors['cccountry'])) { formerr($this->authorizeerrors['cccountry']); } ?> @@ -101,7 +111,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry; + authorizeerrors['cczip'])) { formerr($this->authorizeerrors['cczip']); } ?>
url = 'enrol.php?id='.$course->id.'&paymentmethod='.AN_METHOD_ECHECK; + print_string("usingecheckmethod", "enrol_authorize", $a); + ?> +
: - ccerrors['cc'])) { formerr($this->ccerrors['cc']); } ?>
: - ccerrors['ccfirstlast'])) { formerr($this->ccerrors['ccfirstlast']); } ?>
:
: cctype); - if (!empty($this->ccerrors['cctype'])) { formerr($this->ccerrors['cctype']); } + if (!empty($this->authorizeerrors['cctype'])) { formerr($this->authorizeerrors['cctype']); } ?>
: - ccerrors['cvv'])) { formerr($this->ccerrors['cvv']); } ?>
: - ccerrors['ccaddress'])) { formerr($this->ccerrors['ccaddress']); } ?>
/ : / - ccerrors['cccity'])) { formerr($this->ccerrors['cccity']); } ?>
: - ccerrors['cccountry'])) { formerr($this->ccerrors['cccountry']); } ?>
: - ccerrors['cczip'])) { formerr($this->ccerrors['cczip']); } ?>
"> diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index 273e87abf5..b504aa0874 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -10,12 +10,12 @@ require_once($CFG->dirroot.'/enrol/authorize/const.php'); class enrolment_plugin_authorize { /** - * Credit card error messages. + * Credit card and Echeck error messages. * * @var array * @access public */ - var $ccerrors = array(); + var $authorizeerrors = array(); /** * Cron log. @@ -89,7 +89,9 @@ class enrolment_plugin_authorize $strcourses = get_string('courses'); $strloginto = get_string('loginto', '', $course->shortname); - print_header($strloginto, $course->fullname, "wwwroot/course/\">$strcourses -> $strloginto"); + print_header($strloginto, + $course->fullname, + "wwwroot/course/\">$strcourses -> $strloginto"); print_course($course, '80%'); if ($course->password) { @@ -126,16 +128,30 @@ class enrolment_plugin_authorize * @param object $course Course info * @access public */ - function check_entry($form, $course) { + function check_entry($form, $course) + { + global $CFG; + if (enrolment_plugin_authorize::zero_cost($course) or - (!empty($course->password) and !empty($form->password))) { + (!empty($course->password) and !empty($form->password))) { // MANUAL ENROLMENT $manual = enrolment_factory::factory('manual'); $manual->check_entry($form, $course); if (!empty($manual->errormsg)) { $this->errormsg = $manual->errormsg; } - } elseif ((!empty($form->ccsubmit)) and $this->validate_enrol_form($form)) { - $this->cc_submit($form, $course); + } + else { // AUTHORIZE.NET ENROLMENT + $paymentmethodsenabled = enrolment_plugin_authorize::get_list_of_payment_methods(); + if (in_array(AN_METHOD_CC, $paymentmethodsenabled) and + !empty($form->ccsubmit) and + $this->validate_cc_form($form)) { + $this->cc_submit($form, $course); + } + elseif (in_array(AN_METHOD_ECHECK, $paymentmethodsenabled) and + !empty($form->echecksubmit) and + $this->validate_echeck_form($form)) { + $this->echeck_submit($form, $course); + } } } @@ -175,7 +191,7 @@ class enrolment_plugin_authorize $order->id = insert_record("enrol_authorize", $order); if (!$order->id) { enrolment_plugin_authorize::email_to_admin("Error while trying to insert new data", $order); - $this->ccerrors['header'] = "Insert record error. Admin has been notified!"; + $this->authorizeerrors['header'] = "Insert record error. Admin has been notified!"; return; } @@ -209,7 +225,7 @@ class enrolment_plugin_authorize $success = authorize_action($order, $message, $extra, $action); if (!$success) { enrolment_plugin_authorize::email_to_admin($message, $order); - $this->ccerrors['header'] = $message; + $this->authorizeerrors['header'] = $message; return; } @@ -306,72 +322,88 @@ class enrolment_plugin_authorize redirect($destination); } + function echeck_submit($form, $course) + { + global $CFG, $USER, $SESSION; + require_once('authorizenetlib.php'); + + } + + /** - * validate_enrol_form + * validate_cc_form (static method) * - * @param object $form Form parameters - * @access private + * @param unknown_type $form + * @return bool */ - function validate_enrol_form($form) + function validate_cc_form($form) { global $CFG; require_once('ccval.php'); if (empty($form->cc)) { - $this->ccerrors['cc'] = get_string('missingcc', 'enrol_authorize'); + $this->authorizeerrors['cc'] = get_string('missingcc', 'enrol_authorize'); } if (empty($form->ccexpiremm) || empty($form->ccexpireyyyy)) { - $this->ccerrors['ccexpire'] = get_string('missingccexpire', 'enrol_authorize'); + $this->authorizeerrors['ccexpire'] = get_string('missingccexpire', 'enrol_authorize'); } else { $expdate = sprintf("%02d", intval($form->ccexpiremm)) . $form->ccexpireyyyy; $validcc = CCVal($form->cc, $form->cctype, $expdate); if (!$validcc) { if ($validcc === 0) { - $this->ccerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize'); + $this->authorizeerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize'); } else { - $this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize'); + $this->authorizeerrors['cc'] = get_string('ccinvalid', 'enrol_authorize'); } } } if (empty($form->ccfirstname) || empty($form->cclastname)) { - $this->ccerrors['ccfirstlast'] = get_string('missingfullname'); + $this->authorizeerrors['ccfirstlast'] = get_string('missingfullname'); } if (empty($form->cvv) || !is_numeric($form->cvv)) { - $this->ccerrors['cvv'] = get_string('missingcvv', 'enrol_authorize'); + $this->authorizeerrors['cvv'] = get_string('missingcvv', 'enrol_authorize'); } if (empty($form->cctype) or !in_array($form->cctype, array_keys(enrolment_plugin_authorize::get_list_of_creditcards()))) { - $this->ccerrors['cctype'] = get_string('missingcctype', 'enrol_authorize'); + $this->authorizeerrors['cctype'] = get_string('missingcctype', 'enrol_authorize'); } if (!empty($CFG->an_avs)) { if (empty($form->ccaddress)) { - $this->ccerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize'); + $this->authorizeerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize'); } if (empty($form->cccity)) { - $this->ccerrors['cccity'] = get_string('missingcity'); + $this->authorizeerrors['cccity'] = get_string('missingcity'); } if (empty($form->cccountry)) { - $this->ccerrors['cccountry'] = get_string('missingcountry'); + $this->authorizeerrors['cccountry'] = get_string('missingcountry'); } } if (empty($form->cczip) || !is_numeric($form->cczip)) { - $this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize'); + $this->authorizeerrors['cczip'] = get_string('missingzip', 'enrol_authorize'); } - if (!empty($this->ccerrors)) { - $this->ccerrors['header'] = get_string('someerrorswerefound'); + if (!empty($this->authorizeerrors)) { + $this->authorizeerrors['header'] = get_string('someerrorswerefound'); return false; } return true; } + function validate_echeck_form($form) + { + global $CFG; + + + return true; + } + /** * Gets access icons. @@ -481,7 +513,9 @@ class enrolment_plugin_authorize set_config('an_test', optional_param('an_test', 0, PARAM_BOOL)); set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL)); - $acceptmethods = optional_param('acceptmethods', array('cc'), PARAM_ALPHA); + $acceptmethods = optional_param('acceptmethods', + enrolment_plugin_authorize::get_list_of_payment_methods(), + PARAM_ALPHA); set_config('an_acceptmethods', implode(',', $acceptmethods)); $acceptccs = optional_param('acceptccs', @@ -678,6 +712,29 @@ class enrolment_plugin_authorize return $ret; } + function get_list_of_payment_methods($getall = false) + { + global $CFG; + + $alltypes = array(AN_METHOD_CC, AN_METHOD_ECHECK); + + if ($getall) { + return $alltypes; + } + + $ret = array(); + if (empty($CFG->an_acceptmethods)) { + $ret[] = AN_METHOD_CC; // default + } + else { + $mthds = explode(',', $CFG->an_acceptmethods); + foreach ($mthds as $mthd) { + $ret[] = $mthd; + } + } + return $ret; + } + /** * This function is run by admin/cron.php every time if admin has enabled this plugin. -- 2.39.5