Permalink
Browse files

Autoconfigure credit card types. This is not a Makefile :)))

  • Loading branch information...
1 parent 8146506 commit 35f4a0772a46ce123b428cf018116663ce850acb ethem committed Aug 30, 2006
Showing with 63 additions and 5 deletions.
  1. +36 −4 enrol/authorize/authorizenetlib.php
  2. +18 −0 enrol/authorize/const.php
  3. +9 −1 enrol/authorize/enrol.php
View
40 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 <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,16 +357,47 @@ 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)) {
$avs = "avs" . strtolower($response[5]);
$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;
}
}
View
18 enrol/authorize/const.php
@@ -11,6 +11,24 @@
/**#@-*/
/**#@+
+ * 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
*
* Cash Concentration or Disbursement (CCD)
View
10 enrol/authorize/enrol.php
@@ -222,7 +222,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);
+ $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 @@ function echeck_submit($form, $course)
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 @@ function validate_cc_form($form)
function validate_echeck_form($form)
{
global $CFG;
+ require_once('abaval.php');
return true;

0 comments on commit 35f4a07

Please sign in to comment.