* @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 int $method Transaction method. AN_METHOD_CC or AN_METHOD_ECHECK
* @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)
+function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $method=AN_METHOD_CC)
{
global $CFG;
static $conststring;
$test = !empty($CFG->an_test);
if (!isset($conststring)) {
- $consdata = array(
+ $constdata = array(
'x_version' => '3.1',
'x_delim_data' => 'True',
'x_delim_char' => AN_DELIM,
'x_encap_char' => AN_ENCAP,
'x_relay_response' => 'FALSE',
- 'x_method' => 'CC',
- 'x_login' => $CFG->an_login,
- 'x_test_request' => $test ? 'TRUE' : 'FALSE'
+ 'x_login' => $CFG->an_login
);
$str = '';
- foreach($consdata as $ky => $vl) {
+ foreach($constdata as $ky => $vl) {
$str .= $ky . '=' . urlencode($vl) . '&';
}
$str .= (!empty($CFG->an_tran_key)) ?
'x_password=' . urlencode($CFG->an_password);
$conststring = $str;
+ $str = '';
}
- $action = intval($action);
-
if (empty($order) or empty($order->id)) {
$message = "Check order->id!";
return false;
}
- elseif ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
+
+ if (empty($method)) {
+ $method = AN_METHOD_CC;
+ }
+ elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) {
+ $message = "Missing method: $method";
+ return false;
+ }
+
+ if ($method == AN_METHOD_ECHECK) {
+ if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) {
+ $message = "Please perform AUTH_CAPTURE or CREDIT for echecks";
+ return false;
+ }
+ }
+
+ $action = intval($action);
+ if ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
$message = "Invalid action!";
return false;
}
$poststring = $conststring;
+ $poststring .= '&x_method=' . ($method==AN_METHOD_CC ? 'CC' : 'ECHECK');
+ $poststring .= '&x_test_request=' . ($test ? 'TRUE' : 'FALSE');
+ $timenowsettle = getsettletime(time());
switch ($action) {
case AN_ACTION_AUTH_ONLY:
if ($message == '[[' . $reason . ']]') {
$message = isset($response[3]) ? $response[3] : 'unknown error';
}
- if (!empty($CFG->an_avs)) {
+ if (!empty($CFG->an_avs) and $method == AN_METHOD_CC) {
$avs = "avs" . strtolower($response[5]);
$stravs = get_string($avs, "enrol_authorize");
$message .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs);
$frm->an_cutoff_min = (intval(round($timezone)) != intval($timezone)) ? 35 : 5;
}
+if (!isset($frm->acceptmethods)) {
+ if (empty($CFG->an_acceptmethods)) {
+ $frm->acceptmethods = array('cc');
+ $CFG->an_acceptmethods = implode(',', $frm->acceptmethods);
+ }
+ else {
+ $frm->acceptmethods = explode(',', $CFG->an_acceptmethods);
+ }
+}
+
if (!isset($frm->acceptccs)) {
$frm->acceptccs = array_keys(enrolment_plugin_authorize::get_list_of_creditcards());
$CFG->an_acceptccs = implode(',', $frm->acceptccs);
<td><?php print_string("antestmode", "enrol_authorize") ?></td>
</tr>
+<tr valign="top">
+ <td align="right">an_acceptmethods:</td>
+ <td><?php
+ $allmethods = array('CC','ECHECK');
+ foreach ($allmethods as $key) {
+ print_checkbox('acceptmethods[]', strtolower($key), stristr($CFG->an_acceptmethods, $key) !== false, $key); echo "<br />\n";
+ }
+ ?></td>
+ <td><?php print_string("adminacceptmethods", "enrol_authorize") ?></td>
+</tr>
+
<tr valign="top">
<td align="right">an_acceptccs:</td>
<td><?php
<?php // $Id$
+/**#@+
+ * Authorize.net methods.
+ *
+ * Credit Card (CC)
+ * ECheck (ECHECK)
+ */
+define('AN_METHOD_CC', 1);
+define('AN_METHOD_ECHECK', 2);
+/**#@-*/
+
+/**#@+
+ * E-Check types
+ *
+ * Cash Concentration or Disbursement (CCD)
+ * Prearranged Payment and Deposit Entry (PPD)
+ * 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');
+/**#@-*/
+
/**#@+
* Order status used in enrol_authorize table.
*
/**#@-*/
/**#@+
- * Actions used in authorize_action function.
+ * Actions used in authorizenet_action function.
*
* NONE: No action. Function always returns false.
* AUTH_ONLY: Used to authorize only, don't capture.
* CAPTURE_ONLY: Authorization code received from a bank over the phone and capture now.
- * PRIOR_AUTH_CAPTURE: Used to capture, it was authorized before.
* AUTH_CAPTURE: Used to authorize and capture.
+ * PRIOR_AUTH_CAPTURE: Used to capture, it was authorized before.
* CREDIT: Used to return funds to a customer's credit card.
* VOID: Used to cancel an exiting pending transaction.
*
-<?PHP //$Id$
+<?php //$Id$
// MySQL commands for upgrading this enrolment module
-<?PHP //$Id$
+<?php //$Id$
// PostgreSQL commands for upgrading this enrolment module
-<?php // $Id$
+<?php // $Id$
require_once($CFG->dirroot.'/enrol/enrol.class.php');
require_once($CFG->dirroot.'/enrol/authorize/const.php');
set_config('an_test', optional_param('an_test', 0, PARAM_BOOL));
set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL));
+ $acceptmethods = optional_param('acceptmethods', array('cc'), PARAM_ALPHA);
+ set_config('an_acceptmethods', implode(',', $acceptmethods));
+
$acceptccs = optional_param('acceptccs',
array_keys(enrolment_plugin_authorize::get_list_of_creditcards()),
PARAM_ALPHA);
$timenow = time();
$settlementtime = authorize_getsettletime($timenow);
$timediff30 = $settlementtime - (30 * $oneday);
-
$mconfig = get_config('enrol/authorize');
set_config('an_lastcron', $timenow, 'enrol/authorize');
-<?PHP // $Id$
+<?php // $Id$
/// Load libraries
require_once('../../config.php');
-<?PHP // $Id$
+<?php // $Id$
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
-<?PHP // $Id$
+<?php // $Id$
$plugin->version = 2006081401;
$plugin->requires = 2005072200;