Gravity Forms has a Stripe add-on that allows you to charge your users at form submission using your Stripe.com account, but this add-on doesn’t support (currently) coupons created at your Stripe account.
Gravity Forms has a also its own Coupons add-on. Using this add-on you can create a workaround for the mentioned limitation of the Stripe add-on.
Basically we’re going to use the coupon at Stripe.com, a coupon created in the Gravity Forms Coupons add-on with the same name and discount, and a little snippet of code. Simply follow the steps below.
NOTE: Stripe.com only allows creating coupons for recurring payments. If you’re using only a product and services feed in your form, you don’t need to follow this tutorial. This is ONLY for subscriptions.
Create and configure the coupon in Gravity Forms
Go to Forms -> Coupons menu and create your coupon.
If you already have the coupon created at your Stripe.com account make sure you use in the Coupon Code field the same value you used in ID (Code) at your Stripe.com account.
Obviously you will want to add a Coupon field to your form to allow the user enter the coupon code before submitting the form. Also you need to select the Coupon field in your Stripe feed settings.
Create the coupon at your Stripe.com account
If you already have the coupon created in your Stripe.com account you can skip this step, if not, go to Products -> Coupons in your Stripe.com account and create the coupon.
During the coupon creation, make sure to setup only the following settings:
- Percentage off / Discount Amount
And leave all other settings as default.
For the Stripe Coupon ID, make sure to use the same you used for the Gravity Forms Coupon Code. The Coupon ID in Stripe must be uppercase.
How the discount is going to be applied to your subscription at Stripe.com is determined by this coupon setup. For example, if you want the discount to be applied only to the first payment, you will want to select “Once” in the Duration setting as shown in the screenshot.
Note that there’s an exception to this. If you use the Stripe Checkout Payment Collection Method the Stripe API does not support passing a coupon in the subscription data. Parameters allowed for Stripe Checkout can be found here.
This means that if you use Stripe Checkout, the coupon would be added to the customer not to the subscription, therefore the coupon would be applied to all future invoices.
As explained this is a Stripe.com API limitation, not a Gravity Forms issue.
So if you want to limit how many times the coupon is applied, you will want to make sure you use a Stripe Card field in your form and have the add-on Payment Collection Method setting set to Stripe Credit Card Field.
Make sure to use in ID (Code) the same value you used in Coupon Code field in Gravity Forms.
Use a filter to override the payment amount sent to Stripe.com
If you’re not using the form total as payment amount in your feed, you can skip this step.
Assuming that you’re using the Form Total as recurring amount in your Stripe add-on subscription feed. As the Gravity Forms Coupons add-on applies the discount to the form total, you will want to alter the amount passed to Stripe.com by using another field (not a Total field type) as source for the payment amount, to prevent the discount from being applied two times, one by the Coupons add-on and then by Stripe.com
So you need a field in your form containing the total amount before the discount, an easy solution for this would be to use the Subtotal field provided by the Gravity Perks eCommerce Fields add-on. Or you could also create a number field, set to currency type, with calculation enabled and create your own formula to calculate the total.
To do this you can use the first example snippet in the doc page for gform_submission_data_pre_process_payment filter, you can find it below with some extra lines to ensure it runs only for subscriptions and log the process with logging enabled if you have any issue:
If you did all steps above as explained, now the Gravity Forms Coupons add-on will apply the discount to your form and entry. Then the original amount for the Total field, without the discount, will be passed to Stripe.com and there the Stripe coupon will be applied.
You’re done :)
By the way, note that although we’re using the above snippet to pass the form total without a discount to Stripe.com in this use case, you can use the snippet also to alter the payment amount passed to any other payment add-on based on the Add-on Framework.