Moodle
  1. Moodle
  2. MDL-30647

PayPal Setup Needs notify_url variable

    Details

    • Database:
      Any
    • Affected Branches:
      MOODLE_20_STABLE

      Description

      Many Moodle users would like to use their PayPal account for purchases other than Moodle transactions. This is not possible since Moodle requires that the PayPal IPN be set within PayPal to return ALL purchase notifications to the Moodle server. If the PayPal account is used to purchase something other than a Moodle transaction, an IPN will be generated and sent to Moodle. Moodle will reject the IPN and evetually, after too many rejects/failures, PayPal will autmically turn off IPN all together.

      What is needed is to include the PayPal notify_url (max characters 255) variable within the Moodle PayPal setup screen to be sent to PayPal along with the other purchase information. PayPal says to have Admins enable IPN on their PayPal account but to turn off notifications.

        Gliffy Diagrams

        1. ipn-fixed.php
          13 kB
          James Snell
        2. ipn-fixed.php
          13 kB
          James Snell

          Issue Links

            Activity

            Hide
            Michael de Raadt added a comment -

            Thanks for suggesting this.

            Show
            Michael de Raadt added a comment - Thanks for suggesting this.
            Hide
            Jim Cook added a comment -

            I just found where this function IS present in the current Moodle build. The PayPal integration documentation needs to be updated.

            Show
            Jim Cook added a comment - I just found where this function IS present in the current Moodle build. The PayPal integration documentation needs to be updated.
            Hide
            James Snell added a comment -

            +Thanks for posting.

            This has been producing much grief for me in the last several months. Jim's comment's also pretty interesting.

            Show
            James Snell added a comment - +Thanks for posting. This has been producing much grief for me in the last several months. Jim's comment's also pretty interesting.
            Hide
            James Snell added a comment -

            I've tried to dump all my notes about my minor attempts at debugging this annoying issue in the forum post here: http://moodle.org/mod/forum/discuss.php?d=177130

            Show
            James Snell added a comment - I've tried to dump all my notes about my minor attempts at debugging this annoying issue in the forum post here: http://moodle.org/mod/forum/discuss.php?d=177130
            Hide
            James Snell added a comment -

            I'm not convinced what the description gives reflects all of what's going on here. Either that, or I have an additional problem with the paypal enrolment plugin. It seems very clearly indicated in my paypal IPN history that the notify url is being correctly set for my different moodle sites (that go through the same paypal account).

            In the ipn.php there is a function to notify admins of problems with IPNs. That function is dying when it's called on my servers. Part of the error message I get is:

            Does the component and name you supplied to message_send() match a row in message_providers? Message providers must appear in the database so users can configure how they will be notified when they receive messages

            I added some lines to dump any messages that the ipn.php 'message_paypal_error_to_admin' function tries to use message_send() to sent to me in to a text file. I'm seeing that paypal seems to resend the ipn messages fairly quickly. Not sure THAT's causing a problem. Anyway, tid-bits of helpful info I hope.

            Show
            James Snell added a comment - I'm not convinced what the description gives reflects all of what's going on here. Either that, or I have an additional problem with the paypal enrolment plugin. It seems very clearly indicated in my paypal IPN history that the notify url is being correctly set for my different moodle sites (that go through the same paypal account). In the ipn.php there is a function to notify admins of problems with IPNs. That function is dying when it's called on my servers. Part of the error message I get is: — Does the component and name you supplied to message_send() match a row in message_providers? Message providers must appear in the database so users can configure how they will be notified when they receive messages — I added some lines to dump any messages that the ipn.php 'message_paypal_error_to_admin' function tries to use message_send() to sent to me in to a text file. I'm seeing that paypal seems to resend the ipn messages fairly quickly. Not sure THAT's causing a problem. Anyway, tid-bits of helpful info I hope.
            Hide
            James Snell added a comment -

            Yeah, so here's a (super crude) way 'around' the issue as I'm experiencing it.

            1. Find & Replace all instances of "message_send" in ipn.php with "discard_message_send"

            2. Add a function to ipn.php "function discard_message_send($msg)

            { return; }

            "

            3. Move on.

            What's happening for me is the ipn script was dying on the message_send function, for reasons I haven't yet investigated. It trying to use message_send for successful paypal payments to notify students/teachers/admins about the payment - but since that function was dying the script was dying and the connection to paypal wasn't being closed correctly.

            Of course the next step is to either figure out what's going on with message_send or alter ipn.php to handle sending messages in a way that doesn't otherwise block exec of the script.

            Show
            James Snell added a comment - Yeah, so here's a (super crude) way 'around' the issue as I'm experiencing it. 1. Find & Replace all instances of "message_send" in ipn.php with "discard_message_send" 2. Add a function to ipn.php "function discard_message_send($msg) { return; } " 3. Move on. What's happening for me is the ipn script was dying on the message_send function, for reasons I haven't yet investigated. It trying to use message_send for successful paypal payments to notify students/teachers/admins about the payment - but since that function was dying the script was dying and the connection to paypal wasn't being closed correctly. Of course the next step is to either figure out what's going on with message_send or alter ipn.php to handle sending messages in a way that doesn't otherwise block exec of the script.
            Hide
            James Snell added a comment -

            This version of ipn.php renames all calls to 'message_send' to 'attempt_message_send' - then specifies a function called 'attempt_message_send' that passes the input through to 'message_send', while wrapping it in a try-catch block. This allows calls to be made to "message_send" that won't crash the script if "message_send" fails - which has been preventing a lot of people from being able to use the paypal plugin with success.

            Show
            James Snell added a comment - This version of ipn.php renames all calls to 'message_send' to 'attempt_message_send' - then specifies a function called 'attempt_message_send' that passes the input through to 'message_send', while wrapping it in a try-catch block. This allows calls to be made to "message_send" that won't crash the script if "message_send" fails - which has been preventing a lot of people from being able to use the paypal plugin with success.
            Hide
            James Snell added a comment -

            By the way, my attachment assumes the reporter incorrectly identified what the issue is here. Maybe the issue my attached file addresses is actually a different issue and should have its own ticket?

            Show
            James Snell added a comment - By the way, my attachment assumes the reporter incorrectly identified what the issue is here. Maybe the issue my attached file addresses is actually a different issue and should have its own ticket?
            Hide
            James Snell added a comment -

            I created my own ticket with my fix attached. I guess this ticket may be about something else, though I doubt it. Anyway, since nothing's happened with this lately, I'm hoping my ticket will get marked as resolved and my fix will be merged by a dev sooner than later. Here's my ticket: http://tracker.moodle.org/browse/MDL-31410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#issue-tabs

            Show
            James Snell added a comment - I created my own ticket with my fix attached. I guess this ticket may be about something else, though I doubt it. Anyway, since nothing's happened with this lately, I'm hoping my ticket will get marked as resolved and my fix will be merged by a dev sooner than later. Here's my ticket: http://tracker.moodle.org/browse/MDL-31410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#issue-tabs
            Hide
            Chris Follin added a comment -

            We found on one site that the IPN was failing (and Paypal was reporting a 404) due to mismatched capitalization in the email addresses. The business email address in the Paypal settings on the Moodle site was, for example, camel-case BusinessName@domainname.com. The email address included in the IPN message was all lowercase, businessname@domainname.com.

            That caused the following code (starting at line 184 of ipn.php in my version) to evaluate to false and the execution to die. When it dies, the connection to Paypal isn't closed and they interpret it as a 404.

            if ($data->business != $plugin->get_config('paypalbusiness')) {   // Check that the email is the one we want it to be
              message_paypal_error_to_admin("Business email is {$data->business} (not ".
                               $plugin->get_config('paypalbusiness').")", $data);
              die;
            }
            

            Like James, our message_send() is not completing successfully so the admin never received the message regarding the email mismatch. However, once we discovered the mismatch and had the client change the email address on the Moodle site to all lowercase, the IPN completed successfully. The notifications to student, teacher, and admin still failed but that's a separate issue that did not crash the IPN for us.

            Since a difference merely of capitalization does not cause a real problem, both strings should be forced to the same case before comparing them so that IPNs do not fail unnecessarily. I opened a new ticket and am including a patch for that. http://tracker.moodle.org/browse/MDL-31424

            Show
            Chris Follin added a comment - We found on one site that the IPN was failing (and Paypal was reporting a 404) due to mismatched capitalization in the email addresses. The business email address in the Paypal settings on the Moodle site was, for example, camel-case BusinessName@domainname.com. The email address included in the IPN message was all lowercase, businessname@domainname.com. That caused the following code (starting at line 184 of ipn.php in my version) to evaluate to false and the execution to die. When it dies, the connection to Paypal isn't closed and they interpret it as a 404. if ($data->business != $plugin->get_config('paypalbusiness')) { // Check that the email is the one we want it to be message_paypal_error_to_admin("Business email is {$data->business} (not ". $plugin->get_config('paypalbusiness').")", $data); die; } Like James, our message_send() is not completing successfully so the admin never received the message regarding the email mismatch. However, once we discovered the mismatch and had the client change the email address on the Moodle site to all lowercase, the IPN completed successfully. The notifications to student, teacher, and admin still failed but that's a separate issue that did not crash the IPN for us. Since a difference merely of capitalization does not cause a real problem, both strings should be forced to the same case before comparing them so that IPNs do not fail unnecessarily. I opened a new ticket and am including a patch for that. http://tracker.moodle.org/browse/MDL-31424
            Hide
            Chris Follin added a comment -

            Also please see MDL-31429 for a patch to install the message provider for enrol/paypal. The message provider not being installed is what is causing message_send() to fail.

            Show
            Chris Follin added a comment - Also please see MDL-31429 for a patch to install the message provider for enrol/paypal. The message provider not being installed is what is causing message_send() to fail.
            Hide
            Petr Skoda added a comment -

            Hello,

            I have updated the docs at http://docs.moodle.org/24/en/Paypal_enrolment#What_to_set_up_in_Paypal

            I just tested it is not necessary to setup IPN in paypal settings because moodle sends the correct notify_url as parameter.

            The other issues should be already resolved too, thanks everybody.

            Ciao

            Show
            Petr Skoda added a comment - Hello, I have updated the docs at http://docs.moodle.org/24/en/Paypal_enrolment#What_to_set_up_in_Paypal I just tested it is not necessary to setup IPN in paypal settings because moodle sends the correct notify_url as parameter. The other issues should be already resolved too, thanks everybody. Ciao

              People

              • Votes:
                6 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: