A NestJS backend service for the BitcoinDeepa DCA (Dollar Cost Averaging) Telegram Mini App, providing subscription management, payment integration, and user management with Telegram authentication.
- Telegram Mini App Authentication: Secure JWT-based authentication using Telegram's init data
- Subscription Management: Create, manage, and cancel user subscriptions
- Package System: Handle different subscription packages
- PayHere Payment Integration: Recurring payments, webhook, and subscription cancellation
- Transaction Tracking: Webhook for payment notifications and user transaction history
- User Management: Create and manage user profiles
- Database Integration: PostgreSQL with Knex.js for migrations and seeding
- TypeScript: Full type safety throughout the application
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL
- ORM: Knex.js
- Authentication: JWT with Telegram Mini App validation
- Node.js v22
- Docker (for PostgreSQL and Redis via Docker Compose)
- Telegram Bot Token
- PayHere Merchant credentials (see below)
- pnpm (recommended)
git clone https://github.com/CeyLabs/BitcoinDeepa-DCA-TMA-BE.git
cd BitcoinDeepa-DCA-TMA-BEpnpm installCreate a .env file in the root directory:
cp .env.template .envStart PostgreSQL and Redis using Docker Compose:
docker compose up -dThis starts:
- PostgreSQL 16 on port
5432(user/pass/db:bitcoindeepa_dca) - Redis 7 on port
6379(password:redis_password)
To stop services:
docker compose downTo stop and remove all data:
docker compose down -v# Run migrations
pnpm migrate
# Seed the database with initial data
pnpm seed# Development mode
pnpm start:dev
# Production mode
pnpm start:prodThe server will start on http://localhost:3000
Validates Telegram Mini App init data and returns a JWT token.
Request:
{
"initData": "<initDataStringFromTelegram>"
}Create a new user profile (requires authentication).
Headers:
Authorization: Bearer <jwt_token>
Request:
{
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com",
"phone": "1234567890",
"address": "123 Main St",
"city": "Colombo",
"country": "Sri Lanka"
}Response:
- 201 Created (empty body)
Get all available packages.
Get the current subscription for the authenticated user.
Headers:
Authorization: Bearer <jwt_token>
Get a PayHere payment link for a package.
Headers:
Authorization: Bearer <jwt_token>
Request:
{
"package_id": "<uuid>"
}Cancel the current user's active subscription (PayHere API integration).
Headers:
Authorization: Bearer <jwt_token>
PayHere will POST payment notifications to this endpoint
List all transactions for the current authenticated user.
Headers:
Authorization: Bearer <jwt_token>
- Recurring Payments: Generates PayHere payment links for subscriptions.
- Webhook: Handles payment notifications and updates transaction status.
- Cancel Subscription: Cancels PayHere subscriptions and updates local DB.
- OAuth: Uses PayHere OAuth for secure API access.
src/modules/user- User managementsrc/modules/package- Subscription packagessrc/modules/subscription- Subscription logic and PayHere integrationsrc/modules/transaction- Payment notifications and transaction historysrc/modules/payhere- PayHere API helpers
- Ensure your PayHere notify_url is public and points to
/transaction/payhere-webhook. - The backend expects all PayHere secrets and IDs to be set in your environment.
- All endpoints (except webhook) require JWT authentication.
For more details, see the code and comments in each module.