]> git.mjollnir.org Git - moodle.git/commitdiff
Autoconfigure credit card types. This is not a Makefile :)))
authorethem <ethem>
Wed, 30 Aug 2006 18:59:53 +0000 (18:59 +0000)
committerethem <ethem>
Wed, 30 Aug 2006 18:59:53 +0000 (18:59 +0000)
enrol/authorize/authorizenetlib.php
enrol/authorize/const.php
enrol/authorize/enrol.php

index 38ffc7795e4dfa0918b67f995e74b85bd280b48b..9f4b5ba4dc147720d79441dc2dbb7a0d05b21746 100644 (file)
@@ -83,11 +83,12 @@ function authorize_expired(&$order)
  * @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)
+function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $method=AN_METHOD_CC, $cctype=NULL)
 {
     global $CFG;
     static $conststring;
@@ -356,9 +357,10 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
     }
     else
     {
-        $reason = "reason" . $response[2];
-        $message = get_string($reason, "enrol_authorize");
-        if ($message == '[[' . $reason . ']]') {
+        $reasonno = $response[2];
+        $reasonstr = "reason" . $reasonno;
+        $message = get_string($reasonstr, "enrol_authorize");
+        if ($message == '[[' . $reasonstr . ']]') {
             $message = isset($response[3]) ? $response[3] : 'unknown error';
         }
         if ($method == AN_METHOD_CC and !empty($CFG->an_avs)) {
@@ -366,6 +368,36 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
             $stravs = get_string($avs, "enrol_authorize");
             $message .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs);
         }
+        if (!$test) { // Autoconfigure :)
+            switch($reasonno) {
+                // Credit card type isn't accepted
+                case AN_REASON_NOCCTYPE:
+                case AN_REASON_NOCCTYPE2:
+                {
+                    if (!empty($cctype)) {
+                        $ccaccepts = enrolment_plugin_authorize::get_list_of_creditcards();
+                        unset($ccaccepts[$cctype]);
+                        set_config('an_acceptccs', array_keys($ccaccepts));
+                        enrolment_plugin_authorize::email_to_admin("Autoconfigure; This card type " .
+                        "isn't accepted: $cctype. New config:", $ccaccepts);
+                    }
+                    break;
+                }
+                // Electronic checks aren't accepted
+                case AN_REASON_NOACH:
+                {
+                    // Not implemented yet.
+                    break;
+                }
+                // This echeck type isn't accepted
+                case AN_REASON_NOACHTYPE:
+                case AN_REASON_NOACHTYPE2:
+                {
+                    // Not implemented yet.
+                    break;
+                }
+            }
+        }
         return false;
     }
 }
index 4396fca8db14b7a2f74221724c9993ec43a34af3..f092f0d7e7b6a5e3caa42fb80d23ca63fb328cd3 100644 (file)
@@ -10,6 +10,24 @@ define('AN_METHOD_CC',     'CC');
 define('AN_METHOD_ECHECK', 'ECHECK');
 /**#@-*/
 
+/**#@+
+ * Some useful authorize.net responses.
+ * Autoconfigure payment methods and credit card types.
+ *
+ * NOCCTYPE: The merchant does not accept this type of credit card.
+ *    NOACH: ACH transactions are not accepted by this merchant.
+ *  ACHONLY: This merchant accepts ACH transactions only;
+ *           no credit card transactions are accepted.
+ *
+ */
+define('AN_REASON_NOCCTYPE', 17);
+define('AN_REASON_NOCCTYPE2', 28);
+define('AN_REASON_NOACH', 18);
+define('AN_REASON_ACHONLY', 56);
+define('AN_REASON_NOACHTYPE', 245);
+define('AN_REASON_NOACHTYPE2', 246);
+/**#@-*/
+
 /**#@+
  * E-Check types
  *
index b3ff93cac829609963b54b4b49ff41e44aeae26e..b3ff23699408d9a64e1bc39926e1635ed032e295 100755 (executable)
@@ -222,7 +222,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);
+        $success = authorize_action($order, $message, $extra, $action, $form->cctype);
         if (!$success) {
             enrolment_plugin_authorize::email_to_admin($message, $order);
             $this->authorizeerrors['header'] = $message;
@@ -327,6 +327,13 @@ class enrolment_plugin_authorize
         global $CFG, $USER, $SESSION;
         require_once('authorizenetlib.php');
 
+        enrolment_plugin_authorize::prevent_double_paid($course);
+
+        $useripno = getremoteaddr();
+        $curcost = enrolment_plugin_authorize::get_course_cost($course);
+
+
+        return; // not implemented yet
     }
 
     function validate_cc_form($form)
@@ -392,6 +399,7 @@ class enrolment_plugin_authorize
     function validate_echeck_form($form)
     {
         global $CFG;
+        require_once('abaval.php');
 
 
         return true;