Now text sent to PayPal can be 'sanitised' to avoid

some diacritics (spanish for now) break the enrol process.
Only German and French diacritics are supported for now by PayPal.
Functionality can be easily expanded to other characters.
It make the sanitity when $CFG->sanitise_for_paypal is enabled.
This commit is contained in:
stronk7
2005-01-05 00:25:35 +00:00
parent 9e749677e5
commit 77d94a35e3
2 changed files with 46 additions and 7 deletions
+7 -7
View File
@@ -8,11 +8,11 @@
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php p($CFG->enrol_paypalbusiness)?>">
<input type="hidden" name="item_name" value="<?php p($course->fullname) ?>">
<input type="hidden" name="item_number" value="<?php p($course->shortname) ?>">
<input type="hidden" name="item_name" value="<?php p($coursefullname) ?>">
<input type="hidden" name="item_number" value="<?php p($courseshortname) ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="on0" value="<?php print_string("user") ?>">
<input type="hidden" name="os0" value="<?php echo fullname($USER) ?>">
<input type="hidden" name="os0" value="<?php p($userfullname) ?>">
<input type="hidden" name="custom" value="<?php echo "$USER->id-$course->id" ?>">
<input type="hidden" name="currency_code" value="<?php p($CFG->enrol_currency) ?>">
@@ -26,10 +26,10 @@
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="<?php print_string("continuetocourse") ?>">
<input type="hidden" name="first_name" value="<?php p($USER->firstname) ?>">
<input type="hidden" name="last_name" value="<?php p($USER->lastname) ?>">
<input type="hidden" name="address" value="<?php p($USER->address) ?>">
<input type="hidden" name="city" value="<?php p($USER->city) ?>">
<input type="hidden" name="first_name" value="<?php p($userfirstname) ?>">
<input type="hidden" name="last_name" value="<?php p($userlastname) ?>">
<input type="hidden" name="address" value="<?php p($useraddress) ?>">
<input type="hidden" name="city" value="<?php p($usercity) ?>">
<input type="hidden" name="email" value="<?php p($USER->email) ?>">
<input type="hidden" name="country" value="<?php p($USER->country) ?>">
+39
View File
@@ -39,6 +39,14 @@ function print_entry($course) {
print_course($course, "80%");
print_simple_box_start("center");
//Sanitise some fields before building the PayPal form
$coursefullname = $this->sanitise_for_paypal($course->fullname);
$courseshortname = $this->sanitise_for_paypal($course->shortname);
$userfullname = $this->sanitise_for_paypal(fullname($USER));
$userfirstname = $this->sanitise_for_paypal($USER->firstname);
$userlastname = $this->sanitise_for_paypal($USER->lastname);
$useraddress = $this->sanitise_for_paypal($USER->address);
$usercity = $this->sanitise_for_paypal($USER->city);
include("$CFG->dirroot/enrol/paypal/enrol.html");
@@ -143,6 +151,37 @@ function process_config($config) {
}
//To avoid wrong (for PayPal) characters in sent data
function sanitise_for_paypal($text) {
global $CFG;
if (!empty($CFG->sanitise_for_paypal)) {
//Array of characters to replace (not allowed by PayPal)
//Can be expanded as necessary to add other diacritics
$replace = array('á' => 'a', //Spanish characters
'é' => 'e',
'í' => 'i',
'ó' => 'o',
'ú' => 'u',
'Á' => 'A',
'É' => 'E',
'Í' => 'I',
'Ó' => 'O',
'Ú' => 'U',
'ñ' => 'n',
'Ñ' => 'N',
'ü' => 'u',
'Ü' => 'U');
$text = strtr($text, $replace);
//Make here other sanities if necessary
}
return $text;
}
} // end of class definition