Answers.Body: <p><a href="https://squarebit.co.uk/software/craft/charge/overview" rel="nofollow">Developer of Charge here</a>. </p>
  
  <p><strong>Setup for installs up to (and including) 2.0.x  :</strong></p>
  
  <p>The simplest setup would be to use the <a href="http://squarebit.co.uk/software/craft/charge/usage/hook-events#charge.onbeforecharge" rel="nofollow">onBeforeCharge event</a>. </p>
  
  <p>This fires at the very start of the charge request, after validation but before anything has actually <em>happened</em>.</p>
  
  <p>You'd use that to jump in, and create your user, entry, or anything else you might want to do. As part of that same event you can modify the actual <strong>ChargeModel</strong> which will be used in the payment request too.</p>
  
  <p>The <em>onBeforeCharge</em> event fires before we pull out the user for the request, so as long as you're creating the user at that point, you won't need to do anything else to have all the subsequent steps properly associated to that user either. </p>
  
  <p>Of course be aware that a payment can fail for any number of reasons, so check in that <em>onBeforeCharge</em> event if you actually do need to create the user before blindly going ahead. </p>
  
  <p>Additionally, you can use the <em>onCharge</em> event to later perform any clean up you might need once the payment has actually succeeded. </p>
  
  <p><strong>Setup for installs from 2.1+</strong></p>
  
  <p>2.1 (not yet released as of 25/04/16) is bringing inline user registration to the payment forms, so in that case you'd just pass a new flag on the request to <code>registerUser = true</code>, and let Charge do the rest. </p>
  
  <p>Charge will only attempt to register a new user if required, and will use the <code>customerEmail</code> as the default base, but that can be overridden with other parameters and inputs on the form. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-26T13:47:57.090Z
Answers.Text: Thanks Joel, will be working my way through this ASAP, Charge 2.1 looks perfect for this use case - wish we could wait!
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-25T16:18:11.667Z
Answers.LastActivityDate: 2016-04-25T16:18:11.667Z
Answers.UserDisplayName: Joel Bradbury
Body: <p>A project I'm working on requires that publicly registered users pay a fee upon registration, and when payment is successful an Entry belonging to them should automatically be created.</p>
  
  <p>I have component pieces of this working but am struggling with how to tie them together.</p>
  
  <p>I currently have a basic plugin I wrote which handles the creation of an Entry when a user is Activated. The plugin has no money-taking facility. It works fine; the public user registration form posts to the built-in 'users/saveUser' action, and the plugin listens for the users.activateUser event which is fired when an admin manually activates their account.</p>
  
  <p>We want to take that 'manual' step out by having the system automatically activate the user if a Charge has been successful. This means integrating Charge into the public registration form. Which would seem to involve me having to change the action for the form to 'charge/charge', so Charge can do its thing.</p>
  
  <p>How then do I also get it to create the user?</p>
  
  <p>I see that Charge has an event for successful payment, which I'd like to hook onto and trigger the 'user/saveUser' like what's already working - but how, and how do I pass the username/email fields through from the form to 'user/saveUser' via Charge?</p>
  
Tags: <plugins><plugin-charge>
Title: Using the Charge plugin for membership subscriptions
ThreadText: # Using the Charge plugin for membership subscriptions
  
  (Asked by: username_0 on 2016-04-21)
  
  A project I'm working on requires that publicly registered users pay a fee upon registration, and when payment is successful an Entry belonging to them should automatically be created.
  
  I have component pieces of this working but am struggling with how to tie them together.
  
  I currently have a basic plugin I wrote which handles the creation of an Entry when a user is Activated. The plugin has no money-taking facility. It works fine; the public user registration form posts to the built-in 'users/saveUser' action, and the plugin listens for the users.activateUser event which is fired when an admin manually activates their account.
  
  We want to take that 'manual' step out by having the system automatically activate the user if a Charge has been successful. This means integrating Charge into the public registration form. Which would seem to involve me having to change the action for the form to 'charge/charge', so Charge can do its thing.
  
  How then do I also get it to create the user?
  
  I see that Charge has an event for successful payment, which I'd like to hook onto and trigger the 'user/saveUser' like what's already working - but how, and how do I pass the username/email fields through from the form to 'user/saveUser' via Charge?
  
  **Tags:** plugins, plugin-charge
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-25. Score: 3 | Accepted answer
  
  [Developer of Charge here](https://squarebit.co.uk/software/craft/charge/overview).
  
  **Setup for installs up to (and including) 2.0.x :**
  
  The simplest setup would be to use the [onBeforeCharge event](http://squarebit.co.uk/software/craft/charge/usage/hook-events#charge.onbeforecharge).
  
  This fires at the very start of the charge request, after validation but before anything has actually *happened*.
  
  You'd use that to jump in, and create your user, entry, or anything else you might want to do. As part of that same event you can modify the actual **ChargeModel** which will be used in the payment request too.
  
  The *onBeforeCharge* event fires before we pull out the user for the request, so as long as you're creating the user at that point, you won't need to do anything else to have all the subsequent steps properly associated to that user either.
  
  Of course be aware that a payment can fail for any number of reasons, so check in that *onBeforeCharge* event if you actually do need to create the user before blindly going ahead.
  
  Additionally, you can use the *onCharge* event to later perform any clean up you might need once the payment has actually succeeded.
  
  **Setup for installs from 2.1+**
  
  2.1 (not yet released as of 25/04/16) is bringing inline user registration to the payment forms, so in that case you'd just pass a new flag on the request to `registerUser = true`, and let Charge do the rest.
  
  Charge will only attempt to register a new user if required, and will use the `customerEmail` as the default base, but that can be overridden with other parameters and inputs on the form.
  
  > **Comments:**
  > **username_0**: Thanks username_1, will be working my way through this ASAP, Charge 2.1 looks perfect for this use case - wish we could wait!  
  
  ---
  
  