1.0.0 • Published 12 months ago

stripe-product-bootstrapper v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Stripe Product Bootstrapper

This tool automates the process of creating Stripe products and prices, and generates a TypeScript file with the corresponding IDs for easy reference in your codebase.

Installation

npm install -g stripe-product-bootstrapper
# or
bun add -g stripe-product-bootstrapper

Usage

CLI

You can use this tool directly from the command line:

STRIPE_SECRET_KEY=your_stripe_secret_key stripe-product-bootstrapper [input-file] [output-file]

Or with bunx:

STRIPE_SECRET_KEY=your_stripe_secret_key bunx stripe-product-bootstrapper [input-file] [output-file]
  • input-file: Path to your JSON file with product data (default: stripe-products.json)
  • output-file: Path where the TypeScript file will be generated (default: stripe-products.ts)

Programmatic Usage

You can also use this tool programmatically in your Node.js or Bun projects:

const { bootstrapStripeProducts } = require('stripe-product-bootstrapper');
// or
import { bootstrapStripeProducts } from 'stripe-product-bootstrapper';

bootstrapStripeProducts({
  stripeSecretKey: 'your_stripe_secret_key',
  inputFilePath: 'path/to/your/stripe-products.json',
  outputFilePath: 'path/to/output/stripe-products.ts'
})
  .then(() => console.log('Stripe products bootstrapped successfully'))
  .catch(console.error);

Input File Format

Your input JSON file should have the following structure:

[
  {
    "name": "Basic Plan",
    "description": "Basic features for individuals",
    "prices": [
      {
        "name": "Monthly",
        "unit_amount": 999,
        "currency": "usd",
        "recurring": {
          "interval": "month"
        }
      },
      {
        "name": "Yearly",
        "unit_amount": 9990,
        "currency": "usd",
        "recurring": {
          "interval": "year"
        }
      }
    ]
  },
  // Add more products as needed
]

Output

The tool will generate a TypeScript file with constants for your Stripe product and price IDs:

// This file is auto-generated. Do not edit manually.

export const STRIPE_PRODUCTS = {
  BASIC_PLAN: {
    ID: 'prod_1234567890',
    PRICES: {
      MONTHLY: 'price_1234567890',
      YEARLY: 'price_0987654321',
    },
  },
  // ... other products
};

Best Practices

  • Keep the generated TypeScript file in version control, but don't edit it manually.
  • Run this tool in your CI/CD pipeline or during deployment to ensure Stripe products are up-to-date.
  • Use environment-specific Stripe API keys to separate test and production data.

Contributing

Feel free to submit issues or pull requests to improve this tool!

License

MIT

1.0.0

12 months ago