# Retail Management and Payment API A FastAPI-based REST API for retail management including inventory, orders, sales, and payment processing with Stripe integration. ## Features - **Product Management**: Create, read, update, and delete products - **Inventory Management**: Track and update product inventory - **Customer Management**: Manage customer information - **Order Management**: Process and track customer orders - **Payment Processing**: Process payments via Stripe integration - **Authentication**: JWT-based user authentication and authorization ## Tech Stack - **Framework**: FastAPI - **Database**: SQLite (with SQLAlchemy ORM) - **Migrations**: Alembic - **Authentication**: JWT (JSON Web Tokens) - **Payment Processing**: Stripe SDK ## API Endpoints ### Authentication - `POST /api/v1/auth/login` - Get access token - `POST /api/v1/auth/register` - Register a new user - `GET /api/v1/auth/me` - Get current user info ### Products - `GET /api/v1/products` - List all products - `POST /api/v1/products` - Create a new product - `GET /api/v1/products/{product_id}` - Get a single product - `PUT /api/v1/products/{product_id}` - Update a product - `DELETE /api/v1/products/{product_id}` - Delete a product ### Inventory - `GET /api/v1/inventory` - List all inventory items - `POST /api/v1/inventory` - Create a new inventory record - `GET /api/v1/inventory/{product_id}` - Get inventory for a product - `PUT /api/v1/inventory/{inventory_id}` - Update an inventory record - `PUT /api/v1/inventory/{inventory_id}/adjust` - Adjust inventory quantity ### Customers - `GET /api/v1/customers` - List all customers - `POST /api/v1/customers` - Create a new customer - `GET /api/v1/customers/{customer_id}` - Get a customer - `PUT /api/v1/customers/{customer_id}` - Update a customer - `DELETE /api/v1/customers/{customer_id}` - Delete a customer ### Orders - `GET /api/v1/orders` - List all orders - `POST /api/v1/orders` - Create a new order - `GET /api/v1/orders/{order_id}` - Get an order - `PUT /api/v1/orders/{order_id}` - Update an order - `DELETE /api/v1/orders/{order_id}` - Cancel an order ### Payments - `POST /api/v1/payments/create-payment-intent/{order_id}` - Create a Stripe payment intent - `POST /api/v1/payments/webhook` - Handle Stripe webhook events ### Health Check - `GET /health` - API health status check ## Setup and Installation ### Prerequisites - Python 3.8+ - pip (Python package manager) ### Installation Steps 1. Clone the repository: ```bash git clone [repository_url] cd retailmanagementandpaymentapi ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` 3. Set up environment variables (create a `.env` file in the project root): ``` JWT_SECRET_KEY=your-secret-key-change-in-production STRIPE_API_KEY=your-stripe-api-key STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret ``` 4. Run database migrations: ```bash alembic upgrade head ``` 5. Start the development server: ```bash uvicorn main:app --reload ``` ## API Documentation Once the server is running, you can access the auto-generated API documentation: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## Testing the API For testing the API endpoints, you can use the Swagger UI documentation or tools like Postman or curl. ### Stripe Testing For testing Stripe integration: - Use Stripe's test API keys - Use Stripe's test card numbers for payment simulation: - Test successful payment: 4242 4242 4242 4242 - Test failed payment: 4000 0000 0000 0002