2006-03-27 08:31:16 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2006-04-26 16:03:16 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
2006-05-12 19:56:02 +00:00
|
|
|
die('Direct access to this script is forbidden.');
|
2006-04-26 16:03:16 +00:00
|
|
|
}
|
2006-04-24 17:15:13 +00:00
|
|
|
|
2006-04-26 16:03:16 +00:00
|
|
|
require_once('const.php');
|
2006-05-17 08:18:51 +00:00
|
|
|
require_once('authorizenetlib.php');
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
define('ORDER_CAPTURE', 'capture');
|
|
|
|
define('ORDER_DELETE', 'delete');
|
|
|
|
define('ORDER_REFUND', 'refund');
|
|
|
|
define('ORDER_VOID', 'void');
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_print_orders
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-04-11 12:37:41 +00:00
|
|
|
function authorize_print_orders()
|
2006-03-27 08:31:16 +00:00
|
|
|
{
|
|
|
|
global $CFG, $USER;
|
|
|
|
global $strs, $authstrs;
|
2006-04-26 17:29:52 +00:00
|
|
|
global $courseid, $userid;
|
2006-03-27 08:31:16 +00:00
|
|
|
require_once $CFG->libdir.'/tablelib.php';
|
|
|
|
|
|
|
|
$perpage = 10;
|
|
|
|
$status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
|
|
|
|
|
|
|
|
if (!isteacher($courseid)) {
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$baseurl = $CFG->wwwroot."/enrol/authorize/index.php?user=$userid";
|
2006-04-24 16:46:39 +00:00
|
|
|
$statusmenu = array(AN_STATUS_NONE => $strs->all,
|
2006-03-27 08:31:16 +00:00
|
|
|
AN_STATUS_AUTH => $authstrs->authorizedpendingcapture,
|
|
|
|
AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured,
|
|
|
|
AN_STATUS_CREDIT => $authstrs->refunded,
|
|
|
|
AN_STATUS_VOID => $authstrs->cancelled,
|
2006-05-12 19:56:02 +00:00
|
|
|
AN_STATUS_EXPIRE => $authstrs->expired,
|
|
|
|
AN_STATUS_TEST => $authstrs->tested
|
2006-03-27 08:31:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($courses = get_courses('all', 'c.sortorder ASC', 'c.id,c.fullname,c.enrol')) {
|
|
|
|
$popupcrs = array();
|
|
|
|
foreach ($courses as $crs) {
|
|
|
|
if ($crs->enrol == 'authorize' || (empty($crs->enrol) && $CFG->enrol == 'authorize')) {
|
2006-05-12 19:56:02 +00:00
|
|
|
$popupcrs[intval($crs->id)] = $crs->fullname;
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-12 19:56:02 +00:00
|
|
|
if (!empty($popupcrs)) {
|
|
|
|
print_simple_box_start('center', '100%');
|
|
|
|
echo "$strs->status: ";
|
2006-05-13 08:33:55 +00:00
|
|
|
echo popup_form($baseurl.'&course='.$courseid.'&status=',$statusmenu,'statusmenu',$status,'','','',true);
|
2006-05-12 19:56:02 +00:00
|
|
|
echo " $strs->course: ";
|
|
|
|
echo popup_form($baseurl.'&status='.$status.'&course=',$popupcrs,'coursesmenu',$courseid,'','','',true);
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = new flexible_table('enrol-authorize');
|
|
|
|
$table->set_attribute('width', '100%');
|
|
|
|
$table->set_attribute('cellspacing', '0');
|
|
|
|
$table->set_attribute('cellpadding', '3');
|
|
|
|
$table->set_attribute('id', 'orders');
|
|
|
|
$table->set_attribute('class', 'generaltable generalbox');
|
|
|
|
|
|
|
|
$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($baseurl."&status=$status");
|
|
|
|
|
2006-05-12 19:56:02 +00:00
|
|
|
$table->sortable(true, 'id', SORT_DESC);
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->pageable(true);
|
|
|
|
$table->setup();
|
|
|
|
|
2006-05-13 08:33:55 +00:00
|
|
|
$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 ";
|
|
|
|
$where = "WHERE (1=1) ";
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
if ($status > AN_STATUS_NONE) {
|
2006-05-13 08:33:55 +00:00
|
|
|
switch ($status)
|
|
|
|
{
|
|
|
|
case AN_STATUS_CREDIT:
|
2006-03-27 08:31:16 +00:00
|
|
|
$from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds R ON E.id = R.orderid ";
|
2006-05-13 08:33:55 +00:00
|
|
|
$where .= "AND (E.status = '" . AN_STATUS_AUTHCAPTURE . "') ";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AN_STATUS_TEST:
|
2006-05-12 19:56:02 +00:00
|
|
|
$newordertime = time() - 120; // -2 minutes. Order may be still in process.
|
2006-05-13 08:33:55 +00:00
|
|
|
$where .= "AND (E.status = '" . AN_STATUS_NONE . "') AND (E.transid = '0') AND (E.timecreated<$newordertime) ";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$where .= "AND (E.status = '$status') ";
|
|
|
|
break;
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-12 19:56:02 +00:00
|
|
|
else { // No filter
|
2006-03-27 08:31:16 +00:00
|
|
|
if (empty($CFG->an_test)) {
|
2006-05-13 08:33:55 +00:00
|
|
|
$where .= "AND (E.status != '" . AN_STATUS_NONE . "') ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($userid > 0) {
|
|
|
|
$where .= "AND (userid = '" . $userid . "') ";
|
|
|
|
}
|
|
|
|
if ($courseid != SITEID) {
|
|
|
|
$where .= "AND (courseid = '" . $courseid . "') ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sort = $table->get_sql_sort()) {
|
|
|
|
$sort = ' ORDER BY ' . $sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
$totalcount = count_records_sql('SELECT COUNT(*) ' . $from . $where);
|
|
|
|
$table->initialbars($totalcount > $perpage);
|
|
|
|
$table->pagesize($perpage, $totalcount);
|
|
|
|
if ($table->get_page_start() !== '' && $table->get_page_size() !== '') {
|
|
|
|
$limit = ' ' . sql_paging_limit($table->get_page_start(), $table->get_page_size());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$limit = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($records = get_records_sql($select . $from . $where . $sort . $limit)) {
|
|
|
|
foreach ($records as $record) {
|
2006-04-11 12:37:41 +00:00
|
|
|
$actionstatus = authorize_get_status_action($record);
|
2006-03-27 08:31:16 +00:00
|
|
|
$actions = '';
|
|
|
|
|
|
|
|
if (empty($actionstatus->actions)) {
|
|
|
|
$actions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($actionstatus->actions as $value) {
|
2006-05-16 15:34:24 +00:00
|
|
|
$actions .= " <a href='index.php?$value=y&sesskey=$USER->sesskey&order=$record->id'>{$authstrs->$value}</a> ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->add_data(array(
|
|
|
|
"<a href='index.php?order=$record->id'>$record->id</a>",
|
|
|
|
userdate($record->timecreated),
|
|
|
|
$record->ccname,
|
|
|
|
$authstrs->{$actionstatus->status},
|
|
|
|
$actions
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->print_html();
|
|
|
|
}
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_print_order_details
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
* @param int $orderno
|
|
|
|
*/
|
2006-04-11 12:37:41 +00:00
|
|
|
function authorize_print_order_details($orderno)
|
2006-04-07 11:23:10 +00:00
|
|
|
{
|
2006-03-27 08:31:16 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
global $strs, $authstrs;
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
$cmdcapture = optional_param(ORDER_CAPTURE, '', PARAM_ALPHA);
|
|
|
|
$cmddelete = optional_param(ORDER_DELETE, '', PARAM_ALPHA);
|
|
|
|
$cmdrefund = optional_param(ORDER_REFUND, '', PARAM_ALPHA);
|
|
|
|
$cmdvoid = optional_param(ORDER_VOID, '', PARAM_ALPHA);
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-04-05 10:08:57 +00:00
|
|
|
$unenrol = optional_param('unenrol', '', PARAM_ALPHA);
|
|
|
|
$confirm = optional_param('confirm', '', PARAM_ALPHA);
|
|
|
|
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->width = '100%';
|
|
|
|
$table->size = array('30%', '70%');
|
|
|
|
$table->align = array('right', 'left');
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
$sql = "SELECT E.*, C.shortname, C.enrolperiod FROM {$CFG->prefix}enrol_authorize E " .
|
|
|
|
"INNER JOIN {$CFG->prefix}course C ON C.id = E.courseid " .
|
|
|
|
"WHERE E.id = '$orderno'";
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$order = get_record_sql($sql);
|
|
|
|
if (!$order) {
|
|
|
|
notice("Order $orderno not found.", "index.php");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($USER->id != $order->userid) { // Current user viewing someone else's order
|
|
|
|
if (!isteacher($order->courseid)) {
|
|
|
|
error("Students can view their order.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-16 15:34:24 +00:00
|
|
|
echo "<form action=\"index.php\" method=\"post\">\n";
|
|
|
|
echo "<input type=\"hidden\" name=\"order\" value=\"$orderno\">\n";
|
|
|
|
echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$settled = settled($order);
|
2006-04-11 12:37:41 +00:00
|
|
|
$status = authorize_get_status_action($order);
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$table->data[] = array("<b>$authstrs->orderid:</b>", $orderno);
|
|
|
|
$table->data[] = array("<b>$authstrs->transid:</b>", $order->transid);
|
|
|
|
$table->data[] = array("<b>$authstrs->amount:</b>", "$order->currency $order->amount");
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($cmdcapture) and empty($cmdrefund) and empty($cmdvoid) and empty($cmddelete)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->course:</b>", $order->shortname);
|
|
|
|
$table->data[] = array("<b>$strs->status:</b>", $authstrs->{$status->status});
|
|
|
|
$table->data[] = array("<b>$strs->user:</b>", $order->ccname);
|
|
|
|
$table->data[] = array("<b>$strs->time:</b>", userdate($order->timecreated));
|
|
|
|
$table->data[] = array("<b>$authstrs->settlementdate:</b>", $settled ?
|
|
|
|
userdate($order->settletime) : $authstrs->notsettled);
|
|
|
|
}
|
|
|
|
$table->data[] = array(" ", "<hr size='1' noshade>\n");
|
|
|
|
|
2006-05-16 15:34:24 +00:00
|
|
|
if (!empty($cmdcapture) and confirm_sesskey()) { // CAPTURE
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_CAPTURE, $status->actions)) {
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->capture;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-05-16 15:34:24 +00:00
|
|
|
"$authstrs->captureyes<br /><a href='index.php?order=$orderno&sesskey=$USER->sesskey&".ORDER_CAPTURE."=y&confirm=y'>$strs->yes</a>
|
2006-03-27 08:31:16 +00:00
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = '';
|
|
|
|
$extra = NULL;
|
|
|
|
$success = authorizenet_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE);
|
|
|
|
update_record("enrol_authorize", $order); // May be expired.
|
|
|
|
if (!$success) {
|
|
|
|
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (empty($CFG->an_test)) {
|
|
|
|
$timestart = $timeend = 0;
|
|
|
|
if ($order->enrolperiod) {
|
|
|
|
$timestart = time(); // early start
|
|
|
|
$timeend = $order->settletime + $order->enrolperiod; // lately end
|
|
|
|
}
|
|
|
|
if (enrol_student($order->userid, $order->courseid, $timestart, $timeend, 'authorize')) {
|
|
|
|
$user = get_record('user', 'id', $order->userid);
|
|
|
|
$teacher = get_teacher($order->courseid);
|
|
|
|
$a->coursename = $order->shortname;
|
|
|
|
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
|
|
|
|
email_to_user($user, $teacher,
|
|
|
|
get_string("enrolmentnew", '', $order->shortname),
|
|
|
|
get_string('welcometocoursetext', '', $a));
|
|
|
|
redirect("index.php?order=$orderno");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>",
|
|
|
|
"Error while trying to enrol ".fullname($user)." in '$order->shortname'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_REFUND, $status->actions)) {
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->refund;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
|
|
|
$extra = new stdClass();
|
|
|
|
$extra->sum = 0.0;
|
|
|
|
$extra->orderid = $orderno;
|
|
|
|
|
|
|
|
$sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " .
|
|
|
|
"WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')";
|
|
|
|
|
|
|
|
if ($refund = get_record_sql($sql)) {
|
|
|
|
$extra->sum = floatval($refund->refunded);
|
|
|
|
}
|
|
|
|
$upto = format_float($order->amount - $extra->sum, 2);
|
|
|
|
if ($upto <= 0) {
|
|
|
|
error("Refunded to original amount.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$amount = format_float(optional_param('amount', $upto), 2);
|
2006-04-05 10:08:57 +00:00
|
|
|
if (($amount > $upto) || empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$a->upto = $upto;
|
|
|
|
$strcanbecredit = get_string('canbecredit', 'enrol_authorize', $a);
|
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>",
|
|
|
|
"<input type='checkbox' name='unenrol' value='y'" . (!empty($unenrol) ? " checked" : "") . ">");
|
|
|
|
$table->data[] = array("<b>$authstrs->howmuch</b>",
|
|
|
|
"<input type='hidden' name='confirm' value='y'>
|
|
|
|
<input type='text' size='5' name='amount' value='$amount'>
|
2006-04-05 05:28:56 +00:00
|
|
|
$strcanbecredit<br /><input type='submit' name='".ORDER_REFUND."' value='$authstrs->refund'>");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$extra->amount = $amount;
|
|
|
|
$message = '';
|
|
|
|
$success = authorizenet_action($order, $message, $extra, AN_ACTION_CREDIT);
|
|
|
|
if ($success) {
|
|
|
|
if (empty($CFG->an_test)) {
|
2006-05-12 19:56:02 +00:00
|
|
|
unset($extra->sum); // this is not used in refunds table.
|
2006-03-27 08:31:16 +00:00
|
|
|
$extra->id = insert_record("enrol_authorize_refunds", $extra);
|
2006-05-12 19:56:02 +00:00
|
|
|
if (empty($extra->id)) {
|
|
|
|
$emailsubject = "Authorize.net: insert record error";
|
|
|
|
$emailmessage = "Error while trying to insert new data to enrol_authorize_refunds table:\n";
|
|
|
|
$data = (array)$extra;
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$emailmessage .= "$key => $value\n";
|
|
|
|
}
|
|
|
|
$adminuser = get_admin();
|
|
|
|
email_to_user($adminuser, $adminuser, $emailsubject, $emailmessage);
|
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", $emailmessage);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
2006-05-12 19:56:02 +00:00
|
|
|
else {
|
|
|
|
if (!empty($unenrol)) {
|
|
|
|
unenrol_student($order->userid, $order->courseid);
|
|
|
|
}
|
2006-05-16 15:02:52 +00:00
|
|
|
redirect("index.php?order=$orderno");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmdvoid) and confirm_sesskey()) { // VOID
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_VOID, $status->actions)) {
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->void;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
|
|
|
$suborderno = optional_param('suborder', 0, PARAM_INT);
|
|
|
|
if (empty($suborderno)) { // cancel original transaction.
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$strvoidyes = get_string('voidyes', 'enrol_authorize');
|
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"$strvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<input type='hidden' name='confirm' value='y'>
|
|
|
|
<input type='submit' value='$strs->yes'>
|
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$extra = NULL;
|
|
|
|
$message = '';
|
|
|
|
$success = authorizenet_action($order, $message, $extra, AN_ACTION_VOID);
|
|
|
|
update_record("enrol_authorize", $order); // May be expired.
|
|
|
|
if ($success) {
|
|
|
|
if (empty($CFG->an_test)) {
|
|
|
|
redirect("index.php?order=$orderno");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // cancel refunded transaction
|
2006-04-05 05:28:56 +00:00
|
|
|
$suborder = get_record('enrol_authorize_refunds',
|
|
|
|
'id', $suborderno,
|
|
|
|
'orderid', $orderno,
|
|
|
|
'status', AN_STATUS_CREDIT);
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!$suborder) { // not found
|
|
|
|
error("Transaction can not be voided because of already been voided.");
|
|
|
|
}
|
|
|
|
else {
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$a->transid = $suborder->transid;
|
|
|
|
$a->amount = $suborder->amount;
|
|
|
|
$strsubvoidyes = get_string('subvoidyes', 'enrol_authorize', $a);
|
|
|
|
|
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>",
|
|
|
|
"<input type='checkbox' name='unenrol' value='y'" . (!empty($unenrol) ? " checked" : "") . ">");
|
|
|
|
|
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"$strsubvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<input type='hidden' name='confirm' value='y'>
|
|
|
|
<input type='hidden' name='suborder' value='$suborderno'>
|
|
|
|
<input type='submit' value='$strs->yes'>
|
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = '';
|
|
|
|
$extra = NULL;
|
|
|
|
$success = authorizenet_action($suborder, $message, $extra, AN_ACTION_VOID);
|
|
|
|
update_record("enrol_authorize_refunds", $suborder); // May be expired.
|
|
|
|
if ($success) {
|
|
|
|
if (empty($CFG->an_test)) {
|
|
|
|
if (!empty($unenrol)) {
|
|
|
|
unenrol_student($order->userid, $order->courseid);
|
|
|
|
}
|
|
|
|
redirect("index.php?order=$orderno");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_DELETE, $status->actions)) {
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->delete;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>",
|
|
|
|
"<input type='checkbox' name='unenrol' value='y'" . (!empty($unenrol) ? " checked" : "") . ">");
|
|
|
|
|
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"<input type='hidden' name='".ORDER_DELETE."' value='y'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<input type='hidden' name='confirm' value='y'>
|
|
|
|
<input type='submit' value='$strs->yes'>
|
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!empty($unenrol)) {
|
|
|
|
unenrol_student($order->userid, $order->courseid);
|
|
|
|
}
|
|
|
|
delete_records('enrol_authorize', 'id', $orderno);
|
|
|
|
redirect("index.php");
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
|
|
|
else { // SHOW
|
|
|
|
$actions = '';
|
|
|
|
if (empty($status->actions)) {
|
|
|
|
$actions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($status->actions as $value) {
|
|
|
|
$actions .= "<input type='submit' name='$value' value='{$authstrs->$value}'> ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$table->data[] = array("<b>$strs->action</b>", $actions);
|
|
|
|
print_table($table);
|
|
|
|
if ($settled) { // show refunds.
|
2006-04-24 17:03:42 +00:00
|
|
|
echo "<h4>" . get_string('returns', 'enrol_authorize') . "</h4>\n";
|
2006-04-05 05:28:56 +00:00
|
|
|
$t2->size = array('15%', '15%', '20%', '35%', '15%');
|
2006-05-12 19:56:02 +00:00
|
|
|
$t2->align = array('right', 'right', 'right', 'right', 'right');
|
2006-04-05 05:28:56 +00:00
|
|
|
$t2->head = array($authstrs->transid,
|
2006-05-12 19:56:02 +00:00
|
|
|
$authstrs->amount,
|
|
|
|
$strs->status,
|
|
|
|
$authstrs->settlementdate,
|
|
|
|
$strs->action);
|
2006-03-27 08:31:16 +00:00
|
|
|
$refunds = get_records('enrol_authorize_refunds', 'orderid', $orderno);
|
|
|
|
if ($refunds) {
|
|
|
|
foreach ($refunds as $rf) {
|
2006-04-11 12:37:41 +00:00
|
|
|
$substatus = authorize_get_status_action($rf);
|
2006-03-27 08:31:16 +00:00
|
|
|
$subactions = ' ';
|
|
|
|
if (empty($substatus->actions)) {
|
|
|
|
$subactions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($substatus->actions as $vl) {
|
|
|
|
$subactions .=
|
2006-05-16 15:34:24 +00:00
|
|
|
"<a href='index.php?$vl=y&sesskey=$USER->sesskey&order=$orderno&suborder=$rf->id'>{$authstrs->$vl}</a> ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-05 05:28:56 +00:00
|
|
|
$t2->data[] = array($rf->transid,
|
2006-05-12 19:56:02 +00:00
|
|
|
$rf->amount,
|
|
|
|
$authstrs->{$substatus->status},
|
|
|
|
userdate($rf->settletime),
|
|
|
|
$subactions);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-05-12 19:56:02 +00:00
|
|
|
$t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'','');
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
2006-04-05 05:28:56 +00:00
|
|
|
print_table($t2);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</form>';
|
|
|
|
}
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_get_status_action
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
* @param object $order Order details.
|
|
|
|
* @return object
|
|
|
|
*/
|
2006-04-11 12:37:41 +00:00
|
|
|
function authorize_get_status_action($order)
|
2006-03-27 08:31:16 +00:00
|
|
|
{
|
2006-05-12 19:56:02 +00:00
|
|
|
global $CFG;
|
|
|
|
static $timediff30, $newordertime;
|
2006-04-07 11:23:10 +00:00
|
|
|
|
|
|
|
if (empty($timediff30)) {
|
2006-05-12 19:56:02 +00:00
|
|
|
$timenow = time();
|
|
|
|
$timediff30 = getsettletime($timenow) - (30 * 3600 * 24);
|
|
|
|
$newordertime = $timenow - 120; // -2 minutes. Order may be still in process.
|
2006-04-07 11:23:10 +00:00
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$ret = new stdClass();
|
|
|
|
$ret->actions = array();
|
|
|
|
|
2006-05-12 19:56:02 +00:00
|
|
|
if (intval($order->transid) == 0) { // test transaction or new order
|
|
|
|
if ($order->timecreated < $newordertime) {
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'tested';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ret->status = 'new';
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($order->status) {
|
|
|
|
case AN_STATUS_AUTH:
|
|
|
|
if (getsettletime($order->timecreated) < $timediff30) {
|
|
|
|
$order->status = AN_STATUS_EXPIRE;
|
|
|
|
update_record("enrol_authorize", $order);
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'expired';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_CAPTURE, ORDER_VOID);
|
|
|
|
}
|
|
|
|
$ret->status = 'authorizedpendingcapture';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_AUTHCAPTURE:
|
|
|
|
if (settled($order)) {
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_REFUND);
|
|
|
|
}
|
|
|
|
$ret->status = 'capturedsettled';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_VOID);
|
|
|
|
}
|
|
|
|
$ret->status = 'capturedpendingsettle';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_CREDIT:
|
|
|
|
if (settled($order)) {
|
|
|
|
$ret->status = 'settled';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_VOID);
|
|
|
|
}
|
|
|
|
$ret->status = 'refunded';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_VOID:
|
|
|
|
$ret->status = 'cancelled';
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_EXPIRE:
|
|
|
|
if (isadmin() || (!empty($CFG->an_teachermanagepay) && isteacher($order->courseid))) {
|
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'expired';
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|