Getting Charges

Just like craft.entries, you can access the recorded charges with a twig tag. It's exactly the same:


craft.charge.charges accepts the following parameters :

Only get charges with a specific customerName
Only get charges with a specific customerEmail
Only get charges with a specific hash
Only fetch charges from a specific userId
Only fetch charges for a specific time period
Only get charges with a specific sourceUlr
Only get charges for a specific currency (defined by the 3 letter currency code - usd/eur/gbp etc..)
Only get charges of a specific type - either charge or recurring

For example :

{% set charges = craft.charge.charges.customerEmail('').find() %}

Will set charges to be all the charges recorded with the customerEmail of ''.

More likely you'll want to just show a single charge, relating to a specific purchase. For example, if on the payment form, we set the following value as our redirect :

<input type="hidden" name="redirect" value="payment/thanks/{hash}"/>

The user would be directed to a url like : http://site.url/payment/thanks/xxxxxx-xxxxx-xxxxx on success. On that page, we'll already have the relevant charge object defined, but if they revisit that page later, you can get the charge object back like so :

{% set hash = craft.request.getSegment(3) %}
{% if charge is not defined %}
    {% set charge = craft.charge.hash(hash).first() %}
{% endif %}

{% if charge is defined %}
    Thanks for your payment of {{ charge.formatPlanAmount() }}
{% endif %}

You could also use this method build retrievable receipts.