From 2e37b629aedc7efaeac2144ca8139052271b632f Mon Sep 17 00:00:00 2001 From: ethem Date: Thu, 5 Jan 2006 16:04:28 +0000 Subject: [PATCH] Address Verification System (AVS). --- enrol/authorize/config.html | 10 +++++ enrol/authorize/enrol.html | 15 ++++++++ enrol/authorize/enrol.php | 75 +++++++++++++++++++++++-------------- lang/en/enrol_authorize.php | 3 +- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/enrol/authorize/config.html b/enrol/authorize/config.html index c95282e2861fc..96a69a96acf7f 100755 --- a/enrol/authorize/config.html +++ b/enrol/authorize/config.html @@ -90,6 +90,16 @@ + + an_avs: + + an_avs)) echo "checked=\"true\"" ?> /> + + + + + + an_test: diff --git a/enrol/authorize/enrol.html b/enrol/authorize/enrol.html index a7070495c15a4..b30df43a1aa91 100755 --- a/enrol/authorize/enrol.html +++ b/enrol/authorize/enrol.html @@ -56,6 +56,21 @@ +an_avs)) { /* Address Verification System */ ?> + + : + + + + / : + / + + + + : + + + : diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index d986905a94461..8c4ba717a24e0 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -13,21 +13,21 @@ require_once("$CFG->dirroot/enrol/enrol.class.php"); class enrolment_plugin extends enrolment_base { - + var $ccerrormsg; /// Override: print_entry() function print_entry($course) { global $CFG, $USER, $form; - + if ($this->zero_cost($course) || isguest()) { parent::print_entry($course); return; } - + // check paid? $this->check_paid(); - + // I want to paid on SSL. if (empty($_SERVER['HTTPS'])) { if (empty($CFG->loginhttps)) { @@ -40,23 +40,27 @@ function print_entry($course) { } } - $formvars = array('password', 'ccfirstname','cclastname','cc','ccexpiremm','ccexpireyyyy','cctype','cvv','cczip'); + $formvars = array('password', 'ccfirstname','cclastname','cc','ccexpiremm','ccexpireyyyy','cctype','cvv', + 'ccaddress', 'cccity', 'ccstate', 'cccountry', 'cczip'); foreach ($formvars as $var) { if (!isset($form->$var)) { $form->$var = ''; } } - + $teacher = get_teacher($course->id); + $cost = $this->get_course_cost($course); $strloginto = get_string("loginto", "", $course->shortname); $strcourses = get_string("courses"); $userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname; $userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname; - $cost = $this->get_course_cost($course); + $useraddress = empty($form->ccaddress) ? $USER->address : $form->ccaddress; + $usercity = empty($form->cccity) ? $USER->city : $form->cccity; + $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry; print_header($strloginto, $course->fullname, "wwwroot/course/\">$strcourses -> $strloginto"); print_course($course, "80%"); - + if ($course->password) { print_simple_box(get_string('choosemethod', 'enrol_authorize'), 'center'); $password = ''; @@ -66,7 +70,7 @@ function print_entry($course) { print_simple_box_start("center"); include($CFG->dirroot . '/enrol/authorize/enrol.html'); print_simple_box_end(); - + print_footer(); } @@ -91,14 +95,24 @@ function cc_submit($form, $course) return; } + if (!empty($CFG->an_avs)) { + if (empty($form->ccaddress) || empty($form->cccity) || + empty($form->cccountry) || empty($form->cczip)) { + $this->ccerrormsg = get_string("allfieldsrequired"); + return; + } + } + $exp_date = (($form->ccexpiremm<10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm)) . ($form->ccexpireyyyy); - if (! CCVal($form->cc, $form->cctype, $exp_date)) { - $this->ccerrormsg = get_string( (($valid_cc===0) ? 'ccexpired' : 'ccinvalid'), 'enrol_authorize' ); + $valid_cc = CCVal($form->cc, $form->cctype, $exp_date); + if (!$valid_cc) { + $this->ccerrormsg = get_string((($valid_cc===0) ? 'ccexpired' : 'ccinvalid'), 'enrol_authorize'); return; } $this->check_paid(); $order_number = 0; // can be get from db + $cost = $this->get_course_cost($course); $formdata = array ( 'x_version' => '3.1', 'x_delim_data' => 'True', @@ -111,15 +125,15 @@ function cc_submit($form, $course) 'x_method' => 'CC', 'x_first_name' => $form->ccfirstname, 'x_last_name' => $form->cclastname, - 'x_address' => $USER->address, - 'x_city' => $USER->city, + 'x_address' => $form->ccaddress, + 'x_city' => $form->cccity, 'x_zip' => $form->cczip, - 'x_country' => $USER->country, - 'x_state' => '', + 'x_country' => $form->cccountry, + 'x_state' => $form->ccstate, 'x_card_num' => $form->cc, 'x_card_code' => $form->cvv, 'x_currency_code' => $CFG->enrol_currency, - 'x_amount' => $this->get_course_cost($course), + 'x_amount' => $cost, 'x_exp_date' => $exp_date, 'x_email' => $USER->email, 'x_email_customer' => 'False', @@ -137,7 +151,7 @@ function cc_submit($form, $course) $poststring .= $k . "=" . urlencode($v) . "&"; } $poststring .= (!empty($CFG->an_tran_key)) ? - "x_tran_key" . "=" . urlencode($CFG->an_tran_key): + "x_tran_key" . "=" . urlencode($CFG->an_tran_key): "x_password" . "=" . urlencode($CFG->an_password); // referer @@ -292,11 +306,11 @@ function get_access_icons($course) { } switch ($CFG->enrol_currency) { - case 'EUR': $currency = '€'; break; - case 'CAD': $currency = '$'; break; - case 'GBP': $currency = '£'; break; - case 'JPY': $currency = '¥'; break; - default: $currency = '$'; break; + case 'EUR': $currency = '€'; break; + case 'CAD': $currency = '$'; break; + case 'GBP': $currency = '£'; break; + case 'JPY': $currency = '¥'; break; + default: $currency = '$'; break; } $str .= "

$strcost: " . @@ -310,7 +324,7 @@ function get_access_icons($course) { function config_form($frm) { global $CFG; - $vars = array('an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_test', + $vars = array('an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_avs', 'an_test', 'enrol_cost', 'enrol_currency', 'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins'); foreach ($vars as $var) { @@ -322,7 +336,7 @@ function config_form($frm) { if (!$this->check_openssl_loaded()) { notify('PHP must be compiled with SSL support (--with-openssl)'); } - + if (data_submitted()) { // Some required fields if (empty($frm->an_login)) { @@ -350,7 +364,7 @@ function process_config($config) { { return false; } - + $return = true; if (!isset($config->an_login)) { @@ -381,6 +395,11 @@ function process_config($config) { } set_config('an_referer', $config->an_referer); + if (!isset($config->an_avs)) { + $config->an_avs = ''; + } + set_config('an_avs', $config->an_avs); + if (!isset($config->an_test)) { $config->an_test = ''; } @@ -419,11 +438,11 @@ function email_cc_error_to_admin($subject, $data) { $admin = get_admin(); $site = get_site(); $message = "$site->fullname: Transaction failed.\n\n$subject\n\n"; - + foreach ($data as $key => $value) { $message .= "$key => $value\n"; } - + email_to_user($admin, $admin, "CC ERROR: ".$subject, $message); } @@ -436,6 +455,6 @@ function check_paid() { exit; } } - + } // end of class definition ?> diff --git a/lang/en/enrol_authorize.php b/lang/en/enrol_authorize.php index 63225eb434d19..386e153dd5887 100755 --- a/lang/en/enrol_authorize.php +++ b/lang/en/enrol_authorize.php @@ -1,7 +1,8 @@