Permalink
Browse files

AVS and Reason messages.

  • Loading branch information...
ethem
ethem committed Jan 19, 2006
1 parent 9d025f4 commit c1a91db06ebace4481a3924dce3c41b38c7ff011
Showing with 239 additions and 216 deletions.
  1. +35 −31 enrol/authorize/action.php
  2. +37 −8 enrol/authorize/enrol.html
  3. +163 −173 enrol/authorize/enrol.php
  4. +4 −4 enrol/authorize/index.php
View
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php // $Id$
define('AN_HOST', 'secure.authorize.net');
define('AN_HOST_TEST', 'certification.authorize.net');
@@ -10,7 +10,7 @@
define('AN_DELIM', '|');
define('AN_ENCAP', '"');
-require_once("const.php");
+require_once $CFG->dirroot.'/enrol/authorize/const.php';
/**
* Gets settlement date and time
@@ -42,7 +42,7 @@ function getsettletime($time)
function settled($order)
{
return (($order->status == AN_STATUS_AUTHCAPTURE || $order->status == AN_STATUS_CREDIT) &&
- $order->settletime > 0 && $order->settletime < time());
+ ($order->settletime > 0) && ($order->settletime < time()));
}
/**
@@ -87,13 +87,12 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
$action = intval($action);
- // sanity check
if (empty($order) || empty($order->id)) {
- $message = "check order->id!";
+ $message = "Check order->id!";
return false;
}
elseif ($action <= AN_ACTION_NONE || $action > AN_ACTION_VOID) {
- $message = "no action taken!";
+ $message = "No action taken!";
return false;
}
@@ -105,11 +104,11 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
case AN_ACTION_AUTH_CAPTURE:
{
if ($order->status != AN_STATUS_NONE) {
- $message = "order->status must be AN_STATUS_NONE!";
+ $message = "Order status must be AN_STATUS_NONE(0)!";
return false;
}
if (empty($extra)) {
- $message = "need extra fields!";
+ $message = "Need extra fields!";
return false;
}
$ext = (array)$extra;
@@ -124,7 +123,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
case AN_ACTION_PRIOR_AUTH_CAPTURE:
{
if ($order->status != AN_STATUS_AUTH) {
- $message = "order->status must be AN_STATUS_AUTH!";
+ $message = "Order status must be authorized!";
return false;
}
$timediff = $timenowsettle - (30 * 3600 * 24);
@@ -141,26 +140,23 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
case AN_ACTION_CREDIT:
{
if ($order->status != AN_STATUS_AUTHCAPTURE) {
- $message = "order->status must be AN_STATUS_AUTHCAPTURE!";
+ $message = "Order status must be authorized/captured!";
return false;
}
if (!settled($order)) {
- $message = "Order wasn't settled, try VOID. Check Cut-Off time if it fails!";
+ $message = "Order must be settled. Try VOID, check Cut-Off time if it fails!";
return false;
}
- // 120 days
$timediff = $timenowsettle - (120 * 3600 * 24);
if ($order->settletime < $timediff) {
- $message = "Order can be credited within 120 days!";
+ $message = "Order must be credited within 120 days!";
return false;
}
- // extra fields
if (empty($extra)) {
$message = "need extra fields for CREDIT!";
return false;
}
- // up to original amount
- $total = doubleval($extra->sum) + doubleval($extra->amount);
+ $total = floatval($extra->sum) + floatval($extra->amount);
if (($extra->amount == 0) || ($total > $order->amount)) {
$message = "Can be credited up to original amount.";
return false;
@@ -175,11 +171,10 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
case AN_ACTION_VOID:
{
if ($order->status == AN_STATUS_AUTH) {
- // 30 days for authonly, make it expired (**settletime**)
$timediff = $timenowsettle - (30 * 3600 * 24);
$timecreatedsettle = getsettletime($order->timecreated);
if ($timecreatedsettle < $timediff) {
- $message = "Auth_only transaction must be voided within 30 days. EXPIRED!";
+ $message = "Authorized transaction must be voided within 30 days. EXPIRED!";
$order->status = AN_STATUS_EXPIRE;
return false;
}
@@ -191,35 +186,34 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
}
}
else {
- $message = "order->status must be AUTH, AUTH_CAPTURE or CREDIT!";
+ $message = "Order status must be authorized, auth/captured or refunded!";
return false;
}
$poststring .= '&x_type=VOID&x_trans_id=' . urlencode($order->transid);
break;
}
- default: { // ???
- $message = "missing action: $action";
+ default: {
+ $message = "Missing action? $action";
return false;
}
}
- // referer
- $anrefererheader = '';
+ $referer = '';
if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
- $anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
+ $referer = "Referer: $CFG->an_referer\r\n";
}
$response = array();
- $connect_host = $an_test ? AN_HOST_TEST : AN_HOST;
- $fp = fsockopen("ssl://" . $connect_host, AN_PORT, $errno, $errstr, 60);
+ $host = $an_test ? AN_HOST_TEST : AN_HOST;
+ $fp = fsockopen("ssl://" . $host, AN_PORT, $errno, $errstr, 60);
if (!$fp) {
$message = "no connection: $errstr ($errno)";
return false;
}
fwrite($fp, "POST " . AN_PATH . " HTTP/1.0\r\n" .
- "Host: $connect_host\r\n" . $anrefererheader .
+ "Host: $host\r\n" . $referer .
"Content-type: application/x-www-form-urlencoded\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($poststring) . "\r\n\r\n" .
@@ -254,15 +248,16 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
if ($response[0] == AN_APPROVED)
{
- if ($an_test || intval($response[6]) == 0) {
+ $transid = intval($response[6]);
+ if ($an_test || $transid == 0) {
return true; // don't update original transaction in test mode.
}
switch ($action) {
case AN_ACTION_AUTH_ONLY:
case AN_ACTION_AUTH_CAPTURE:
case AN_ACTION_PRIOR_AUTH_CAPTURE:
{
- $order->transid = strval($response[6]); // TransactionID
+ $order->transid = $transid;
if ($action == AN_ACTION_AUTH_ONLY) {
$order->status = AN_STATUS_AUTH;
// dont't update settletime
@@ -277,7 +272,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
// Credit generates new transaction id.
// So, $extra must be updated, not $order.
$extra->status = AN_STATUS_CREDIT;
- $extra->transid = strval($response[6]);
+ $extra->transid = $transid;
$extra->settletime = getsettletime(time());
break;
}
@@ -293,7 +288,16 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
}
else
{
- $message = isset($response[3]) ? $response[3] : 'unknown error';
+ $reason = "reason" . $response[2];
+ $message = get_string($reason, "enrol_authorize");
+ if ($message == '[[' . $reason . ']]') {
+ $message = isset($response[3]) ? $response[3] : 'unknown error';
+ }
+ if (!empty($CFG->an_avs)) {
+ $avs = "avs" . strtolower($response[5]);
+ $stravs = get_string($avs, "enrol_authorize");
+ $message .= "<br />" . get_string("avsresult", "enrol_authorize") . $stravs;
+ }
return false;
}
}
View
@@ -1,4 +1,24 @@
-<p align="center"><?php if (!empty($this->ccerrormsg)) { formerr($this->ccerrormsg); } ?></p>
+<?php // $Id$
+
+$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 = $this->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;
+
+?>
+
+<p align="center"><?php if (!empty($this->ccerrors['header'])) { formerr($this->ccerrors['header']); } ?></p>
<div align="center">
@@ -11,12 +31,14 @@
<table align="center" width="100%" border=0>
<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) ?>" /></td>
+ <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>
</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) ?>" /></td>
+ <input type="text" name="cclastname" size="8" value="<?php p($userlastname) ?>" />
+ <?php if (!empty($this->ccerrors['ccfirstlast'])) { formerr($this->ccerrors['ccfirstlast']); } ?></td>
</tr>
<tr>
<td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
@@ -31,6 +53,7 @@
$years[$i] = $i;
}
choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy);
+ if (!empty($this->ccerrors['ccexpire'])) { formerr($this->ccerrors['ccexpire']); }
?></td>
</tr>
<tr>
@@ -42,32 +65,38 @@
'swi' => 'Switch', 'dlt' => 'Delta', 'enr' => 'EnRoute'
);
choose_from_menu($CCTYPES, 'cctype', $form->cctype);
+ if (!empty($this->ccerrors['cctype'])) { formerr($this->ccerrors['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')); ?></td>
+ <?php helpbutton('', '', 'enrol_authorize', true, 'cvv', get_string('ccvvhelp', 'enrol_authorize')); ?>
+ <?php if (!empty($this->ccerrors['cvv'])) { formerr($this->ccerrors['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) ?>" /></td>
+ <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>
</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) ?>" /></td>
+ <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>
</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")."..."); ?></td>
+ <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>
</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) ?>" /></td>
+ <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>
</tr>
</table>
<input type="submit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
Oops, something went wrong.

0 comments on commit c1a91db

Please sign in to comment.