Skip to content

Use Stripe coupons with Gravity Forms

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 the coupon in Gravity Forms

Go to Forms -> Coupons menu and create your coupon.

Gravity Forms Coupon Example
Gravity Forms Coupon Example

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.

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 Billing -> Coupons in your Stripe.com account

and create the coupon.

Stripe Coupon Example

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.

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.

Published inGravity Forms

8 Comments

  1. Daniele Daniele

    Hi Samuel,

    Thanks for this!
    But it’s not clear to me where you send the Gform coupon to Stripe.
    Is it automatically added to the payment request by the Gform Stripe add-on?

    Thanks

  2. Adam Winchester Adam Winchester

    Hi Samuel

    Thanks for your post.

    What if I have a custom Stripe coupon which gives a 100% discount for the first 4 months of a subscription and then continues at the regular rate for the balance of 12 months?

    Cheers

    Adam

    • Travis Travis

      Adam – can you tell me if this needs to be changed:

      ‘modify_submission_data’, 10, 4 );

      Does the 10 need to be changed to the form ID #? What about the 4?

    • Samuel Aguilera Samuel Aguilera

      Don’t touch those values, read the comment in the snippet for how to change the form id.

  3. Adam Adam

    Does this method still work with the Modal method of stripe add on?

  4. Samuel Aguilera Samuel Aguilera

    @Adam, yes the gform_submission_data_pre_process_payment filter runs no matter the Payment Collection Method you’re using.

  5. Clarentia Clarentia

    Hey Sam,

    Could you help me? I have followed this tutorial step by step. It seems like the amount without the discount is successfully sent to stripe, but no discount was applied?

    I noticed on your screenshot that your Stripe UI looks different to mine.. I have had to do Products>Coupons instead of Subscriptions>Coupons, as the later does not exist…

    Could this be the issue? If so, how do i resolve it?

    Thank you!!
    Clarentia

    • Samuel Aguilera Samuel Aguilera

      Hi Clarentia, I never saw Coupons under the Products menu, but I have noticed currently Coupons are no longer under the Subscription menu in my Stripe.com account, but directly in the Billing menu. I have updated the article with new screenshots for this menu and how the Coupon creation looks (that also changed). You may need to clear your browser cache to see the new screenshots.

      You will need to contact with Stripe.com for assistance.

Leave a Reply

Your email address will not be published. Required fields are marked *