2006-09-02 11:49:02 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
|
|
|
function get_course_cost($course)
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$cost = (float)0;
|
|
|
|
$currency = (!empty($course->currency))
|
|
|
|
? $course->currency :( empty($CFG->enrol_currency)
|
|
|
|
? 'USD' : $CFG->enrol_currency );
|
|
|
|
|
|
|
|
if (!empty($course->cost)) {
|
|
|
|
$cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cost = format_float($cost, 2);
|
|
|
|
$ret = array(
|
|
|
|
'cost' => $cost,
|
|
|
|
'currency' => $currency
|
|
|
|
);
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function zero_cost($course) {
|
|
|
|
$curcost = get_course_cost($course);
|
|
|
|
return (abs($curcost['cost']) < 0.01);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prevent_double_paid($course)
|
|
|
|
{
|
|
|
|
global $CFG, $SESSION, $USER;
|
|
|
|
|
2006-11-23 16:22:39 +00:00
|
|
|
$sql = "SELECT id FROM {$CFG->prefix}enrol_authorize WHERE userid = '$USER->id' AND courseid = '$course->id' ";
|
2006-09-02 11:49:02 +00:00
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
if (empty($CFG->an_test)) { // Real mode
|
|
|
|
$sql .= 'AND status IN('.AN_STATUS_AUTH.','.AN_STATUS_UNDERREVIEW.','.AN_STATUS_APPROVEDREVIEW.')';
|
|
|
|
}
|
|
|
|
else { // Test mode
|
|
|
|
$sql .= 'AND status='.AN_STATUS_NONE;
|
|
|
|
}
|
|
|
|
|
2006-11-23 16:22:39 +00:00
|
|
|
if ($recid = get_field_sql($sql)) {
|
2006-09-02 11:49:02 +00:00
|
|
|
$a = new stdClass;
|
2006-11-23 16:22:39 +00:00
|
|
|
$a->orderid = $recid;
|
2006-09-02 11:49:02 +00:00
|
|
|
$a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$a->orderid";
|
|
|
|
redirect($a->url, get_string("paymentpending", "enrol_authorize", $a), '10');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isset($SESSION->ccpaid)) {
|
|
|
|
unset($SESSION->ccpaid);
|
2007-03-02 16:47:38 +00:00
|
|
|
redirect($CFG->wwwroot . '/login/logout.php?sesskey='.sesskey());
|
2006-09-02 11:49:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_list_of_creditcards($getall = false)
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$alltypes = array(
|
|
|
|
'mcd' => 'Master Card',
|
|
|
|
'vis' => 'Visa',
|
|
|
|
'amx' => 'American Express',
|
|
|
|
'dsc' => 'Discover',
|
|
|
|
'dnc' => 'Diners Club',
|
|
|
|
'jcb' => 'JCB',
|
|
|
|
'swi' => 'Switch',
|
|
|
|
'dlt' => 'Delta',
|
|
|
|
'enr' => 'EnRoute'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($getall or empty($CFG->an_acceptccs)) {
|
|
|
|
return $alltypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
$ccs = explode(',', $CFG->an_acceptccs);
|
|
|
|
foreach ($ccs as $key) {
|
|
|
|
$ret[$key] = $alltypes[$key];
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_list_of_payment_methods($getall = false)
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
2006-09-04 07:33:11 +00:00
|
|
|
if ($getall || empty($CFG->an_acceptmethods)) {
|
2006-09-02 11:49:02 +00:00
|
|
|
return array(AN_METHOD_CC, AN_METHOD_ECHECK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return explode(',', $CFG->an_acceptmethods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-04 09:44:00 +00:00
|
|
|
function get_list_of_bank_account_types($getall = false)
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($getall || empty($CFG->an_acceptechecktypes)) {
|
|
|
|
return array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return explode(',', $CFG->an_acceptechecktypes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
function email_to_admin($subject, $data)
|
|
|
|
{
|
|
|
|
global $SITE;
|
|
|
|
|
|
|
|
$admin = get_admin();
|
|
|
|
$data = (array)$data;
|
|
|
|
|
|
|
|
$message = "$SITE->fullname: Transaction failed.\n\n$subject\n\n";
|
|
|
|
$message .= print_r($data, true);
|
|
|
|
email_to_user($admin, $admin, "$SITE->fullname: Authorize.net ERROR", $message);
|
|
|
|
}
|
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
|
|
|
|
function send_welcome_messages($orderdata)
|
|
|
|
{
|
|
|
|
global $CFG, $SITE;
|
|
|
|
|
|
|
|
if (empty($orderdata)) {
|
2006-11-03 11:20:13 +00:00
|
|
|
return;
|
2006-10-16 09:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($orderdata)) {
|
|
|
|
$orderdata = array($orderdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
$select = "SELECT e.id, e.courseid, e.userid, c.fullname
|
|
|
|
FROM {$CFG->prefix}enrol_authorize e
|
|
|
|
INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid
|
|
|
|
WHERE e.id IN(" . implode(',', $orderdata) . ")
|
|
|
|
ORDER BY e.userid";
|
|
|
|
|
|
|
|
$emailinfo = get_records_sql($select);
|
2006-11-03 11:20:13 +00:00
|
|
|
if (1 == count($emailinfo)) {
|
2006-10-16 09:39:08 +00:00
|
|
|
$ei = reset($emailinfo);
|
2006-11-03 11:20:13 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $ei->courseid);
|
|
|
|
$paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
|
|
|
|
$sender = array_shift($paymentmanagers);
|
2006-10-16 09:39:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sender = get_admin();
|
|
|
|
}
|
|
|
|
|
|
|
|
$ei = reset($emailinfo);
|
|
|
|
while ($ei !== false) {
|
|
|
|
$usercourses = array();
|
|
|
|
$lastuserid = $ei->userid;
|
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
|
|
|
for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
|
2006-11-03 11:20:13 +00:00
|
|
|
$usercourses[] = $current->fullname;
|
2006-10-16 09:39:08 +00:00
|
|
|
}
|
|
|
|
$ei = $current;
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->courses = implode("\n", $usercourses);
|
|
|
|
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
|
|
|
|
$a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
|
|
|
|
$emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
|
|
|
|
$user = get_record('user', 'id', $lastuserid);
|
|
|
|
@email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
function check_openssl_loaded()
|
|
|
|
{
|
|
|
|
return extension_loaded('openssl');
|
|
|
|
}
|
|
|
|
|
2008-01-16 17:19:30 +00:00
|
|
|
|
|
|
|
function authorize_verify_account(&$message)
|
|
|
|
{
|
|
|
|
global $CFG, $USER, $SITE;
|
|
|
|
require_once('authorizenetlib.php');
|
|
|
|
|
|
|
|
$CFG->an_test = 1; // Test mode
|
|
|
|
|
|
|
|
$order = new stdClass();
|
|
|
|
$order->id = -1;
|
|
|
|
$order->paymentmethod = AN_METHOD_CC;
|
|
|
|
$order->refundinfo = '1111';
|
|
|
|
$order->ccname = 'Test User';
|
|
|
|
$order->courseid = $SITE->id;
|
|
|
|
$order->userid = $USER->id;
|
|
|
|
$order->status = AN_STATUS_NONE;
|
|
|
|
$order->settletime = 0;
|
|
|
|
$order->transid = 0;
|
|
|
|
$order->timecreated = time();
|
|
|
|
$order->amount = '0.01';
|
|
|
|
$order->currency = 'USD';
|
|
|
|
|
|
|
|
$extra = new stdClass();
|
|
|
|
$extra->x_card_num = '4111111111111111';
|
|
|
|
$extra->x_card_code = '123';
|
|
|
|
$extra->x_exp_date = "129999";
|
|
|
|
$extra->x_currency_code = $order->currency;
|
|
|
|
$extra->x_amount = $order->amount;
|
|
|
|
$extra->x_first_name = 'Test';
|
|
|
|
$extra->x_last_name = 'User';
|
|
|
|
$extra->x_country = $USER->country;
|
|
|
|
|
|
|
|
$extra->x_invoice_num = $order->id;
|
|
|
|
$extra->x_description = 'Verify Account';
|
|
|
|
|
|
|
|
$message = '';
|
|
|
|
return authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis');
|
|
|
|
}
|
|
|
|
|
2006-09-02 11:49:02 +00:00
|
|
|
?>
|