Permalink
Browse files

Some UI stuff for ECHECK

  • Loading branch information...
ethem
ethem committed Aug 30, 2006
1 parent 35f4a07 commit 2c50dc0b6396b6db34469c44569b97b57c61cefb
Showing with 206 additions and 130 deletions.
  1. +7 −0 enrol/authorize/authorizenetlib.php
  2. +0 −18 enrol/authorize/const.php
  3. +199 −112 enrol/authorize/enrol.html
@@ -10,6 +10,13 @@
define('AN_DELIM', '|');
define('AN_ENCAP', '"');
+define('AN_REASON_NOCCTYPE', 17);
+define('AN_REASON_NOCCTYPE2', 28);
+define('AN_REASON_NOACH', 18);
+define('AN_REASON_ACHONLY', 56);
+define('AN_REASON_NOACHTYPE', 245);
+define('AN_REASON_NOACHTYPE2', 246);
+
require_once($CFG->dirroot.'/enrol/authorize/const.php');
require_once($CFG->dirroot.'/enrol/authorize/enrol.php');
View
@@ -10,24 +10,6 @@
define('AN_METHOD_ECHECK', 'ECHECK');
/**#@-*/
-/**#@+
- * Some useful authorize.net responses.
- * Autoconfigure payment methods and credit card types.
- *
- * NOCCTYPE: The merchant does not accept this type of credit card.
- * NOACH: ACH transactions are not accepted by this merchant.
- * ACHONLY: This merchant accepts ACH transactions only;
- * no credit card transactions are accepted.
- *
- */
-define('AN_REASON_NOCCTYPE', 17);
-define('AN_REASON_NOCCTYPE2', 28);
-define('AN_REASON_NOACH', 18);
-define('AN_REASON_ACHONLY', 56);
-define('AN_REASON_NOACHTYPE', 245);
-define('AN_REASON_NOACHTYPE2', 246);
-/**#@-*/
-
/**#@+
* E-Check types
*
View
@@ -1,120 +1,207 @@
<?php // $Id$
-enrolment_plugin_authorize::prevent_double_paid($course);
-$formvars = array('password', 'ccaddress', 'cccity', 'ccstate', 'cccountry', 'cczip',
- 'ccfirstname', 'cclastname', 'cc', 'ccexpiremm', 'ccexpireyyyy', 'cctype', 'cvv');
+/// Prevent double paid
+ enrolment_plugin_authorize::prevent_double_paid($course);
-foreach ($formvars as $var) {
- if (!isset($form->$var)) {
- $form->$var = '';
+/// Get payment methods enabled and use the first method as default payment method
+ $paymentmethodsenabled = enrolment_plugin_authorize::get_list_of_payment_methods(); // methods enabled
+ $paymentmethod = optional_param('paymentmethod', $paymentmethodsenabled[0], PARAM_ALPHA); // user's payment preference
+
+ if (!in_array($paymentmethod, $paymentmethodsenabled)) {
+ error("Invalid payment method: $paymentmethod");
}
-}
-$curcost = enrolment_plugin_authorize::get_course_cost($course);
-$userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname;
-$userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname;
-$useraddress = empty($form->ccaddress) ? $USER->address : $form->ccaddress;
-$usercity = empty($form->cccity) ? $USER->city : $form->cccity;
-$usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
+ switch ($paymentmethod)
+ {
+ case AN_METHOD_CC:
+ {
+ print_cc_form($this);
+ break;
+ }
+
+ case AN_METHOD_ECHECK:
+ {
+ print_eheck_form($this);
+ break;
+ }
+ }
+?>
+
+<?php
+function print_cc_form($classreference)
+{
+ global $form, $course, $paymentmethodsenabled;
+ global $CFG, $USER;
+ $formvars = array(
+ 'password', 'ccaddress', 'cccity', 'ccstate', 'cccountry', 'cczip',
+ 'ccfirstname', 'cclastname', 'cc', 'ccexpiremm', 'ccexpireyyyy', 'cctype', 'cvv'
+ );
+ foreach ($formvars as $var) {
+ if (!isset($form->$var)) {
+ $form->$var = '';
+ }
+ }
+
+ $curcost = enrolment_plugin_authorize::get_course_cost($course);
+ $userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname;
+ $userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname;
+ $useraddress = empty($form->ccaddress) ? $USER->address : $form->ccaddress;
+ $usercity = empty($form->cccity) ? $USER->city : $form->cccity;
+ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
?>
+<!-- BEGIN CC -->
+ <p align="center"><?php if (!empty($classreference->authorizeerrors['header'])) { formerr($classreference->authorizeerrors['header']); } ?></p>
+ <div align="center">
+
+ <p><?php print_string("paymentrequired") ?></p>
+ <p><b><?php echo get_string("cost").": $curcost[currency] $curcost[cost]"; ?></b></p>
+ <p><?php print_string("paymentinstant") ?></p>
-<p align="center"><?php if (!empty($this->authorizeerrors['header'])) { formerr($this->authorizeerrors['header']); } ?></p>
-
-<div align="center">
-
-<p><?php print_string("paymentrequired") ?></p>
-<p><b><?php echo get_string("cost").": $curcost[currency] $curcost[cost]"; ?></b></p>
-<p><?php print_string("paymentinstant") ?></p>
-
-<form name="form" method="post" action="enrol.php" autocomplete="off">
-<input type="hidden" name="id" value="<?php p($course->id) ?>" />
-<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>
- <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) ?>" />
- <?php if (!empty($this->authorizeerrors['cc'])) { formerr($this->authorizeerrors['cc']); } ?></td>
-</tr>
-<tr>
- <td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
- <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) ?>" />
- <?php if (!empty($this->authorizeerrors['ccfirstlast'])) { formerr($this->authorizeerrors['ccfirstlast']); } ?></td>
-</tr>
-<tr>
- <td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
- <td align="left"><?php
- for ($i=1; $i<=12; $i++) {
- $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
- }
- choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm);
- $nowdate = getdate();
- $nowyear = $nowdate["year"]-1;
- for ($i=$nowyear; $i<=$nowyear+11; $i++) {
- $years[$i] = $i;
- }
- choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy);
- if (!empty($this->authorizeerrors['ccexpire'])) { formerr($this->authorizeerrors['ccexpire']); }
- ?></td>
-</tr>
-<tr>
- <td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
- <td align="left"><?php
- choose_from_menu(enrolment_plugin_authorize::get_list_of_creditcards(), 'cctype', $form->cctype);
- if (!empty($this->authorizeerrors['cctype'])) { formerr($this->authorizeerrors['cctype']); }
- ?>
-</td>
-</tr>
-<tr>
- <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) ?>" />
- <?php helpbutton('', '', 'enrol_authorize', true, 'cvv', get_string('ccvvhelp', 'enrol_authorize')); ?>
- <?php if (!empty($this->authorizeerrors['cvv'])) { formerr($this->authorizeerrors['cvv']); } ?></td>
-</tr>
-<?php if (!empty($CFG->an_avs)) { /* Address Verification System */ ?>
-<tr>
- <td align="right"><?php print_string("address") ?>: </td>
- <td align="left"><input type="text" name="ccaddress" size="32" value="<?php p($useraddress) ?>" />
- <?php if (!empty($this->authorizeerrors['ccaddress'])) { formerr($this->authorizeerrors['ccaddress']); } ?></td>
-</tr>
-<tr>
- <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) ?>" /> /
- <input type="text" name="ccstate" size="2" maxlength="2" value="<?php p($form->ccstate) ?>" />
- <?php if (!empty($this->authorizeerrors['cccity'])) { formerr($this->authorizeerrors['cccity']); } ?></td>
-</tr>
-<tr>
- <td align="right"><?php print_string("country") ?>: </td>
- <td align="left"><?php choose_from_menu(get_list_of_countries(), "cccountry", $usercountry, get_string("selectacountry")."..."); ?>
- <?php if (!empty($this->authorizeerrors['cccountry'])) { formerr($this->authorizeerrors['cccountry']); } ?></td>
-</tr>
-<?php } else { /* not AVS */ ?>
-<tr>
-<td colspan="2">
- <input type="hidden" name="ccstate" value="" />
- <input type="hidden" name="ccaddress" value="<?php p($useraddress) ?>" />
- <input type="hidden" name="cccity" value="<?php p($usercity) ?>" />
- <input type="hidden" name="cccountry" value="<?php p($usercountry) ?>" />
-</td>
-</tr>
-<?php } ?>
-<tr>
- <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) ?>" />
- <?php if (!empty($this->authorizeerrors['cczip'])) { formerr($this->authorizeerrors['cczip']); } ?></td>
-</tr>
-</table>
-<input type="submit" name="ccsubmit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
-</form>
-
-</div>
+ <form name="form" method="post" action="enrol.php" autocomplete="off">
+ <input type="hidden" name="id" value="<?php p($course->id) ?>" />
+ <table align="center" width="100%" border=0>
+ <tr>
+ <td align="right" colspan="2">&nbsp;<?php print_other_method(AN_METHOD_CC, $paymentmethodsenabled, $course); ?></td>
+ </tr>
+ <tr>
+ <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) ?>" />
+ <?php if (!empty($classreference->authorizeerrors['cc'])) { formerr($classreference->authorizeerrors['cc']); } ?></td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
+ <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) ?>" />
+ <?php if (!empty($classreference->authorizeerrors['ccfirstlast'])) { formerr($classreference->authorizeerrors['ccfirstlast']); } ?></td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
+ <td align="left"><?php
+ for ($i=1; $i<=12; $i++) {
+ $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
+ }
+ choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm);
+ $nowdate = getdate();
+ $nowyear = $nowdate["year"]-1;
+ for ($i=$nowyear; $i<=$nowyear+11; $i++) {
+ $years[$i] = $i;
+ }
+ choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy);
+ if (!empty($classreference->authorizeerrors['ccexpire'])) { formerr($classreference->authorizeerrors['ccexpire']); }
+ ?></td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
+ <td align="left"><?php
+ choose_from_menu(enrolment_plugin_authorize::get_list_of_creditcards(), 'cctype', $form->cctype);
+ if (!empty($classreference->authorizeerrors['cctype'])) { formerr($classreference->authorizeerrors['cctype']); }
+ ?>
+ </td>
+ </tr>
+ <tr>
+ <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) ?>" />
+ <?php helpbutton('', '', 'enrol_authorize', true, 'cvv', get_string('ccvvhelp', 'enrol_authorize')); ?>
+ <?php if (!empty($classreference->authorizeerrors['cvv'])) { formerr($classreference->authorizeerrors['cvv']); } ?></td>
+ </tr>
+ <?php if (!empty($CFG->an_avs)) { /* Address Verification System */ ?>
+ <tr>
+ <td align="right"><?php print_string("address") ?>: </td>
+ <td align="left"><input type="text" name="ccaddress" size="32" value="<?php p($useraddress) ?>" />
+ <?php if (!empty($classreference->authorizeerrors['ccaddress'])) { formerr($classreference->authorizeerrors['ccaddress']); } ?></td>
+ </tr>
+ <tr>
+ <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) ?>" /> /
+ <input type="text" name="ccstate" size="2" maxlength="2" value="<?php p($form->ccstate) ?>" />
+ <?php if (!empty($classreference->authorizeerrors['cccity'])) { formerr($classreference->authorizeerrors['cccity']); } ?></td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string("country") ?>: </td>
+ <td align="left"><?php choose_from_menu(get_list_of_countries(), "cccountry", $usercountry, get_string("selectacountry")."..."); ?>
+ <?php if (!empty($classreference->authorizeerrors['cccountry'])) { formerr($classreference->authorizeerrors['cccountry']); } ?></td>
+ </tr>
+ <?php } else { /* not AVS */ ?>
+ <tr>
+ <td colspan="2">
+ <input type="hidden" name="ccstate" value="" />
+ <input type="hidden" name="ccaddress" value="<?php p($useraddress) ?>" />
+ <input type="hidden" name="cccity" value="<?php p($usercity) ?>" />
+ <input type="hidden" name="cccountry" value="<?php p($usercountry) ?>" />
+ </td>
+ </tr>
+ <?php } ?>
+ <tr>
+ <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) ?>" />
+ <?php if (!empty($classreference->authorizeerrors['cczip'])) { formerr($classreference->authorizeerrors['cczip']); } ?></td>
+ </tr>
+ </table>
+ <input type="submit" name="ccsubmit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
+ </form>
+ </div>
+<!-- END CC -->
+<?php } /* end: print_cc_form */ ?>
+<?php
+function print_echeck_form($classreference)
+ {
+ global $form, $course, $paymentmethodsenabled;
+ global $CFG, $USER;
+
+ $formvars = array('password', 'abacode', 'accnum', 'acctype', 'bankname', 'firstname', 'lastname');
+ foreach ($formvars as $var) {
+ if (!isset($form->$var)) {
+ $form->$var = '';
+ }
+ }
+
+ $curcost = enrolment_plugin_authorize::get_course_cost($course);
+ $userfirstname = empty($form->firstname) ? $USER->firstname : $form->firstname;
+ $userlastname = empty($form->lastname) ? $USER->lastname : $form->lastname;
+?>
+<!-- BEGIN ECHECK -->
+ <p align="center"><?php if (!empty($classreference->authorizeerrors['header'])) { formerr($classreference->authorizeerrors['header']); } ?></p>
+ <div align="center">
+
+ <p><?php print_string("paymentrequired") ?></p>
+ <p><b><?php echo get_string("cost").": $curcost[currency] $curcost[cost]"; ?></b></p>
+ <p><?php print_string("paymentinstant") ?></p>
+
+ <form name="form" method="post" action="enrol.php" autocomplete="off">
+ <input type="hidden" name="id" value="<?php p($course->id) ?>" />
+ <table align="center" width="100%" border=0>
+ <tr>
+ <td align="right" colspan="2">&nbsp;<?php print_other_method(AN_METHOD_ECHECK, $paymentmethodsenabled, $course); ?></td>
+ </tr>
+
+
+ echeck form (not ready)
+
+
+ </table>
+ <input type="submit" name="echecksubmit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
+ </form>
+ </div>
+<!-- END ECHECK -->
+<?php } /* end: print_echeck_form */ ?>
+<?php
+function print_other_method($currentmethod, $paymentmethodsenabled, $course)
+{
+ if ($currentmethod == AN_METHOD_CC) {
+ $otheravailable = in_array(AN_METHOD_ECHECK, $paymentmethodsenabled);
+ $url = 'enrol.php?id='.$course->id.'&amp;paymentmethod='.AN_METHOD_ECHECK;
+ $stringtofetch = 'usingecheckmethod';
+ }
+ else {
+ $otheravailable = in_array(AN_METHOD_CC, $paymentmethodsenabled);
+ $url = 'enrol.php?id='.$course->id.'&amp;paymentmethod='.AN_METHOD_CC;
+ $stringtofetch = 'usingccmethod';
+ }
+ if ($otheravailable) {
+ $a = new stdClass;
+ $a->url = $url;
+ print_string($stringtofetch, "enrol_authorize", $a);
+ }
+}
+?>

0 comments on commit 2c50dc0

Please sign in to comment.