Paypal Enrollment IPN sending

Paypal Enrollment IPN sending

by Tom Wootton -
Number of replies: 25

I have moodle 2.0.3 and paypal enrollments works fine. I talked with paypal about wanting to sell books and videos in addition to courses and they suggested changing the way the IPN is handled.

If I leave paypal to global settings as moodle wants me to, then paypal will try to send book purchases info to moodle and it will confuse everything. Paypal says that moodle will not give paypal the proper response and in a few days paypal will turn off IPN thinking it is not working. When that happens my course enrollments will break too.

The suggestion is to send a hidden field with notify_url with the IPN value instead of having global settings handled at paypal. Does anyone know how to do that?

Average of ratings: -
In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by Kevin Freeborn -

This may be too simplistic for your purposes but .... I just created some web pages; then created paypal buy now buttons and pasted the paypal code into the web pages.

You can see what I mean at http://learn.nfstp.ca/

In reply to Kevin Freeborn

Re: Paypal Enrollment IPN sending

by Tom Wootton -

Hi Kevin,

I see that you too like Accentuate Theme. I searched the source code of the page and could not find notify_url there at all. If you have a solution that might work I am very interested in finding out more.

In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by James Snell -

I believe I'm having the same problem, or at least something close. I've had paypal enrollments working just fine on Moodle 2.0.3+... However, over the last two days, I received the following message twice now:

Hello [my name],

Please check your server that handles PayPal Instant Payment Notifications (IPN). IPNs sent to the following URL(s) are failing:

https://[my domain]/enrol/paypal/ipn.php

If you do not recognize this URL, you may be using a service provider that is using IPN on your behalf. Please contact your service provider with the above information. If this problem continues, IPNs may be disabled for your account.

Thank you for your prompt attention to this issue.


Thanks,

PayPal

Obviously, [my name] and [my domain] were set to sane things.

In my paypal account history, I received a payment TWO days ago that is flagged as an "eCheck payment" and is apparently "Pending Until Jul 5, 2011". Given the timing of it all, it would seem that this payment has trigged this issue in my case.

Further, paypal indicates that this payment is not yet complete and advises not to "ship" anything until it clears. However, the enrollment plugin has granted this student access to the course. (inferred via dates, names and enrollment method). Which makes me think students could possibly provide a bogus eCheck but still get enrolled.. Right?

Anyway, I'm fairly unsure what I ought to do about this. Perhaps I should look for a way to reject eChecks in my Paypal account?

I'd certainly appreciate some feedback!

Thanks friends!

James

 

UPDATE: I found that I could block eCheck payments in my paypal account profile preferences. So I've gone ahead and done that on the assumption that that's the issue here. Nice to also see that in changing that setting the pending eCheck payment is still pending and thus didn't seem to get clobbered. I'd still appreciate some feedback on this as I just acted on a guess.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

This has continued to be an issue for us - anyone else currently experiencing this? I think that the one eCheck payment we've received triggered it and since that's going to expire in a few days, I hope not to see this again. But maybe someone else here knows better?

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

Okay this is becoming a bigger issue for me.. I've now tried a ton of things to resolve this and I remain stumped. I get regular messages from Paypal informing me that:

Please check your server that handles PayPal Instant Payment Notifications (IPN). IPNs sent to the following URL(s) are failing:

https://[my domain name here]/enrol/paypal/ipn.php

The weird part is that I receive these messages for many days and then Paypal turns off IPN. Only when they turn IPN off, paypal enrollment of students stops working. I can go back in to Paypal and re-enable IPN and everything works - though I start getting these IPN messages again and everything implodes again when they auto-disable IPN.

Here's a copy of a transaction message from my IPN history in paypal:

mc_gross=0.01&protection_eligibility=Ineligible&payer_id=4G88CJM5VRC7G&tax=0.00&payment_date=16:04:40 Sep 06, 2011 PDT&payment_status=Completed&charset=UTF-8&first_name=James&option_selection1=test 30&mc_fee=0.01&notify_version=3.2&custom=497-5-32&payer_status=unverified&business=accounting@[my domain name here]&quantity=1&verify_sign=AjNMT9nRtuKS2auTxcxdsRz9rRvkPAI-HjDhvM9vs-2E5orNEoFCYZWSD&payer_email=james.snell@dawning.ca&option_name1=User&txn_id=8FK39807ME3U94457&payment_type=instant&last_name=Snell&receiver_email=tuition-payments@[my domain name here]&payment_fee=&receiver_id=DJDPUMUWT9N87&txn_type=web_accept&item_name=TEST&mc_currency=CAD&item_number=TEST&residence_country=CA&handling_amount=0.00&transaction_subject=497-5-32&payment_gross=&shipping=0.00&ipn_track_id=TRd5yqsVXxTjNp.rRW-oWd

 

I changed various keys/ids in there, but that's apparently the IPN message that Paypal's been trying to send (for a recent test/example) paypal enrollment. From the student perspective all seems well, It's weird.

On my server, I have corresponding 404 messages:

66.211.170.66 - - [06/Sep/2011:23:04:51 +0000] "POST /enrol/paypal/ipn.php HTTP/1.0" 404 34813 "-" "-"

These are then followed up by what I believe is normal traffic logs (and from a student perspective the experience related to the following line is totally normal:

[student's ip addr] - - [06/Sep/2011:23:05:01 +0000] "POST /enrol/paypal/return.php?id=5 HTTP/1.1" 200 10144 "https://www.paypal.com/ca/cgi-bin/merchantpaymentweb?SESSION=GGVyu8z6hHR8-lthvpZUO3NUV1ETpbg3c14D5nFmieTnMb6Use7yhXi3zMEoq&dispatch=50a222a57771930b6a38790606533de4d529b525e067e68bf0224adecfb9124e9671f737bafgh170819886897c0dd98fg2f17cd8d2763f541hfkanra" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1"

 

I'm currently running "Moodle 2.1.1+ (Build: 20110831)". Though I've had this problem for many months now and it's persisted accross various upgrades.

   I could really use some help with this, please!!   

 

 

In reply to James Snell

Re: Paypal Enrollment IPN sending

by maer israel -

I have a Moodle 2.1 site with this same problem (IPN warning messages, but registrations work).

 

I checked the .htaccess possibility, and there are no redirects or aliases.

I work on a Moodle 1.98 site whose IPN works flawlessly.  I wonder if the ipn.php script changed between versions?

Does anyone have any idea?

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

Alright, thanks to the comments posted in this ticket. Specifically: "PayPal says to have Admins enable IPN on their PayPal account but to turn off notifications." -- That statement kind of confused me as I tried various things and didn't seem to have much luck. Then I completely disabled IPN in Paypal, or so it seems. This appears to have 'resolved' this issue for me.

Paypal actually continues to throw IPN messages at my Moodle installation, but doesn't seem bothered by the http 404 response that is returned.

I really wanted to see why it's getting a 404, I can't say I know, but I collected some more raw data..

I dumped $_REQUEST coming in to ipn.php and got:

Array
(
[mc_gross] => 0.01
[protection_eligibility] => Ineligible
[payer_id] => 0A4GZCCJ39VRC7G
[tax] => 0.00
[payment_date] => 18:53:03 Dec 29, 2011 PST
[payment_status] => Completed
[charset] => UTF-8
[first_name] => James
[option_selection1] => Test 37
[mc_fee] => 0.01
[notify_version] => 3.4
[custom] => 1340-3-16
[payer_status] => unverified
[business] => avalidemail@gmail.com
[quantity] => 1
[verify_sign] => AKlWsd5Tes2oROahKK4pJaUQsTR7AdgiDcbs.e7rs5AGxDFwkxJddS54fK6pKd232
[payer_email] => i@jts.me
[option_name1] => User
[txn_id] => 9BN64824T18812816
[payment_type] => instant
[last_name] => Snell
[receiver_email] => alsovalidemail@gmail.com
[payment_fee] =>
[receiver_id] => DRDPVNUQW9N95
[txn_type] => web_accept
[item_name] => My Course Name
[mc_currency] => CAD
[item_number] => My Course Name
[residence_country] => CA
[handling_amount] => 0.00
[transaction_subject] => 1340-3-16
[payment_gross] =>
[shipping] => 0.00
[ipn_track_id] => J3rSUe78nf-mtyMIhV9MBcVw
)

 I dug in to ipn.php a bit and also found that it seems the function it uses for notifying admins upon failures isn't working for me. I edited it to dump any messages it tries to email me also in to a text file. Doing that I figured I'd find a message I was supposed to be getting that explained it all - but no. Doesn't seem the notify admin fxn is being called. So I still don't know why it's dying.

Hope this extra info helps someone... I'll settle for having completely disabled IPN in Paypal as everything functions just fine, it seems. Guess time will tell.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

False victory yet again. I really don't get this. So I had explicitly completely disabled IPN in Paypal before and could then go in and enrol through the paypal enrollment module in Moodle with complete success - or so it seemed. After a few days I started getting IPN warning messages from Paypal yet again. My Paypal's IPN settings clearly remain completely disabled. A few days after the IPN warnings resumed paypal enrollments in Moodle ceased working in the same style as when IPN would get automatically disabled.

Suffice to say, this horrible beast continues to cause me vast headaches. Any tips would be extremely awesome. I'll probably have to take another look at that ipn.php file in the paypal plugin to try to figure it out..

Over and out.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

Okay, I fixed it. You can view my ticket here to get a copy of a fixed version of ipn.php. Please up-vote that ticket if it's still not marked as resolved when you view it. I just need a Moodle dev to actually merge my fix in to the main development branches.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by maer israel -

Thanks James, I'm going to try this out and hopefully it will fix our problem with paypal periodically disabling IPN due to these erroneous 404 messages.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by Tom Wootton -

I gave up on using paypal to sell books and returned to the standard way of setting it up. It has been working great, but now I am getting the same problems as James. My last transaction worked great from my end, the customer was enrolled in the course, and we all got email notifications as expected. Then I started getting daily notices from Paypal that IPN is not working. Today they said they turned it off.

I logged into Paypal and found the transaction. Although it worked on my end, paypal thinks it did not (same 404 message from Paypal as James) and tried to resend it 15 times before disabling it. I re-enabled IPN, but suspect that it will keep having problems. Does anyone else have the same problems?

I am running Moodle 2.1.1+ (Build: 20110921) which is the latest as of Sept 24, 2011

In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by Jim Cook -

I speaking with PayPal and reviewing my IPN log in PayPal (which I previosly did not know I could do), it appears that something has changed in Moodle or on my Moodle server.  PayPal is now receiving a 404 response instead of the 200 response they are looking for.  404 of course indicates "page not found".  When you try to manually access the page I get the Moodle page I expect to see for the IPN.  Anyone have any ideas on why Moodle is now returning a 404 instead of 200? 

In reply to Jim Cook

Re: Paypal Enrollment IPN sending

by James Snell -
This remains an on going problem for me. I'm starting to feel that if I'm to resolve it, I'll have to really really dig in to the paypal enrollment plugin code. I guess that's just what it'll take as it appears to not be a problem for anyone who helped develop that plugin as is - but obviously this is a problem for most of us. :\
In reply to James Snell

Re: Paypal Enrollment IPN sending

by John Andrewartha -
This could be a problem with Paypal and there security. Something they change frequently. A simple solution, untried by me, but safe. In your Unix root shell as root change directory to your Moodle install. Further cd to enrol/paypal . Do a ls and you should see ipn.php . Now in you shell (you are the super user Root) execute the following command ln ./ipn.php ../../ You have now created a symbolic link to the file ipn.php in the Moodle root directory. cd ../../ and do a ls you should see it there. If you ever need to unlink then as root from the Moodle root type unlink ipn.php . Now change the URL in Paypal to point to the link. Apache and any decent webserver will follow symbolic links with out altering the original URL. Bonus, the link is not effected by upgrades to Moodle. If you try this and it works let us know. Please.
In reply to John Andrewartha

Re: Paypal Enrollment IPN sending

by Jim Cook -

I started running into this problem this week when our company started payments through our PayPal account that were not related to our Moodle site.  Each non-Moodle site payment generated an IPN (which go directly to my Moodle site) that was rejected by Moodle becuase it the payment has nothing to do with a Moodle purchase.

I too spoke with PayPal and they suggest, while trying to make two order systems work with the same PayPal Account, turning off PayPal notifications (while keeping IPN enabled) and sending the IPN URL (Moodle site) as a variable within the Moodle file that goes to PayPal through the use of the notify_url variable.

That all makes GREAT sense but I have no idea where to insert this variable.  It would seem that since PayPal can use the variable, that Moodle should make a little change to use the variable int he PayPal setup options in Moodle.

Any ideas on a more immediate way to do this?

Average of ratings: Useful (1)
In reply to John Andrewartha

Re: Paypal Enrollment IPN sending

by James Snell -

I don't understand why you think changing the url that paypal's meant to call moodle at would help? I can call up the ipn.php script at the default location just fine. 

What's your thinking?

Thanks for the suggestion regardless..

In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by James Snell -

This ticket seems focused on addressing this issue.

Please go vote for it to help the Moodle dev's prioritize it!

 

PS - I continue to have this issue on Moodle 2.2+

In reply to James Snell

Re: Paypal Enrollment IPN sending

by James Snell -

I think I've got a much better grasp on this annoying problem now. Hopefully I've actually resolved this now.. Read on!

From my investigation, I found that ipn.php was dying when it tried to call "message_send". It was using "message_send" to notify students, teachers and admins that an enrollment had been completed. In my case, for reasons I'm currently unaware of, 'message_send' fails completely. This causes ipn.php to spew all over the place and paypal's left wondering where all the love went (I'm guessing as ipn.php crashes, an open connection from paypal is closed in a '404' generating way - hence paypal thinking the whole ipn message wasn't handled sufficiently).

My fix for it is to find/replace all instances of "message_send" with a call to "attempt_message_send" - then define a function:

function attempt_message_send($eventdata) {
  try { message_send($eventdata); }
  catch (Exception $e) {}
}

This insulates ipn.php from whatever conditions that produce a 'message_send' call to die horribly. Afterall, having the whole ipn message receipt fail over moodle not being able to notify users that the thing they were trying to do worked (while they're looking at their screen seeing it work) is kind of lame. Granted, I'd like the notifications working anyway. But that's another quest.

I've attached my version of the file to the ticket associated with this problem, so hopefully a moodle dev will commit it to the main core of Moodle soon.

 

How to fix ipn.php

I've attached a copy of my modified version of ipn.php (called ipn-fixed.php visible to the upper right) - you can rename your ipn.php and place this one in its stead (so it must be renamed to 'ipn.php'). 

If you weren't having problems with 'message_send', this is harmless. If you were having problems, you should notice your ipn history will start showing ipn messages as "sent" and with a '200' response code, which has been the goal.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi James,

I've just come across this post started by Tom Wootn, but did wonder if everyone here has read and followed the instructions in the Moodle Doc on this method of PayPal enrollment/payments etc and the role of the IPN especially?

http://docs.moodle.org/22/en/Paypal_enrolment#Course_settings_for_Paypal

The instructions are as follows:

What to set up in Paypal

  • Setup your PayPal account at paypal.com
  1. Create a Paypal account
  2. Not required but recommended for selling: Upgrade your account to "Premier" status and get "Verified"
  3. Setup IPN in Paypal to interact with Moodle. Log into Paypal, go to "Profile > Instant Payment Notifications (IPN)”, click "Turn On IPN", click the "Edit settings" and enter a URL that references your IPN file in your Moodle installation (for example: http://<domain name>/moodle/enrol/paypal/ipn.php)
  4. Set the Encoding to UFT-8. In Paypal, go to "Profile > Language Encoding" (under the Selling Preferences column) and set your website's language (like select "Western European Languages (including English)" as it is the only English version). Then click on the "More Options" button and set the Encoding to "UTF-8", select "Yes" to use the same encoding for data sent from Paypay to you, and save.

Just curious smile

Cheers

Mary

In reply to Mary Evans

Re: Paypal Enrollment IPN sending

by James Snell -

Hi Mary, Thanks for posting the instructions - certainly that was the first thing I tried - about a dozen times.

 

Indeed RTFMing is the way to begin. But for many, there's an actual problem here. I think why it may be an issue for some, but not all, has a lot to do with the configuration of the server environment in use for each paypal installation. The "message_send()" function called by ipn.php is where my installations where failing miserably and causing paypal to send me IPN error messages. I don't know (yet) why my message_send calls fail, but I'm betting it's a server config thing. The fix I applied to ipn.php is really minor, but functional - it just insulates the script against the case of calls to message_send failing - doesn't seem to me like the way it was failing was anywhere near as graceful.

Thanks for chimining in - certainly some people crusing this topic may do well to first try the steps you've pointed out. Though I'll add that I've found that those steps aren't necessary. Seems that the paypal enrollment module has come far enough since that was written that those steps are no longer required. But, perhaps that isn't true for everyone. Certainly, knowing what to do manually is a good thing!

Cheers

In reply to James Snell

Re: Paypal Enrollment IPN sending

by Deleted user -

THis may be a red herring, but we had a problem whereby having the price, with € symbol, within the course name, caused Paypal some (and us) some issues.  Just a thought.

In reply to James Snell

Re: Paypal Enrollment IPN sending

by Tom Wootton -

Hi James,

I am trying your solution and wonder if you can help me with the text file dump? What do I need to do to get that to work?

 

catch (Exception $e) {
//You may want to enable a plain text file to dump the message in
/*
$notifcation_file = "ipn_failed-to-send_notifications.txt"
$fh = fopen($notification_file, 'a');
fwrite($fh, $eventdata->fullmessage."\r\n###########\r\n");
fclose($fh);
*/
}

 

I guess my questions are: where do I put the text file? Do I have to create a blank first? Do I need to give it permissions of any sort? I assume I just remove the comment tags of /* and */ to turn it on.

In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by James Snell -

Yup, just uncomment the section by removing the /* and the */. You may need to manually create the file as I've named it there and make sure that the user/process running the web service on your service can write to that file.

In reply to Tom Wootton

Re: Paypal Enrollment IPN sending

by James Snell -

Please upvote my ticket which includes my repaired version of ipn.php.

Hopefully a dev will recognize it and merge it in the main development branch soon. Upvotes will certainly help that!

In reply to James Snell

Re: Paypal Enrollment IPN sending

by Kamal Joshi -

Thanks James,

 FYI, I am getting following error messages in error log when I tried your script. Anyways i got the idea what could be the actuall reason.

 

[04-Jun-2012 05:38:15] PHP Warning:  Missing argument 2 for message_paypal_error_to_admin(), called in /home/kamal/public_html/enrol/paypal/ipn.php on line 38 and defined in /home/kamal/public_html/enrol/paypal/ipn.php on line 307
[04-Jun-2012 05:38:15] PHP Notice:  Undefined variable: data in /home/kamal/public_html/enrol/paypal/ipn.php on line 315
[04-Jun-2012 05:38:15] PHP Warning:  Invalid argument supplied for foreach() in /home/kamal/public_html/enrol/paypal/ipn.php on line 315
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 84
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 85
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 116
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 313
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 347
[04-Jun-2012 05:38:15] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 121
[04-Jun-2012 05:38:15] PHP Notice:  Undefined variable: notification_file in /home/kamal/public_html/enrol/paypal/ipn.php on line 343
[04-Jun-2012 05:38:15] PHP Warning:  fopen() [<a href='function.fopen'>function.fopen</a>]: Filename cannot be empty in /home/kamal/public_html/enrol/paypal/ipn.php on line 343
[04-Jun-2012 05:38:15] PHP Warning:  fwrite(): supplied argument is not a valid stream resource in /home/kamal/public_html/enrol/paypal/ipn.php on line 344
[04-Jun-2012 05:38:15] PHP Warning:  fclose(): supplied argument is not a valid stream resource in /home/kamal/public_html/enrol/paypal/ipn.php on line 345
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 84
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 85
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 116
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 313
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 347
[04-Jun-2012 05:38:16] PHP Notice:  Trying to get property of non-object in /home/kamal/public_html/lib/messagelib.php on line 121
[04-Jun-2012 05:38:16] PHP Notice:  Undefined variable: notification_file in /home/kamal/public_html/enrol/paypal/ipn.php on line 343
[04-Jun-2012 05:38:16] PHP Warning:  fopen() [<a href='function.fopen'>function.fopen</a>]: Filename cannot be empty in /home/kamal/public_html/enrol/paypal/ipn.php on line 343
[04-Jun-2012 05:38:16] PHP Warning:  fwrite(): supplied argument is not a valid stream resource in /home/kamal/public_html/enrol/paypal/ipn.php on line 344
[04-Jun-2012 05:38:16] PHP Warning:  fclose(): supplied argument is not a valid stream resource in /home/kamal/public_html/enrol/paypal/ipn.php on line 345