Getting Started with Prices as Code

This guide will walk you through setting up Prices as Code and creating your first pricing configuration.

Installation

Install the package using npm:

npm install prices-as-code

Or with yarn:

yarn add prices-as-code

Or with pnpm:

pnpm add prices-as-code

Setup Environment Variables

Create a .env file in your project root with your API key:

# .env file
STRIPE_SECRET_KEY=sk_test_your_stripe_key

Create a Configuration File

TypeScript
YAML

Create a pricing.ts file:

import { Config } from 'prices-as-code';

const config: Config = {
  products: [
    {
      provider: 'stripe',
      name: 'Basic Plan',
      description: 'For individuals and small teams',
      features: ['5 projects', '10GB storage', 'Email support'],
      highlight: false,
      metadata: {
        displayOrder: 1
      }
    },
    {
      provider: 'stripe',
      name: 'Pro Plan',
      description: 'For growing businesses',
      features: ['Unlimited projects', '100GB storage', 'Priority support'],
      highlight: true,
      metadata: {
        displayOrder: 2
      }
    }
  ],
  prices: [
    {
      provider: 'stripe',
      name: 'Basic Monthly',
      nickname: 'Basic Monthly',
      unitAmount: 999, // $9.99
      currency: 'usd',
      type: 'recurring',
      recurring: {
        interval: 'month',
        intervalCount: 1
      },
      productKey: 'basic_plan',
      metadata: {
        displayName: 'Basic Monthly'
      }
    },
    {
      provider: 'stripe',
      name: 'Pro Monthly',
      nickname: 'Pro Monthly',
      unitAmount: 1999, // $19.99
      currency: 'usd',
      type: 'recurring',
      recurring: {
        interval: 'month',
        intervalCount: 1
      },
      productKey: 'pro_plan',
      metadata: {
        displayName: 'Pro Monthly'
      }
    }
  ]
};

export default config;