# 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 ``` ## 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) ## `@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 or Express.js) 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) or Express.js (Node.js web framework) * **Payment Provider**: Dodo Payments ### Generated Files After running `init`, 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/ ├── src/ │ ├── lib/ │ │ └── dodopayments.ts │ └── routes/ │ └── dodopayments/ │ ├── route.ts │ ├── 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 ### Dependencies Installed ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest" } } ``` ```json { "dependencies": { "dodopayments": "latest", "standardwebhooks": "latest", "zod": "latest", "express": "latest", "@types/express": "latest" } } ``` After running `init`, copy `.env.example` to `.env.local` (Next.js) or `.env` (Express.js) and configure your Dodo Payments API keys and webhook secrets. ## 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 ``` ### Available API Endpoints The Express.js template provides these endpoints: * `POST /api/dodopayments/checkout` - Create checkout sessions * `GET /api/dodopayments/customer` - Retrieve customer data * `POST /api/dodopayments/customer` - Create new customers * `PUT /api/dodopayments/customer` - Update customer information * `GET /api/dodopayments/customer/subscriptions` - Get customer subscriptions * `GET /api/dodopayments/customer/payments` - Get customer payment history * `GET /api/dodopayments/products` - List all products * `GET /api/dodopayments/product` - Get specific product details * `GET /api/dodopayments/subscriptions` - Retrieve subscription details * `GET /api/dodopayments/payments` - Get payment information * `POST /api/dodopayments/webhook` - Handle DodoPayments webhooks ### 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" } } ``` ## `@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. ## Supported Frameworks ### Next.js (App Router) * ✅ **Status**: Fully supported * 📁 **Structure**: App Router with API routes * 🔧 **Features**: Server components, server actions, middleware support ### Express.js * ✅ **Status**: Fully supported * 📁 **Structure**: Modular route-based architecture * 🔧 **Features**: RESTful API routes, middleware support, TypeScript integration ### Coming Soon * 🚧 **Fastify**: High-performance backend framework * 🚧 **Additional React Frameworks**: Vite, Remix support ## Supported Payment Providers ### Dodo Payments * ✅ **Status**: Fully supported * 🔧 **Features**: Payment processing, subscriptions, webhooks * 📚 **Integration**: Complete API route templates included ### Coming Soon * 🚧 **Stripe**: Industry-standard payment processing * 🚧 **Additional Providers**: Based on community demand ## Configuration ### Environment Variables After running `@billingsdk/cli init`, configure these environment variables: ```bash # Dodo Payments Configuration DODO_PAYMENTS_API_KEY=your-api-key DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret DODO_PAYMENTS_RETURN_URL=https://yourdomain.com/checkout/success DODO_PAYMENTS_ENVIRONMENT="test"or"live" # Next.js Configuration NEXT_PUBLIC_APP_URL=http://localhost:3000 ``` ### Customizing Templates The CLI uses templates from the public registry. You can: * Modify generated files after installation * Create custom templates for your organization * Extend existing components with additional features ## 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)! If you find anything confusing or need help getting started, please open an issue on [GitHub Issues](https://github.com/dodopayments/billingsdk)! # 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'