]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes not checked in yet
authormoodler <moodler>
Tue, 6 Jul 2004 16:00:43 +0000 (16:00 +0000)
committermoodler <moodler>
Tue, 6 Jul 2004 16:00:43 +0000 (16:00 +0000)
enrol/enrol.class.php
enrol/paypal/enrol.html
enrol/paypal/ipn.php

index bb064835e71950b57b3b2e69676e4c6b882f7a8e..be2701cefdb30e6faf298bae71fef5bf2bf0478a 100644 (file)
@@ -275,9 +275,11 @@ function cron() {
 function get_access_icons($course) {
     global $CFG;
 
+    $str = '';
+
     if ($course->guest) {
         $strallowguests = get_string("allowguests");
-        $str  = "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
+        $str .= "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
         $str .= "<img vspace=4 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/guest.gif\"></a>&nbsp;&nbsp;";
     }
     if ($course->password) {
index ff73a57317ac8885099fbe97f5235e96fc328c9a..7d59f3ad2dd911fdf7985115a65a41877dbd1b05 100644 (file)
 <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="for_auction" value="false">
 <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="rm" value="2">
 <input type="hidden" name="cbt" value="<?php print_string("continuetocourse") ?>">
 
 <input type="hidden" name="first_name" value="<?php p($USER->firstname) ?>">
index 4062d7ec9b75d12afd9fca5d6fc66cf331128b05..f12609f2e77a75ffa88f0a02727a2126964ef88a 100644 (file)
     $data->payment_currency = $data->mc_currency;
 
 
+/// get the user and course records
+
+    if (! $user = get_record("user", "id", $data->userid) ) {
+        email_paypal_error_to_admin("Not a valid user id", $data);
+        die;
+    }
+
+    if (! $course = get_record("course", "id", $data->courseid) ) {
+        email_paypal_error_to_admin("Not a valid course id", $data);
+        die;
+    }
+
+
 /// Open a connection back to PayPal to validate the data
 
     $header = '';
         $result = fgets($fp, 1024);
         if (strcmp($result, "VERIFIED") == 0) {          // VALID PAYMENT!
 
-            // check the payment_status is Completed
 
-            if ($data->payment_status != "Completed") {   // Not complete?
-                email_paypal_error_to_admin("Transaction status is: $data->payment_status", $data);
+            // check the payment_status and payment_reason
+
+            // If status is not completed or pending then unenrol the student if already enrolled
+            // and notify admin
+
+            if ($data->payment_status != "Completed" and $data->payment_status != "Pending") {
+                unenrol_student($data->userid, $data->courseid);
+                email_paypal_error_to_admin("Status not completed or pending. User unenrolled from course", $data);
                 die;
             }
 
+            // If status is pending and reason is other than echeck then we are on hold until further notice
+            // Email user to let them know. Email admin.
+
+            if ($data->payment_status == "Pending" and $data->pending_reason != "echeck") {
+                email_to_user($user, getadmin(), "Moodle: Paypal payment", "Your Paypal payment is pending.");
+                email_paypal_error_to_admin("Payment pending", $data);
+                die;
+            }
+
+            // 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 
+                   ($data->payment_status == "Pending" and $data->pending_reason == "echeck") ) ) {
+                die;
+            }
+
+            // At this point we only proceed with a status of completed or pending with a reason of echeck
+
+
+
             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 (!empty($CFG->enrol_paypalmailstudents)) {
                     $a->coursename = "$course->fullname";
                     $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
-                    email_to_user($user, $teacher, get_string("enrolmentnew"), get_string('welcometocoursetext', '', $a));
+                    email_to_user($user, $teacher, get_string("enrolmentnew", '', $course->shortname), get_string('welcometocoursetext', '', $a));
                 }
 
                 if (!empty($CFG->enrol_paypalmailteachers)) {
-                    email_to_user($teacher, $user, get_string("enrolmentnew"), "I have enrolled in your class via Paypal");
+                    email_to_user($teacher, $user, get_string("enrolmentnew", '', $course->shortname), "I have enrolled in your class via Paypal");
                 }
             }