Fields

You can add Craft fields to your Charges. It's an excellent way to collect extra information as part of the checkout process.

Upgrade to Pro Fields are a Pro only feature. If you're using the free edition, you'll need to upgrade to use fields

Whenever you're taking payments it's likely you'll want to collect additional information from the customer.

This may be as simple as an input for Gift Aid, or could be a much large set of fields. With Fields support on Charge you can collect as much information as you'd need, and have all that information accessible and searchable later.

Setup #

To add fields to your charges, you'll need to first create your fields. Fields are standard Craft fields, so create them in the same way, going to the CP > Settings > Fields.

With your fields created, then go to the Charge Settings > Fields, and you'll see the familiar fields blueprint UI. Just drag and drop what fields you'd like available.

From the front-end the setup is exactly the same as other front-end form submissions. In your Charge form, just add the fields you need, in the fields[fieldName] format.

For example, if we have two fields called exampleFieldOne and exampleFieldTwo, we'd add them to our form like so :

<input type="text" name="fields[exampleFieldOne]" value="{{ charge is defined ? charge.exampleFieldOne }}"/>

<input type="text" name="fields[exampleFieldTwo]" value="{{ charge is defined ? charge.exampleFieldTwo }}"/>

You can set any fields to be required too, and the validation will run as part of the normal Charge validation. Be sure to anticipate the error states for your fields in that case.

Accessing the Values #

Accessing the field data on Charges is exactly the same as on other Craft elements. In your templates, you'd output the values as simply as :

{{ charge.exampleFieldOne }}

{{ charge.exampleFieldTwo }}

 Using Fields to Purchase Access to specific items #

One usage of fields is to allow purchase of specific items, ie. for a training video access site.

Instead of setting up a membership subscription you might want to sell individual access to videos. In that case, Charge fields can be of use.

For this example we might add a field called chargeVideoAccess, and then in our payment form, include that as a hidden input with the entry id of the video the customer is purchasing access to.

To later test if a customer has access to a specific item, we can run a standard Craft query to check. Like so :

{% set accessCharge = craft.charge.charges({ 
      userId: currentUser.id, 
      search : { query : 'chargeVideoAccess:' ~ entry.id }}
   ).first %}

{% if accessCharge %} .. {% endif %}

CP Only Fields #

You don't need to expose all the fields to the Customer. If you've added fields to the Charge element, you'll also be able to view and edit the values within the Charge CP, when viewing the specific Charge details.