Coupons

Coupons can be used to apply discounts to any payment, one-off or recurring.

To use coupons, you'll need to do just three things - create a coupon in the Charge CP, add a coupon field to your payment form, and add a little bit of extra logic on your success page to show the value of any discount applied.

Creating Coupons

In the Charge CP, you'll see a tab called 'Coupons', that will list all the coupons currently setup. Add a new coupon, and you'll have the following options :

Name
A friendly name for the coupon
Code
The actual code users will need to use to redeem the coupon on the front-end
Coupon Type
Can be either 'Fixed Amount' or 'Percentage Off'. Depending on the choice here, different information will be required for the coupon
Percentage Off
The % off the amount to discount
Amount Off
The amount to deduct from the payment. This is also tied to a specific currency. '5' == '500 cents/pence' etc...
Currency
Used together with amount off, for Fixed Amount discounts
Payment Types
What type of payment the coupon can be used with. Either One-Off payments, or Recurring payments
Max Redemptions
How many times a coupon can be used in total
Duration
How long the discount remains applied for against recurring payments. Can be once, forever or repeating.
Duration In Months
If the discount is set to 'repeating', how many months it remains applied for

Set the details as you need, and Charge will do the rest.

Note: Depending on the Payment Type selected, the coupon will be dealt with differently. One-off coupons are handled entirely internally, recurring coupons are handled on the Stripe side. Charge handles all the details of this, but it's good to be aware of the difference when looking at the payments in the Stripe dashboard

Adding a Coupon Field to your Form

This is very simple. All that's needed is a new field called coupon on your payment form. For example it's as simple as :

<label for="planCoupon">Coupon</label>
<input type="text" name="coupon" id="coupon" value="{% if charge is defined %}{{ charge.coupon }}{% endif %}"/>

{% if charge is defined %}
{{ _self.errorList(charge.getErrors('coupon')) }}
{% endif %}

Note: Be sure to include the getErrors('coupon') block. If the customer tries to use an invalid coupon, we'll return an error message based on why it fails. That might be it's invalid, expired, or not possible for the current purchase payment.

Adding new variables to the success page

On the success page, you'll want to add a little bit of extra logic, so you can show what discount (if any) was applied. We've made this super simple. We've got variables for all the various values, for example :

{% if charge is defined %}
    Thank you for you payment of {{ charge.formatPlanAmount }}

    {% if charge.hasDiscount %}
        Coupon Code : {{ charge.coupon }}
        Discounted from {{ charge.formatPlanFullAmount }},
        with a discount of {{ charge.formatDiscountAmount }}
    {% endif %}
{% endif %}

Which, assuming the customer used a valid coupon, would output something like this :

Thank you for you payment of $18.75

Coupon Code : 25OFF
Discounted from $25.00,
with a discount of $6.25