]> git.mjollnir.org Git - moodle.git/commitdiff
+ New ENUM field: paymentmethod(cc,echeck);
authorethem <ethem>
Thu, 31 Aug 2006 18:24:37 +0000 (18:24 +0000)
committerethem <ethem>
Thu, 31 Aug 2006 18:24:37 +0000 (18:24 +0000)
    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.

enrol/authorize/authorizenetlib.php
enrol/authorize/const.php
enrol/authorize/db/install.xml
enrol/authorize/db/mysql.php
enrol/authorize/db/mysql.sql
enrol/authorize/db/postgres7.php
enrol/authorize/db/postgres7.sql
enrol/authorize/enrol.php
enrol/authorize/locallib.php
enrol/authorize/version.php

index 61ccee00f4ed8fd128df370765e89c2dd8782607..272178a0047aec2f2da0e71573c27fefac3995e5 100644 (file)
@@ -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)) {
index 4396fca8db14b7a2f74221724c9993ec43a34af3..e7f4c10a5e1af44fa80fa3bf0f2fb0c12d1f5de3 100644 (file)
@@ -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');
 /**#@-*/
 
 /**#@+
index 63bf767969f7d10592238e09da921af3895a3277..72705335adc35c43e7a3ffed1fa885a2447c7cf4 100644 (file)
@@ -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"/>
index afd558de54acb4d875cee468defea97fa4c9fb92..ea193d4269fb7872ba34bc8ff6f2b1d819c35016 100755 (executable)
@@ -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;
 }
 
index 1946160c658b0e6f1514275684546f43a6d37db3..e0bd8c1d37cd45172fb5ad95c4edef180cce51d6 100755 (executable)
@@ -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',
index 18fae57242ade388bd05c624a0521bc139e510ff..107e1d2063ddf78ac6883272dbd8eb84a7221baa 100644 (file)
@@ -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;
 }
 
index 91398f80ab231c8ecdfd8a3380103eb77b5aafec..8f789e7aec8b57bf518909ac47be93ab1ccb3808 100644 (file)
@@ -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);
index 2b1a36bf414b8548559d33e9e835c68cf90a4ed9..cf0a04a25c62ec72b31b7b44bf2e70316109ff49 100755 (executable)
@@ -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) {
index a923dffa923e4d8a6cb5508323dc393380fe8bc8..3d211ce49fd47a66c3e533408f520c611bd35a73 100644 (file)
@@ -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';
         }
index 15513fbcfdc02ec05ee672fa7137ee3cd620f9d7..d038af9a372b2b7b9591827bf8623f3129161371 100755 (executable)
@@ -1,6 +1,6 @@
 <?php // $Id$
 
-$plugin->version  = 2006081401;
+$plugin->version  = 2006083100;
 $plugin->requires = 2005072200;
 
 ?>