Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Enrolment plugins

From MoodleDocs

Testing paypal using the paypal developer sandbox

For moodle 1.4 - 1.8

If you follow these steps, you can test paypal payments using the paypal developer sandbox instead of the real paypal site. No money is actually charged to any account. All other actions are the same as if you were using the real paypal site.

  • create a paypal developer account at https://developer.paypal.com/cgi-bin/devscr?cmd=_home
  • change the address being used to send data to paypal to use the sandbox. in enrol/paypal/enrol.html:
  • change the address that is used to check the acknowledgment from paypal. in enrol/paypal/ipn.php, change:
    • $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
  • to
    • $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
  • create a couple of user accounts in the paypal sandbox and test enrolling in a course that requires payment (note that you need to be logged into the paypal sandbox while doing this testing)
  • under the "business" sandbox account you created, log in, go to "Profile", "Instant Payment Notification", and enter the full web-visible HTTPS URL to ../enrol/paypal/ipn.php. Failing to do this is a common mistake, and the cause of most headaches with this plugin.

For moodle 1.8.2 - 1.9.x

The above changes to the code were made part of the release starting with version 1.8.2

If you follow these steps, you can test paypal payments using the paypal developer sandbox instead of the real paypal site. No money is actually charged to any account. All other actions are the same as if you were using the real paypal site.

  • create a paypal developer account at https://developer.paypal.com/cgi-bin/devscr?cmd=_home
  • create a couple of user accounts in the paypal sandbox and test enrolling in a course that requires payment (note that you need to be logged into the paypal sandbox while doing this testing)
  • under the "business" sandbox account you created, log in, go to "Profile", "Instant Payment Notification", and enter the full web-visible HTTPS URL to ../enrol/paypal/ipn.php. Failing to do this is a common mistake, and the cause of most headaches with this plugin.
  • add the following line to config.php located in the root directory of your installation (where you installed Moodle).
    • $CFG->usepaypalsandbox = 'TRUE';
  • Add the business account email address from "business" account you created to the paypal module settings (in 1.9.x - Site Administration>Courses>Enrolments>Paypal>Edit)
  • You should be ready to test

Note about Paypal Sandbox

Only implement these changes if the above is not working and Moodle is returning the "...Unfortunately your payment..." message after returning from Paypal Sandbox.

At the time of this writing (14 June 2008) some changes are necessary to test successfully in the Paypal Sandbox. Details can be found here. This could change at any time at which point this may become unnecessary. For now do the following (only tested in 1.9.x so far):

  • Locate ipn.php in your installation on your server by migrating to to ../enrol/paypal/ipn.php
  • Create a backup copy of ipn.php and give it a name something like ipn.php-backup
  • Return to ipn.php and locate the following code :

$header = ;
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$paypaladdr = empty($CFG->usepaypalsandbox) ? 'www.paypal.com' : 'www.sandbox.paypal.com';
$fp = fsockopen ($paypaladdr, 80, $errno, $errstr, 30);

  • Change that code to :

$header = ;
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$paypaladdr = empty($CFG->usepaypalsandbox) ? 'www.paypal.com' :
'ssl://www.sandbox.paypal.com';
$fp = fsockopen ($paypaladdr, 443, $errno, $errstr, 30);

  • Try the course purchase again.

If the above still is not working you will need to seek help in the Enrolment Plugins Forum.

Enrolment plugins 1.7

Background

  1. isteacher(), isstudent(), isadmin(), iscoursecreator() are all deprecated and should be replaced with checks on has_capability instead.
  2. enrol_student() and add_teacher() are obsolete, so use the generic role_assign() or the convenience function for "students" called enrol_into_course() instead.
  3. unenrol_student() and remove_teacher() are obsolete, so use the generic role_unassign() instead.
  4. All the roles have a "shortname", so by default we can refer to them using "teacher", "student", "editingteacher" etc. Note that new roles may have different names. Enrolment plugins can use these to map outside data onto the inside roles without needing to know internal role id numbers. For example, it would be really handy for the flatfile plugin to refer to roles directly like this.
  5. Each plugin used to implement get_student_courses() and get_teacher_courses() for use at login time. These now need to be converted to one new function called $enrol->setup_enrolments($user) which looks up sets all enrolments for a given user (using role_assign and role_unassign).
  6. All the session arrays like $USER->student[] and $USER->teacher[] are gone and should not be relied on. You can check what roles a user already has by calling get_user_roles() on that course context.

What's been done

  1. enrol/manual has been converted to use the new functions
  2. enrol/imsenterprise has been converted - testing needed though

What still needs to be done

  1. enrol/authorize
  2. enrol/database
  3. enrol/flatfile
  4. enrol/ldap
  5. enrol/paypal

See also