Skip to content
Browse files

+ 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.
  • Loading branch information...
1 parent 6459b8f commit 79c63c44157c102a720c10889448317878e71f7c ethem committed Aug 31, 2006
View
10 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 <ethem a.t evlice d.o.t com>
* @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)) {
View
12 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 @@
* 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');
/**#@-*/
/**#@+
View
5 enrol/authorize/db/install.xml
@@ -3,8 +3,9 @@
<TABLES>
<TABLE NAME="enrol_authorize" COMMENT="Holds all known information about authorize.net transactions" NEXT="enrol_authorize_refunds">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="cclastfour"/>
- <FIELD NAME="cclastfour" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="ccname"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="paymentmethod"/>
+ <FIELD NAME="paymentmethod" TYPE="char" LENGTH="6" NOTNULL="true" DEFAULT="cc" SEQUENCE="false" ENUM="true" ENUMVALUES="'cc', 'echeck'" PREVIOUS="id" NEXT="cclastfour"/>
+ <FIELD NAME="cclastfour" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="paymentmethod" NEXT="ccname"/>
<FIELD NAME="ccname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="cclastfour" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="ccname" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="transid"/>
View
9 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;
}
View
1 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',
View
10 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;
}
View
4 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);
View
32 enrol/authorize/enrol.php
@@ -175,9 +175,10 @@ function cc_submit($form, $course)
$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 @@ function cc_submit($form, $course)
$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 @@ function echeck_submit($form, $course)
$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 @@ function cron()
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) {
View
13 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("<b><font color='red'>$strs->error:</font></b>", $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';
}
View
2 enrol/authorize/version.php
@@ -1,6 +1,6 @@
<?php // $Id$
-$plugin->version = 2006081401;
+$plugin->version = 2006083100;
$plugin->requires = 2005072200;
?>

0 comments on commit 79c63c4

Please sign in to comment.
Something went wrong with that request. Please try again.