Setting Paypal

Setting Paypal

by Stephan Tinschert -
Number of replies: 8

Hi,

I’m trying to set up Paypal on our Moodle server. I’ve looked everywhere for proper documentation, but I couldn’t find anything. Then I did a forum search and found this post (http://moodle.org/mod/forum/discuss.php?d=49460) where they were discussing setting Moodle to access Paypal’s sandbox service, to test if everything is working properly. They said that you needed to change some settings in the enrol.html file. I did all that, then created 2 test accounts. One for the buyer and one for the seller. So when I finally test I get this: "Thank you for your payment! Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the course "XXX-XXX". Please try continuing to the course in a few seconds, but if you continue to have trouble then please alert the Teacher or the site administrator.”

I found in the forums that someone has had the same trouble(http://moodle.org/mod/forum/discuss.php?d=16883). The thing is that the post is 2 years old. They are using a older version of Moodle and there is no solution posted.

Now I remember, during the Moodle installation, I remember reading something about my Paypal plug-in being out of date. Is this the problem? If so can you tell me where I can download the newer version (I looked in the download section and didn’t find anything)?

Thank you in advance!
Stephan

Average of ratings: -
In reply to Stephan Tinschert

Re: Setting Paypal

by Stephan Tinschert -
I just wanted to say I found the solution for my problem. An additional line also needed to be changed in the code beside the paypal to sandbox.paypal one.
Everything is documented here: http://docs.moodle.org/en/Enrolment_plugins_%28developer%29
What I found misleading was the description. It said only for versions 1.4 - 1.6 and I'm using 1.8 so I thought it didn't concerned me. But I did what it said, and it works just fine. I also changed it in the wiki, so it now should say 1.8 too.

Hope this helps someone.

Regards,
Stephan
In reply to Stephan Tinschert

Re: Setting Paypal

by Starr Eaddy -

Thank you in advance. I am trying to set up paypal and thought it would be wise to browse this discussion board prior to getting started.

In reply to Stephan Tinschert

Re: Setting Paypal

by Tony Phillips -

Hello guys,

First of all, thank you for pointing out the documentation.  I already made the changes on that page, but I still get that message:

Thank you for your payment! Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the course "My Test Course". Please try continuing to the course in a few seconds, but if you continue to have trouble then please alert the Teacher or the site administrator

It must be something else.

In reply to Tony Phillips

Re: Setting Paypal

by Leang Chumsoben -
I also encountered the same problem. I have modified enrol/paypal/enrol.html and enrol/paypal/ipn.php as mentioned at http://docs.moodle.org/en/Enrolment_plugins_%28developer%29, but I still get "Thank you for your payment! Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the course "XXX-XXX". Well, the PayPal payment is working without problem.

Anyone can give us the clue?
In reply to Leang Chumsoben

Re: Setting Paypal

by Lisa Dodson -
I am having the same issue.  The payment is not the problem because it's going through on the Paypal side.  Help! 
In reply to Lisa Dodson

Re: Setting Paypal

by Joel Bratsch -

Yes... I've also just recently waisted MUCH time on this (over 8 hours...)

 I'm using Moodle version  1.8

Here's what I found.. and this did FIX the issue for me, as I'm also using GoDaddy as the hosting site as mentioned in this forum posting.

 

http://paypal.lithium.com/pdn/board/message?board.id=pdt&message.id=681&jump=true

So... you'll need to do the following:

  1. Edit the file ipn.php in the folder enrol\paypal
  2. Look for the code that set's the Paypal header info ($header)
    /// Open a connection back to PayPal to validate the data
  3. As describe in the above article... add the following line

      $header .= "HOST: www.sandbox.paypal.com:80\r\n";
  4. So the $header building will look  like:
      $header = '';
      $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
      $header .= "HOST: www.sandbox.paypal.com:80\r\n";
      $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
      $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  5. I'm using the sandbox... however the following is probably more appropriate.
  6. Now.. you can (and should) use the variable for the "HOST"... so that the URL isn't hardcoded... something more like this

        $header .= empty($CFG->usepaypalsandbox) ? 'HOST: www.paypal.com:80\r\n' : 'HOST: www.sandbox.paypal.com:80\r\n';
  7. good luck!
In reply to Joel Bratsch

Re: Setting Paypal

by Lisa Dodson -

I'm still having the same problem.

Here's the code that I modified.   Is there still something wrong with it?

 $header = ";
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "HOST:www.sandbox.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);

    if (!$fp) {  /// Could not open a socket to PayPal - FAIL
        echo "<p>Error: could not access paypal.com</p>";
        email_paypal_error_to_admin("Could not access paypal.com to verify payment", $data);
        die;
    }

In reply to Lisa Dodson

Re: Setting Paypal

by Joel Bratsch -
  1. First of all... in my previous example, I was specifically going  to paypal sandbox 'www.sandbox.paypal.com'
  2. Secondly...  I'm using GoDaddy.com as my hosting service, and this solution, from what I gathered, was addressed specifically at modifying the header for godaddy.
  3. Here's the code in ipn.php, for the Paypal connection section: I have specifically set the variable $paypaladdr  to use "live" or "sandbox" paypal (depending on $CFG->usepaypalsandbox), which  is then used in setting the header, and accessing fsockopen.

/// Open a connection back to PayPal to validate the data

    $paypaladdr = empty($CFG->usepaypalsandbox) ? 'www.paypal.com' : 'www.sandbox.paypal.com';

  $header = '';
  $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  
  $header .= "HOST: ".$paypaladdr.":80\r\n";

  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
   
    $fp = fsockopen ($paypaladdr, 80, $errno, $errstr, 30);

fyi... during testing on paypal sandbox.. I'm also  setting up the following 2 variables in my config.php file.

  1. $CFG->usepaypalsandbox = 'TRUE';
  2. $CFG->enrol_paypalbusiness = 'your test business merchant email here';

Hope this helps...