Applying Discounts to Customers

Coupons are used to provide discounts to a customer on recurring charges. A coupon will reduce the amount of an invoice (by either a percentage of the total of all invoice items, or a flat amount). To start, you’ll need to create the coupon, which can be done in the dashboard or via the API. Coupons have the following parameters:

  • percent_off or amount_off
  • currency
  • duration: either once, forever, or repeating. When using repeating, also specify duration_in_months: the number of months for which the coupon should repeatedly apply.
  • id: a unique identifier that serves as the “code” for the coupon.
  • max_redemptions: the total number of times that this coupon can be applied to customers. For example, you can restrict a coupon to the first 50 customers that use it, or you can make a coupon expire by a certain date.
  • redeem_by: the latest date at which this coupon can be applied to customers.

The maximum number of redemptions and the expiration date apply to every customer you have. If you do the latter, this only impacts when the coupon can be applied to a customer. If you set a coupon to last forever when used by a customer, but have it expire on January 1st, any customer given that coupon will have that coupon’s discount forever, but no new customers can apply the coupon after January 1st.

TIP: Coupons can be designed to work once (e.g., apply to one invoice), apply to a number of months regardless of the billing period in use, or to last forever. The duration settings individually impact each customer, based on the time that the coupon was applied to the customer.

Coupons can be applied to a customer when the customer is created:

# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"

Stripe::Customer.create(
  :source => token,
  :plan => "basic_monthly",
  :email => "[email protected]",
  :coupon => "coupon_ID"
)
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"

stripe.Customer.create(
  source=token,
  plan="basic_monthly",
  email="[email protected]",
  coupon="coupon_ID"
)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

\Stripe\Customer::create(array(
  "source" => $token,
  "plan" => "basic_monthly",
  "email" => "[email protected]",
  "coupon" => "coupon_ID"
));
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

stripe.customers.create({
  source: token,
  plan: "basic_monthly",
  email: "[email protected]",
  coupon: "coupon_ID"
}, function(err, customer) {
  // asynchronously called
});
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2";

Map<String, Object> customerParams = new HashMap<String, Object>();
customerParams.put("source", token);
customerParams.put("plan", "basic_monthly");
customerParams.put("email", "[email protected]");
customerParams.put("coupon", "coupon_ID");

Customer.create(customerParams);

Coupons can also be added to existing customers by updating the customer:

# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"

cu = Stripe::Customer.retrieve("cus_3R1W8PG2DmsmM9")
cu.coupon = "coupon_ID"
cu.save
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"

cu = stripe.Customer.retrieve("cus_3R1W8PG2DmsmM9")
cu.coupon = "coupon_ID"
cu.save()
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

$cu = \Stripe\Customer::retrieve("cus_3R1W8PG2DmsmM9");
$cu->coupon = "coupon_ID";
$cu->save();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

stripe.customers.update("cus_3R1W8PG2DmsmM9", {
  coupon: "coupon_ID"
}, function(err, customer) {
  // asynchronously called
});
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2";

Customer cu = Customer.retrieve("cus_3R1W8PG2DmsmM9");

Map<String, Object> customerParams = new HashMap<String, Object>();
customerParams.put("coupon", "coupon_ID");

cu.update(customerParams);

If you delete a coupon, customers that already have discounts that were created using the coupon will keep those discounts, but no new redemptions of the coupon will be allowed.

Next up