Still polishing the GUI side of things now.
+<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>
/// Override the base print_entry() function
function print_entry($course) {
- global $CFG;
+ global $CFG, $USER;
$strloginto = get_string("loginto", "", $course->shortname);
} else {
$cost = (float) $course->cost;
}
+ $cost = format_float($cost, 2);
if (abs($cost) < 0.01) { // no cost, default to base class entry to 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>";
*/
+ 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();
--- /dev/null
+<?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);
+ }
+
+
+?>
+++ /dev/null
-<?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);
-
-
-?>
$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';
<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';