]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7535 PayPal communication now fully utf-8 compatible, users must check/fix encodi...
authorskodak <skodak>
Tue, 14 Nov 2006 20:52:15 +0000 (20:52 +0000)
committerskodak <skodak>
Tue, 14 Nov 2006 20:52:15 +0000 (20:52 +0000)
enrol/paypal/enrol.html
enrol/paypal/enrol.php
enrol/paypal/ipn.php

index 4e18b43f7eecee38a4c16fecd40b6330ce1d9c28..793e6bc87ec60ce2fbb8588444a855d44e51760c 100644 (file)
@@ -10,6 +10,7 @@
 <form action="<?php echo $paypalurl ?>" method="post">
 
 <input type="hidden" name="cmd" value="_xclick" />
+<input type="hidden" name="charset" value="utf-8" />
 <input type="hidden" name="business" value="<?php p($CFG->enrol_paypalbusiness)?>" />
 <input type="hidden" name="item_name" value="<?php p($coursefullname) ?>" />
 <input type="hidden" name="item_number" value="<?php p($courseshortname) ?>" />
index fc13238d076260d7b281411ddc212c28d9df0083..7700caeec8e53314f174f9410920176a15488a1e 100644 (file)
@@ -32,7 +32,7 @@ function print_entry($course) {
 
     } else {
 
-        print_header($strloginto, $course->fullname, 
+        print_header($strloginto, $course->fullname,
                      "<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
         print_course($course, "80%");
 
@@ -56,13 +56,13 @@ function print_entry($course) {
             echo '</div>';
         } else {
             //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);
+            $coursefullname  = $course->fullname;
+            $courseshortname = $course->shortname;
+            $userfullname    = fullname($USER);
+            $userfirstname   = $USER->firstname;
+            $userlastname    = $USER->lastname;
+            $useraddress     = $USER->address;
+            $usercity        = $USER->city;
 
             include($CFG->dirroot.'/enrol/paypal/enrol.html');
         }
@@ -99,7 +99,7 @@ function get_access_icons($course) {
         $str = $manual->get_access_icons($course);
 
     } else {
-    
+
         $strrequirespayment = get_string("requirespayment");
         $strcost = get_string("cost");
 
@@ -115,10 +115,10 @@ function get_access_icons($course) {
            case 'AUD': $currency = '$'; break;
            default:    $currency = '$'; break;
         }
-        
+
         $str .= '<div class="cost" title="'.$strrequirespayment.'">'.$strcost.': ';
         $str .= $currency.format_float($cost,2).'</div>';
-        
+
     }
 
     return $str;
@@ -137,12 +137,12 @@ function config_form($frm) {
                                 'AUD' => 'Australian Dollars'
                              );
 
-    $vars = array('enrol_cost', 'enrol_currency', 'enrol_paypalbusiness', 
+    $vars = array('enrol_cost', 'enrol_currency', 'enrol_paypalbusiness',
                   'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins');
     foreach ($vars as $var) {
         if (!isset($frm->$var)) {
             $frm->$var = '';
-        } 
+        }
     }
 
     include("$CFG->dirroot/enrol/paypal/config.html");
@@ -179,17 +179,9 @@ function process_config($config) {
         $config->enrol_mailadmins = '';
     }
     set_config('enrol_mailadmins', $config->enrol_mailadmins);
-    
-    return true;
 
-}
+    return true;
 
-//To avoid wrong (for PayPal) characters in sent data
-function sanitise_for_paypal($text) {
-    $textlib = textlib_get_instance();
-    $text  = $textlib->specialtoascii($text);
-    // TODO: characters that have no ascii equivalents are not sanitized properly :-(
-    return $text;
 }
 
 /**
index 4aefe4c7777a01921ea7c88330c800bf74a4e5e9..6cde62a6df90b2c75f7a6672e850fc470c1c78b8 100644 (file)
@@ -6,7 +6,7 @@
 * This script waits for Payment notification from PayPal,
 * then double checks that data by sending it back to PayPal.
 * If PayPal verifies this then it sets up the enrolment for that
-* 
+*
 * Set the $user->timeaccess course array
 *
 * @param    user  referenced object, must contain $user->id already set
         error("Sorry, you can not use the script that way.");
     }
 
-/// Read all the data from PayPal and get it ready for later
+/// Read all the data from PayPal and get it ready for later;
+/// we expect only valid UTF-8 encoding, it is the responsibility
+/// of user to set it up properly in PayPal business acount,
+/// it is documented in docs wiki.
 
     $req = 'cmd=_notify-validate';
 
+    $data = new object();
+
     foreach ($_POST as $key => $value) {
-        $value = urlencode(stripslashes($value));
-        $req .= "&$key=$value";
-        $data->$key = urldecode($value);
+        $value = stripslashes($value);
+        $req .= "&$key=".urlencode($value);
+        $data->$key = $value;
     }
 
     $custom = explode('-', $data->custom);
             // If our status is not completed or not pending on an echeck clearance then ignore and die
             // This check is redundant at present but may be useful if paypal extend the return codes in the future
 
-            if (! ( $data->payment_status == "Completed" or 
+            if (! ( $data->payment_status == "Completed" or
                    ($data->payment_status == "Pending" and $data->pending_reason == "echeck") ) ) {
                 die;
             }
                 email_paypal_error_to_admin("Transaction $data->txn_id is being repeated!", $data);
                 die;
 
-            } 
-            
+            }
+
             if ($data->business != $CFG->enrol_paypalbusiness) {   // Check that the email is the one we want it to be
                 email_paypal_error_to_admin("Business email is $data->business (not $CFG->enrol_paypalbusiness)", $data);
                 die;
 
-            } 
-            
+            }
+
             if (!$user = get_record('user', 'id', $data->userid)) {   // Check that user exists
                 email_paypal_error_to_admin("User $data->userid doesn't exist", $data);
                 die;
             }
             $cost = format_float($cost, 2);
 
-            if ($data->payment_gross < $cost) {   
+            if ($data->payment_gross < $cost) {
                 email_paypal_error_to_admin("Amount paid is not enough ($data->payment_gross < $cost))", $data);
                 die;
 
                 if (!empty($CFG->enrol_mailstudents)) {
                     $a->coursename = "$course->fullname";
                     $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
-                    email_to_user($user, $teacher, get_string("enrolmentnew", '', $course->shortname), 
+                    email_to_user($user, $teacher, get_string("enrolmentnew", '', $course->shortname),
                                   get_string('welcometocoursetext', '', $a));
                 }
 
                 if (!empty($CFG->enrol_mailteachers)) {
                     $a->course = "$course->fullname";
                     $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));
                 }
 
                     $a->user = fullname($user);
                     $admins = get_admins();
                     foreach ($admins as $admin) {
-                        email_to_user($admin, $user, get_string("enrolmentnew", '', $course->shortname), 
+                        email_to_user($admin, $user, get_string("enrolmentnew", '', $course->shortname),
                                       get_string('enrolmentnewuser', '', $a));
                     }
                 }