Skip to content

abdelhamidadel418-droid/saas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ SaaS Management System - Dahila & Stripe Integration

Complete backend system for managing SaaS subscriptions with Stripe payments and Dahila integration.


πŸ“‹ Features

βœ… Stripe Integration

  • Payment Intent creation and management
  • Customer management
  • Subscription handling
  • Webhook support for real-time events
  • Invoice management

βœ… Dahila Integration

  • Master Key authentication
  • Product management
  • Order management
  • Invoice generation
  • Dashboard statistics

βœ… User Management

  • User registration and login
  • JWT authentication
  • Profile management
  • Password encryption with bcryptjs

βœ… Subscription Management

  • Create subscriptions
  • Change subscription plans
  • Cancel subscriptions
  • Track subscription status

πŸ› οΈ Installation

1. Clone the repository

```bash git clone cd saas ```

2. Install dependencies

```bash npm install ```

3. Configure environment variables

```bash cp .env.example .env ```

Edit .env and add your credentials: ```env

Stripe

STRIPE_SECRET_KEY=sk_test_your_key_here STRIPE_PUBLISHABLE_KEY=pk_test_your_key_here STRIPE_WEBHOOK_SECRET=whsec_your_secret_here

Dahila

DAHILA_API_KEY=your_dahila_master_key_here DAHILA_API_URL=https://api.dahila.com

JWT

JWT_SECRET=your_jwt_secret_key_here JWT_EXPIRE=7d

Database

MONGODB_URI=mongodb://localhost:27017/saas-db

Server

PORT=5000 NODE_ENV=development ```

4. Start the server

```bash npm run dev # Development with auto-reload npm start # Production ```


πŸ“‘ API Endpoints

Stripe Routes (/api/stripe)

Method Endpoint Description
POST /create-payment-intent Create a payment intent
GET /payment-intent/:id Get payment intent status
POST /customer Create a customer
GET /customer/:id Get customer details
POST /subscription Create a subscription
POST /subscription/:id/cancel Cancel subscription
GET /subscription/:id Get subscription details
POST /webhook Handle Stripe webhooks

Dahila Routes (/api/dahila)

Method Endpoint Description
GET /master-key Validate Master Key
GET /products Get all products
POST /products Create a product
GET /orders Get all orders
POST /orders Create an order
GET /orders/:id Get order details
PUT /orders/:id Update an order
GET /invoices Get all invoices
POST /invoices Generate an invoice
GET /dashboard Get dashboard statistics

User Routes (/api/users)

Method Endpoint Description
POST /register Register a new user
POST /login Login a user
GET /profile/:id Get user profile
PUT /profile/:id Update user profile

Subscription Routes (/api/subscriptions)

Method Endpoint Description
POST /create Create a subscription
GET /:id Get subscription details
PUT /:id/change-plan Change subscription plan
POST /:id/cancel Cancel subscription
GET /user/:userId Get user subscriptions

πŸ“ Example Requests

1. Register User

```bash curl -X POST http://localhost:5000/api/users/register \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "password": "securePassword123", "fullName": "John Doe" }' ```

2. Create Payment Intent

```bash curl -X POST http://localhost:5000/api/stripe/create-payment-intent \ -H "Content-Type: application/json" \ -d '{ "amount": 29.99, "currency": "USD", "description": "Premium Plan Subscription" }' ```

3. Create Stripe Customer

```bash curl -X POST http://localhost:5000/api/stripe/customer \ -H "Content-Type: application/json" \ -d '{ "email": "customer@example.com", "name": "John Doe" }' ```

4. Create Subscription

```bash curl -X POST http://localhost:5000/api/subscriptions/create \ -H "Content-Type: application/json" \ -d '{ "customerId": "cus_xxxxx", "planId": "price_xxxxx", "userId": "user_id_here" }' ```

5. Validate Dahila Master Key

```bash curl -X GET http://localhost:5000/api/dahila/master-key \ -H "Authorization: Bearer YOUR_TOKEN" ```


πŸ” Security Best Practices

βœ… Environment Variables: Never commit .env file - use .env.example as template
βœ… JWT Tokens: Tokens expire after configured time (default: 7 days)
βœ… Password Hashing: Uses bcryptjs for secure password storage
βœ… HTTPS: Use HTTPS in production
βœ… Rate Limiting: Implement rate limiting in production
βœ… Input Validation: Always validate API inputs


πŸ§ͺ Testing

Use Stripe's test cards for development:

  • Valid: 4242 4242 4242 4242
  • Declined: 4000 0000 0000 0002
  • 3D Secure Required: 4000 0025 0000 3155

Dahila test credentials should be obtained from Dahila documentation.


πŸ“š Project Structure

``` saas/ β”œβ”€β”€ config/ β”‚ β”œβ”€β”€ stripe.js # Stripe configuration β”‚ └── dahila.js # Dahila API client β”œβ”€β”€ routes/ β”‚ β”œβ”€β”€ stripe.js # Stripe endpoints β”‚ β”œβ”€β”€ dahila.js # Dahila endpoints β”‚ β”œβ”€β”€ user.js # User authentication β”‚ └── subscription.js # Subscription management β”œβ”€β”€ server.js # Main server file β”œβ”€β”€ package.json # Dependencies β”œβ”€β”€ .env.example # Environment template └── README.md # This file ```


πŸš€ Deployment

Heroku

```bash heroku login heroku create your-app-name git push heroku main ```

Environment Variables on Heroku

```bash heroku config:set STRIPE_SECRET_KEY=sk_live_xxxxx heroku config:set DAHILA_API_KEY=your_master_key heroku config:set JWT_SECRET=your_secret ```


🀝 Support

For issues or questions:


πŸ“„ License

MIT License - Feel free to use this project commercially


Made with ❀️ by abdelhamidadel418-droid

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors