We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    Hello, I am embarking on yet another project. I want to sell digital goods and automate a new user registration which ends with an email to the new user containing user name and password and some documentation.

    It seems to me this isn't a novel task, is there a tool or framework for this already?

    Anyway, I have been researching and found an old post with code from BobRay, just some simple php:

    $user = $modx->newObject('modUser', array ('username'=>'MyUser'));
    $user->set('password',md5('somePassword'));
    $userProfile = $modx->newObject('modUserProfile');
    $userProfile->set('fullname','My User');
    $userProfile->set('email','[email protected]');
    $success = $user->addOne($userProfile);
    if ($success) {
    $user->save();
    return '<p>User object and profile created</p>';
    } else {
    return '<p>failed to add profile. User not saved.</p>';
    }

    And I would just need to have success lead to the email going out, and to put in the new user's email value into the code.

    Then, I just need a system event as trigger, and boom the tool fires every time!

    Or so it goes, in my mind lol...

    Any advice appreciated! smiley

    This question has been answered by multiple community members. See the first response.

      • 3749
      • 24,544 Posts
      The register snippet will register the user and send an email. The Subscribe extra wraps the Register snippet with more bells and whistles.

      Neither of those does payments, though you might be able to adapt either one.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 46886
        • 1,154 Posts
        Thanks for your comments, BobRay, always appreciated.

        In my sense payment is going first and registration is delivery, so the email is from payments and I want to automate both registration and e-delivery. I can arrange an email, with the appropriate username, to arrive from the payment tool when a payment is made, I believe.

        So let the event trigger the register snippet, that's easy enough, and it send out the email, use the extra to make it easier...

        Can an email sent to [email protected] trigger the register snippet? How can I "notify" Modx that a payment has been confirmed, so that it can take certain steps?
        • discuss.answer
          mhPayPal can be used to accept a payment via PayPal and to do something after they paid. You could make people signup before they pay, or write a post payment hook that creates the account.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 3749
            • 24,544 Posts
            If you want to roll your own system, you could create a new System Event, fire it with $modx-invokeEvent('EventName', $params) when the user has paid, then have a plugin attached to that event take whatever steps you need.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 46886
              • 1,154 Posts
              Whoa, I didn't see all these replies, thanks Mark and BobRay!

              You could make people signup before they pay, or write a post payment hook that creates the account.

              Mark, thanks for thinking about what this might look like. You might be unsurprised to know I think making them sign up first is not a good idea, these days people want access, when the credit card is out do not add extra steps haha. So, the hook is probably the way to go.

              I figure email addy is great for username and pass can be randomized easily, maybe make them do a one-time password change on account confirmation. Their accounts don't need any special security so I am sure they will all pick basic passwords.

              We are looking at SubscribeMe (not Subscribe, I made a mistake here) as a basis now because these would be re-occurring. Subscribe may not actually do much on the user account side, but it would be the only way to create a login on the site, and the "premium" content would require login, so that seems simple enough to me. If there were multiple user classes it would be trickier, but I don't foresee that.

              But maybe mhPayPal with a hook makes more sense, I will look into it with my dev

              Thanks BobRay for confirming my thinking about a plugin, lol I can't write one but sometimes maybe I can see where one could go. I do indeed like to roll my own!

              I had decided my thinking was all wrong, good to see I wasn't out in space completely.

              Will report back soon! Thanks again! [ed. note: nuan88 last edited this post 6 years, 1 month ago.]
              • discuss.answer
                • 46886
                • 1,154 Posts
                Edit: Ok mhPayPal does look good for my needs!! I can manually make the user accounts when I get notified of payment while the plugin is under development