mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Authorize.net plugin, some fixes for Default Field Separator & Field Encapsulation Character.
This commit is contained in:
parent
64a39414dd
commit
54e0f2ef8e
1 changed files with 61 additions and 49 deletions
|
@ -7,6 +7,8 @@ define('AN_PATH', '/gateway/transact.dll');
|
||||||
define('AN_APPROVED', '1');
|
define('AN_APPROVED', '1');
|
||||||
define('AN_DECLINED', '2');
|
define('AN_DECLINED', '2');
|
||||||
define('AN_ERROR', '3');
|
define('AN_ERROR', '3');
|
||||||
|
define('AN_DELIM', '|');
|
||||||
|
define('AN_ENCAP', '"');
|
||||||
|
|
||||||
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
||||||
|
|
||||||
|
@ -24,12 +26,7 @@ function print_entry($course) {
|
||||||
parent::print_entry($course);
|
parent::print_entry($course);
|
||||||
} else {
|
} else {
|
||||||
// check payment
|
// check payment
|
||||||
if (isset($SESSION->ccpaid)) {
|
$this->check_paid();
|
||||||
// security check: don't duplicate payment
|
|
||||||
unset($SESSION->ccpaid);
|
|
||||||
redirect("$CFG->wwwroot/login/logout.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!empty($CFG->loginhttps)) && (!isset($_SERVER['HTTPS']))) {
|
if ((!empty($CFG->loginhttps)) && (!isset($_SERVER['HTTPS']))) {
|
||||||
$wwwsroot = str_replace('http://','https://', $CFG->wwwroot);
|
$wwwsroot = str_replace('http://','https://', $CFG->wwwroot);
|
||||||
|
@ -62,20 +59,20 @@ function print_entry($course) {
|
||||||
'enr' => 'EnRoute'
|
'enr' => 'EnRoute'
|
||||||
);
|
);
|
||||||
|
|
||||||
$formvars = array('cc', 'ccexpiremm', 'ccexpireyyyy', 'cctype', 'cvv', 'cczip');
|
$formvars = array('ccfirstname','cclastname','cc','ccexpiremm','ccexpireyyyy','cctype','cvv','cczip');
|
||||||
foreach ($formvars as $var) {
|
foreach ($formvars as $var) {
|
||||||
if (!isset($form->$var)) {
|
if (!isset($form->$var)) {
|
||||||
$form->$var = '';
|
$form->$var = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include($CFG->dirroot.'/enrol/authorize/enrol.html');
|
include($CFG->dirroot . '/enrol/authorize/enrol.html');
|
||||||
print_simple_box_end();
|
print_simple_box_end();
|
||||||
print_footer();
|
print_footer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override: base check_entry()
|
/// Override: check_entry()
|
||||||
function check_entry($form, $course) {
|
function check_entry($form, $course) {
|
||||||
if ($this->zero_cost($course)) {
|
if ($this->zero_cost($course)) {
|
||||||
parent::check_entry($form, $course);
|
parent::check_entry($form, $course);
|
||||||
|
@ -87,38 +84,32 @@ function check_entry($form, $course) {
|
||||||
function cc_submit($form, $course)
|
function cc_submit($form, $course)
|
||||||
{
|
{
|
||||||
global $CFG, $USER, $SESSION;
|
global $CFG, $USER, $SESSION;
|
||||||
// check payment
|
require_once($CFG->dirroot . '/enrol/authorize/ccval.php');
|
||||||
if (isset($SESSION->ccpaid))
|
|
||||||
{
|
|
||||||
// security check: don't duplicate payment
|
|
||||||
unset($SESSION->ccpaid);
|
|
||||||
redirect("$CFG->wwwroot/login/logout.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($form->ccfirstname) || empty($form->cclastname) ||
|
if (empty($form->ccfirstname) || empty($form->cclastname) ||
|
||||||
empty($form->cc) || empty($form->ccexpiremm) || empty($form->ccexpireyyyy) ||
|
empty($form->cc) || empty($form->cvv) || empty($form->cctype) ||
|
||||||
empty($form->cvv) || empty($form->cctype)) {
|
empty($form->ccexpiremm) || empty($form->ccexpireyyyy)) {
|
||||||
$this->errormsg = get_string("allfieldsrequired");
|
$this->errormsg = get_string("allfieldsrequired");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once("$CFG->dirroot/enrol/authorize/ccval.php");
|
if (! CCVal($form->cc, $form->cctype)) {
|
||||||
$ccvalresult = CCVal($form->cc, $form->cctype);
|
|
||||||
if (!$ccvalresult) {
|
|
||||||
$this->errormsg = get_string("ccinvalid", "enrol_authorize");
|
$this->errormsg = get_string("ccinvalid", "enrol_authorize");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->check_paid();
|
||||||
$order_number = 0; // can be get from db
|
$order_number = 0; // can be get from db
|
||||||
$formdata = array (
|
$formdata = array (
|
||||||
'x_version' => '3.1',
|
'x_version' => '3.1',
|
||||||
'x_delim_data' => 'True',
|
'x_delim_data' => 'True',
|
||||||
'x_delim_char' => '|',
|
'x_delim_char' => AN_DELIM,
|
||||||
|
'x_encap_char' => AN_ENCAP,
|
||||||
'x_relay_response' => 'False',
|
'x_relay_response' => 'False',
|
||||||
'x_login' => $CFG->an_login,
|
'x_login' => $CFG->an_login,
|
||||||
'x_test_request' => (!empty($CFG->an_test)) ? 'True' : 'False',
|
'x_test_request' => (!empty($CFG->an_test)) ? 'True' : 'False',
|
||||||
'x_type' => 'AUTH_CAPTURE',
|
'x_type' => 'AUTH_CAPTURE',
|
||||||
|
'x_method' => 'CC',
|
||||||
// user
|
// user
|
||||||
'x_first_name' => (empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname),
|
'x_first_name' => (empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname),
|
||||||
'x_last_name' => (empty($form->cclastname) ? $USER->lastname : $form->cclastname),
|
'x_last_name' => (empty($form->cclastname) ? $USER->lastname : $form->cclastname),
|
||||||
|
@ -129,7 +120,8 @@ function cc_submit($form, $course)
|
||||||
'x_country' => $USER->country,
|
'x_country' => $USER->country,
|
||||||
'x_card_num' => $form->cc,
|
'x_card_num' => $form->cc,
|
||||||
'x_card_code' => $form->cvv,
|
'x_card_code' => $form->cvv,
|
||||||
'x_amount' => $CFG->enrol_currency . " " . $this->get_cource_cost($course),
|
'x_currency_code' => $CFG->enrol_currency,
|
||||||
|
'x_amount' => $this->get_cource_cost($course),
|
||||||
'x_exp_date' => (($form->ccexpiremm<10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm)) . ($form->ccexpireyyyy),
|
'x_exp_date' => (($form->ccexpiremm<10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm)) . ($form->ccexpireyyyy),
|
||||||
'x_email' => $USER->email,
|
'x_email' => $USER->email,
|
||||||
'x_email_customer' => 'False',
|
'x_email_customer' => 'False',
|
||||||
|
@ -141,31 +133,30 @@ function cc_submit($form, $course)
|
||||||
'x_description' => $course->shortname
|
'x_description' => $course->shortname
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($CFG->an_tran_key)) {
|
|
||||||
$formdata['x_tran_key'] = $CFG->an_tran_key;
|
|
||||||
} else {
|
|
||||||
$formdata['x_password'] = (isset($CFG->an_password)) ? $CFG->an_password : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
//build the post string
|
//build the post string
|
||||||
$poststring = '';
|
$poststring = '';
|
||||||
foreach($formdata AS $key => $val) {
|
if (!empty($CFG->an_tran_key)) {
|
||||||
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
|
$poststring .= urlencode("x_tran_key") . "=" . urlencode($CFG->an_tran_key);
|
||||||
}
|
|
||||||
// strip off trailing ampersand
|
|
||||||
$poststring = substr($poststring, 0, -1);
|
|
||||||
|
|
||||||
$fp = fsockopen("ssl://" . AN_HOST, AN_PORT, $errno, $errstr, $timeout = 60);
|
|
||||||
if(!$fp) {
|
|
||||||
$this->errormsg = "$errstr ($errno)";
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
|
$an_pswd = (isset($CFG->an_password)) ? $CFG->an_password : '';
|
||||||
|
$poststring .= urlencode("x_password") . "=" . urlencode($an_pswd);
|
||||||
|
}
|
||||||
|
foreach($formdata as $key => $val) {
|
||||||
|
$poststring .= "&" . urlencode($key) . "=" . urlencode($val);
|
||||||
|
}
|
||||||
|
//built
|
||||||
|
|
||||||
|
$response = array();
|
||||||
$anrefererheader = "";
|
$anrefererheader = "";
|
||||||
if (isset($CFG->an_referer) && (!empty($CFG->an_referer)) &&
|
if (isset($CFG->an_referer) && (!empty($CFG->an_referer)) &&
|
||||||
($CFG->an_referer != "http://") && ($CFG->an_referer != "https://")) {
|
($CFG->an_referer != "http://") && ($CFG->an_referer != "https://")) {
|
||||||
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
||||||
}
|
}
|
||||||
|
$fp = fsockopen("ssl://" . AN_HOST, AN_PORT, $errno, $errstr, 60);
|
||||||
|
if(!$fp) {
|
||||||
|
$this->errormsg = "$errstr ($errno)";
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
//send the server request
|
//send the server request
|
||||||
fputs($fp,
|
fputs($fp,
|
||||||
"POST " . AN_PATH . " HTTP/1.1\r\n" .
|
"POST " . AN_PATH . " HTTP/1.1\r\n" .
|
||||||
|
@ -194,7 +185,19 @@ function cc_submit($form, $course)
|
||||||
// Get real data
|
// Get real data
|
||||||
$data = fgets($fp, $length);
|
$data = fgets($fp, $length);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$response = explode("|", $data);
|
$response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
|
||||||
|
if ($response === false)
|
||||||
|
{
|
||||||
|
$this->errormsg = "response error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$rcount = count($response) - 1;
|
||||||
|
if ($response[0]{0} == AN_ENCAP) {
|
||||||
|
$response[0] = substr($response[0], 1);
|
||||||
|
}
|
||||||
|
if (substr($response[$rcount], -1) == AN_ENCAP) {
|
||||||
|
$response[$rcount] = substr($response[$rcount], 0, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($response[0] != AN_APPROVED) {
|
if ($response[0] != AN_APPROVED) {
|
||||||
|
@ -219,14 +222,12 @@ function cc_submit($form, $course)
|
||||||
email_to_user($USER, $teacher, get_string("enrolmentnew", '', $course->shortname),
|
email_to_user($USER, $teacher, get_string("enrolmentnew", '', $course->shortname),
|
||||||
get_string('welcometocoursetext', '', $a));
|
get_string('welcometocoursetext', '', $a));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($CFG->enrol_mailteachers)) {
|
if (!empty($CFG->enrol_mailteachers)) {
|
||||||
$a->course = "$course->fullname";
|
$a->course = "$course->fullname";
|
||||||
$a->user = fullname($USER);
|
$a->user = fullname($USER);
|
||||||
email_to_user($teacher, $USER, get_string("enrolmentnew", '', $course->shortname),
|
email_to_user($teacher, $USER, get_string("enrolmentnew", '', $course->shortname),
|
||||||
get_string('enrolmentnewuser', '', $a));
|
get_string('enrolmentnewuser', '', $a));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($CFG->enrol_mailadmins)) {
|
if (!empty($CFG->enrol_mailadmins)) {
|
||||||
$a->course = "$course->fullname";
|
$a->course = "$course->fullname";
|
||||||
$a->user = fullname($USER);
|
$a->user = fullname($USER);
|
||||||
|
@ -248,7 +249,6 @@ function cc_submit($form, $course)
|
||||||
$datax->userid = $USER->id;
|
$datax->userid = $USER->id;
|
||||||
$datax->avscode = strval($response[5]);
|
$datax->avscode = strval($response[5]);
|
||||||
$datax->transid = strval($response[6]);
|
$datax->transid = strval($response[6]);
|
||||||
|
|
||||||
if (!insert_record("enrol_authorize", $datax)) { // Insert a transaction record
|
if (!insert_record("enrol_authorize", $datax)) { // Insert a transaction record
|
||||||
$this->email_cc_error_to_admin("Error while trying to insert valid transaction", $datax);
|
$this->email_cc_error_to_admin("Error while trying to insert valid transaction", $datax);
|
||||||
}
|
}
|
||||||
|
@ -348,9 +348,10 @@ function check_openssl_loaded($die)
|
||||||
{
|
{
|
||||||
if (!extension_loaded('openssl')) {
|
if (!extension_loaded('openssl')) {
|
||||||
echo "<font color=red><center>PHP must be compiled --with-openssl</center></font>";
|
echo "<font color=red><center>PHP must be compiled --with-openssl</center></font>";
|
||||||
if ($die)
|
if ($die) {
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_config($config) {
|
function process_config($config) {
|
||||||
|
@ -436,5 +437,16 @@ function email_cc_error_to_admin($subject, $data) {
|
||||||
email_to_user($admin, $admin, "CC ERROR: ".$subject, $message);
|
email_to_user($admin, $admin, "CC ERROR: ".$subject, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_paid() {
|
||||||
|
|
||||||
|
global $CFG, $SESSION;
|
||||||
|
|
||||||
|
if (isset($SESSION->ccpaid)) {
|
||||||
|
unset($SESSION->ccpaid);
|
||||||
|
redirect($CFG->wwwroot . '/login/logout.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end of class definition
|
} // end of class definition
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue