boltRomain Simon on SaaS & tech

How to setup Stripe codes for your AppSumo deal

tech

I recently published an AppSumo deal for Beanvest and try to find a way to quickly create 10,000 coupon codes on Stripe.

As I did not find any solution to do so, here's a script I created to quickly create those 10,000 coupons with 100% off forever (actually it creates only 1 coupon but with 10,000 codes to make it more readable on your Stripe account).

This script also generates a csv file with all coupon codes which is ready-to-upload on AppSumo.

AppSumo Stripe Coupon Code Generator

NEW I've built a Stripe Coupon Generator to make this process even easier.

This free tool allows you to generate and create Stripe coupon codes directly from your browser with a user-friendly interface.

It's completely free to use, configurable, and of course doesn't store any of your Stripe API keys or generated codes.

If you prefer to run the script locally or want more control over the process, you can still use the script provided below.

Script to generate Stripe coupon codes for AppSumo

The script is available on Github or you can copy-paste from here:

'use strict'
// Copy-paste a Secret key from https://dashboard.stripe.com/apikeys
const STRIPE_API_KEY = 'sk_live_.........'
// Coupon code length (including prefix). Must be between 3 and 200
const CODE_LENGTH = 40
// Number of coupons to generate. Must be between 100 and 10000
const NB_COUPONS = 10000
// Optional prefix for codes
const PREFIX = 'SuMo'
// List of characters to generate code from
const chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'
// This csv file will contain all your AppSumo coupon codes
const fileName = `AppSumo-${NB_COUPONS}-codes.csv`
const fs = require('fs')
const stripe = require('stripe')(STRIPE_API_KEY)
async function createCodes() {
  const stream = fs.createWriteStream(fileName)
  const coupon = await stripe.coupons.create({
    name: 'AppSumo Lifetime Deal',
    percent_off: 100,
    duration: 'forever'
  })
  for (let i = 0; i < NB_COUPONS; i++) {
    const code = await createPromo(coupon.id)
    stream.write(`${code}\r\n`)
    console.log(`${i + 1}/${NB_COUPONS} - ${code}`)
  }
  stream.end()
  console.log(`✨✨✨ ${NB_COUPONS} coupons created on Stripe & saved in a csv file ${fileName}`)
}
function generateRandomCode () {
  return PREFIX + Array.from(
    { length: CODE_LENGTH - PREFIX.length },
    (v, k) => chars[Math.floor(Math.random() * chars.length)]
  ).join('')
}
async function createPromo (coupon) {
  const code = generateRandomCode()
  try {
    await stripe.promotionCodes.create({
      coupon,
      code,
      max_redemptions: 1
    })
 } catch (e) {
   console.log(e)
 }
  return code
}
createCodes()

Hope you found this useful for your AppSumo LTD :)

Related Articles