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.
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
Code
Coupon Type
Percentage Off
Amount Off
Currency
Payment Types
Max Redemptions
Duration
Duration In Months
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
This is very simple. All that's needed is a new field called 'planCoupon' on your payment form. For example it's as simple as :
<label for="planCoupon">Coupon</label> <input type="text" name="planCoupon" id="planCoupon" value="{% if charge is defined %}{{ charge.planCoupon }}{% endif %}"/> {% if charge is defined %} {{ _self.errorList(charge.getErrors('planCoupon')) }} {% endif %}
Note: Be sure to include the getErrors('planCoupon')
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.
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.planCoupon }} 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
Note: The planAmount
will always be the amount they actually paid