Creating Coupons that Expire in a Certain Number of Days

This article applies to Classic Commerce. (Looking for Contextual Commerce documentation?)


When you want to set up a coupon that expires a certain number of days after it is created, and provide it to your customer after the order process is completed for a product, you need to set up a license fulfillment as a call to the coupon API to generate the code to make the coupon be created at the time of order and then a condition for validity for the number of days can be set up on a coupon.

Creating the Coupon

Go to SpringBoard's Store Home » Promotions and Appearance » Offers. Click Create Discount.


Enter in a name for your discount. This is not displayed for the customers, but is used to for managerial purposes. Optionally, enter in a message for the
discount you would like displayed to your customers. Pick the type of discount you would like to offer. These discounts include:

  • Percent Off
  • Amount Off Unit - If customers purchase more than one unit, they get the discount off of all units purchased.
  • Amount Off Product - If customers purchase more than one unit, they get the discount off of one unit purchased and the others are not discounted.
  • Free

Percent Off and Amount Off

When you choose Percent Off or Amount Off, you will need to enter the specific percent or dollar amount you would like this discount to subtract from the price. For Amount Off discounts, you can also specify the amount off in country currencies other than USD by clicking on the + sign. SpringBoard offers a currency calculator for setting foreign currency amounts, showing real time exchange rates and +5% and +10% calculations for each. This can be accessed via the small calculator icon. 

327.png  328.png                  329.png

Under Conditions, select the checkbox for Add Coupon Condition. Change the Coupon Type to Multiple Random Codes. Enter in the actual coupon code prefix you would like to use. Coupon codes are case insensitive so the customer may enter them in any combination of lowercase and capital letters. Click Create.


Under Conditions, click on the coupon condition you just made or click Edit.


Under Conditions, select the length of time a coupon code is considered valid. Current expiration time options are shown below.

707.png 708.png

Click Save. Move the discount to Active Status.

Create API Only User

If you do not already have a Limited API User set up on your account, you will need to create one. This user will not be able to log in to your store in SpringBoard. Instead, the user can interact with FastSpring's Order API and Subscription API. The username (Login Email) and password (that will be sent automatically to your Login Email) for this user would be used in the code below to access the coupon API.

Go to SpringBoard's Store Home » Account. Click Users and then click Add User. Click Add User. Select Limited API User from the drop-down menu under Role, enter in the other fields, and click Create. 

account.png 277.png

Creating the License Fulfillment

Go to SpringBoard's Store Home » Products and Pages. Select the product that will trigger the discount coupon you just created, or create a new product.


Next to Fulfillment Actions, click Add. Choose Generate a License and select Script (PHP or JavaScript) from the drop down menu. Click Next.

502.png 709.png

Select Single License Only for the Output Format. Select Not Name Based for the License Name. Click Create.


Replace the default Script Source Code (JS) with the following code, but replace testcompanyid with the company ID you use to log in to SpringBoard, replace testcompanyapiusername and testcompanyapipassword with the username (you entered it for Login Email when you created the Limited API User) and password, respectively, you used when creating the Limited API User. Replace abcd with the coupon prefix you chose when making the coupon.

// Get single coupon code from Coupon API

var companyID = "testcompanyid";
var APIUser = "testcompanyapiusername";
var APIPassword = "testcompanyapipassword";
var couponPrefix = "abcd";
var URL = "" + companyID + "/coupon/" + couponPrefix + "/generate?user=" + APIUser + "&pass=" + APIPassword;
var response = httpPost(URL);
// strip all xml tags from result
var coupon = response.body.replace(/<.*?>/g,"");


Click Run Test to make sure everything is working properly. You should see a license code under Licenses Captured. If you see Access Denied or any other message, there is an error in your Script Source Code (JS).


Click on Script License Configuration to get back to your Script Source Code (JS). If needed, make any changes to fix errors and Run Test again. Once you have successfully captured a license in your test, click Save. 


Under Fulfillment Action, click Edit on your License Generator (JavaScript Script). Click on the Advanced tab.


Under Custom Template Key enter coupon. Click Save. 


Adding an Expiring Coupon to an Email Fulfillment

Under Fulfillment Actions, click Add. Select Send Email / Show Web Notification and click Next. (Note: If you already have an email fulfillment set on the product, click Edit on your Email and add the variable below.)


Select an Existing Template for your Email Fulfillment and click Next or Define a New Template and click Create.

You will want to include the variable #{[0]} in your Email Fulfillment, which will provide the coupon code. An example of how to use this variable is below. Save your Email Fulfillment.


Below is an example of what this will look like to your customer.


Adding an Expiring Coupon to the Order Confirmation / Thank You page of the Order Process

In your Email Fulfillment, click on the Web tab. To display the coupon code on the final page of the order process, include the same variable #{[0]} .  An example of how to use this variable is below. Click Save.


Below is an example of what this will look like to your customer.


We're Here to Help

If you need assistance creating coupons that expire in a certain number of days, please open a support ticket.


Powered by Zendesk