]> git.mjollnir.org Git - moodle.git/commitdiff
OK, Paypal is now working. I've been buying access into some test courses. :-)
authormoodler <moodler>
Sat, 26 Jun 2004 14:40:25 +0000 (14:40 +0000)
committermoodler <moodler>
Sat, 26 Jun 2004 14:40:25 +0000 (14:40 +0000)
Still polishing the GUI side of things now.

enrol/paypal/enrol.html
enrol/paypal/enrol.php
enrol/paypal/ipn.php
enrol/paypal/return.php [new file with mode: 0644]
enrol/paypal/thankyou.php [deleted file]
lang/en/moodle.php

index f275635bba29cb45c5b301d114cec69d9336048d..ff73a57317ac8885099fbe97f5235e96fc328c9a 100644 (file)
@@ -1,18 +1,39 @@
+<div align="center">
+
+<p><?php print_string("paymentrequired") ?></p>
+<p><b><?php echo get_string("cost").": $CFG->enrol_paypalcurrency $cost"; ?></b></p>
+<p><?php print_string("paymentinstant") ?></p>
+        
 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
 
 <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->id) ?>">
-<input type="hidden" name="custom" value="<?php p($USER->id) ?>">
+<input type="hidden" name="item_number" value="<?php p($course->shortname) ?>">
 <input type="hidden" name="quantity" value="1">
-<input type="hidden" name="return" value="<?php echo "$CFG->wwwroot/enrol/paypal/thankyou.php?courseid=$course->id" ?>">
-<input type="hidden" name="cancel_return" value="<?php echo $CFG->wwwroot ?>">
+<input type="hidden" name="on0" value="<?php print_string("user") ?>">
+<input type="hidden" name="os0" value="<?php echo fullname($USER) ?>">
+<input type="hidden" name="custom" value="<?php echo "$USER->id-$course->id" ?>">
 
 <input type="hidden" name="currency_code" value="<?php p($CFG->enrol_paypalcurrency) ?>">
 <input type="hidden" name="amount" value="<?php p($cost) ?>">
 
+<input type="hidden" name="no_note" value="1">
+<input type="hidden" name="notify_url" value="<?php echo "$CFG->wwwroot/enrol/paypal/ipn.php"?>">
+<input type="hidden" name="return" value="<?php echo "$CFG->wwwroot/enrol/paypal/return.php?id=$course->id" ?>">
+<input type="hidden" name="cancel_return" value="<?php echo $CFG->wwwroot ?>">
+<input type="hidden" name="rm" value="1">
+<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="email" value="<?php p($USER->email) ?>">
+<input type="hidden" name="country" value="<?php p($USER->country) ?>">
+
 <input type="submit" value="<?php print_string("sendpaymentbutton", "enrol_paypal") ?>">
 
 </form>
 
+</div>
index 49f1d3cc034051093485498ca3c29aba0a808561..67829c90b34ab3b56b9064b2931e8fb91f5932ad 100644 (file)
@@ -22,7 +22,7 @@ class enrolment_plugin extends enrolment_base {
 
 /// Override the base print_entry() function
 function print_entry($course) {
-    global $CFG;
+    global $CFG, $USER;
 
 
     $strloginto = get_string("loginto", "", $course->shortname);
@@ -37,6 +37,7 @@ function print_entry($course) {
     } else {
         $cost = (float) $course->cost;
     }
+    $cost = format_float($cost, 2);
 
 
     if (abs($cost) < 0.01) { // no cost, default to base class entry to course
@@ -46,13 +47,12 @@ function print_entry($course) {
 
     } else {
 
-        print_header($strloginto, $course->fullname, "<a href=\".\">$strcourses</a> -> $strloginto");
-        print_course($course);
+        print_header($strloginto, $course->fullname, 
+                     "<a href=\"$CFG->wwwroot/courses/\">$strcourses</a> -> $strloginto");
+        print_course($course, "80%");
         print_simple_box_start("center");
 
-        printf ("<p align=\"center\"><b>$course->fullname</b> has a cost of $CFG->enrol_paypalcurrency %01.2f</p>", $cost);
-        
-        echo "<div align=\"center\">";
+
         include("$CFG->dirroot/enrol/paypal/enrol.html");
         echo "</div>";
 
index 1b4c122cd8181d26b36eb407c584fb101d6b33f6..23a2fa656a107beb9bfb65c32c12cc7705eff2cd 100644 (file)
 */
 
 
+    require("../../config.php");
+    require("enrol.php");
+
 /// Keep out casual intruders
-    if (empty($_POST)) {
+    if (empty($_POST) or !empty($_GET)) {
         error("Sorry, you can not use the script that way.");
     }
 
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&$key=$value";
-        $data->$key = $value;
+        $data->$key = urldecode($value);
     }
 
-    $data->courseid         = $data->item_number;
-    $data->userid           = $data->custom;
+    $custom = explode('-', $data->custom);
+    $data->userid           = $custom[0];
+    $data->courseid         = $custom[1];
     $data->payment_amount   = $data->mc_gross;
     $data->payment_currency = $data->mc_currency;
 
             }
 
             if ($existing = get_record("enrol_paypal", "txn_id", $data->txn_id)) {   // Make sure this transaction doesn't exist already
+                email_paypal_error_to_admin("Transaction $data->txn_id is being repeated!", $data);
+                die;
 
             } 
             
-            if () {   // Check that the email is the one we want it to be
+            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;
             }
 
             if (!$course = get_record('user', 'id', $data->courseid)) { // Check that course exists
-                email_paypal_error_to_admin("Course $data->courseid doesn't exist", $data);
+                email_paypal_error_to_admin("Course $data->courseid doesn't exist", $data);;
+                die;
             }
 
-            if () {   // Check that amount paid is the correct amount
+            // Check that amount paid is the correct amount
+            if ( (float) $course->cost < 0 ) {
+                $cost = (float) $CFG->enrol_cost;
+            } else {
+                $cost = (float) $course->cost;
+            }
+            $cost = format_float($cost, 2);
+
+            if ($data->payment_gross < $cost) {   
+                email_paypal_error_to_admin("Amount paid is not enough ($data->payment_gross < $cost))", $data);
+                die;
 
             }
 
 
             if (!enrol_student($user->id, $course->id)) {       // Enrol the student
                 email_paypal_error_to_admin("Error while trying to enrol ".fullname($user)." in '$course->fullname'", $data);
+                die;
             } else {
                 if (!empty($CFG->enrol_paypalemail)) {
                     $teacher = get_teacher();
diff --git a/enrol/paypal/return.php b/enrol/paypal/return.php
new file mode 100644 (file)
index 0000000..4ee264e
--- /dev/null
@@ -0,0 +1,34 @@
+<?php  // $Id$
+
+    require("../../config.php");
+    require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
+
+    require_variable($id);
+
+    if (!$course = get_record("course", "id", $id)) {
+        redirect($CFG->wwwroot);
+    }
+
+    require_login();
+
+/// Refreshing enrolment data in the USER session
+    $enrol = new enrolment_plugin();
+    $enrol->get_student_courses($USER);
+
+    if ($SESSION->wantsurl) {
+        $destination = $SESSION->wantsurl;
+        unset($SESSION->wantsurl);
+    } else {
+        $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
+    }
+    
+    if (isstudent($course->id) or isteacher($course->id)) {
+        redirect($destination, get_string('paymentthanks', '', $course->fullname));
+
+    } else {   /// Somehow they aren't enrolled yet!  :-(
+        print_header();
+        notice(get_string('paymentsorry', '', $course), $destination);
+    }
+    
+
+?>
diff --git a/enrol/paypal/thankyou.php b/enrol/paypal/thankyou.php
deleted file mode 100644 (file)
index 9d28633..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-require ("../../config.php");
-
-
-if (isset($_GET['courseid'])) {
-    $course = get_record("course", "id", $_GET['courseid']);
-}
-
-if ($SESSION->wantsurl) {
-    $destination = $SESSION->wantsurl;
-    unset($SESSION->wantsurl);
-} else {
-    if ($course) {
-        $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
-    } else {
-        $destination = "$CFG->wwwroot/course/";
-    }
-}
-
-
-$str = "Thank you for your payment.";
-if ($course) {
-    $str .= "You should now be able to access $course->fullname";
-}
-
-
-
-print_header();
-
-notice($str, $destination);
-
-
-?>
index 8aff1f5053bca81dd265d6a6fc29c50b0cfe9293..93b8d16473684db2f1af633087aeacd1c23b7aa9 100644 (file)
@@ -188,12 +188,14 @@ $string['confirm'] = 'Confirm';
 $string['confirmed'] = 'Your registration has been confirmed';
 $string['confirmednot'] = 'Your registration has not yet been confirmed!';
 $string['continue'] = 'Continue';
+$string['continuetocourse'] = 'Click here to enter your course';
 $string['cookiesenabled'] = 'Cookies must be enabled in your browser';
 $string['copy'] = 'copy';
 $string['copyingcoursefiles'] = 'Copying course files';
 $string['copyinguserfiles'] = 'Copying user files';
 $string['copyingzipfile'] = 'Copying zip file';
 $string['copyrightnotice'] = 'Copyright notice';
+$string['cost'] = 'Cost';
 $string['country'] = 'Country';
 $string['course'] = 'Course';
 $string['courseavailable'] = 'This course is available to students';
@@ -721,6 +723,10 @@ $string['passwordsenttext'] = '   <P>An email has been sent to your address at $
    <P><B>Please check your email for your new password</B>
    <P>The new password was automatically generated, so you might like to
    <A HREF=$a->link>change it to something easier to remember</A>.';
+$string['paymentinstant'] = 'Use the button below to pay and be enrolled within minutes!';
+$string['paymentrequired'] = 'This course requires a payment for entry.';
+$string['paymentsorry'] = 'Thank you for your payment!  Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the course \"$a->fullname\".  Please try continuing to the course in a few seconds, but if you continue to have trouble then please alert the $a->teacher or the site administrator';
+$string['paymentthanks'] = 'Thank you for your payment!  You are now enrolled in your course:<br />\"$a\"';
 $string['people'] = 'People';
 $string['personalprofile'] = 'Personal profile';
 $string['phone'] = 'Phone';