diff --git a/enrol/authorize/action.php b/enrol/authorize/action.php index 61c0d5f59cc..196af10cbb7 100644 --- a/enrol/authorize/action.php +++ b/enrol/authorize/action.php @@ -1,15 +1,10 @@ dirroot.'/enrol/authorize/const.php'; /** @@ -61,7 +56,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE global $CFG; static $conststring; - $an_test = !empty($CFG->an_test); + $test = !empty($CFG->an_test); if (!isset($conststring)) { $consdata = array( @@ -72,7 +67,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE 'x_relay_response' => 'FALSE', 'x_method' => 'CC', 'x_login' => $CFG->an_login, - 'x_test_request' => $an_test ? 'TRUE' : 'FALSE' + 'x_test_request' => $test ? 'TRUE' : 'FALSE' ); $str = ''; foreach($consdata as $ky => $vl) { @@ -205,14 +200,14 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE } $response = array(); - $host = $an_test ? AN_HOST_TEST : AN_HOST; - $fp = fsockopen("ssl://" . $host, AN_PORT, $errno, $errstr, 60); + $host = $test ? 'certification.authorize.net' : 'secure.authorize.net'; + $fp = fsockopen("ssl://$host", 443, $errno, $errstr, 60); if (!$fp) { $message = "no connection: $errstr ($errno)"; return false; } - fwrite($fp, "POST " . AN_PATH . " HTTP/1.0\r\n" . + fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" . "Host: $host\r\n" . $referer . "Content-type: application/x-www-form-urlencoded\r\n" . "Connection: close\r\n" . @@ -249,7 +244,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE if ($response[0] == AN_APPROVED) { $transid = intval($response[6]); - if ($an_test || $transid == 0) { + if ($test || $transid == 0) { return true; // don't update original transaction in test mode. } switch ($action) { diff --git a/enrol/authorize/ccval.php b/enrol/authorize/ccval.php index b8936bf3eb6..26ebda999fc 100644 --- a/enrol/authorize/ccval.php +++ b/enrol/authorize/ccval.php @@ -123,4 +123,4 @@ function CCVal($Num, $Name = "n/a", $Exp = "") // evenly divisible by 10, it's cool! return ($GoodCard && $Total % 10 == 0); } -?> \ No newline at end of file +?> diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index 433c08a693e..3e252ade0e8 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -121,7 +121,7 @@ class enrolment_plugin extends enrolment_base $this->ccerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize'); } else { - $this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize'); + $this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize'); } return; } @@ -179,7 +179,7 @@ class enrolment_plugin extends enrolment_base } $SESSION->ccpaid = 1; // security check: don't duplicate payment - if (intval($order->transid) == 0) { // TEST MODE + if ($order->transid == 0) { // TEST MODE if ($an_review) { redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30'); } @@ -293,16 +293,29 @@ class enrolment_plugin extends enrolment_base if (empty($form->ccfirstname) || empty($form->cclastname)) { $this->ccerrors['ccfirstlast'] = get_string('missingfullname'); } - if (empty($form->cc)) $this->ccerrors['cc'] = get_string('missingcc', 'enrol_authorize'); - if (empty($form->cvv)) $this->ccerrors['cvv'] = get_string('missingcvv', 'enrol_authorize'); - if (empty($form->cctype)) $this->ccerrors['cctype'] = get_string('missingcctype', 'enrol_authorize'); + if (empty($form->cc)) { + $this->ccerrors['cc'] = get_string('missingcc', 'enrol_authorize'); + } + if (empty($form->cvv) || !is_int($form->cvv)) { + $this->ccerrors['cvv'] = get_string('missingcvv', 'enrol_authorize'); + } + if (empty($form->cctype)) { + $this->ccerrors['cctype'] = get_string('missingcctype', 'enrol_authorize'); + } if (!empty($CFG->an_avs)) { - if (empty($form->ccaddress)) $this->ccerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize'); - if (empty($form->cccity)) $this->ccerrors['cccity'] = get_string('missingcity'); - if (empty($form->cccountry)) $this->ccerrors['cccountry'] = get_string('missingcountry'); - if (empty($form->cczip)) $this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize'); + if (empty($form->ccaddress)) { + $this->ccerrors['ccaddress'] = get_string('missingaddress', 'enrol_authorize'); + } + if (empty($form->cccity)) { + $this->ccerrors['cccity'] = get_string('missingcity'); + } + if (empty($form->cccountry)) { + $this->ccerrors['cccountry'] = get_string('missingcountry'); + } + } + if (empty($form->cczip) || !is_int($form->cczip)) { + $this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize'); } - if (!empty($this->ccerrors)) { $this->ccerrors['header'] = get_string('someerrorswerefound'); $return = false; @@ -327,8 +340,8 @@ class enrolment_plugin extends enrolment_base /** * get_course_cost * - * @param unknown_type $course - * @return unknown + * @param object $course + * @return array * @access private */ function get_course_cost($course) @@ -574,32 +587,24 @@ class enrolment_plugin extends enrolment_base delete_records_select('enrol_authorize', $select); } - if (empty($CFG->an_review) || !empty($CFG->an_test)) { - return; - } - - if (intval($CFG->an_capture_day < 1)) { - if (empty($CFG->an_emailexpired) || intval($mconfig->an_nextmail) > $timenow) { - return; - } + if (!empty($CFG->an_emailexpired) && intval($mconfig->an_nextmail) < $timenowsettle) { + set_config('an_nextmail', $timenowsettle + $oneday + 1, 'enrol/authorize'); $timediffem = $timenowsettle - ((30 - intval($CFG->an_emailexpired)) * $oneday); $select = "(status = '" . AN_STATUS_AUTH . "') AND " . "(timecreated < '$timediffem') AND (timecreated > '$timediff30')"; - if (!$count = count_records_select('enrol_authorize', $select)) { - return; + if ($count = count_records_select('enrol_authorize', $select)) { + $a->pending = $count; + $a->days = $CFG->an_emailexpired; + $a->enrolurl = "$CFG->wwwroot/$CFG->admin/users.php"; + $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH; + $message = get_string('pendingordersemail', 'enrol_authorize', $a); + $adminuser = get_admin(); + email_to_user($adminuser, $adminuser, "WARNING: PENDING PAYMENTS", $a); } - $a->pending = $count; - $a->days = $CFG->an_emailexpired; - $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=" . AN_STATUS_AUTH; - $a->enrolurl = "$CFG->wwwroot/$CFG->admin/users.php"; - $message = get_string('pendingordersemail', 'enrol_authorize', $a); - $adminuser = get_admin(); - email_to_user($adminuser, $adminuser, "WARNING: PENDING PAYMENTS", $a); - set_config('an_nextmail', $timenow + $oneday, 'enrol/authorize'); - return; } - if (!$this->check_openssl_loaded()) { + if (empty($CFG->an_review) || (!empty($CFG->an_test)) || + intval($CFG->an_capture_day < 1) || (!$this->check_openssl_loaded())) { return; } diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php index 045f929141d..3635abd9670 100644 --- a/enrol/authorize/index.php +++ b/enrol/authorize/index.php @@ -1,9 +1,9 @@ dirroot.'/enrol/authorize/const.php'; +require_once $CFG->dirroot.'/enrol/authorize/enrol.php'; +require_once $CFG->dirroot.'/enrol/authorize/action.php'; define('ORDER_CAPTURE', 'capture'); define('ORDER_DELETE', 'delete'); @@ -20,12 +20,11 @@ if (!isadmin()) { error("You must be an administrator to use this page."); } -$csv = optional_param('csv', '', PARAM_ALPHA); $orderid = optional_param('order', 0, PARAM_INT); $strs = get_strings(array('user','status','action','delete','time','course','confirm','yes','no','none','error')); $authstrs = get_strings(array('paymentmanagement','orderid','void','capture','refund','delete', - 'authorizedpendingcapture','capturedpendingsettle','capturedsettled', + 'authcaptured','authorizedpendingcapture','capturedpendingsettle','capturedsettled', 'settled','refunded','cancelled','expired','tested', 'transid','settlementdate','notsettled','amount', 'howmuch','captureyes','unenrolstudent'), 'enrol_authorize'); @@ -34,10 +33,7 @@ print_header("$site->shortname: $authstrs->paymentmanagement", "$site->fullname", "$authstrs->paymentmanagement", ""); -if (!empty($csv)) { - authorize_csv(); -} -elseif (!empty($orderid)) { +if (!empty($orderid)) { authorize_order_details($orderid); } else { @@ -56,6 +52,18 @@ function authorize_orders() $userid = optional_param('user', 0, PARAM_INT); $courseid = optional_param('course', 0, PARAM_INT); $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); + $baseurl = $CFG->wwwroot."/enrol/authorize/index.php?course=$courseid&user=$userid"; + $statusmenu = array(AN_STATUS_NONE => get_string('all'), + AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, + AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, + AN_STATUS_CREDIT => $authstrs->refunded, + AN_STATUS_VOID => $authstrs->cancelled, + AN_STATUS_EXPIRE => $authstrs->expired + ); + + print_simple_box_start('center'); + echo $strs->status . ': ' . popup_form($baseurl.'&status=', $statusmenu, 'statusmenu', $status, '', '', '', true); + print_simple_box_end(); $table = new flexible_table('enrol-authorize'); $table->set_attribute('width', '100%'); @@ -66,19 +74,35 @@ function authorize_orders() $table->define_columns(array('id', 'timecreated', 'userid', 'status', '')); $table->define_headers(array($authstrs->orderid, $strs->time, $strs->user, $strs->status, $strs->action)); - $table->define_baseurl($CFG->wwwroot."/enrol/authorize/index.php?course=$courseid&user=$userid&status=$status"); + $table->define_baseurl($baseurl."&status=$status"); $table->sortable(true); $table->pageable(true); $table->setup(); - if ($status > AN_STATUS_NONE) $where = "WHERE (status = '$status') "; - else $where = "WHERE (status != '" . AN_STATUS_NONE . "') "; - if ($userid > 0) { $where .= "AND (userid = '" . $userid . "') "; } - if ($courseid > 0) { $where .= "AND (courseid = '" . $courseid . "') "; } + $select = "SELECT E.id, E.transid, E.courseid, E.userid, E.status, E.ccname, E.timecreated, E.settletime"; + $from = " FROM {$CFG->prefix}enrol_authorize E "; + + if ($status > AN_STATUS_NONE) { + if ($status == AN_STATUS_CREDIT) { + $from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds R ON E.id = R.orderid "; + $where = "WHERE (E.status = '" . AN_STATUS_AUTHCAPTURE . "') "; + } + else { + $where = "WHERE (status = '$status') "; + } + } + else { + $where = "WHERE (status != '" . AN_STATUS_NONE . "') "; + } + + if ($userid > 0) { + $where .= "AND (userid = '" . $userid . "') "; + } + if ($courseid > 0) { + $where .= "AND (courseid = '" . $courseid . "') "; + } - $select = "SELECT id, transid, courseid, userid, status, ccname, timecreated, settletime "; - $from = " FROM {$CFG->prefix}enrol_authorize "; if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } @@ -411,10 +435,6 @@ function authorize_order_details($orderno) { echo ''; } -function authorize_csv() -{ - return; -} function get_order_status_desc($order) { diff --git a/lang/en/enrol_authorize.php b/lang/en/enrol_authorize.php index 2823e0502bb..dea01df5bad 100755 --- a/lang/en/enrol_authorize.php +++ b/lang/en/enrol_authorize.php @@ -1,7 +1,7 @@