# Airpero SaaS System (9PSB Naira Implementation)

This is a standalone SaaS system designed for Merchant and Customer account management, powered by the 9PSB Naira infrastructure.

## Core Features

- **Merchant Management**: Every merchant gets a unique 9PSB static account number for easy funding.
- **Customer Management**: Merchants can create and manage multiple customer accounts, each with its own 9PSB virtual account.
- **Transaction Reporting**: Detailed records including Total Volume, Total Credit, and Total Debit.
- **Filtering**: View transactions on a daily, monthly, or yearly basis.
- **Merchant Payouts**: Secure payouts from merchant/customer pools to external bank accounts.
- **Fee Management**:
    - **Deposits (Pay-in)**: 0.5% per transaction, capped at ₦100.
    - **Payouts (Pay-out)**: Flat fee of ₦20 per transaction.

## Project Structure

```
airpero_saas/
├── src/
│   ├── controllers/      # Merchant, Customer, Transaction, Admin logic
│   ├── models/           # Sequelize models (Merchant, Customer, Transaction)
│   ├── thirdParties/     # 9PSB PsbService
│   ├── utils/            # Fee calculation logic
│   ├── routes/           # API endpoints
│   ├── app.js            # Express config
│   └── server.js         # Entry point
├── config/               # Database config
└── tests/                # Automated tests
```

## Setup Instructions

1. **Install Dependencies**:
   ```bash
   npm install
   ```

2. **Environment Variables**:
   Copy `.env.example` to `.env` and fill in your 9PSB credentials from the original `airpero_1` project.

3. **Database**:
   Run your MySQL server and ensure the database `airpero_saas` exists. Models will auto-sync on development start (see `src/app.js`).

4. **Start Development Server**:
   ```bash
   npm run dev
   ```

## API Endpoints (v1)

### Merchants
- `POST /api/v1/merchants`: Create a new merchant.
- `GET /api/v1/merchants/:id`: Get merchant details and account number.

### Customers
- `POST /api/v1/customers`: Create a customer under a merchant.
- `GET /api/v1/customers/:customerId/report`: Get transaction report (volume, credit, debit) with filters (`?startDate=...&endDate=...` or `?period=daily/monthly/yearly`).

### Transactions
- `POST /api/v1/payouts`: Initiate a payout.
- `POST /api/v1/webhooks/9psb`: 9PSB webhook endpoint for funding.

### Admin
- `GET /api/v1/admin/report`: Overall platform report.
