}
}
- $referer = '';
+ $header = 'Connection: close' . "\r\n" .
+ 'Content-type: application/x-www-form-urlencoded' . "\r\n" .
+ 'Content-length: ' . strlen($poststring);
+
if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
- $referer = "Referer: $CFG->an_referer\r\n";
+ $header .= "\r\n" . 'Referer: ' . $CFG->an_referer;
}
- $errno = 0; $errstr = '';
- $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
- $fp = fsockopen("ssl://$host", 443, $errno, $errstr, 60);
- if (!$fp) {
- $message = "no connection: $errstr ($errno)";
- return AN_RETURNZERO;
- }
+ $contextopts = array('http' => array('method' => 'POST',
+ 'header' => $header,
+ 'content' => $poststring));
- // critical section
+ $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
+ $context = stream_context_create($contextopts);
@ignore_user_abort(true);
if (intval(ini_get('max_execution_time')) > 0) {
@set_time_limit(300);
}
-
- 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" .
- "Content-length: " . strlen($poststring) . "\r\n\r\n" .
- $poststring . "\r\n"
- );
-
- $tmpstr = '';
- while(!feof($fp) && !stristr($tmpstr, 'content-length')) {
- $tmpstr = fgets($fp, 4096);
- }
- if (!stristr($tmpstr, 'content-length')) {
- $message = "content-length error";
- @fclose($fp);
+ $data = file_get_contents("https://$host:443/gateway/transact.dll", false, $context);
+ if (!$data) {
+ $message = "no connection to https://$host:443/gateway/transact.dll";
return AN_RETURNZERO;
}
- $length = trim(substr($tmpstr, strpos($tmpstr,'content-length')+15));
- fgets($fp, 4096);
- $data = fgets($fp, $length);
- @fclose($fp);
$response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
if ($response === false) {
$message = "response error";
return; // notice breaks the form and xhtml later
}
- if (optional_param('verifyaccount', 0, PARAM_INT))
- {
- $message = '';
- if (AN_APPROVED == authorize_verify_account($message)) {
- notify(get_string('verifyaccountresult', 'enrol_authorize', get_string('success')));
- } else {
- notify(get_string('verifyaccountresult', 'enrol_authorize', $message));
- }
+ if (optional_param('verifyaccount', 0, PARAM_INT)) {
+ notify(authorize_verify_account());
return;
}
$sender = get_admin();
}
- $ei = reset($emailinfo);
- while ($ei !== false) {
+ for($ei = reset($emailinfo); $ei !== false; ) {
$usercourses = array();
$lastuserid = $ei->userid;
- for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
+ for($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
$usercourses[] = $current->fullname;
}
$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);
+ if ($user = get_record('user', 'id', $lastuserid)) {
+ $a = new stdClass;
+ $a->name = $user->firstname;
+ $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);
+ @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
+ }
}
}
}
-function authorize_verify_account(&$message)
+function authorize_verify_account()
{
global $CFG, $USER, $SITE;
require_once('authorizenetlib.php');
$extra->x_invoice_num = $order->id;
$extra->x_description = 'Verify Account';
- $message = '';
- return authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis');
+ if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis')) {
+ return get_string('verifyaccountresult', 'enrol_authorize', get_string('success'));
+ }
+ else {
+ return get_string('verifyaccountresult', 'enrol_authorize', $message);
+ }
}
?>