Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-35349

Paypal auto-enrol does not work with Moodle 2.3

    Details

    • Testing Instructions:
      Hide
      1. Visit <yoursite>/admin/settings.php?section=manageenrols and turn on PayPal.
      2. Click on the settings and set PayPal business email to 'markn_1351839182_biz@moodle.com' (you can use yours if you have one set up)
      3. In the config.php file add '$CFG->usepaypalsandbox = true;'
      4. Create a course that uses the PayPal enrolment plugin and set the price to $1.
      5. Log in as a student and click on the course, then the PayPal link.
      6. Enter your email as 'markn_1351765059_per@moodle.com' (again, use another one if you have an account set up) and the password '12345678'.
      7. Confirm payment and click on the link to go back to your Moodle site.
      8. Ensure the following error does not occur -

      Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result

      Note: You will not be enrolled in the course as PayPal needs to be able to communicate to your localhost server. This test simply ensures the PHP error does not occur which the community has reported is causing the issue with users not enrolling.

      Show
      Visit <yoursite>/admin/settings.php?section=manageenrols and turn on PayPal. Click on the settings and set PayPal business email to 'markn_1351839182_biz@moodle.com' (you can use yours if you have one set up) In the config.php file add '$CFG->usepaypalsandbox = true;' Create a course that uses the PayPal enrolment plugin and set the price to $1. Log in as a student and click on the course, then the PayPal link. Enter your email as 'markn_1351765059_per@moodle.com' (again, use another one if you have an account set up) and the password '12345678'. Confirm payment and click on the link to go back to your Moodle site. Ensure the following error does not occur - Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result Note: You will not be enrolled in the course as PayPal needs to be able to communicate to your localhost server. This test simply ensures the PHP error does not occur which the community has reported is causing the issue with users not enrolling.
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-35349_master

      Description

      Payment goes through. IPN History shows return code of 200 for the transaction. Receipt is sent twenty minutes after payment notification is sent (money definitely flows, just not fast).

      User gets: "Thank you for your payment! Unfortunately your payment has not yet been fully processed". Does not get enroled.

      PHP errors read:
      Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result
      line 458 of /lib/pagelib.php: call to debugging()
      line 1429 of /lib/pagelib.php: call to moodle_page->magic_get_context()
      line 1444 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
      line 55 of /enrol/paypal/return.php: call to bootstrap_renderer->__call()
      line 55 of /enrol/paypal/return.php: call to bootstrap_renderer->header()

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            skodak Petr Skoda added a comment -

            Thanks for the report.

            Show
            skodak Petr Skoda added a comment - Thanks for the report.
            Hide
            cfollin Chris Follin added a comment -

            Same problem for us in 2.2.3 but so far we have only seen it with the Paypal sandbox environment. Live transactions are working on at least one site.

            Show
            cfollin Chris Follin added a comment - Same problem for us in 2.2.3 but so far we have only seen it with the Paypal sandbox environment. Live transactions are working on at least one site.
            Hide
            clancyhood Clancy Hood added a comment -

            I traced my version of the problem down to return.php - $context is set up but not used. About line 40, add $PAGE->set_context($context);

            $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
            require_login();
            $PAGE->set_context($context);

            Also, it's impossible to enrol unless paypal sends mooodle a payment_status of either "Complete" or "Pending" and the "pending_reason" status of "echeck". If you haven't yet set up a withdrawal account for the recipient email at paypal, or for a plethora of other reasons, payment_status will come up as pending and then students won't get enrolled. You should get an email from moodle when a paypal enrolment fails, telling you why.

            If you wish, you can fix your ipn.php to accept some other "pending_reason"s that don't apply or are otherwise not an issue. There's a list of each and their explanation here:

            https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables

            Show
            clancyhood Clancy Hood added a comment - I traced my version of the problem down to return.php - $context is set up but not used. About line 40, add $PAGE->set_context($context); $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); require_login(); $PAGE->set_context($context); Also, it's impossible to enrol unless paypal sends mooodle a payment_status of either "Complete" or "Pending" and the "pending_reason" status of "echeck". If you haven't yet set up a withdrawal account for the recipient email at paypal, or for a plethora of other reasons, payment_status will come up as pending and then students won't get enrolled. You should get an email from moodle when a paypal enrolment fails, telling you why. If you wish, you can fix your ipn.php to accept some other "pending_reason"s that don't apply or are otherwise not an issue. There's a list of each and their explanation here: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables
            Hide
            clancyhood Clancy Hood added a comment - - edited

            Here's the fix for enrol/paypal/ipn.php (about line 132, replacing code between the comments "// If status is pending and reason ..." and "// At this point we only ..."), with the status quo as the initial. To add reasons you are happy to accept, alter the reason from false to true.

            $pending_reasons_acceptable = array(
            	'address' => false,
            	'authorization' => false,
            	'echeck' => true,
            	'intl' => false,
            	'multi-currency' => false,
            	'order' => false,
            	'paymentreview' => false,
            	'unilateral' => false,
            	'upgrade' => false,
            	'verify' => false,
            	'other' => false
            );
             
            if ($data->payment_status == "Pending"){
             
                $accept = @$pending_reasons_acceptable[$data->pending_reason];
            	
                if($accept !== true) {
                    $eventdata = new stdClass();
                    $eventdata->modulename        = 'moodle';
                    $eventdata->component         = 'enrol_paypal';
                    $eventdata->name              = 'paypal_enrolment';
                    $eventdata->userfrom          = get_admin();
                    $eventdata->userto            = $user;
                    $eventdata->subject           = "Moodle: PayPal payment";
                    $eventdata->fullmessage       = "Your PayPal payment is pending.";
                    $eventdata->fullmessageformat = FORMAT_PLAIN;
                    $eventdata->fullmessagehtml   = '';
                    $eventdata->smallmessage      = '';
                    message_send($eventdata);
             
                    message_paypal_error_to_admin("Payment pending", $data);
                    die;
                }
               
            }else{
             
                // If our status is not completed or not pending for a reason we don't mind about then ignore and die
                // This check is redundant at present but may be useful if paypal extend the return codes in the future
             
                if ( $data->payment_status != "Completed" ){
            	message_paypal_error_to_admin("Payment not complete", $data);
            	die;
                }
            }

            Show
            clancyhood Clancy Hood added a comment - - edited Here's the fix for enrol/paypal/ipn.php (about line 132, replacing code between the comments "// If status is pending and reason ..." and "// At this point we only ..."), with the status quo as the initial. To add reasons you are happy to accept, alter the reason from false to true. $pending_reasons_acceptable = array( 'address' => false, 'authorization' => false, 'echeck' => true, 'intl' => false, 'multi-currency' => false, 'order' => false, 'paymentreview' => false, 'unilateral' => false, 'upgrade' => false, 'verify' => false, 'other' => false );   if ($data->payment_status == "Pending"){   $accept = @$pending_reasons_acceptable[$data->pending_reason]; if($accept !== true) { $eventdata = new stdClass(); $eventdata->modulename = 'moodle'; $eventdata->component = 'enrol_paypal'; $eventdata->name = 'paypal_enrolment'; $eventdata->userfrom = get_admin(); $eventdata->userto = $user; $eventdata->subject = "Moodle: PayPal payment"; $eventdata->fullmessage = "Your PayPal payment is pending."; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; message_send($eventdata);   message_paypal_error_to_admin("Payment pending", $data); die; } }else{   // If our status is not completed or not pending for a reason we don't mind about then ignore and die // This check is redundant at present but may be useful if paypal extend the return codes in the future   if ( $data->payment_status != "Completed" ){ message_paypal_error_to_admin("Payment not complete", $data); die; } }
            Hide
            icauto Doug added a comment -

            Hello,

            Just wondering how this is a minor priority? Paypal is not working correctly in 2.2.2, and according to this it is not working at all in 2.3. Dont we think this is a little more importatn then minor?

            Doug

            Show
            icauto Doug added a comment - Hello, Just wondering how this is a minor priority? Paypal is not working correctly in 2.2.2, and according to this it is not working at all in 2.3. Dont we think this is a little more importatn then minor? Doug
            Hide
            akmiecik Alan Kmiecik added a comment -

            Doug, I don't get it either. I had a miserable time getting help. Made me wonder if I was the only one using Paypal with Moodle.

            But, along came Clancy! THANK YOU CLANCY. That fix seems to be working fine so far. Enrolments went live Sep 24th.

            Doug, ping me if you need help on how to put the fix in. Alan at AlanK dot net.

            Show
            akmiecik Alan Kmiecik added a comment - Doug, I don't get it either. I had a miserable time getting help. Made me wonder if I was the only one using Paypal with Moodle. But, along came Clancy! THANK YOU CLANCY. That fix seems to be working fine so far. Enrolments went live Sep 24th. Doug, ping me if you need help on how to put the fix in. Alan at AlanK dot net.
            Hide
            cfollin Chris Follin added a comment -

            Bumping priority because I agree with Doug that this isn't minor. Also adding patch tag for Clancy's solution.

            Show
            cfollin Chris Follin added a comment - Bumping priority because I agree with Doug that this isn't minor. Also adding patch tag for Clancy's solution.
            Hide
            icauto Doug added a comment -

            Thank You.

            Doug

            Show
            icauto Doug added a comment - Thank You. Doug
            Hide
            macdan Daniel S added a comment -

            This issue has been driving me crazy. We just upgraded from 1.9 to 2.3 specifically to use Paypal and it just doesn't work.

            I tried Clancy's fix, though it didn't solve it for me.

            Is this actively being worked on? Anything I can do to help in terms of reporting or troubleshooting - just let me know.

            Show
            macdan Daniel S added a comment - This issue has been driving me crazy. We just upgraded from 1.9 to 2.3 specifically to use Paypal and it just doesn't work. I tried Clancy's fix, though it didn't solve it for me. Is this actively being worked on? Anything I can do to help in terms of reporting or troubleshooting - just let me know.
            Hide
            clancyhood Clancy Hood added a comment -

            Worth noting that "my" fix is for a live paypal setup - I've never tried it in the paypal sandbox environment, and have no idea if the same "payment_status"es are sent by paypal when in sandbox mode, though I would imagine they ought to be.

            @Daniel: with page context set as above, cutting out errors early in the process, you should at least be receiving emails from Moodle telling you why payments fail. If not, I can't imagine what is happening - perhaps the error logs will tell you something. Remember paypal needs to access a page on your server itself from without, so your development server must of course be accessible from the wider world (am making wild guesses at your setup here...)

            Show
            clancyhood Clancy Hood added a comment - Worth noting that "my" fix is for a live paypal setup - I've never tried it in the paypal sandbox environment, and have no idea if the same "payment_status"es are sent by paypal when in sandbox mode, though I would imagine they ought to be. @Daniel: with page context set as above, cutting out errors early in the process, you should at least be receiving emails from Moodle telling you why payments fail. If not, I can't imagine what is happening - perhaps the error logs will tell you something. Remember paypal needs to access a page on your server itself from without, so your development server must of course be accessible from the wider world (am making wild guesses at your setup here...)
            Hide
            andyjdavis Andrew Davis added a comment - - edited

            [Y] Syntax
            [NA] Output
            [Y] Whitespace
            [NA] Language
            [NA] Databases
            [Y] Testing
            [NA] Security
            [NA] Documentation
            [Y] Git
            [Y] Sanity check

            The fix looks simple enough. Is there any way to test this completely including the student actually getting enrolled? Could this be set up on qa.moodle.net? Alternatively is anyone who is experiencing the problem able to test this fix (https://github.com/markn86/moodle/compare/master...MDL-35349_master) and check that it does resolve all of the issues.

            Show
            andyjdavis Andrew Davis added a comment - - edited [Y] Syntax [NA] Output [Y] Whitespace [NA] Language [NA] Databases [Y] Testing [NA] Security [NA] Documentation [Y] Git [Y] Sanity check The fix looks simple enough. Is there any way to test this completely including the student actually getting enrolled? Could this be set up on qa.moodle.net? Alternatively is anyone who is experiencing the problem able to test this fix ( https://github.com/markn86/moodle/compare/master...MDL-35349_master ) and check that it does resolve all of the issues.
            Hide
            markn Mark Nelson added a comment -

            Changing priority as this breaks sites for users relying on PayPal.

            Show
            markn Mark Nelson added a comment - Changing priority as this breaks sites for users relying on PayPal.
            Hide
            poltawski Dan Poltawski added a comment -

            Integrated, thanks Mark

            Show
            poltawski Dan Poltawski added a comment - Integrated, thanks Mark
            Hide
            ankit_frenz Ankit Agarwal added a comment -

            Works as described.
            Thanks

            Show
            ankit_frenz Ankit Agarwal added a comment - Works as described. Thanks
            Hide
            stronk7 Eloy Lafuente (stronk7) added a comment -

            Amazed. Inspired. Grateful. That’s how your generosity makes me feel.

            (not really)

            Closing, thanks!

            Show
            stronk7 Eloy Lafuente (stronk7) added a comment - Amazed. Inspired. Grateful. That’s how your generosity makes me feel. (not really) Closing, thanks!
            Hide
            stuti31 stuti bhavsar added a comment -

            When I returned back to the site after payment, my screen displays:
            "Thank you for your payment! Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the project "<course_name>". Please try continuing to the project in a few seconds, but if you continue to have trouble then please alert the Mentor or the site"
            What is the next step to access the course?

            Show
            stuti31 stuti bhavsar added a comment - When I returned back to the site after payment, my screen displays: "Thank you for your payment! Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the project "<course_name>". Please try continuing to the project in a few seconds, but if you continue to have trouble then please alert the Mentor or the site" What is the next step to access the course?
            Hide
            stuti31 stuti bhavsar added a comment -

            Can anyone help me on this?

            Show
            stuti31 stuti bhavsar added a comment - Can anyone help me on this?
            Hide
            markn Mark Nelson added a comment -

            HI Stuti, what version of Moodle are you using? It may not include this patch as it was just released. If you visit the notifications page it should be display the version you are running there. Thanks.

            Show
            markn Mark Nelson added a comment - HI Stuti, what version of Moodle are you using? It may not include this patch as it was just released. If you visit the notifications page it should be display the version you are running there. Thanks.
            Hide
            dvillemure Diane Villemure added a comment -

            Stuti,

            It is not good practice to post in a Tracker item that has been closed. Best to ask for support in the related forum: https://moodle.org/mod/forum/discuss.php?d=210863

            Show
            dvillemure Diane Villemure added a comment - Stuti, It is not good practice to post in a Tracker item that has been closed. Best to ask for support in the related forum: https://moodle.org/mod/forum/discuss.php?d=210863
            Hide
            stuti31 stuti bhavsar added a comment - - edited

            Hi Mark, The version is Moodle 2.3.2+

            Show
            stuti31 stuti bhavsar added a comment - - edited Hi Mark, The version is Moodle 2.3.2+
            Hide
            stuti31 stuti bhavsar added a comment -

            Hi Diane, I have post the issue in some of the forums but did not received any response. So, thought of posting here

            Show
            stuti31 stuti bhavsar added a comment - Hi Diane, I have post the issue in some of the forums but did not received any response. So, thought of posting here
            Hide
            markn Mark Nelson added a comment -

            Hi Stuti, this fix was applied just before the 2.3.3 release, I would upgrade to this version and recheck. If it still an issue please create a separate tracker issue. Thanks.

            Show
            markn Mark Nelson added a comment - Hi Stuti, this fix was applied just before the 2.3.3 release, I would upgrade to this version and recheck. If it still an issue please create a separate tracker issue. Thanks.
            Hide
            stuti31 stuti bhavsar added a comment -

            Thanks Mark. Will wait for your acknowledgement.

            Show
            stuti31 stuti bhavsar added a comment - Thanks Mark. Will wait for your acknowledgement.
            Hide
            markn Mark Nelson added a comment -

            Hi Stuti, not sure what acknowledgement you require. The patch has already been released in the latest 2.3.3 version, so please upgrade to that.

            Show
            markn Mark Nelson added a comment - Hi Stuti, not sure what acknowledgement you require. The patch has already been released in the latest 2.3.3 version, so please upgrade to that.

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  12/Nov/12