How to setup Stripe codes for your AppSumo deal
August 22, 2022
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.
You can copy-paste the script below, or simply do:
git clone https://github.com/romainsimon/appsumo-stripe
The script is also available on Github
Script to generate Stripe coupon codes for AppSumo
'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 :)