Moodle & Paypal integration (godaddy.com style)
I’ve spent the last 6 hours trying to get moodle to integrate with paypal.com. It’s been ugly, dirty, and I may have blurted out a few curse words here and there, but I’m happy to say I got it working. So I thought I’d share the love.
First a brief overview of the methodology and desire. We have a 5 year spanish leadership course we offer through our church for people who want to learn what it means and how to lead in a church, either in a pastoral position or a layman leadership role. For years we have struggled with maintaining this daunting task by sending out VHS then DVD’s to students for fees that would make your head spin. So we converted all of the audio to an mp3 format with the dream of putting in online so students could attend the classes from anywhere in the world (Often our DVD’s and VHS tapes would be confiscated at the borders of less then loving countries.) So we looked at moodle.org as a platform to disburse our data, which worked out great, except we lacked a clean method of payment. For about 9 months we took payment by checks then would give them access. So as roles changed inside of KCBT it became clear that we needed to find an automated method of getting all this done. I’d known for some time that moodle would work with paypal but lacked the time and desire to make that happen. But the time had come to do it.
So, our goal was to have interested parties go to quedicelabiblia.com and register for classes online, pay online, get instant access, then if we had any problems with a specific student to simply remove them from the system (which I should mention that denying a student was very rare.) I proptly (well some what promptly) got with our Finance Director and setup a buisness paypal account and got things authorized. The next steps where fuzzy at best, and the documentation to make them happen was all but spread accross the entire web, but I’ve tried to condense them to this little post to make life more reasonable for he next guy.
First, we logged into our moodle account as an admin, and went to Site Administration> Users Authenticaiton and enabled Email-based self-registration. This is vital since a user needs to be logged in before he is able to pay for a course so the system can track who it is that actually paid. Then we went to Site Administraiton > Courses > Enrollement and enabled Paypal and made it the default. Next, you need to edit the setting for paypal by clicking “edit” and entering the email that is tied to your buisness paypal account and enabling Inform students, teachers, and admins (just for good measure.)
Next, you need to set the price for each class. So going to Site Administration > Courses > Add/edit classes > (then navigating to your specific classes) we clicked the edit button we scrolled down to the Availability seciton. Here we verified that guest access = do not allow guest access, Cost = x.xx; and clicked save changes. Oh don’t get feeling good about yourself yet, we’ve got more to do.
Now, we need to log into your paypal account, hopefully you can just get the login info from your Financial Director and save the time of having to do it from standing over their shoulder. After logging in we need to click on the “profile” link under “my account.” First go to “Language encoding” then “more options” and change it to “utf-8″ for both fields. Next back at the Profile page, go to “Instant Payment notifications prefrences” and click “edit.” Here you need to checkmark the box to turn on IPNP, and enter the address of your ipn.php file for moodle. In moodles case this is “http://yourdomain.com/moodle/enrol/paypal/ipn.php.” Mind you if you installed moodle at your root and not in the /moodle/ folder you’d drop the /moodle/…duh. So you think your cool now…eh, well you might be? But if your like me and using the down and dirty godaddy.com account….Brother I’m about to save you four hours of forum searching!
ADDED: Now if your using the Godaddy VPS accounts you do not need to follow this next step. Your deep pockets have saved you again! But for my cheap brothers, read on, I swear this won’t hurt much. -Thanks to Bruno-Pierre Carrier for finding this out.
Ok my godaddy brothers, it turns out that cheap comes at a cost, over and over again I’ve noticed that things just don’t work like they ought to in godaddy. But I digress, lets stay at the task at hand. Your going to need to pull down a copy of your “http://yourdomain.com/moodle/enrol/paypal/ipn.php” file and make a little change…..I’ll wait, go head and get it.
Your looking for this section & your going to add the code in red:
/// Open a connection back to PayPal to validate the data
$header = ”;
$header .= “POST /cgi-bin/webscr HTTP/1.0\r\n”;
$header .= “HOST: www.paypal.com:80\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);
Why do you need to add this, I have no idea, but it works. I found this info on a forum buried several pages in on the moodle.org site, but it reference making it work for the sandbox.paypal.com site. I figured it only standed to reason that it might just work for the paypal.com site too. Turns out I was right.
The good news is your done. It should work perfectly now, and you can go to your boss proclaiming that you’ve accomplished the impossible, and you should get a nominal 10% revenue fee for your hard work…..yea right.
Truth be told, this was a real headache, and I’m glad it’s over, but I can’t ignore how great of a resource this site could become for latin-american christians who want to further their growth in Christ and ministry. We have a four year leadership course for gringo’s too. Tomorrow, I’ll be going to their administrator and trying to talk them into doing the same thing!
As difficult as IT can be at times, it’s moments like this that I’m reminded of what an impact we can have on the Christian community as a whole. using entirely free tools, we’ve established an online school, that is making enough money to support itself financially, and train latin-american christians to do the work of the ministry. It boggles my mind when I consider that I’ve been apart of a ministry that will effect 100’s if not 1000’s and I don’t even speak spanish!
Jim Edwards is the IT Director for KCBT. Jim also began a print / web design company with his wife in December of 2006 called Edwards Design.
Email this author | All posts by Jim Edwards
A forum for non-profit Information Technology
Just an FYI, this is required because godaddy has some kind of proxy setup for connections like this. I’ve dealt with this through 1and1 before as well. With 1and1 we had to setup the connection to go through a specific proxy server (and we were writing our own code for it).
You might want to check on the security of this connection too. Seems to me like this type of connection should go through HTTPS (SSL) so all the data passed to and from paypal is encrypted. Might want to check with Moodle on this!
I’m with Travis on the security concern, but that technically depends on when/where the payment info is being entered. If they are bounced to PayPal and have to login there with their PayPal login (i.e. now giving them a secure connection) and all moodle is getting back is and Up or Down that the payment is good or not, then no worries that I see.
Does this mean we can see online enrollment for Shepard School soon too? (hehe)
LeeBing,
your absolutely right here, they don’t login till they hit the paypal site and Paypal simply gives a yea or nah concerning the processing of their card.
As for SSM, funny you should ask, I met with the Registrar yesterday to pitch the idea and she seemed responsive, I have a meeting next week to discuss some changes to the moodle platform for SSM and this topic is on the top of the list of requested features by them. I can safely say with 100% accuracy we should be using the same model for SSM by August of 2008.
Hi Jim!
I deeply thank you for the wonderful tutorial! It definitely is the best ressource on integrating paypal with Moodle
I followed the steps you’ve written down to the letter. I thought that since I had a GoDaddy VPS, I had to include that line in the ipn.php file. You could make your tutorial better by mentionning that GoDaddy users with a VPS don’t need to add that line
Again, thanks a lot to for the great tutorial!
Bruno-Pierre Carrier
Thanks Bruno-Pierre! I’ve added the info you discovered about the VPS accounts, I’m sure that will definately help a few people out.
Jim,
Thank you for saving me hours! I agree with Bruno. Excellent write up. By the way, I followed the same instructions but I am hosting at Dreamhost.com and it works the same. Jim