Guest Registration

Charge can directly register guests as part of the payment process. Learn more about the Guest Registration feature by reading the overview. This reference is designed to help you implement guest registrations in your payment forms.

Upgrade to Pro Guest registrations are a pro only feature. If you're running the Free charge edition, you'll need to upgrade to use it.

All the following parts are designed to work inside the payment form The following attributes and inputs are designed for usage within the main Charge payment form. Checkout a demo of this in the included demo templates you can find in the Charge plugin download.

Filter out Registered Users #

You'll only want the guest registration fields to be exposed to guest users.

Charge only ever attempt to run the guest registration logic if the current visitor isn't logged in. If they are, all the inputs will be safely ignored.

To only expose the inputs to guest users, simply wrap the relevant parts in a currentUser conditional. Like so :

{% if not currentUser %}
   ... all the guest registration inputs
{% endif %}

Create Account #

The option to optionally control the guest account creation is exposed to the guest user in the form via an input called createAccount.

The exact behaviour of this depends on the settings you've picked in the Charge > Settings > Guest Registration area.

If you've chosen to Always create an account. the createAccount input will be ignored as part of the form submission. Otherwise pass a value of yes, no or blank. If blank is passed, the behaviour will default to your chosen default in your settings.

Usage

..
<select name="createAccount">
    <option value="yes">Yes, create an account</option>
    <option value="no">No, don't create an account</option>
</select>
..

Inputs #

The following inputs are available on the payment form (in addition to the standard payment fields).

createAccount eg. 'yes', 'no' or ''
Should we override the default create account behaviour to create / not create an account.
password required
The password for the new user account. This is required for all new user accounts.
user[] Mixed
Set fields attached to the user with the user[fieldName] syntax.

The Guest's User Model #

As part of a charge payment request we'll create the guest's new user account at the very start of the request. If the payment fails, or there are validation errors on the form, the request will return back to the payment form.

For these cases, you can access all the data on the user via a new UserModel object, attached to charge.user. Be sure to first check if charge is defined, and the user attribute is not null.

Additionally, any user specific errors are attached to that user model. General user model errors are attached to the base Charge model, and will show in the charge.getErrors('general') array in your templates.

To access the errors on a user password field, you'd do the following:

{% if charge is defined and charge.user %}
   {{ charge.user.getError('password') }}
{% endif %}

Additionally, any user field data and their errors are accessible there too.

If we had a field called 'body', and another of 'optionOne' attached to the user model, you'd access the value's for the form repopulation like so:

<label>User Body</label>
<input type="text" name="user[body]" value="{% if charge is defined and charge.user %}{{ charge.user.body }}"/>
{% if charge is defined and charge.user %}
    {{ charge.user.getError('body') }}
{% endif %}

<label>User Option One</label>
<input type="text" name="user[optionOne]" value="{% if charge is defined and charge.user %}{{ charge.user.optionOne }}"/>
{% if charge is defined and charge.user %}
    {{ charge.user.getError('optionOne') }}
{% endif %}