From 3abe79ff52b570c26bf97ea06d0467bbc4573a91 Mon Sep 17 00:00:00 2001 From: ethem Date: Mon, 11 Feb 2008 15:18:48 +0000 Subject: [PATCH] Moved libraries to index.php --- enrol/authorize/authorizenetlib.php | 10 ++-------- enrol/authorize/index.php | 3 +++ enrol/authorize/locallib.php | 16 ++++++---------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index 71fdcdc234d..1e3a82926fe 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.php @@ -204,13 +204,8 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ $message = "Order must be credited within 120 days!"; return AN_RETURNZERO; } - if (empty($extra)) { - $message = "Need extra fields to REFUND!"; - return AN_RETURNZERO; - } - $total = floatval($extra->sum) + floatval($extra->amount); - if (($extra->amount == 0) || ($total > $order->amount)) { - $message = "Can be credited up to original amount."; + if (empty($extra->amount)) { + $message = "No valid amount!"; return AN_RETURNZERO; } $poststring .= '&x_type=CREDIT&x_trans_id=' . urlencode($order->transid); @@ -336,7 +331,6 @@ 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)) { unset($extra->id); email_to_admin("Error while trying to insert data " . diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php index 552cfba5ec0..9db5f4817c1 100644 --- a/enrol/authorize/index.php +++ b/enrol/authorize/index.php @@ -2,7 +2,10 @@ /// Load libraries require_once('../../config.php'); + require_once('const.php'); require_once('locallib.php'); + require_once('localfuncs.php'); + require_once('authorizenetlib.php'); /// Parameters $orderid = optional_param('order', 0, PARAM_INT); diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php index 7746b9c77fc..e6cc0d5f812 100644 --- a/enrol/authorize/locallib.php +++ b/enrol/authorize/locallib.php @@ -4,9 +4,6 @@ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); } -require_once('const.php'); -require_once('authorizenetlib.php'); - define('ORDER_CAPTURE', 'capture'); define('ORDER_DELETE', 'delete'); define('ORDER_REFUND', 'refund'); @@ -304,17 +301,14 @@ function authorize_print_order_details($orderno) error(get_string('youcantdo', 'enrol_authorize', $a)); } - $extra = new stdClass; - $extra->sum = 0.0; - $extra->orderid = $orderno; - + $refunded = 0.0; $sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " . "WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')"; - if (($refund = get_record_sql($sql))) { - $extra->sum = floatval($refund->refunded); + if (($refundval = get_field_sql($sql))) { + $refunded = floatval($refundval); } - $upto = format_float($order->amount - $extra->sum, 2); + $upto = format_float($order->amount - $refunded, 2); if ($upto <= 0) { error("Refunded to original amount."); } @@ -333,6 +327,8 @@ function authorize_print_order_details($orderno) $strcanbecredit
"); } else { + $extra = new stdClass; + $extra->orderid = $orderno; $extra->amount = $amount; $message = ''; $success = authorize_action($order, $message, $extra, AN_ACTION_CREDIT);