From 3d970777f4c24331ca2f88447304af71feaf7a7c Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 26 Jun 2004 14:40:25 +0000 Subject: [PATCH] OK, Paypal is now working. I've been buying access into some test courses. :-) Still polishing the GUI side of things now. --- enrol/paypal/enrol.html | 29 +++++++++++++++++++++++++---- enrol/paypal/enrol.php | 12 ++++++------ enrol/paypal/ipn.php | 35 ++++++++++++++++++++++++++++------- enrol/paypal/return.php | 34 ++++++++++++++++++++++++++++++++++ enrol/paypal/thankyou.php | 33 --------------------------------- lang/en/moodle.php | 6 ++++++ 6 files changed, 99 insertions(+), 50 deletions(-) create mode 100644 enrol/paypal/return.php delete mode 100644 enrol/paypal/thankyou.php diff --git a/enrol/paypal/enrol.html b/enrol/paypal/enrol.html index f275635bba..ff73a57317 100644 --- a/enrol/paypal/enrol.html +++ b/enrol/paypal/enrol.html @@ -1,18 +1,39 @@ +
+ +

+

enrol_paypalcurrency $cost"; ?>

+

+
- - + -wwwroot/enrol/paypal/thankyou.php?courseid=$course->id" ?>"> - +"> + +id-$course->id" ?>"> + +wwwroot/enrol/paypal/ipn.php"?>"> +wwwroot/enrol/paypal/return.php?id=$course->id" ?>"> + + +"> + + + + + + + + ">
+
diff --git a/enrol/paypal/enrol.php b/enrol/paypal/enrol.php index 49f1d3cc03..67829c90b3 100644 --- a/enrol/paypal/enrol.php +++ b/enrol/paypal/enrol.php @@ -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, "$strcourses -> $strloginto"); - print_course($course); + print_header($strloginto, $course->fullname, + "wwwroot/courses/\">$strcourses -> $strloginto"); + print_course($course, "80%"); print_simple_box_start("center"); - printf ("

$course->fullname has a cost of $CFG->enrol_paypalcurrency %01.2f

", $cost); - - echo "
"; + include("$CFG->dirroot/enrol/paypal/enrol.html"); echo "
"; diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index 1b4c122cd8..23a2fa656a 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -13,8 +13,11 @@ */ + 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."); } @@ -25,11 +28,12 @@ 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; @@ -66,22 +70,38 @@ } 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; } @@ -93,6 +113,7 @@ 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 index 0000000000..4ee264e7e5 --- /dev/null +++ b/enrol/paypal/return.php @@ -0,0 +1,34 @@ +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 index 9d28633ffe..0000000000 --- a/enrol/paypal/thankyou.php +++ /dev/null @@ -1,33 +0,0 @@ -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); - - -?> diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 8aff1f5053..93b8d16473 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -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'] = '

An email has been sent to your address at $

Please check your email for your new password

The new password was automatically generated, so you might like to link>change it to something easier to remember.'; +$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:
\"$a\"'; $string['people'] = 'People'; $string['personalprofile'] = 'Personal profile'; $string['phone'] = 'Phone'; -- 2.39.5