Skip to content

Repository files navigation

SmartPay API

A RESTful backend API for a digital wallet / money transfer application built with ASP.NET Core 8 and SQL Server. It includes a plain HTML/JS frontend and supports user registration, admin approval, JWT-authenticated transfers, beneficiary management, and transaction history.


Table of Contents


Features

  • User registration with admin approval workflow
  • JWT-based authentication (5-hour token lifetime)
  • Secure password hashing with BCrypt
  • Money transfers between approved users
  • Beneficiary management (add, list, delete)
  • Transaction history per user
  • Admin panel to view pending users and approve accounts
  • New users receive an automatic ₹5,000 initial deposit on approval
  • Swagger UI for API exploration

Tech Stack

Layer Technology
Backend ASP.NET Core 8 Web API (C#)
ORM Entity Framework Core 9 (SQL Server provider)
Auth JWT Bearer Tokens
Passwords BCrypt.Net-Next
Docs Swashbuckle / Swagger UI
Frontend Vanilla HTML, CSS, JavaScript
Database Microsoft SQL Server

Project Structure

SmartPayAPI/
├── Controllers/
│   ├── AdminController.cs          # Pending users, approve user
│   ├── AuthController.cs           # Login, JWT token issuing
│   ├── BeneficiaryController.cs    # CRUD for beneficiaries
│   ├── RegisterController.cs       # New user registration
│   ├── TransactionController.cs    # Transaction history
│   └── TransferController.cs       # Money transfer logic
│
├── Models/
│   ├── AppDbContext.cs             # EF Core DB context
│   ├── Beneficiary.cs              # Beneficiary entity
│   ├── LoginRequest.cs             # Login DTO
│   ├── Transaction.cs              # Transaction entity
│   └── User.cs                     # User entity
│
├── Migrations/                     # EF Core migrations
│
├── Frontend/                       # Static HTML pages
│   ├── login.html
│   ├── register.html
│   ├── dashboard.html
│   ├── transfer.html
│   ├── beneficiaries.html
│   ├── history.html
│   ├── success.html
│   └── admin.html
│
├── appsettings.json                # App configuration
├── Program.cs                      # App bootstrap & middleware
└── SmartPayAPI.csproj              # Project file

Getting Started

Prerequisites

  • .NET 8 SDK
  • Microsoft SQL Server (local or remote instance)
  • (Optional) Visual Studio 2022 or VS Code

Installation

  1. Clone / extract the project.

  2. Restore dependencies:

    dotnet restore
  3. Update the connection string in appsettings.json (see Configuration).

  4. Apply database migrations:

    dotnet ef database update
  5. Run the API:

    dotnet run
  6. Open Swagger UI at https://localhost:<port>/swagger to explore and test endpoints.


Configuration

Edit appsettings.json before running:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=SmartPayDB;Trusted_Connection=True;TrustServerCertificate=True;"
  },
  "Jwt": {
    "Key": "YourSuperSecretKeyHere_AtLeast32Chars!!",
    "Issuer": "SmartPayAPI"
  }
}

Security note: Replace the default Jwt:Key with a strong, unique secret before deploying to any environment outside localhost.


Database Setup

The project uses EF Core Code-First migrations. Run the following to create (or update) the database:

dotnet ef database update

To add a new migration after model changes:

dotnet ef migrations add <MigrationName>

Tables

Table Description
Users Registered users with roles and balances
Transactions All money movement records
Beneficiaries Saved payees per user

API Endpoints

All protected routes require the header:

Authorization: Bearer <jwt_token>

Auth

Method Route Auth Description
POST /Auth/login No Login and receive JWT token

Request body:

{ "mobileNumber": "03001234567", "password": "yourpassword" }

Register

Method Route Auth Description
POST /Register No Register new user

Request body:

{
  "fullName": "Ali Raza",
  "email": "ali@example.com",
  "mobileNumber": "03001234567",
  "password": "yourpassword"
}

Admin

Method Route Auth Description
GET /Admin/pending-users No List users awaiting approval
POST /Admin/approve-user No Approve a user and credit ₹5,000

Approve request body: "03001234567" (plain string)


Transfer

Method Route Auth Description
GET /api/Transfer/beneficiaries Yes Get current user's saved beneficiaries
POST /api/Transfer Yes Send money to another user

Transfer request body:

{
  "receiverMobile": "03007654321",
  "amount": 500.00,
  "type": "Personal"
}

Transaction

Method Route Auth Description
GET /Transaction/history Yes Get current user's full history

Beneficiary

Method Route Auth Description
GET /api/Beneficiary Yes List saved beneficiaries
POST /api/Beneficiary Yes Add a new beneficiary
DELETE /api/Beneficiary/{id} Yes Remove a beneficiary

Add request body:

{ "fullName": "Sara Khan", "beneficiaryMobile": "03007654321" }

Frontend Pages

Open the HTML files in the Frontend/ folder directly in a browser or serve them with any static file server.

File Purpose
login.html User login form
register.html New user registration form
dashboard.html Balance overview and quick actions
transfer.html Send money to a beneficiary
beneficiaries.html Manage saved payees
history.html View past transactions
success.html Transfer success confirmation
admin.html Admin panel — approve pending users

Business Rules

  • Mobile numbers must be exactly 11 digits.
  • New users have Pending status and a ₹0 balance until an admin approves them.
  • On approval, the user automatically receives an ₹5,000 initial deposit from the system.
  • Only Approved users can log in, transfer money, or be added as beneficiaries.
  • Users cannot transfer money to themselves or to the admin account.
  • JWT tokens expire after 5 hours.

About

SmartPay API — A .NET 8 digital wallet REST API with JWT auth, admin approval workflow, money transfers, and beneficiary management, backed by SQL Server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages