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.
* @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;
return false;
}
+ $method = $order->paymentmethod;
if (empty($method)) {
$method = AN_METHOD_CC;
}
}
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)) {
* 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');
/**#@-*/
/**#@+
* 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');
/**#@-*/
/**#@+
<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"/>
}
}
+ 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;
}
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',
}
}
+ 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;
}
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,
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);
$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;
$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;
$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)
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) {
$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) ";
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);
}
}
}
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. "'";
$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'";
$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';
}
<?php // $Id$
-$plugin->version = 2006081401;
+$plugin->version = 2006083100;
$plugin->requires = 2005072200;
?>