How do you get Moodle 2.0+ to point a PayPal transaction to the PayPal Sandbox? I tried what I found in the 1.9 docs to add a $CFG line to Moodle config.php file but that did not work. Any thoughts?
I don't have a direct answer for your question but maybe this will help. I messed with the Paypal sandbox when I was originally setting up my Moodle site to use the enrollment. Before I found out about the automatic enrollment feature, I had tried using the PayPal buttons (which is a different approach). In order to route users to the sandbox from a Paypal button I had to create the button from the PayPal Sandbox after having to create a Buyer and Seller accounts from within the Sandbox. This worked and routed the buyer user to the Sandbox once I clicked the button and could perform the transaction, but Moodle ends up failing when Paypal tries to route them back. One of my thoughts was because if you look at the email you receive it dumps the various variables back and one has a bad status for the purchase which I think is because its coming from the Sandbox. If you want to continue working with the sandbox you might want to look at the code generated for the button to help you with routing URLs.
However I found out how to utilize the Moodle automatic enrollment which was a different approach and I didn't have to mess with the Sandbox anymore.
Thanks for the post Shawn.
I can see the following line in the enrol.html file -
It appears to send the request to either the Sandbox or the live site. What I can't firgure out is what forces the change. It appears that when something is empty it goes to the sandbox, when it is not empty it goes to the live site. What is that SOMETHING?? Or can I just hack the line to for my requests to go to the sandbox (I could probably do that)? But I would really like to fugure out what this trigger is.
To speed things up I experimented with the $paypalurl line and removed the option to go to the sandbox or not and forced it to go to the sandbox.
$paypalurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
At least getting to th Sandbox is not a problem now. Seeing if the rest of the transaction works now.
Although I got the connection TO PayPal (sandbox) working I was getting the dreaded "Thank you for your payment! Unfortunately your payment has not yet been fully processed..." and pressing the Continue button (even after waiting a 10-15 seconds) made no difference. I was NOT enrolled in the course.
It appeared what he had here was "A failure to communicate" (Cool Hand Luke). In reviewing some other Moodle posts I learned that a PayPal transaction goes back and forth in a verification process. Being the Moodle noobie that I am, and not a PHP programmer, I began looking at the code to see where else the sandbox/livesite variable was listed (there seems to be something wrong in the code with selecting one or the other). I found another variable selection line pointing to either the sandbox or the live site in the ipn.php file. The line begins with $paypaladdr =. Once I removed the variable and directed the line to just the sandbox all began to work fine. (I still have not figured out what triggers that variable. So there are TWO places one needs to change this variable. At least if you are beginning your Moodle/PayPal project in the PayPal Sandbox. Here (as above) and in the enrol.php (the $paypalurl=).
Thank you Jim, you help me so much!
Sorry for my english.
I hope you have set the configuration in Site administration->plugins-> Enrolments->Manage enrol plugins->paypal->settings correctly
also if you assign $CFG->usepaypalsandbox in moodle/config.php what results you get ?
Did anyone ever get a clear answer for this issue?
I would like to use sandbox but I'm confused by this thread.
yeah, me too.
DUDES! Really! don't go posting all this "change this" "edit that" without posting HOW TO DO IT!
So, somebody says change "$paypaladdr ="
Does anybody know if this is the proper syntax?
$paypaladdr = 'www.sandbox.paypal.com';
Somebody says change config.php, it this the proper syntax?
$CFG->usepaypalsandbox = 'www.sandbox.paypal.com';
and does it go under the
And has anybody got it working?
Okay, I found out how to get the Moodle PayPal plugin to work with the PayPal Sandbox site for testing. Here we go:
- Okay, add the following line of code to your config.php file (in red). This tells the plugin to use the sandbox (don't forget to remove this when you are ready to go live!):
$CFG->admin = 'admin';
$CFG->usepaypalsandbox = 'www.sandbox.paypal.com';
$CFG->directorypermissions = 0777;
- Now, first make sure you have created a developer account with (1) a Business profile and a (2) personal profile. Instructions for that can be found here.
- Next, you will need to login to your business account's sandbox site and configure the Instant Payment Notification (IPN). This is what tells Moodle that the transaction is complete so the auto enrollment can be completed for the user into the course.
- In the paypal sandbox site go to Profile > Selling Preferences column > Instant Payment Notification Preferences.
- click to create a new IPN instance.
- For the notification URL put: http://<yourmoodlesite.com>/enrol/paypal/ipn.php
- enable the message delivery and save your changes.
- Now you should be ready to test it out.
- IMPORTANT!! You must be logged in to your PayPal developer account in order to use the sandbox. The new Developer-beta site is different than the old site.
- When you click on the payment button in Moodle to open the PayPal page, just make sure that it reads http://www.sandbox.paypal.com in the address bar.
- For the actual purchase in your sandbox account, make sure you either login using your sandbox personal account or use the credit card you setup for your personal account (see next step).
- To find your personal sandbox credit card information for testing, login to your developer account at http://developer.paypal.com
- click on the Application tab in the top menu then Applications > Sandbox accounts.
- click on the email address of the personal test account and then on Profile
- Use the "Funding" tab to copy/paste the credit card number and card expiry. Paypal also requires the code on the back of the card, just use "123".
- And ta-da!
Hope this helps.
For Step 6, shouldn't it be http://<yourmoodlesite.com>/online/enrol/paypal/ipn.php?
Insert Step 7a (while still in Paypal Sandbox /Profile)
+ click Language settings - choose your language and under "more Options" specify "UTF-8" as encoding and "yes" for the returning information in the same format. UTF-8 is required for final enrolment of the student into the course.
By the way: Notification URL as set in Step 6 () is correct.
Okay, I'm stumped. I've changed my config.php to go to the sandbox, and the sandbox URL shows up in the address bar.
Logged in to PayPal with the address where the money goes. I've changed the Instant Payment Notification (IPN) URL to http://xxx.com/moodle/enrol/paypal/ipn.php, which is the full path to that file on my site (Moodle is installed in the directory /moodle at the root). I've changed the encoding to UTF-8, and use the same encoding for data sent from PayPal.
In Moodle, I click onto the PayPal button, sign into there with the fake user account that I created. That all seems flawless, but when I am taken back to my site, it still gives me the message that my payment is not fully processed.
Any other suggestions on what to look for?
The plot thickens.....
I worked on this for a couple more hours, with no luck. Decided to try it 'live', transferring real money ($0.01). I got the same error message that my payment wasn't processed, but if I wait for a few seconds and hit the "continue" button, it shows that I am enrolled. What's up with that? Is it normal?
The paypal sandbox configurations probably has been changed since Brannon Carter's post. As of now, step 1 and 2 are enough. You do not have to set up the IPN on your paypal sandbox. As a matter of fact, there are no IPN setting options anymore. There is an IPN simulator option but perhaps that is for something else as the name suggests. You do have to use your paypal developer business email address when setting up Paypal in Moodle (I am using Moodle 2.9)
Nope, It isn't work for me.
Changed all the instances but display's the error!
Please can anyone help me.
Thanks in advance.