# Billing SDK CLI Reference URL: /docs/cli Complete guide to the Billing SDK CLI for project setup and component management *** title: Billing SDK CLI Reference description: Complete guide to the Billing SDK CLI for project setup and component management --------------------------------------------------------------------------------------------- import { Callout } from 'fumadocs-ui/components/callout' import { Tab, Tabs } from 'fumadocs-ui/components/tabs' import { Cards, Card } from 'fumadocs-ui/components/card' The Billing SDK CLI is a powerful command-line tool that helps you initialize new billing projects, add components, and manage your billing infrastructure with ease. ## Installation The CLI is published as an npm package and can be used with `npx` without installation: ```bash npx @billingsdk/cli --help ``` For frequent use, you can install it globally: ```bash npm install -g @billingsdk/cli @billingsdk/cli --help ``` ## Quick Start ```bash # Initialize a project (interactive) npx @billingsdk/cli init # Add a component to an existing project npx @billingsdk/cli add ``` ## Commands Initialize a new billing project with framework setup and payment provider integration Add individual billing components to your existing project Build the component registry for distribution (developer tool) ## Supported Frameworks | Framework | Dodo Payments | Stripe | | ---------- | ------------- | ----------- | | Next.js | Yes | Yes | | Express.js | Yes | Yes | | Hono | Yes | Yes | | NestJS | Yes | Yes | | React | Yes | Yes | | Fastify | Yes | Coming soon | ## Supported Payment Providers ### Dodo Payments * โœ… **Status**: Fully supported * ๐Ÿ“š **Integration**: Next.js, Express.js, React.js, Hono, Fastify ### Stripe * โœ… **Status**: Supported for Next.js, React.js, Express.js, and Hono * ๐Ÿ“š **Integration**: Next.js, React.js, Express.js, Hono * ๐Ÿšง **Adding Soon**: Fastify ## `@billingsdk/cli init` Initialize a new billing project with complete setup including framework configuration, payment provider integration, and essential dependencies. ### Usage ```bash npx @billingsdk/cli init ``` ### What it does 1. **Framework Selection**: Choose your preferred framework (Next.js, Express.js, Hono, NestJS, Fastify) 2. **Provider Selection**: Select your payment provider (currently Dodo Payments) 3. **Template Installation**: Downloads and installs framework-specific templates 4. **Dependency Management**: Automatically installs required dependencies 5. **File Generation**: Creates necessary configuration files and boilerplate code ### Interactive Setup The command launches an interactive setup process: ```bash npx @billingsdk/cli init ``` You'll be prompted to select: * **Framework**: Next.js (with App Router), Express.js (Node.js web framework), Hono (lightweight web framework for edge runtimes), NestJS (progressive Node.js framework), Fastify (fast and low overhead web framework) * **Payment Provider**: Dodo Payments or Stripe (Stripe currently supported for Express.js and Hono) ### Generated Files (Dodo Payments) After running `init` with Dodo Payments, you'll get: ``` your-project/ โ”œโ”€โ”€ app/api/ โ”‚ โ”œโ”€โ”€ (dodopayments)/ โ”‚ โ”‚ โ”œโ”€โ”€ checkout/route.ts โ”‚ โ”‚ โ”œโ”€โ”€ customer/route.ts โ”‚ โ”‚ โ”œโ”€โ”€ customer/payments/route.ts โ”‚ โ”‚ โ”œโ”€โ”€ customer/subscriptions/route.ts โ”‚ โ”‚ โ”œโ”€โ”€ product/route.ts โ”‚ โ”‚ โ”œโ”€โ”€ products/route.ts โ”‚ โ”‚ โ””โ”€โ”€ webhook/route.ts โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts โ””โ”€โ”€ .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts โ””โ”€โ”€ routes/ โ””โ”€โ”€ dodopayments/ โ”œโ”€โ”€ route.ts โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ dodopayments/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts โ””โ”€โ”€ routes/ โ”œโ”€โ”€ route.ts โ””โ”€โ”€ dodopayments/ โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts โ””โ”€โ”€ modules/ โ””โ”€โ”€ dodopayments/ โ”œโ”€โ”€ checkout.controller.ts โ”œโ”€โ”€ customer.controller.ts โ”œโ”€โ”€ dodopayments.module.ts โ”œโ”€โ”€ payments.controller.ts โ”œโ”€โ”€ products.controller.ts โ”œโ”€โ”€ subscriptions.controller.ts โ””โ”€โ”€ webhook.controller.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ dodopayments.ts โ””โ”€โ”€ routes/ โ””โ”€โ”€ dodopayments/ โ”œโ”€โ”€ route.ts โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ### Generated Files (Stripe) After running `init` with Stripe, you'll get: ``` your-project/ โ”œโ”€โ”€ app/api/ โ”‚ โ””โ”€โ”€ (stripe)/ โ”‚ โ”œโ”€โ”€ checkout โ”‚ โ”œโ”€โ”€ customer โ”‚ โ”œโ”€โ”€ payments โ”‚ โ”œโ”€โ”€ products โ”‚ โ”œโ”€โ”€ subscriptions โ”‚ โ””โ”€โ”€ webhook โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ stripe/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts โ””โ”€โ”€ routes/ โ””โ”€โ”€ stripe/ โ”œโ”€โ”€ route.ts โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts โ””โ”€โ”€ routes/ โ”œโ”€โ”€ route.ts โ””โ”€โ”€ stripe/ โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts โ””โ”€โ”€ modules/ โ””โ”€โ”€ stripe/ โ”œโ”€โ”€ checkout.controller.ts โ”œโ”€โ”€ customer.controller.ts โ”œโ”€โ”€ payments.controller.ts โ”œโ”€โ”€ products.controller.ts โ”œโ”€โ”€ stripe.module.ts โ”œโ”€โ”€ subscriptions.controller.ts โ””โ”€โ”€ webhook.controller.ts .env.example ``` ### API Routes Included The init command sets up comprehensive API routes for: * **Checkout**: Payment processing and order creation * **Customer Management**: Customer data and subscription handling * **Product Management**: Product catalog and pricing * **Webhook Handling**: Payment provider webhook integration ### Setup Instructions
Next.js Setup Instructions ### Basic Next.js Integration After running `@billingsdk/cli init` and selecting Next.js, the CLI scaffolds API routes under `app/api/(dodopayments)/*` and adds `lib/dodopayments.ts` and `hooks/useBilling.ts`. * Routes are auto-registered by the App Router. No extra wiring is required. * Client components can call the API directly or use `hooks/useBilling.ts`. #### Environment Configuration Copy `.env.example` to `.env.local` in the project root and set: ```bash # DodoPayments DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # App URL NEXT_PUBLIC_APP_URL=http://localhost:3000 ``` #### Using the billing hook (optional) ```tsx // app/(or any client component) "use client" import { useEffect } from 'react' import { useBilling } from "@/app/hooks/useBilling" export default function BillingExample() { const { fetchProducts } = useBilling() useEffect(() => { fetchProducts().catch(console.error) }, [fetchProducts]) return null } ```
Express.js Setup Instructions ### Basic Express.js Integration After running `@billingsdk/cli init` and selecting Express.js, you'll need to integrate the generated routes into your Express application: ```javascript // app.js or server.js const express = require('express'); const { dodopaymentsRouter } = require('./src/routes/dodopayments/route'); const app = express(); // Middleware app.use(express.json()); // Mount DodoPayments routes app.use('/api/dodopayments', dodopaymentsRouter); // Start server const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 NODE_ENV=development ``` #### TypeScript Support The template includes full TypeScript support. To use with TypeScript: ```bash npm install -D typescript @types/node ts-node nodemon ``` Create a `tsconfig.json`: ```json { "compilerOptions": { "target": "ES2020", "module": "commonjs", "lib": ["ES2020"], "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"] } ``` Update your `package.json` scripts: ```json { "scripts": { "dev": "nodemon --exec ts-node src/app.ts", "build": "tsc", "start": "node dist/app.js" } } ```
Hono Setup Instructions ### Basic Hono Integration After running `@billingsdk/cli init` and selecting Hono, you'll need to integrate the generated routes into your Hono application: ```typescript // src/index.ts import { Hono } from 'hono' import { dodopaymentsRouter } from './routes/route' const app = new Hono() // Mount DodoPayments routes app.route('/api/dodopayments', dodopaymentsRouter) // Start server export default app ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 ``` #### Running with Bun Hono works great with Bun. To run your application: Add this to your `package.json` scripts: ```json { "scripts": { "dev": "bun run --hot src/routes/route.ts" } } ```
NestJS Setup Instructions ### Basic NestJS Integration After running `@billingsdk/cli init` and selecting NestJS, you'll need to integrate the generated modules into your NestJS application: ```typescript // src/app.module.ts import { Module } from '@nestjs/common'; import { DodoPaymentsModule } from './modules/dodopayments/dodopayments.module'; import { StripeModule } from './modules/stripe/stripe.module'; @Module({ imports: [DodoPaymentsModule, StripeModule], }) export class AppModule {} ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Stripe Configuration STRIPE_API_KEY=your_api_key_here STRIPE_WEBHOOK_SECRET=your_webhook_secret_here # Server Configuration PORT=3000 ```
React.js Setup Instructions ### Basic React.js Integration After running `@billingsdk/cli init` and selecting **React.js**, the CLI generates a `lib/dodopayments.ts` and a `hooks/useBilling.ts` file for your project. You can use the `useBilling` hook directly in your components to interact with the backend API: ```tsx // src/App.tsx or any component import React, { useEffect } from 'react' import { useBilling } from './hooks/useBilling' function App() { const { fetchProducts, loading, error } = useBilling() useEffect(() => { const loadProducts = async () => { try { const products = await fetchProducts() console.log('Products:', products) } catch (err) { console.error('Failed to fetch products:', err) } } loadProducts() }, [fetchProducts]) if (loading) return

Loading...

if (error) return

{error}

return

Welcome to DodoPayments + React

} export default App ``` #### Environment Configuration Create a `.env` (or `.env.local` if using Vite) in your project root: ```bash # Backend API URL (Express.js server or Next.js API routes) VITE_BASE_URL=http://localhost:3000 ```
Fastify Setup Instructions ### Basic Fastify Integration After running `@billingsdk/cli init` and selecting Fastify, integrate the generated routes into your Fastify application. ```ts // src/index.ts import Fastify from 'fastify' import cors from '@fastify/cors' import helmet from '@fastify/helmet' import { dodopaymentsRoutes } from './routes/dodopayments/route' const app = Fastify({ logger: true }) // Plugins (optional but recommended) await app.register(cors) await app.register(helmet) // Mount DodoPayments routes app.register(dodopaymentsRoutes, { prefix: '/api/dodopayments' }) const start = async () => { try { const port = Number(process.env.PORT) || 3000 await app.listen({ port, host: '0.0.0.0' }) app.log.info(`Server running on port ${port}`) } catch (err) { app.log.error(err) process.exit(1) } } start() ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 ``` #### Scripts ```json { "scripts": { "dev": "tsx watch src/server.ts", "build": "tsc", "start": "node dist/server.js" } } ```
### Dependencies Installed (Dodo Payments) ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "express": "latest", "@types/express": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "hono": "latest", "@types/bun": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "@nestjs/common": "latest", "@nestjs/core": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "fastify": "latest", "fastify-raw-body": "latest" } } ``` ### Dependencies Installed (Stripe) ```json { "dependencies": { "stripe": "latest", "standardwebhooks": "latest", "zod": "latest", "express": "latest", "@types/express": "latest" } } ``` ```json { "dependencies": { "stripe": "latest", "standardwebhooks": "latest", "zod": "latest", "hono": "latest", "@types/bun": "latest" } } ``` ```json { "dependencies": { "stripe": "latest", "standardwebhooks": "latest", "zod": "latest", "@nestjs/common": "latest", "@nestjs/core": "latest" } } ``` ### Generated Files (Stripe) After running `init` with Stripe, you'll get: ``` your-project/ โ”œโ”€โ”€ app/api/ โ”‚ โ””โ”€โ”€ (stripe)/ โ”‚ โ”œโ”€โ”€ checkout โ”‚ โ”œโ”€โ”€ customer โ”‚ โ”œโ”€โ”€ payments โ”‚ โ”œโ”€โ”€ products โ”‚ โ”œโ”€โ”€ subscriptions โ”‚ โ””โ”€โ”€ webhook โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ hooks/ โ”‚ โ””โ”€โ”€ stripe/ โ”‚ โ””โ”€โ”€ useBilling.ts โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts โ””โ”€โ”€ routes/ โ””โ”€โ”€ stripe/ โ”œโ”€โ”€ route.ts โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ``` your-project/ โ”œโ”€โ”€ lib/ โ”‚ โ””โ”€โ”€ stripe.ts โ””โ”€โ”€ routes/ โ”œโ”€โ”€ route.ts โ””โ”€โ”€ stripe/ โ”œโ”€โ”€ checkout.ts โ”œโ”€โ”€ customer.ts โ”œโ”€โ”€ payments.ts โ”œโ”€โ”€ products.ts โ”œโ”€โ”€ subscriptions.ts โ””โ”€โ”€ webhook.ts .env.example ``` ### API Routes Included The init command sets up comprehensive API routes for: * **Checkout**: Payment processing and order creation * **Customer Management**: Customer data and subscription handling * **Product Management**: Product catalog and pricing * **Webhook Handling**: Payment provider webhook integration ### Setup Instructions
Next.js Setup Instructions ### Basic Next.js Integration After running `@billingsdk/cli init` and selecting Next.js, the CLI scaffolds API routes under `app/api/(dodopayments)/*` and adds `lib/dodopayments.ts` and `hooks/useBilling.ts`. * Routes are auto-registered by the App Router. No extra wiring is required. * Client components can call the API directly or use `hooks/useBilling.ts`. #### Environment Configuration Copy `.env.example` to `.env.local` in the project root and set: ```bash # DodoPayments DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # App URL NEXT_PUBLIC_APP_URL=http://localhost:3000 ``` #### Using the billing hook (optional) ```tsx // app/(or any client component) "use client" import { useEffect } from 'react' import { useBilling } from "@/app/hooks/useBilling" export default function BillingExample() { const { fetchProducts } = useBilling() useEffect(() => { fetchProducts().catch(console.error) }, [fetchProducts]) return null } ```
Express.js Setup Instructions ### Basic Express.js Integration After running `@billingsdk/cli init` and selecting Express.js, you'll need to integrate the generated routes into your Express application: ```javascript // app.js or server.js const express = require('express'); const { dodopaymentsRouter } = require('./src/routes/dodopayments/route'); const app = express(); // Middleware app.use(express.json()); // Mount DodoPayments routes app.use('/api/dodopayments', dodopaymentsRouter); // Start server const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 NODE_ENV=development ``` #### TypeScript Support The template includes full TypeScript support. To use with TypeScript: ```bash ``` Create a `tsconfig.json`: ```json { "compilerOptions": { "target": "ES2020", "module": "commonjs", "lib": ["ES2020"], "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"] } ``` Update your `package.json` scripts: ```json { "scripts": { "dev": "nodemon --exec ts-node src/app.ts", "build": "tsc", "start": "node dist/app.js" } } ```
Hono Setup Instructions ### Basic Hono Integration After running `@billingsdk/cli init` and selecting Hono, you'll need to integrate the generated routes into your Hono application: ```typescript // src/index.ts import { Hono } from 'hono' import { dodopaymentsRouter } from './routes/route' const app = new Hono() // Mount DodoPayments routes app.route('/api/dodopayments', dodopaymentsRouter) // Start server export default app ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 ``` #### Running with Bun Hono works great with Bun. To run your application: Add this to your `package.json` scripts: ```json { "scripts": { "dev": "bun run --hot src/routes/route.ts" } } ```
React.js Setup Instructions ### Basic React.js Integration After running `@billingsdk/cli init` and selecting **React.js**, the CLI generates a `lib/dodopayments.ts` and a `hooks/useBilling.ts` file for your project. You can use the `useBilling` hook directly in your components to interact with the backend API: ```tsx // src/App.tsx or any component import React, { useEffect } from 'react' import { useBilling } from './hooks/useBilling' function App() { const { fetchProducts, loading, error } = useBilling() useEffect(() => { const loadProducts = async () => { try { const products = await fetchProducts() console.log('Products:', products) } catch (err) { console.error('Failed to fetch products:', err) } } loadProducts() }, [fetchProducts]) if (loading) return

Loading...

if (error) return

{error}

return

Welcome to DodoPayments + React

} export default App ``` #### Environment Configuration Create a `.env` (or `.env.local` if using Vite) in your project root: ```bash # Backend API URL (Express.js server or Next.js API routes) VITE_BASE_URL=http://localhost:3000 ```
Fastify Setup Instructions ### Basic Fastify Integration After running `@billingsdk/cli init` and selecting Fastify, integrate the generated routes into your Fastify application. ```ts // src/index.ts import Fastify from 'fastify' import cors from '@fastify/cors' import helmet from '@fastify/helmet' import { dodopaymentsRoutes } from './routes/dodopayments/route' const app = Fastify({ logger: true }) // Plugins (optional but recommended) await app.register(cors) await app.register(helmet) // Mount DodoPayments routes app.register(dodopaymentsRoutes, { prefix: '/api/dodopayments' }) const start = async () => { try { const port = Number(process.env.PORT) || 3000 await app.listen({ port, host: '0.0.0.0' }) app.log.info(`Server running on port ${port}`) } catch (err) { app.log.error(err) process.exit(1) } } start() ``` #### Environment Configuration Create a `.env` file in your project root: ```bash # DodoPayments Configuration DODO_PAYMENTS_API_KEY=your_api_key_here DODO_PAYMENTS_ENVIRONMENT=test_mode DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key_here # Server Configuration PORT=3000 ``` #### Scripts ```json { "scripts": { "dev": "tsx watch src/server.ts", "build": "tsc", "start": "node dist/server.js" } } ```
### Dependencies Installed (Dodo Payments) ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "express": "latest", "@types/express": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "hono": "latest", "@types/bun": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "fastify": "latest", "fastify-raw-body": "latest" } } ``` ### Dependencies Installed (Stripe) ```json { "dependencies": { "stripe": "latest", "standardwebhooks": "latest", "zod": "latest", "express": "latest", "@types/express": "latest" } } ``` ```json { "dependencies": { "stripe": "latest", "standardwebhooks": "latest", "zod": "latest", "hono": "latest", "@types/bun": "latest" } } ``` ## `@billingsdk/cli add` Add individual billing components to your existing project using the shadcn/ui registry system. ### Usage ```bash npx @billingsdk/cli add ``` ### Available Components See the [components](/docs/components) page for a list of available components. ### Examples ```bash # Add a pricing table npx @billingsdk/cli add pricing-table-one # Add subscription management npx @billingsdk/cli add subscription-management # Add usage monitoring npx @billingsdk/cli add usage-meter-circle ``` ### What happens 1. Downloads the component configuration from the registry 2. Installs the component files in your `components/billingsdk/` directory 3. Updates your project configuration if needed 4. Installs any additional dependencies This command is primarily used by Billing SDK maintainers. Regular users typically don't need to run this command. ## Troubleshooting ### Common Issues **Command not found** ```bash # Make sure you're using npx npx @billingsdk/cli --help ``` **Permission errors** ```bash # On Unix systems, you might need to adjust permissions chmod +x node_modules/.bin/@billingsdk/cli ``` **Network issues** ```bash # Check your internet connection # The CLI downloads templates from @billingsdk/cli.com ``` ### Getting Help ```bash # Show all available commands npx @billingsdk/cli --help # Get help for a specific command npx @billingsdk/cli init --help npx @billingsdk/cli add --help ``` ## Development ### Building the CLI ```bash cd packages/cli npm run build ``` ### Development Mode ```bash cd packages/cli npm run dev ``` ### Contributing The CLI is open source and welcomes contributions. See our [contribution guide](/docs/contribution-open-source) for details. If you encounter issues or have questions about the CLI, please [open an issue](https://github.com/dodopayments/billingsdk/issues) on GitHub. # Contribution & Open Source URL: /docs/contribution-open-source Help us improve Billing SDK - built with transparency and community collaboration *** title: Contribution & Open Source description: Help us improve Billing SDK - built with transparency and community collaboration ---------------------------------------------------------------------------------------------- import { Callout } from 'fumadocs-ui/components/callout' import { Cards, Card } from 'fumadocs-ui/components/card' Billing SDK is built on the principles of open source software - transparency, collaboration, and community-driven development. We believe that great tools should be accessible to everyone and improved by collective effort. ### Why Open Source? * **๐Ÿ” Transparency** - Full visibility into how components work * **๐Ÿค Community** - Built by developers, for developers * **๐Ÿ”’ Security** - Open code means better security through peer review * **๐Ÿ“ˆ Innovation** - Faster iteration through community contributions * **๐Ÿ’ฐ Cost-Effective** - Free to use, modify, and distribute ## How to Contribute We welcome contributions from the community! Whether you're fixing bugs, adding new components, or improving documentation, your help makes Billing SDK better for everyone. ### Getting Started 1. **Fork the repository** on GitHub 2. **Clone your fork** locally 3. **Create a new branch** for your changes 4. **Make your changes** following our guidelines 5. **Test thoroughly** to ensure everything works 6. **Submit a pull request** with a clear description Refer our [CONTRIBUTING.md](https://github.com/dodopayments/billingsdk/blob/main/CONTRIBUTING.md) for more details. ### Contribution Guidelines Make sure you have Node.js 18+ installed and are familiar with React, TypeScript, and Tailwind CSS. #### Adding New Components When adding new components: * Follow the existing component structure and naming conventions * Include comprehensive TypeScript interfaces * Add proper documentation with examples * Ensure responsive design and accessibility * Test with multiple themes #### Code Style * Use TypeScript for all components * Follow the existing code formatting * Use meaningful variable and function names * Add JSDoc comments for complex functions * Ensure components are accessible #### Documentation * Update README files as needed * Add examples for new components * Include prop tables and usage instructions * Test all code examples ### Types of Contributions Welcome * ๐Ÿ› **Bug Fixes** - Help us fix issues and improve stability * โœจ **New Components** - Add new billing and subscription components * ๐Ÿ“š **Documentation** - Improve guides, examples, and API docs * ๐ŸŽจ **Themes** - Create new visual themes and variants * ๐Ÿ”ง **Developer Experience** - Improve tooling and development workflow * ๐Ÿงช **Testing** - Add tests and improve coverage ## License & Usage Billing SDK is released under the GNU General Public License (GPL), ensuring the project remains open and free: * โœ… Use freely for any purpose * โœ… Study and modify the source code * โœ… Distribute copies to help others * โœ… Distribute modified versions * โš ๏ธ Must keep derivatives under GPL license * โš ๏ธ Must provide source code when distributing The GPL license ensures that Billing SDK and all derivative works remain free and open source, protecting the commons and ensuring community benefits are preserved. ## Project Links ## Community & Support ### Core Maintainers The project is actively maintained by a team of developers at [DodoPayments](https://dodopayments.com) who are committed to keeping it up-to-date, secure, and feature-rich. ### Community Support * **Issues & Bugs** - Community-driven issue resolution * **Feature Requests** - Prioritized based on community needs * **Documentation** - Collaborative improvement of guides and examples * **Code Reviews** - Peer review for quality assurance ### Get Involved * Join discussions in GitHub Issues * Share your use cases and feedback * Help answer questions from other users * Suggest new features and improvements Whether you're a seasoned developer or just getting started, there are many ways to contribute to the project and help make it better for everyone. ## Roadmap Our development is guided by community feedback and industry needs: * ๐ŸŽฏ **Short Term** - Bug fixes, performance improvements, new component variants * ๐Ÿš€ **Medium Term** - Advanced theming system, more component types, better accessibility * ๐ŸŒŸ **Long Term** - Framework integrations, design system expansion, enterprise features Join us in building the future of billing components! ## Learn More New to here? Don't worry, we welcome your questions. If you find anything confusing, please give your feedback on [GitHub Issues](https://github.com/dodopayments/billingsdk/issues)! If you find anything confusing or need help getting started, please open an issue on [GitHub Issues](https://github.com/dodopayments/billingsdk/issues)! # Introduction URL: /docs Complete billing infrastructure for modern web applications with React components, CLI tooling, and full-stack integration *** title: Introduction description: Complete billing infrastructure for modern web applications with React components, CLI tooling, and full-stack integration --------------------------------------------------------------------------------------------------------------------------------------- import { Cards, Card } from 'fumadocs-ui/components/card' import { Callout } from 'fumadocs-ui/components/callout'