* @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;
}
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)) {
$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;
}
}
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
*
$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;
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)
function validate_echeck_form($form)
{
global $CFG;
+ require_once('abaval.php');
return true;