A small script to generate a Stripe coupon and promotion codes, and save them to a CSV file.
Thing I learned while making this that might be worth you knowing: Stripe coupons and promotion codes are different things. A coupon is what you see on your end as a seller of a product, and a promotion code is what your users see. So, you can have a bunch of different promotion codes attached to one coupon, and each of those promotion codes gives you whatever value the coupon has.
When I first made this repo, I just had it generate 1000 coupons and save it to a CSV, and now I know that I actually needed to make one coupon, with 1000 promo codes. If you actually want to bulk-generate coupons, you could go to the git history and find that script version. Good luck!
To run the script, follow these steps:
- Run
pip install stripe
in your terminal to install the Stripe library. - Replace
<YOUR_STRIPE_SECRET_KEY>
in the script with your actual Stripe secret key. You can find your Stripe secret key in the Stripe dashboard. This is not your public-facing key! - Replace
Unique Coupon
with the name of the coupon you want for each coupon. You can also edit theamount_off
variable to however much off you want to offer (currently it's $20 off). - Open a terminal or command prompt and navigate to the directory where this repo is cloned.
- Execute the script by running the command
python generate_coupons.py
in the terminal. - Wait for the script to complete. It will create a coupon with 1000 unique promo codes and save them to a CSV file named
promotion_codes.csv
in the same directory as the script. - After the script finishes running, you will see the output message
A total of X promo codes have been generated and saved to promotion_codes.csv
.
Make sure you have appropriate permissions to read and write files in the directory where the script is located.
Note: Ensure that the Python version you are using is compatible with the stripe
library.