Instrumental Commerce Coupons

You can offer coupons and discount codes to your customers using Stripe coupons with Instrumental Commerce.

It's designed in a smart way so that:

  • By default, the coupon field is hidden (preventing cart abandonment from customers who want to hunt for a coupon)
  • You can auto-apply coupons using a URL parameter
  • Your pricing page and checkout flow dynamically validates coupons and dynamically displays the discounted price.

Coupons setup

First, create your coupon(s) in Stripe.

Then, you'll need to to create "Promotion code(s)" for each coupon in Stripe. These define the actual coupon code that customers will see and use to apply the discount.

Applying coupons on pricing & checkout

The plans index view (your pricing page) at /plans as well as your checkout view at /checkout can both take the URL parameter coupon to auto-apply a coupon or to display an empty coupon field.

  • If the coupon URL parameter is set to a coupon's promotion code, such as "summersale", and that coupon is valid, then customers will see their coupon validated and their price discounted on the page.
  • If the coupon URL parameter is simply set to true, then customers will see an empty coupon field (no coupon is applied by default).
  • If the coupon URL parameter is not present, then the coupon field will not be shown.

Customizing the coupon success message

By default, when a coupon is validated successfully, the customer will see a success message "Coupon applied" and see the price discounted. The logic in the Stimulus controller coupons_controller.js handles dynamically displaying the discounted price.

You can further customize the exact wording of the success message(s) and the way the discounted price is displayed by using meta data saved on the promotion codes in Stripe:

  • success_message - shown next to the coupon field when the code is valid.
    • Also displays in the sidebar purchase details as the coupon headline.
    • If not set, this will fallback to Coupon applied!
  • success_description - Small text to show in the sidebar purchase details, underneath the coupon headline. Useful if you need to describe details about the coupon.
  • custom_append_text - The original price amount will be dynamically calculated based on the coupon's discount (percentage or flat amount off). If the original price has an append text (like "/month") then that will be copied to the discounted price—unless custom_append_text is set, in which case we show this text instead. Useful when the normal price says "/year", but the discount only applies to the first year, so you can set this text to "first year".
  • custom_price_text - Hard-code specific text or price info to show when coupon is applied.
Instrumental Components

I created Instrumental Components to make designing and building professional apps with Ruby on Rails easy, fast, and fun. I use it on all of my projects and I hope it helps you build something great.

Brian Casel
Brian Casel
Creator of Instrumental Components
Learn more Send me a question or request