From: ethem Date: Thu, 31 Aug 2006 18:24:37 +0000 (+0000) Subject: + New ENUM field: paymentmethod(cc,echeck); X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=79c63c44157c102a720c10889448317878e71f7c;p=moodle.git + New ENUM field: paymentmethod(cc,echeck); Store in database and when calling authorize_action() pass this method. Hence, removed $method=AN_METHOD_CC from this function. If a refund will be do, unset($order->paymentmethod); Because this field comes when joining(enrol_authorize) + AN_METHOD_CC and AN_METHOD_ECHECK is now lower case, because these fields are stored in database as enum. Eloy's response: They are lowercase because we decided to use lowercase identifiers everywhere and enum contents are, from a DB perspective, identifiers. Ok, NP. :)) set_config('an_acceptmethods', strtolower($CFG->an_acceptmethods)); solves this. --- diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index 61ccee00f4..272178a004 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.php @@ -89,13 +89,12 @@ function authorize_expired(&$order) * @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_* - * @param string $method Transaction method. AN_METHOD_CC or AN_METHOD_ECHECK * @param string $cctype Credit card type, used internally to configure automatically types. * @return bool true Transaction was successful, false otherwise. Use $message for reason. * @author Ethem Evlice * @uses $CFG */ -function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $method=AN_METHOD_CC, $cctype=NULL) +function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $cctype=NULL) { global $CFG; static $conststring; @@ -126,6 +125,7 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ return false; } + $method = $order->paymentmethod; if (empty($method)) { $method = AN_METHOD_CC; } @@ -351,7 +351,11 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ } case AN_ACTION_VOID: { - $tableupdate = ($order->status == AN_STATUS_CREDIT) ? 'enrol_authorize_refunds' : 'enrol_authorize'; + $tableupdate = 'enrol_authorize'; + if ($order->status == AN_STATUS_CREDIT) { + $tableupdate = 'enrol_authorize_refunds'; + unset($order->paymentmethod); + } $order->status = AN_STATUS_VOID; // don't update order->settletime if (! update_record($tableupdate, $order)) { diff --git a/enrol/authorize/const.php b/enrol/authorize/const.php index 4396fca8db..e7f4c10a5e 100644 --- a/enrol/authorize/const.php +++ b/enrol/authorize/const.php @@ -6,8 +6,8 @@ * Credit Card (CC) * ECheck (ECHECK) */ -define('AN_METHOD_CC', 'CC'); -define('AN_METHOD_ECHECK', 'ECHECK'); +define('AN_METHOD_CC', 'cc'); +define('AN_METHOD_ECHECK', 'echeck'); /**#@-*/ /**#@+ @@ -18,10 +18,10 @@ define('AN_METHOD_ECHECK', 'ECHECK'); * Telephone-Initiated Entry (TEL) * Internet-Initiated Entry (WEB) */ -define('AN_ECHECK_CCD', 'CCD'); -define('AN_ECHECK_PPD', 'PPD'); -define('AN_ECHECK_TEL', 'TEL'); -define('AN_ECHECK_WEB', 'WEB'); +define('AN_ECHECK_CCD', 'ccd'); +define('AN_ECHECK_PPD', 'ppd'); +define('AN_ECHECK_TEL', 'tel'); +define('AN_ECHECK_WEB', 'web'); /**#@-*/ /**#@+ diff --git a/enrol/authorize/db/install.xml b/enrol/authorize/db/install.xml index 63bf767969..72705335ad 100644 --- a/enrol/authorize/db/install.xml +++ b/enrol/authorize/db/install.xml @@ -3,8 +3,9 @@ - - + + + diff --git a/enrol/authorize/db/mysql.php b/enrol/authorize/db/mysql.php index afd558de54..ea193d4269 100755 --- a/enrol/authorize/db/mysql.php +++ b/enrol/authorize/db/mysql.php @@ -123,6 +123,15 @@ function enrol_authorize_upgrade($oldversion=0) { } } + if ($oldversion < 2006083100) { + // enums are lower case + if (isset($CFG->an_acceptmethods)) { + set_config('an_acceptmethods', strtolower($CFG->an_acceptmethods)); + } + // new ENUM field: paymentmethod(cc,echeck) + execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD paymentmethod enum('cc', 'echeck') NOT NULL default 'cc' AFTER `id`", true); + } + return $result; } diff --git a/enrol/authorize/db/mysql.sql b/enrol/authorize/db/mysql.sql index 1946160c65..e0bd8c1d37 100755 --- a/enrol/authorize/db/mysql.sql +++ b/enrol/authorize/db/mysql.sql @@ -1,5 +1,6 @@ CREATE TABLE `prefix_enrol_authorize` ( `id` int(10) unsigned NOT NULL auto_increment, + `paymentmethod` enum('cc', 'echeck') NOT NULL default 'cc', `cclastfour` int(4) unsigned NOT NULL default '0', `ccname` varchar(255) NOT NULL default '', `courseid` int(10) unsigned NOT NULL default '0', diff --git a/enrol/authorize/db/postgres7.php b/enrol/authorize/db/postgres7.php index 18fae57242..107e1d2063 100644 --- a/enrol/authorize/db/postgres7.php +++ b/enrol/authorize/db/postgres7.php @@ -134,6 +134,16 @@ function enrol_authorize_upgrade($oldversion=0) { } } + if ($oldversion < 2006083100) { + // enums are lower case + if (isset($CFG->an_acceptmethods)) { + set_config('an_acceptmethods', strtolower($CFG->an_acceptmethods)); + } + // new ENUM field: paymentmethod(cc,echeck) + table_column('enrol_authorize', '', 'paymentmethod', 'varchar', '6', '', 'cc', 'not null'); + execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize ADD CONSTRAINT enroauth_pay_ck CHECK (paymentmethod IN ('cc', 'echeck'))", true); + } + return $result; } diff --git a/enrol/authorize/db/postgres7.sql b/enrol/authorize/db/postgres7.sql index 91398f80ab..8f789e7aec 100644 --- a/enrol/authorize/db/postgres7.sql +++ b/enrol/authorize/db/postgres7.sql @@ -1,5 +1,6 @@ CREATE TABLE prefix_enrol_authorize ( id SERIAL PRIMARY KEY, + paymentmethod varchar(6) default 'cc' NOT NULL, cclastfour integer DEFAULT 0 NOT NULL, ccname varchar(255) DEFAULT '', courseid integer DEFAULT 0 NOT NULL, @@ -9,7 +10,8 @@ CREATE TABLE prefix_enrol_authorize ( timecreated integer DEFAULT 0 NOT NULL, settletime integer DEFAULT 0 NOT NULL, amount varchar(10) DEFAULT '0' NOT NULL, - currency varchar(3) DEFAULT 'USD' NOT NULL + currency varchar(3) DEFAULT 'USD' NOT NULL, + CONSTRAINT enroauth_pay_ck CHECK (paymentmethod IN ('cc', 'echeck')) ); CREATE INDEX prefix_enrol_authorize_courseid_idx ON prefix_enrol_authorize(courseid); diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index 2b1a36bf41..cf0a04a25c 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -175,9 +175,10 @@ class enrolment_plugin_authorize $curcost = enrolment_plugin_authorize::get_course_cost($course); $exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy; - // NEW ORDER + // NEW CC ORDER $timenow = time(); $order = new stdClass(); + $order->paymentmethod = AN_METHOD_CC; $order->cclastfour = substr($form->cc, -4); $order->ccname = $form->ccfirstname . " " . $form->cclastname; $order->courseid = $course->id; @@ -222,7 +223,7 @@ class enrolment_plugin_authorize $message = ''; $an_review = !empty($CFG->an_review); $action = $an_review ? AN_ACTION_AUTH_ONLY : AN_ACTION_AUTH_CAPTURE; - $success = authorize_action($order, $message, $extra, $action, AN_METHOD_CC, $form->cctype); + $success = authorize_action($order, $message, $extra, $action, $form->cctype); if (!$success) { enrolment_plugin_authorize::email_to_admin($message, $order); $this->authorizeerrors['header'] = $message; @@ -332,8 +333,31 @@ class enrolment_plugin_authorize $useripno = getremoteaddr(); $curcost = enrolment_plugin_authorize::get_course_cost($course); + // NEW ECHECK ORDER + $timenow = time(); + $order = new stdClass(); + $order->paymentmethod = AN_METHOD_ECHECK; + $order->cclastfour = 0; + $order->ccname = $form->firstname . ' ' . $form->lastname; + $order->courseid = $course->id; + $order->userid = $USER->id; + $order->status = AN_STATUS_NONE; // it will be changed... + $order->settletime = 0; // cron changes this. + $order->transid = 0; // Transaction Id + $order->timecreated = $timenow; + $order->amount = $curcost['cost']; + $order->currency = $curcost['currency']; + /////////// not implemented yet + /* + $order->id = insert_record("enrol_authorize", $order); + if (!$order->id) { + enrolment_plugin_authorize::email_to_admin("Error while trying to insert new data", $order); + $this->authorizeerrors['header'] = "Insert record error. Admin has been notified!"; + return; + } + */ - return; // not implemented yet + return; } function validate_cc_form($form) @@ -837,7 +861,7 @@ class enrolment_plugin_authorize foreach ($orders as $order) { $message = ''; $extra = NULL; - $success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE, AN_METHOD_CC); + $success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE); if ($success) { $timestart = $timeend = 0; if ($order->enrolperiod) { diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php index a923dffa92..3d211ce49f 100644 --- a/enrol/authorize/locallib.php +++ b/enrol/authorize/locallib.php @@ -73,7 +73,7 @@ function authorize_print_orders() $table->pageable(true); $table->setup(); - $select = "SELECT E.id, E.transid, E.courseid, E.userid, E.status, E.ccname, E.timecreated, E.settletime "; + $select = "SELECT E.id, E.paymentmethod, E.transid, E.courseid, E.userid, E.status, E.ccname, E.timecreated, E.settletime "; $from = "FROM {$CFG->prefix}enrol_authorize E "; $where = "WHERE (1=1) "; @@ -228,7 +228,7 @@ function authorize_print_order_details($orderno) else { $message = ''; $extra = NULL; - $success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE, AN_METHOD_CC); + $success = authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE); if (!$success) { $table->data[] = array("$strs->error:", $message); } @@ -362,7 +362,7 @@ function authorize_print_order_details($orderno) } } else { // cancel refunded transaction - $sql = "SELECT R.*, E.courseid FROM {$CFG->prefix}enrol_authorize_refunds R " . + $sql = "SELECT R.*, E.courseid, E.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds R " . "INNER JOIN {$CFG->prefix}enrol_authorize E ON R.orderid = E.id " . "WHERE R.id = '$suborderno' AND R.orderid = '$orderno' AND R.status = '" .AN_STATUS_CREDIT. "'"; @@ -462,7 +462,7 @@ function authorize_print_order_details($orderno) $strs->action, $authstrs->amount); - $sql = "SELECT R.*, E.courseid FROM {$CFG->prefix}enrol_authorize_refunds R " . + $sql = "SELECT R.*, E.courseid, E.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds R " . "INNER JOIN {$CFG->prefix}enrol_authorize E ON R.orderid = E.id " . "WHERE R.orderid = '$orderno'"; @@ -564,8 +564,9 @@ function authorize_get_status_action($order) $ret->status = 'capturedsettled'; } else { - if (has_capability('enrol/authorize:managepayments', $context)) { - $ret->actions = array(ORDER_VOID); + if ($order->paymentmethod == AN_METHOD_CC && + has_capability('enrol/authorize:managepayments', $context)) { + $ret->actions = array(ORDER_VOID); } $ret->status = 'capturedpendingsettle'; } diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php index 15513fbcfd..d038af9a37 100755 --- a/enrol/authorize/version.php +++ b/enrol/authorize/version.php @@ -1,6 +1,6 @@ version = 2006081401; +$plugin->version = 2006083100; $plugin->requires = 2005072200; ?>