Booking system based on Charge 2.0 I am building an event booking system for a restaurant using Charge 2.0. Everything is working great, but having problems implementing a feature that shows how many spots are left.

An Event channel entry (created by the restaurant) provides parameters such as price, event name, etc and passes them to a Charge form. The Event entry also includes a field that specifies the maximum number of guests.

The Charge form includes a field for specifying a 'number of guests' for the booking. To indicate how many spots are left, we first need to calculate how many guests have already been booked, which is a simple matter of getting the 'numberOfGuests' field from all of the existing Charge entries and summing them. The problem arises when trying to filter the results using a Search parameter, which limits the entries to a specific event (the Event name is passed to the Charge description field). Here is a bit of the code:

{% set q = 'description:' ~ '"' ~ entry.title ~ '"' %}
{% for entry in craft.charge.charges().search(q) %}
   //get the number of guests


I tried a few different things, including a wildcard search, and none of them return any results. Does anyone know if the Charge model supports a Search parameter?
Developer of Charge here.

Yes - Charge supports all the native Craft criteria search parameters for fields. 

Like you mentioned, there are a few special fields that aren't supported currently within that. Those are fields like description, notes etc.. The supported direct attributes on the Charge model that can be searched (in addition to all the basic ElementType attributes) are : 


userId
sourceUrl
timestamp
hash
customerId
mode
meta


This is in addition to all Craft fields you might have attached to the charges. 

For example - if I wanted to find all the charges based on a specific customerId (the stripe identifier), it'd look something like this : 

{% set charges = craft.charge.charges({ customerId : 'cus_00000000' }) %}


They can be of course be combined, so all charges for that customer only in live mode : 

{% set charges = craft.charge.charges({ mode: 'live', customerId : 'cus_00000000' }) %}


If we had a field on the charge model with a name of ourCustomField, we could search for that like : 

{% set charges = craft.charge.charges({ search : { query : 'ourCustomField:' ~ someSearchValue }}) %}


And also, we could combine all those into a single thing too:

{% set charges = craft.charge.charges(
   { mode: 'live', 
     customerId : 'cus_00000000', 
     search : { 
        query : 'ourCustomField:' ~ someSearchValue 
   }}) %}


Or in the alternative syntax, that could be: 

{% set q = 'ourCustomField:' ~ someSearchValue %}
{% set charges = craft.charge.charges()
      .customerId('cus_00000000')
      .mode('live')
      .search(q) %}