PAYPAL ERROR: Not a valid user id

PAYPAL ERROR: Not a valid user id

I need help on completing the Paypal enrollment integration.  I'm at the final stage of using Paypal with my Moodle course.  Everything appears to work except for the final automatic enrollment.  I get an email saying "PAYPAL ERROR: Not a valid user id".  Anyone know why?

Here are my details:
- Moodle release = '1.9.5+ (Build: 20091007)
- setup the Moodle course with:
    > Enrolment Plugins: PayPal
    > Default role: Site Default (Student)
    > Course enrollable: Yes
    > for testing purposes I set the course price to $1
    > Administration->Courses->Enrolments: ENABLED PayPal and set as default.

- setup paypal
    > have a business account created
    > have the IPN URL pointing to the moodle ipn.php file
    > charset is set to UTF-8
    > created a "buy now" button for $1 to test
- testing process
    > on my website, click the "buy now" button
    > sends me to Paypal and it all looks good
    > I buy as a guest account because it sees me as the seller if I log in and it paypal doesn't let you complete the transaction.  So I do it as a guest without a full account created.
    > buying process at paypal is successful, get an email and get a link on paypal to send me to moodle
    > clicking on the link brings me to the Moodle login page - now I need an account to log in.
    > after about 5 minutes I get an email saying "PAYPAL ERROR: Not a valid user id".  Looking through the email details, everything looks good.  The only things I notice that I'm not sure is an issue or not are:
       >> userid => 0
       >> courseid => 0
       >> payer_status => unverified  (I think this is ok as I think it is Paypal's status for accounts; since this was done with a guest account it would be unverified)

Any ideas why I get the "PAYPAL ERROR: Not a valid user id"?  Does this have anything to do with paying as a guest account?  Am I missing something?

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Did another test with a completely different paypal account, credit card and user information.  Got the same error for creating an account.  So it doesn't have to do with the guest account like I thought.  But in looking at the ipn.php file it appears that it is failing on the userid.

Any ideas?

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

I think the moodle user should have to be registered in moodle BEFORE they see the Paypal button. That way when they click through to paypal their user ID will be trapped, so when the payment is processed and they return to moodle following the buttton/link on paypal page, they will be returned INTO moodle.

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Thanks for the reply Jon.  That's not how I understood the feature working. I understood it be like this:

  1. I have a paypal button on my website to sell a class.  The button is created in Paypal and uses the course ID in it.
  2. The user clicks the button, gets redirected to paypal where they pay for the class.
  3. Upon successful payment it sends me an email (which it does), sends the user a confirmation email (which it does) and then provides a link on the final page that when they click it I have that send them to the Moodle login page (which it does).
  4. At this point from the reading it makes it sound like the system would automatically create a username and password by sending a confirmation API call to Paypal using the user information from payment.  To me it appears that this step is attempted because I receive an email saying "PAYPAL ERROR: Not a valid user id" and then it lists all the detailed information from the payment purchase in the email it sends me.  Looking thru the data it all looks good except that I do notice two items that I assume are causing the issue: userid => 0  and  courseid => 0

To me the "automatica enrollment" feature is pointless if it doesn't automatically enroll new users after making a payment.  For some reason it is failing but it appears I have everything set right.  I wish someone who has this working could explain.


Average of ratings: -
Picture of Amy Lee
Re: PAYPAL ERROR: Not a valid user id

Hi Shawn,

Jon's reply was correct. The point is not to use the button created in PayPal at all, but to do two things in Moodle:

1. Enable email-based self-registration. This you can find in Site Admin/Users/Authentication/Manage authentication. You need to properly set it up here, likely after reading all the related Moodle docs.

2. Enable the PayPal Plugin. This is at Site Admin/Courses/Enrolments. Again you need to set it up properly.

The version I'm talking about is 1.9.10.

Both settings are fairly tricky and Moodle docs are not all that correct (for example, I found to make PayPal plugin work you need to set the course as enrollable, instead of not enrollable which was wrongly specified in the Moodle doc instructions I read). I suggest you take time to read all the related docs and even forum discussions before you do your setting. Any step missing or any slight error will make the procedure fail. But once everything is done correctly, it works quite well. You don't need the PayPal button on your website at all. It cannot be integrated with your Moodle auto enrolment.

Good luck!

Average of ratings: Useful (1)
Re: PAYPAL ERROR: Not a valid user id

Thanks Amy.  Do you have this working?  If so how does the workflow work with the email self-registration and Paypal?  You provided two steps to perform #1 enable email self-registration and #2 enable paypal plugin.  I have #2 already setup and it works like my previous post, but I don't see how the email self-registration fits in.  I've read the documentation, but the email self-registration doesn't mention anywhere in it whether you can integrate paypal into the process/workflow.  All that I keep reading is that they seem to discourage you from using this feature because of spammers.  Do you have this working with paypal too?

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Hi Shawn,

I'm just bedding-down my paypal enrollment.  All being well, I will post a link very soon so you can see how I've used email self-enrollment, CAPTCH (to avoid the spammers) and the Paypal buttons for auto-enrollment into a course.

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Thanks Amy - you were right on!  And Jon thanks for your help too.  I got this working and I'm going to list my steps here for confirmation and so hopefully it helps someone else in the future since the documentation on this feature is lacking.

I was real close but  I was missing the "Email-based self-registration" piece (I would have never thought to do this).  So here are my notes on what I did to set this all up and then the workflow experience.

Setup email based self-registration
- Log into Moodle as the Administrator
- Select "Site Administration > Users > Authentication > Manage Authentication"
    > Enable "Email-based self-registration" (make sure the eye appears next to this)
    > scroll down and fill in the rest of the fields
        - Self registration: select "Email-based self-registration"
        - Guest login button: Hide
        - Restrict domains when changing email: checked
        - Fill in ReCAPTCHA keys (go to http://recaptcha.net and fill out the form to create an account; it will then provide you with the public key and the private key to use on this form)
        - all other fields are blank
        - Save Changes

- Now select "Site Administration > Users > Authentication > Email-based self-registration"
    > "Enable reCAPTCHA element": Yes
    > all other fields: Unlocked

- Now select "Site Administration > Courses > Enrolments"
    > PayPal enabled, set to Default
    > "Send course welcome message": Yes

    > PayPal Edit button:
       - Provide an enrolment cost, currency and your personal/business email
       - Check all the checkboxes so that emails are sent
       - Save changes

- Setup your PayPal account at paypal.com

- Do not use a PayPal button on your website (that's what I originally did; it's not needed now)
   > Instead, on your website link to your main login page for Moodle, it will now have a section on the right for "firt time users" with a "Create new account" button.

Workflow - Now the workflow goes like this:
 - On your website link to the main login page for Moodle (mine looks like: http://<domain name>/moodle/login/index.php)
 - Click the "Create new account" button
     > Fill in the form (this is the "Email-based self-registration" form with the reCAPTCHA at the bottom) and click the "Create my new account" button
     > You will get a web page saying to check your email for instructions on completing your registration.
 - Log into your email and you should have an email.  It will have a URL to click in order to confirm the new account.  Click it.
 - A new Moodle page will appear saying "Thanks, <name>" "Your registration has been confirmed"
     > Click the "courses" button

 - Now it lists all the courses available.  When you click on one of the course names that you want to take, it brings you to a page that has the course summary and the price displayed.  Below this is another section that says "This course requires a payment for entry", shows the price and now has a PayPal button that says "Send payment via PayPal".  Clicking this sends you to PayPal with the course lised in the order summary and you can log in to pay. 
   > Once done paying you will receive an email confirmation and a link to the main Moodle login page that you provided in the Paypal setup.
   > The user should be able to log in now.

Hopefully these notes help other people trying to figure this out.

Average of ratings: -
Picture of flavio guzman
Re: PAYPAL ERROR: Not a valid user id

They did! Thank you very much. So I'm I right to assume that you quitted the previous workflow?

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Yes that is correct, the workflow I listed at the top/beginning of this post has been replaced by my final post now that I understand how the integration is supposed to work.  smile

Average of ratings: -
Me (as I would be if I were a cat!)
Re: PAYPAL ERROR: Not a valid user id

Hi Shawn,

Thank you so much for including your step-by-step instructions. I'm going to be working on this same thing on a new installation. I've never done it but having your notes will be really helpful.

Have you considered updating the moodle docs Paypal page to include this information so others can get it there rather than digging through forums?

Thanks again for contributing.

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

Great suggestion Leah!  I didn't realize I could update the documentation myself, but I could (which was fun because the editor syntax is wierd).  I just updated the moodle docs "Paypal enrolment" section.  This was one of the first places I looked in trying to figure it out and it completely lacked any details steps.  So hopefully I didn't leave anything out and this helps others as I know the pain I went through trying to figure this all out.

You guys might want to reference this since I actually enhanced my steps from above with the PayPal stuff and a few other things; and I'm no longer able to edit my post from above.

Average of ratings: -
Picture of Amy Lee
Re: PAYPAL ERROR: Not a valid user id

Hi Shawn,

I finally got to look at your steps in detail. I was pleased to see from the updated moodle docs that you had added the setting up of IPN. So now I have only one small point to add regarding this section (copied below):

 Now select "Site Administration > Courses > Enrolments"

  1. PayPal enabled, set to Default
  2. "Send course welcome message": Yes
  3. PayPal Edit button:
    1. Provide an enrolment cost (this is a global cost, individual course costs defined in the step above will override this setting), currency and your personal/business email
    2. Check all the checkboxes so that emails are sent
    3. Save changes

For the second last step "Check all the checkboxes so that emails are sent", you may want to leave the "inform students" option blank if you have set "Send course welcome message" to "Yes" in the Step 2 above. Otherwise students will get welcome message twice, at least in our case. The two messages are almost identical, with the subject line being the only difference. I choose the other one as the subject line says "Welcome to + course name" which is more user-friendly, while the one sent from here says "New enrolment in + course short name". You can double check if this is the case.

Again good work! Many thanks for doing this (and so thoroughly and meticulously). This is going to be very helpful.

Average of ratings: -
Re: PAYPAL ERROR: Not a valid user id

You're right, both ways work fine.  Personally I just like to know each step has been setup and getting an email along the way just confirms that.  I think it is just preference.  smile  

Glad the steps help.  I'm glad I was able to contribute something that is helpful to others.

Average of ratings: -