Some UI changes.

This commit is contained in:
ethem 2006-08-30 14:06:40 +00:00
parent 6b1d27020d
commit 75bb06e0aa
5 changed files with 170 additions and 109 deletions

View File

@ -82,7 +82,7 @@ function authorize_expired(&$order)
* @param string &$message Information about error message if this function returns false. * @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 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 $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. * @return bool true Transaction was successful, false otherwise. Use $message for reason.
* @author Ethem Evlice <ethem a.t evlice d.o.t com> * @author Ethem Evlice <ethem a.t evlice d.o.t com>
* @uses $CFG * @uses $CFG
@ -92,8 +92,6 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
global $CFG; global $CFG;
static $conststring; static $conststring;
$test = !empty($CFG->an_test);
if (!isset($conststring)) { if (!isset($conststring)) {
$constdata = array( $constdata = array(
'x_version' => '3.1', 'x_version' => '3.1',
@ -124,10 +122,11 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
$method = AN_METHOD_CC; $method = AN_METHOD_CC;
} }
elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) { elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) {
$message = "Missing method: $method"; $message = "Invalid method: $method";
return false; return false;
} }
$action = intval($action);
if ($method == AN_METHOD_ECHECK) { if ($method == AN_METHOD_ECHECK) {
if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) { if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) {
$message = "Please perform AUTH_CAPTURE or CREDIT for echecks"; $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) { if ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
$message = "Invalid action!"; $message = "Invalid action!";
return false; return false;
} }
$poststring = $conststring; $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'); $poststring .= '&x_test_request=' . ($test ? 'TRUE' : 'FALSE');
$timenowsettle = getsettletime(time());
switch ($action) { switch ($action) {
case AN_ACTION_AUTH_ONLY: case AN_ACTION_AUTH_ONLY:
@ -362,7 +361,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
if ($message == '[[' . $reason . ']]') { if ($message == '[[' . $reason . ']]') {
$message = isset($response[3]) ? $response[3] : 'unknown error'; $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]); $avs = "avs" . strtolower($response[5]);
$stravs = get_string($avs, "enrol_authorize"); $stravs = get_string($avs, "enrol_authorize");
$message .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs); $message .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs);

View File

@ -31,13 +31,8 @@ if (!isset($frm->an_cutoff_hour)) {
} }
if (!isset($frm->acceptmethods)) { if (!isset($frm->acceptmethods)) {
if (empty($CFG->an_acceptmethods)) { $frm->acceptmethods = enrolment_plugin_authorize::get_list_of_payment_methods();
$frm->acceptmethods = array('cc'); $CFG->an_acceptmethods = implode(',', $frm->acceptmethods);
$CFG->an_acceptmethods = implode(',', $frm->acceptmethods);
}
else {
$frm->acceptmethods = explode(',', $CFG->an_acceptmethods);
}
} }
if (!isset($frm->acceptccs)) { if (!isset($frm->acceptccs)) {
@ -50,99 +45,100 @@ if (!isset($frm->acceptccs)) {
<table cellspacing="0" cellpadding="5" border="0" align="center"> <table cellspacing="0" cellpadding="5" border="0" align="center">
<tr valign="top"> <tr valign="top">
<td colspan="3" align="right"><a href="../enrol/authorize/index.php"><?php print_string("paymentmanagement", "enrol_authorize") ?></a></td> <td colspan="2" align="right"><a href="../enrol/authorize/index.php"><?php print_string("paymentmanagement", "enrol_authorize") ?></a></td>
</tr> </tr>
<tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizewide", "enrol_authorize") ?></h4></td></tr> <tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizewide", "enrol_authorize") ?></h4></td></tr>
<tr valign="top"> <tr valign="top">
<td align="right">enrol_cost:</td> <td align="right">enrol_cost:</td>
<td><input type="text" size="5" name="enrol_cost" value="<?php p($frm->enrol_cost) ?>" /></td> <td><input type="text" size="5" name="enrol_cost" value="<?php p($frm->enrol_cost) ?>" /><br />
<td><?php print_string("costdefault") ?>. <?php print_string("costdefaultdesc", "enrol_authorize") ?></td> <?php print_string("costdefault") ?>. <?php print_string("costdefaultdesc", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">enrol_currency:</td> <td align="right">enrol_currency:</td>
<td><?php choose_from_menu(get_list_of_currencies(), "enrol_currency", $frm->enrol_currency, "","", "") ?></td> <td><?php choose_from_menu(get_list_of_currencies(), "enrol_currency", $frm->enrol_currency, "","", "") ?><br />
<td><?php print_string("currency") ?> <?php print_string("currency") ?>
</td> </td>
</tr> </tr>
<?php if (substr($CFG->wwwroot, 0, 5) !== 'https') { /* https && loginhttps */ ?> <?php if (substr($CFG->wwwroot, 0, 5) !== 'https') { /* https && loginhttps */ ?>
<tr valign="top"> <tr valign="top">
<td align="right">loginhttps:</td> <td align="right">loginhttps:</td>
<td><?php echo (empty($CFG->loginhttps) ? "<font color=\"red\"><b>off</b></font>" : "<font color=\"green\">on</font>") ?></td>
<td><?php <td><?php
$a->url = "$CFG->wwwroot/$CFG->admin/config.php#configsectionsecurity"; echo (empty($CFG->loginhttps) ? "<font color=\"red\"><b>off</b></font>" : "<font color=\"green\">on</font>");
print_string("logindesc", "enrol_authorize", $a) $a->url = "$CFG->wwwroot/$CFG->admin/config.php#configsectionsecurity";
?></td> echo '<br />'; print_string("logindesc", "enrol_authorize", $a);
?>
</td>
</tr> </tr>
<?php } /* end: https && loginhttps */ ?> <?php } /* end: https && loginhttps */ ?>
<tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizesettings", "enrol_authorize") ?></h4></td></tr> <tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizesettings", "enrol_authorize") ?></h4></td></tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_login:</td> <td align="right">an_login:</td>
<td><input type="text" name="an_login" value="<?php p($frm->an_login) ?>" /></td> <td><input type="text" name="an_login" value="<?php p($frm->an_login) ?>" /><br />
<td><?php print_string("anlogin", "enrol_authorize") ?></td> <?php print_string("anlogin", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">#&nbsp;#&nbsp;</td> <td align="right">#&nbsp;#&nbsp;</td>
<td colspan="2"><?php print_string("chooseone", "enrol_authorize") ?></td> <td><?php print_string("chooseone", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_tran_key:</td> <td align="right">an_tran_key:</td>
<td><input type="text" name="an_tran_key" value="<?php p($frm->an_tran_key) ?>" /><sup>#1</sup></td> <td><input type="text" name="an_tran_key" value="<?php p($frm->an_tran_key) ?>" /><sup>#1</sup><br />
<td><?php print_string("antrankey", "enrol_authorize") ?></td> <?php print_string("antrankey", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_password:</td> <td align="right">an_password:</td>
<td><input type="text" name="an_password" value="" /><sup>#2</sup></td> <td><input type="text" name="an_password" value="" /><sup>#2</sup><br />
<td><?php print_string("anpassword", "enrol_authorize") ?><br />(<?php print_string("leavetokeep") ?>)</td> <?php print_string("anpassword", "enrol_authorize") ?><br />(<?php print_string("leavetokeep") ?>)</td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">delete_current:</td> <td align="right">delete_current:</td>
<td><?php print_checkbox('delete_current', '1', !empty($frm->delete_current)) ?></td> <td><?php print_checkbox('delete_current', '1', !empty($frm->delete_current)) ?> <br />
<td><?php print_string("deletecheck", "moodle", get_string('oldpassword')) ?><br /><br /></td> <?php print_string("deletecheck", "moodle", get_string('oldpassword')) ?><br /><br /></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_referer:</td> <td align="right">an_referer:</td>
<td><input type="text" name="an_referer" value="<?php p($frm->an_referer) ?>" /></td> <td><input type="text" name="an_referer" value="<?php p($frm->an_referer) ?>" /><br />
<td><?php print_string("anreferer", "enrol_authorize") ?></td> <?php print_string("anreferer", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_cutoff:</td> <td align="right">an_cutoff:</td>
<td><?php print_time_selector("an_cutoff_hour","an_cutoff_min",make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min),5); ?></td> <td><?php print_time_selector("an_cutoff_hour","an_cutoff_min",make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min),5); ?><br />
<td><?php print_string("cutofftime", "enrol_authorize") ?></td> <?php print_string("cutofftime", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_avs:</td> <td align="right">an_avs:</td>
<td><?php print_checkbox('an_avs', '1', !empty($frm->an_avs)) ?></td> <td><?php print_checkbox('an_avs', '1', !empty($frm->an_avs)) ?><br />
<td><?php print_string("adminavs", "enrol_authorize") ?></td> <?php print_string("adminavs", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_test:</td> <td align="right">an_test:</td>
<td><?php print_checkbox('an_test', '1', !empty($frm->an_test)) ?></td> <td><?php print_checkbox('an_test', '1', !empty($frm->an_test)) ?><br />
<td><?php print_string("antestmode", "enrol_authorize") ?></td> <?php print_string("antestmode", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_acceptmethods:</td> <td align="right">an_acceptmethods:</td>
<td><?php <td><?php
$allmethods = array('CC','ECHECK'); $allpaymentmethods = enrolment_plugin_authorize::get_list_of_payment_methods(true);
foreach ($allmethods as $key) { $paymentmethodsenabled = enrolment_plugin_authorize::get_list_of_payment_methods();
print_checkbox('acceptmethods[]', strtolower($key), stristr($CFG->an_acceptmethods, $key) !== false, $key); echo "<br />\n"; foreach ($allpaymentmethods as $key) {
print_checkbox('acceptmethods[]', $key, in_array($key, $paymentmethodsenabled), get_string('method'.strtolower($key),'enrol_authorize')); echo "<br />\n";
} }
?></td> ?><br /><?php print_string("adminacceptmethods", "enrol_authorize") ?></td>
<td><?php print_string("adminacceptmethods", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
@ -152,41 +148,40 @@ if (!isset($frm->acceptccs)) {
foreach ($allccs as $key => $val) { foreach ($allccs as $key => $val) {
print_checkbox('acceptccs[]', $key, stristr($CFG->an_acceptccs, $key) !== false, $val); echo "<br />\n"; print_checkbox('acceptccs[]', $key, stristr($CFG->an_acceptccs, $key) !== false, $val); echo "<br />\n";
} }
?></td> ?><br /><?php print_string("adminacceptccs", "enrol_authorize") ?></td>
<td><?php print_string("adminacceptccs", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizeccapture", "enrol_authorize") ?> <tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizeccapture", "enrol_authorize") ?>
<?php helpbutton('orderreview', '', 'enrol/authorize'); ?> <?php helpbutton('orderreview', '', 'enrol/authorize'); ?>
</h4></td></tr> </h4></td></tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_review:</td> <td align="right">an_review:</td>
<td><?php print_checkbox('an_review', '1', !empty($frm->an_review)) ?> <td><?php print_checkbox('an_review', '1', !empty($frm->an_review)) ?>
<?php helpbutton('review', get_string('adminhelpreviewtitle', 'enrol_authorize'), 'enrol/authorize'); ?></td> <?php helpbutton('review', get_string('adminhelpreviewtitle', 'enrol_authorize'), 'enrol/authorize'); ?><br />
<td><?php print_string("adminreview", "enrol_authorize") ?></td> <?php print_string("adminreview", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_capture_day:</td> <td align="right">an_capture_day:</td>
<td><input type="text" name="an_capture_day" size="2" maxlength="2" value="<?php p($frm->an_capture_day) ?>" /> <td><input type="text" name="an_capture_day" size="2" maxlength="2" value="<?php p($frm->an_capture_day) ?>" />
<?php helpbutton('captureday', get_string('adminhelpcapturetitle', 'enrol_authorize'), 'enrol/authorize'); ?></td> <?php helpbutton('captureday', get_string('adminhelpcapturetitle', 'enrol_authorize'), 'enrol/authorize'); ?><br />
<td><?php print_string("reviewday", "enrol_authorize", $frm->an_capture_day) ?></td> <?php print_string("reviewday", "enrol_authorize", $frm->an_capture_day) ?></td>
</tr> </tr>
<tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizeemail", "enrol_authorize") ?></h4></td></tr> <tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizeemail", "enrol_authorize") ?></h4></td></tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_emailexpired:</td> <td align="right">an_emailexpired:</td>
<td><input type="text" name="an_emailexpired" size="1" maxlength="1" value="<?php p($frm->an_emailexpired) ?>" /></td> <td><input type="text" name="an_emailexpired" size="1" maxlength="1" value="<?php p($frm->an_emailexpired) ?>" /><br />
<td><?php print_string("adminemailexpired", "enrol_authorize", $frm->an_emailexpired) ?><br /> <?php print_string("adminemailexpired", "enrol_authorize", $frm->an_emailexpired) ?><br />
<?php print_string("adminemailexpsetting", "enrol_authorize") ?></td> <?php print_string("adminemailexpsetting", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">an_emailexpiredteacher:</td> <td align="right">an_emailexpiredteacher:</td>
<td><?php print_checkbox('an_emailexpiredteacher', '1', !empty($frm->an_emailexpiredteacher)) ?></td> <td><?php print_checkbox('an_emailexpiredteacher', '1', !empty($frm->an_emailexpiredteacher)) ?><br />
<td><?php print_string("adminemailexpiredteacher", "enrol_authorize") ?></td> <?php print_string("adminemailexpiredteacher", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
@ -194,26 +189,26 @@ if (!isset($frm->acceptccs)) {
<td><?php <td><?php
$sorts = array('ttl' => get_string('adminemailexpiredsortsum', 'enrol_authorize'), $sorts = array('ttl' => get_string('adminemailexpiredsortsum', 'enrol_authorize'),
'cnt' => get_string('adminemailexpiredsortcount', 'enrol_authorize')); 'cnt' => get_string('adminemailexpiredsortcount', 'enrol_authorize'));
choose_from_menu($sorts, "an_sorttype", $frm->an_sorttype, "","", "") ?></td> choose_from_menu($sorts, "an_sorttype", $frm->an_sorttype, "","", "") ?><br />
<td><?php print_string("adminemailexpiredsort", "enrol_authorize") ?></td> <?php print_string("adminemailexpiredsort", "enrol_authorize") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">enrol_mailstudents:</td> <td align="right">enrol_mailstudents:</td>
<td><?php print_checkbox('enrol_mailstudents', '1', !empty($frm->enrol_mailstudents)) ?></td> <td><?php print_checkbox('enrol_mailstudents', '1', !empty($frm->enrol_mailstudents)) ?><br />
<td><?php print_string("mailstudents") ?></td> <?php print_string("mailstudents") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">enrol_mailteachers:</td> <td align="right">enrol_mailteachers:</td>
<td><?php print_checkbox('enrol_mailteachers', '1', !empty($frm->enrol_mailteachers)) ?></td> <td><?php print_checkbox('enrol_mailteachers', '1', !empty($frm->enrol_mailteachers)) ?><br />
<td><?php print_string("mailteachers") ?></td> <?php print_string("mailteachers") ?></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td align="right">enrol_mailadmins:</td> <td align="right">enrol_mailadmins:</td>
<td><?php print_checkbox('enrol_mailadmins', '1', !empty($frm->enrol_mailadmins)) ?></td> <td><?php print_checkbox('enrol_mailadmins', '1', !empty($frm->enrol_mailadmins)) ?><br />
<td><?php print_string("mailadmins") ?></td> <?php print_string("mailadmins") ?></td>
</tr> </tr>
</table> </table>

View File

@ -6,8 +6,8 @@
* Credit Card (CC) * Credit Card (CC)
* ECheck (ECHECK) * ECheck (ECHECK)
*/ */
define('AN_METHOD_CC', 1); define('AN_METHOD_CC', 'CC');
define('AN_METHOD_ECHECK', 2); 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. * NONE: No action. Function always returns false.
* AUTH_ONLY: Used to authorize only, don't capture. * AUTH_ONLY: Used to authorize only, don't capture.

View File

@ -19,7 +19,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
?> ?>
<p align="center"><?php if (!empty($this->ccerrors['header'])) { formerr($this->ccerrors['header']); } ?></p> <p align="center"><?php if (!empty($this->authorizeerrors['header'])) { formerr($this->authorizeerrors['header']); } ?></p>
<div align="center"> <div align="center">
@ -30,16 +30,26 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
<form name="form" method="post" action="enrol.php" autocomplete="off"> <form name="form" method="post" action="enrol.php" autocomplete="off">
<input type="hidden" name="id" value="<?php p($course->id) ?>" /> <input type="hidden" name="id" value="<?php p($course->id) ?>" />
<table align="center" width="100%" border=0> <table align="center" width="100%" border=0>
<?php if (false) { /* ECHECK: active */ ?>
<tr>
<td align="right" colspan="2"><?php
$a = new stdClass;
$a->url = 'enrol.php?id='.$course->id.'&amp;paymentmethod='.AN_METHOD_ECHECK;
print_string("usingecheckmethod", "enrol_authorize", $a);
?>
</td>
</tr>
<?php } /* end: ECHECK */ ?>
<tr> <tr>
<td align="right"><?php print_string("ccno", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("ccno", "enrol_authorize") ?>: </td>
<td align="left"><input type="text" name="cc" size="16" value="<?php p($form->cc) ?>" /> <td align="left"><input type="text" name="cc" size="16" value="<?php p($form->cc) ?>" />
<?php if (!empty($this->ccerrors['cc'])) { formerr($this->ccerrors['cc']); } ?></td> <?php if (!empty($this->authorizeerrors['cc'])) { formerr($this->authorizeerrors['cc']); } ?></td>
</tr> </tr>
<tr> <tr>
<td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
<td align="left"><input type="text" name="ccfirstname" size="8" value="<?php p($userfirstname) ?>" /> <td align="left"><input type="text" name="ccfirstname" size="8" value="<?php p($userfirstname) ?>" />
<input type="text" name="cclastname" size="8" value="<?php p($userlastname) ?>" /> <input type="text" name="cclastname" size="8" value="<?php p($userlastname) ?>" />
<?php if (!empty($this->ccerrors['ccfirstlast'])) { formerr($this->ccerrors['ccfirstlast']); } ?></td> <?php if (!empty($this->authorizeerrors['ccfirstlast'])) { formerr($this->authorizeerrors['ccfirstlast']); } ?></td>
</tr> </tr>
<tr> <tr>
<td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
@ -54,14 +64,14 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
$years[$i] = $i; $years[$i] = $i;
} }
choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy); 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']); }
?></td> ?></td>
</tr> </tr>
<tr> <tr>
<td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
<td align="left"><?php <td align="left"><?php
choose_from_menu(enrolment_plugin_authorize::get_list_of_creditcards(), 'cctype', $form->cctype); choose_from_menu(enrolment_plugin_authorize::get_list_of_creditcards(), 'cctype', $form->cctype);
if (!empty($this->ccerrors['cctype'])) { formerr($this->ccerrors['cctype']); } if (!empty($this->authorizeerrors['cctype'])) { formerr($this->authorizeerrors['cctype']); }
?> ?>
</td> </td>
</tr> </tr>
@ -69,24 +79,24 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
<td align="right"><?php print_string("ccvv", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("ccvv", "enrol_authorize") ?>: </td>
<td align="left"><input type="text" name="cvv" size="4" maxlength="4" value="<?php p($form->cvv) ?>" /> <td align="left"><input type="text" name="cvv" size="4" maxlength="4" value="<?php p($form->cvv) ?>" />
<?php helpbutton('', '', 'enrol_authorize', true, 'cvv', get_string('ccvvhelp', 'enrol_authorize')); ?> <?php helpbutton('', '', 'enrol_authorize', true, 'cvv', get_string('ccvvhelp', 'enrol_authorize')); ?>
<?php if (!empty($this->ccerrors['cvv'])) { formerr($this->ccerrors['cvv']); } ?></td> <?php if (!empty($this->authorizeerrors['cvv'])) { formerr($this->authorizeerrors['cvv']); } ?></td>
</tr> </tr>
<?php if (!empty($CFG->an_avs)) { /* Address Verification System */ ?> <?php if (!empty($CFG->an_avs)) { /* Address Verification System */ ?>
<tr> <tr>
<td align="right"><?php print_string("address") ?>: </td> <td align="right"><?php print_string("address") ?>: </td>
<td align="left"><input type="text" name="ccaddress" size="32" value="<?php p($useraddress) ?>" /> <td align="left"><input type="text" name="ccaddress" size="32" value="<?php p($useraddress) ?>" />
<?php if (!empty($this->ccerrors['ccaddress'])) { formerr($this->ccerrors['ccaddress']); } ?></td> <?php if (!empty($this->authorizeerrors['ccaddress'])) { formerr($this->authorizeerrors['ccaddress']); } ?></td>
</tr> </tr>
<tr> <tr>
<td align="right"><?php print_string("city") ?> / <?php print_string("state") ?>: </td> <td align="right"><?php print_string("city") ?> / <?php print_string("state") ?>: </td>
<td align="left"><input type="text" name="cccity" size="16" value="<?php p($usercity) ?>" /> / <td align="left"><input type="text" name="cccity" size="16" value="<?php p($usercity) ?>" /> /
<input type="text" name="ccstate" size="2" maxlength="2" value="<?php p($form->ccstate) ?>" /> <input type="text" name="ccstate" size="2" maxlength="2" value="<?php p($form->ccstate) ?>" />
<?php if (!empty($this->ccerrors['cccity'])) { formerr($this->ccerrors['cccity']); } ?></td> <?php if (!empty($this->authorizeerrors['cccity'])) { formerr($this->authorizeerrors['cccity']); } ?></td>
</tr> </tr>
<tr> <tr>
<td align="right"><?php print_string("country") ?>: </td> <td align="right"><?php print_string("country") ?>: </td>
<td align="left"><?php choose_from_menu(get_list_of_countries(), "cccountry", $usercountry, get_string("selectacountry")."..."); ?> <td align="left"><?php choose_from_menu(get_list_of_countries(), "cccountry", $usercountry, get_string("selectacountry")."..."); ?>
<?php if (!empty($this->ccerrors['cccountry'])) { formerr($this->ccerrors['cccountry']); } ?></td> <?php if (!empty($this->authorizeerrors['cccountry'])) { formerr($this->authorizeerrors['cccountry']); } ?></td>
</tr> </tr>
<?php } else { /* not AVS */ ?> <?php } else { /* not AVS */ ?>
<tr> <tr>
@ -101,7 +111,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
<tr> <tr>
<td align="right"><?php print_string("zipcode", "enrol_authorize") ?>: </td> <td align="right"><?php print_string("zipcode", "enrol_authorize") ?>: </td>
<td align="left"><input type="text" name="cczip" size="5" value="<?php p($form->cczip) ?>" /> <td align="left"><input type="text" name="cczip" size="5" value="<?php p($form->cczip) ?>" />
<?php if (!empty($this->ccerrors['cczip'])) { formerr($this->ccerrors['cczip']); } ?></td> <?php if (!empty($this->authorizeerrors['cczip'])) { formerr($this->authorizeerrors['cczip']); } ?></td>
</tr> </tr>
</table> </table>
<input type="submit" name="ccsubmit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>"> <input type="submit" name="ccsubmit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">

View File

@ -10,12 +10,12 @@ require_once($CFG->dirroot.'/enrol/authorize/const.php');
class enrolment_plugin_authorize class enrolment_plugin_authorize
{ {
/** /**
* Credit card error messages. * Credit card and Echeck error messages.
* *
* @var array * @var array
* @access public * @access public
*/ */
var $ccerrors = array(); var $authorizeerrors = array();
/** /**
* Cron log. * Cron log.
@ -89,7 +89,9 @@ class enrolment_plugin_authorize
$strcourses = get_string('courses'); $strcourses = get_string('courses');
$strloginto = get_string('loginto', '', $course->shortname); $strloginto = get_string('loginto', '', $course->shortname);
print_header($strloginto, $course->fullname, "<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto"); print_header($strloginto,
$course->fullname,
"<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
print_course($course, '80%'); print_course($course, '80%');
if ($course->password) { if ($course->password) {
@ -126,16 +128,30 @@ class enrolment_plugin_authorize
* @param object $course Course info * @param object $course Course info
* @access public * @access public
*/ */
function check_entry($form, $course) { function check_entry($form, $course)
{
global $CFG;
if (enrolment_plugin_authorize::zero_cost($course) or 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 = enrolment_factory::factory('manual');
$manual->check_entry($form, $course); $manual->check_entry($form, $course);
if (!empty($manual->errormsg)) { if (!empty($manual->errormsg)) {
$this->errormsg = $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); $order->id = insert_record("enrol_authorize", $order);
if (!$order->id) { if (!$order->id) {
enrolment_plugin_authorize::email_to_admin("Error while trying to insert new data", $order); 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; return;
} }
@ -209,7 +225,7 @@ class enrolment_plugin_authorize
$success = authorize_action($order, $message, $extra, $action); $success = authorize_action($order, $message, $extra, $action);
if (!$success) { if (!$success) {
enrolment_plugin_authorize::email_to_admin($message, $order); enrolment_plugin_authorize::email_to_admin($message, $order);
$this->ccerrors['header'] = $message; $this->authorizeerrors['header'] = $message;
return; return;
} }
@ -306,72 +322,88 @@ class enrolment_plugin_authorize
redirect($destination); 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 * @param unknown_type $form
* @access private * @return bool
*/ */
function validate_enrol_form($form) function validate_cc_form($form)
{ {
global $CFG; global $CFG;
require_once('ccval.php'); require_once('ccval.php');
if (empty($form->cc)) { 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)) { if (empty($form->ccexpiremm) || empty($form->ccexpireyyyy)) {
$this->ccerrors['ccexpire'] = get_string('missingccexpire', 'enrol_authorize'); $this->authorizeerrors['ccexpire'] = get_string('missingccexpire', 'enrol_authorize');
} }
else { else {
$expdate = sprintf("%02d", intval($form->ccexpiremm)) . $form->ccexpireyyyy; $expdate = sprintf("%02d", intval($form->ccexpiremm)) . $form->ccexpireyyyy;
$validcc = CCVal($form->cc, $form->cctype, $expdate); $validcc = CCVal($form->cc, $form->cctype, $expdate);
if (!$validcc) { if (!$validcc) {
if ($validcc === 0) { if ($validcc === 0) {
$this->ccerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize'); $this->authorizeerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize');
} }
else { else {
$this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize'); $this->authorizeerrors['cc'] = get_string('ccinvalid', 'enrol_authorize');
} }
} }
} }
if (empty($form->ccfirstname) || empty($form->cclastname)) { 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)) { 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 if (empty($form->cctype) or
!in_array($form->cctype, array_keys(enrolment_plugin_authorize::get_list_of_creditcards()))) { !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($CFG->an_avs)) {
if (empty($form->ccaddress)) { if (empty($form->ccaddress)) {
$this->ccerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize'); $this->authorizeerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize');
} }
if (empty($form->cccity)) { if (empty($form->cccity)) {
$this->ccerrors['cccity'] = get_string('missingcity'); $this->authorizeerrors['cccity'] = get_string('missingcity');
} }
if (empty($form->cccountry)) { if (empty($form->cccountry)) {
$this->ccerrors['cccountry'] = get_string('missingcountry'); $this->authorizeerrors['cccountry'] = get_string('missingcountry');
} }
} }
if (empty($form->cczip) || !is_numeric($form->cczip)) { 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)) { if (!empty($this->authorizeerrors)) {
$this->ccerrors['header'] = get_string('someerrorswerefound'); $this->authorizeerrors['header'] = get_string('someerrorswerefound');
return false; return false;
} }
return true; return true;
} }
function validate_echeck_form($form)
{
global $CFG;
return true;
}
/** /**
* Gets access icons. * 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_test', optional_param('an_test', 0, PARAM_BOOL));
set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL)); 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)); set_config('an_acceptmethods', implode(',', $acceptmethods));
$acceptccs = optional_param('acceptccs', $acceptccs = optional_param('acceptccs',
@ -678,6 +712,29 @@ class enrolment_plugin_authorize
return $ret; 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. * This function is run by admin/cron.php every time if admin has enabled this plugin.