Permalink
Browse files

* Update record as soon as possible. If update/insert record fails e…

…mail to admin to have update manually.

 * ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
   This is last change to ignore request for user.
 * Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
   Now, these are static:
   get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
 * Some mtrace cleanup. Removed default new line.

This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
  • Loading branch information...
1 parent b245d2e commit fc9e83ed5c09e4c07865baef0307cd7b1bae9b1f ethem committed Jul 24, 2006
Showing with 181 additions and 190 deletions.
  1. +38 −22 enrol/authorize/authorizenetlib.php
  2. +2 −2 enrol/authorize/config.html
  3. +3 −3 enrol/authorize/enrol.html
  4. +136 −150 enrol/authorize/enrol.php
  5. +2 −13 enrol/authorize/locallib.php
@@ -15,8 +15,8 @@
/**
* Gets settlement date and time
*
- * @param int $time Processed time, usually now.
- * @return int Settlement date
+ * @param int $time Time processed, usually now.
+ * @return int Settlement date and time
*/
function authorize_getsettletime($time)
{
@@ -54,35 +54,34 @@ function authorize_expired(&$order)
{
static $timediff30;
- if (empty($timediff30)) {
- $timediff30 = authorize_getsettletime(time()) - (30 * 24 * 3600);
- }
-
if ($order->status == AN_STATUS_EXPIRE) {
return true;
}
elseif ($order->status != AN_STATUS_AUTH) {
return false;
}
- $exp = (authorize_getsettletime($order->timecreated) < $timediff30);
+ if (empty($timediff30)) {
+ $timediff30 = authorize_getsettletime(time()) - (30 * 24 * 3600);
+ }
- if ($exp) {
+ $isexpired = (authorize_getsettletime($order->timecreated) < $timediff30);
+ if ($isexpired) {
$order->status = AN_STATUS_EXPIRE;
update_record('enrol_authorize', $order);
}
-
- return $exp;
+ return $isexpired;
}
/**
- * Performs an action on authorize.net
+ * Performs an action on authorize.net and updates/inserts records. If record update fails,
+ * sends email to admin.
*
* @param object &$order Which transaction data will be sent. See enrol_authorize table.
- * @param string &$message Information about error messages.
- * @param object &$extra Extra transaction data.
+ * @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_*
- * @return bool true, transaction was successful, false otherwise.
+ * @return bool true Transaction was successful, false otherwise. Use $message for reason.
* @author Ethem Evlice <ethem a.t evlice d.o.t com>
* @uses $CFG
*/
@@ -117,12 +116,12 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$action = intval($action);
- if (empty($order) || empty($order->id)) {
+ if (empty($order) or empty($order->id)) {
$message = "Check order->id!";
return false;
}
- elseif ($action <= AN_ACTION_NONE || $action > AN_ACTION_VOID) {
- $message = "No action taken!";
+ elseif ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
+ $message = "Invalid action!";
return false;
}
@@ -187,11 +186,10 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
return false;
}
if (empty($extra)) {
- $message = "need extra fields for CREDIT!";
+ $message = "Need extra fields to REFUND!";
return false;
}
$total = floatval($extra->sum) + floatval($extra->amount);
- unset($extra->sum); // this is not used in refunds table.
if (($extra->amount == 0) || ($total > $order->amount)) {
$message = "Can be credited up to original amount.";
return false;
@@ -218,15 +216,15 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
}
}
else {
- $message = "Order status must be authorized, auth/captured or refunded!";
+ $message = "Order status must be authorized/pending capture or captured-refunded/pending settlement!";
return false;
}
$poststring .= '&x_type=VOID&x_trans_id=' . urlencode($order->transid);
break;
}
default: {
- $message = "Missing action? $action";
+ $message = "Invalid action: $action";
return false;
}
}
@@ -243,6 +241,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
return false;
}
+ @ignore_user_abort(true); // this is critical section
fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" .
"Host: $host\r\n" . $referer .
"Content-type: application/x-www-form-urlencoded\r\n" .
@@ -297,6 +296,10 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$order->status = AN_STATUS_AUTHCAPTURE;
$order->settletime = authorize_getsettletime(time());
}
+ if (! update_record('enrol_authorize', $order)) {
+ enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
+ "in table enrol_authorize. Please edit manually this record: ID=$order->id.", $order);
+ }
break;
}
case AN_ACTION_CREDIT:
@@ -306,12 +309,25 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE)
$extra->status = AN_STATUS_CREDIT;
$extra->transid = $transid;
$extra->settletime = authorize_getsettletime(time());
+ unset($extra->sum); // this is not used in refunds table.
+ if (! $extra->id = insert_record('enrol_authorize_refunds', $extra)) {
+ enrolment_plugin_authorize::email_to_admin("Error while trying to insert data " .
+ "into table enrol_authorize_refunds. Please add manually this record:", $extra);
+ }
break;
}
case AN_ACTION_VOID:
{
- $order->status = AN_STATUS_VOID;
+ $tableupdate = 'enrol_authorize';
+ if ($order->status == AN_STATUS_CREDIT) {
+ $tableupdate = 'enrol_authorize_refunds';
+ }
// dont't update settletime
+ $order->status = AN_STATUS_VOID;
+ if (! update_record($tableupdate, $order)) {
+ enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
+ "in table $tableupdate. Please edit manually this record: ID=$order->id.", $order);
+ }
break;
}
default: return false;
@@ -31,7 +31,7 @@
}
if (!isset($frm->acceptccs)) {
- $frm->acceptccs = array_keys(get_list_of_creditcards());
+ $frm->acceptccs = array_keys(enrolment_plugin_authorize::get_list_of_creditcards());
$CFG->an_acceptccs = implode(',', $frm->acceptccs);
}
@@ -127,7 +127,7 @@
<tr valign="top">
<td align="right">an_acceptccs:</td>
<td><?php
- $allccs = get_list_of_creditcards(true);
+ $allccs = enrolment_plugin_authorize::get_list_of_creditcards(true);
foreach ($allccs as $key => $val) {
print_checkbox('acceptccs[]', $key, stristr($CFG->an_acceptccs, $key) !== false, $val); echo "<br />\n";
}
@@ -1,6 +1,6 @@
<?php // $Id$
-$this->prevent_double_paid($course);
+enrolment_plugin_authorize::prevent_double_paid($course);
$formvars = array('password', 'ccaddress', 'cccity', 'ccstate', 'cccountry', 'cczip',
'ccfirstname', 'cclastname', 'cc', 'ccexpiremm', 'ccexpireyyyy', 'cctype', 'cvv');
@@ -10,7 +10,7 @@
}
}
-$curcost = $this->get_course_cost($course);
+$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;
@@ -60,7 +60,7 @@
<tr>
<td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
<td align="left"><?php
- choose_from_menu(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']); }
?>
</td>
Oops, something went wrong.

0 comments on commit fc9e83e

Please sign in to comment.