Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

Setting up PayPal development

From MoodleDocs

Moodle allows for PayPal based enrolments, and it is not always desirable to test this functionality during development on a live PayPal merchant account. Fortunately, PayPal provide a reasonably easy-to-use development sandbox for people to use.

Requirements

You will need the following things to develop against PayPal's sandbox:

  • Working Moodle installation (version x and above)
  • A PayPal merchant account (https://paypal.com)
  • A PayPal developer account (https://developer.paypal.com/)
  • Using the Sandbox: $CFG->usepaypalsandbox = 'www.sandbox.paypal.com';
  • ngrok (assuming you're developing on a local/non-web-accessible Moodle instance) (https://ngrok.com/)

On the PayPal developer account, you will need two sandbox accounts: 1 business and 1 personal.

Setup

  • Before configuring the PayPal side of things, we need to make our local Moodle instance publicly accessible. This is so that the PayPal sandbox is able to notify Moodle that it has accepted a Payment, which will allow us to verify that we can enrol a student into a course. Download and install ngrok as per the instructions on their website. Run ngrok and note the URL it provides for you.
  • We need to set the wwwroot to match our ngrok URL. For instance, if my ngrok URL was 'http://4fee0bfa.ngrok.com/' and my moodle instance was called 'paypal' then my wwwroot in config.php would be 'http://4fee0bfa.ngrok.com/paypal'
  • Login to your sandbox account under your business developer account (https://www.sandbox.paypal.com/)
  • Locate Account Settings > Notifications > Instant payment notifications and click Update and then Edit settings
  • Set the notification URL to the URL we set as our wwwroot with '/enrol/paypal/ipn.php' appended. Using our example wwwroot before, our notification URL would be 'http://4fee0bfa.ngrok.com/paypal/enrol/paypal/ipn.php'
  • Select the Receive IPN messages (enabled) radio button and click save

At this stage, Moodle is ready to begin testing with the PayPal sandbox. You can configure PayPal enrolment instances as per the instructions at https://docs.moodle.org/28/en/Paypal_enrolment