From: ethem Date: Wed, 30 Aug 2006 18:59:53 +0000 (+0000) Subject: Autoconfigure credit card types. This is not a Makefile :))) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=35f4a0772a46ce123b428cf018116663ce850acb;p=moodle.git Autoconfigure credit card types. This is not a Makefile :))) --- diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index 38ffc7795e..9f4b5ba4dc 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.php @@ -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 * @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 .= "
" . 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; } } diff --git a/enrol/authorize/const.php b/enrol/authorize/const.php index 4396fca8db..f092f0d7e7 100644 --- a/enrol/authorize/const.php +++ b/enrol/authorize/const.php @@ -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 * diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index b3ff93cac8..b3ff236994 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -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;