A simple, efficient tool to bulk download Stripe invoices as PDF files.
Built with TypeScript and Deno, this script allows you to easily export all your Stripe invoices from a specified date.
- Bulk download Stripe invoices as PDF files
- Customizable date range for invoice retrieval
- Automatic creation of output directory
- Environment variable support for easy configuration
- Built with TypeScript for type safety
- Uses Deno for fast execution and file operations
-
Clone this repository:
git clone https://github.com/yourusername/stripe-invoice-exporter.git cd stripe-invoice-exporter
-
Create a
.env
file in the project root and add your Stripe secret key:STRIPE_SECRET_KEY=your_stripe_secret_key_here OUTPUT_DIRECTORY=./invoices
-
Run the script:
deno task start
You can configure the script by modifying the following variables in the main.ts
file:
const startDate = new Date('2024-10-03').getTime() / 1000; // Convert to Unix timestamp
const params: Stripe.InvoiceListParams = {
limit: 100,
created: { gte: startDate },
};
startDate
: Set this to the earliest date from which you want to download invoices.limit
: Adjust this value to change the number of invoices processed in each batch (default is 100).
By default, invoices will be saved in the ./invoices
directory. You can change this by setting the OUTPUT_DIRECTORY
environment variable in your .env
file.
Each invoice will be saved as a PDF file with the naming format: invoice_<invoice_number>.pdf
.
- The script first ensures that the output directory exists.
- It then fetches invoices from Stripe, starting from the specified date.
- For each invoice with a PDF available, it downloads the PDF and saves it to the output directory.
- The process continues until all invoices have been downloaded.
Never commit your .env
file or expose your Stripe secret key. The .gitignore
file is set up to exclude the .env
file from version control.
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
This project is MIT licensed.
Happy invoicing! If you find this tool useful, please give it a star ⭐️ on GitHub!