Skip to content

Commit 01606a4

Browse files
Add payment-service microservice for billing and subscriptions
Implements NestJS payment service with Stripe integration, Payment/Invoice/Subscription entities, webhook handling, refund processing, payment method management, Docker config, and unit/e2e tests. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a6dc84e commit 01606a4

54 files changed

Lines changed: 12806 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,33 @@ services:
258258
- quest-network
259259
logging: *logging_config
260260

261+
payment-service:
262+
build:
263+
context: ./microservices/payment-service
264+
dockerfile: Dockerfile
265+
container_name: payment_service
266+
ports:
267+
- "3019:3019"
268+
environment:
269+
- NODE_ENV=development
270+
- DB_HOST=postgres
271+
- DB_PORT=5432
272+
- DB_USER=${DB_USER:-postgres}
273+
- DB_PASSWORD=${DB_PASSWORD:-password}
274+
- DB_NAME=payment_db
275+
- SERVICE_PORT=3019
276+
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-mock}
277+
- STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET:-whsec_test}
278+
volumes:
279+
- ./microservices/payment-service:/app
280+
- /app/node_modules
281+
depends_on:
282+
postgres:
283+
condition: service_healthy
284+
networks:
285+
- quest-network
286+
logging: *logging_config
287+
261288
moderation-service:
262289
build:
263290
context: ./microservices/moderation-service

docker/postgres/init-databases.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ create_db "puzzle_db"
2222
create_db "player_db"
2323
create_db "moderation_db"
2424
create_db "analytics_db"
25+
create_db "payment_db"
2526

2627
echo "All microservice databases created successfully!"

microservices/api-gateway/src/config/configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export default () => ({
113113
prefix: '/api/replays',
114114
healthPath: '/health',
115115
},
116+
payment: {
117+
url: process.env.PAYMENT_SERVICE_URL || 'http://localhost:3019',
118+
prefix: '/api/payments',
119+
healthPath: '/health',
120+
},
116121
},
117122

118123
rateLimit: {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
coverage
4+
.env
5+
*.log
6+
.git
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Service Configuration
2+
SERVICE_NAME=payment-service
3+
SERVICE_PORT=3019
4+
NODE_ENV=development
5+
6+
# Database Configuration
7+
DB_HOST=localhost
8+
DB_PORT=5432
9+
DB_NAME=payment_db
10+
DB_USER=postgres
11+
DB_PASSWORD=password
12+
13+
# Stripe Configuration
14+
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
15+
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
16+
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
17+
18+
# PayPal Configuration (optional)
19+
PAYPAL_CLIENT_ID=your_paypal_client_id
20+
PAYPAL_CLIENT_SECRET=your_paypal_client_secret
21+
PAYPAL_MODE=sandbox
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci --only=production
8+
9+
COPY . .
10+
11+
RUN npm run build
12+
13+
EXPOSE 3019
14+
15+
CMD ["npm", "run", "start:prod"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Payment Service
2+
3+
NestJS microservice for fiat payment processing, subscription billing, invoice generation, and refund handling.
4+
5+
## Features
6+
7+
- **Payment Processing** — Process one-time payments via Stripe (with mock fallback for development)
8+
- **Subscription Billing** — Create, cancel, and bill recurring subscriptions
9+
- **Invoice Generation** — Generate and manage invoices with line items
10+
- **Payment Methods** — Store and manage user payment methods
11+
- **Refund Processing** — Process full or partial refunds
12+
- **Webhook Handling** — Handle Stripe payment status webhooks securely
13+
14+
## Quick Start
15+
16+
```bash
17+
cp .env.example .env
18+
npm install
19+
npm run start:dev
20+
```
21+
22+
The service runs on port **3019** by default.
23+
24+
## Docker
25+
26+
```bash
27+
docker-compose up --build
28+
```
29+
30+
## API Endpoints
31+
32+
| Method | Path | Description |
33+
|--------|------|-------------|
34+
| GET | `/health` | Health check |
35+
| GET | `/payments/providers` | List payment providers |
36+
| POST | `/payments/:provider/process` | Process a payment |
37+
| POST | `/payments/:provider/refund` | Refund a payment |
38+
| POST | `/invoices` | Create an invoice |
39+
| POST | `/subscriptions` | Create a subscription |
40+
| POST | `/payment-methods` | Add a payment method |
41+
| POST | `/webhooks/stripe` | Stripe webhook handler |
42+
43+
## Testing
44+
45+
```bash
46+
npm test
47+
npm run test:e2e
48+
```
49+
50+
## Environment Variables
51+
52+
See `.env.example` for required configuration including Stripe keys and database settings.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3.8'
2+
3+
services:
4+
payment-service:
5+
build: .
6+
ports:
7+
- '3019:3019'
8+
environment:
9+
NODE_ENV: development
10+
SERVICE_PORT: 3019
11+
DB_HOST: postgres
12+
DB_PORT: 5432
13+
DB_USER: postgres
14+
DB_PASSWORD: password
15+
DB_NAME: payment_db
16+
STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY:-mock}
17+
STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET:-whsec_test}
18+
depends_on:
19+
- postgres
20+
volumes:
21+
- .:/app
22+
- /app/node_modules
23+
command: npm run start:dev
24+
25+
postgres:
26+
image: postgres:15-alpine
27+
environment:
28+
POSTGRES_DB: payment_db
29+
POSTGRES_USER: postgres
30+
POSTGRES_PASSWORD: password
31+
ports:
32+
- '5439:5432'
33+
volumes:
34+
- postgres_data:/var/lib/postgresql/data
35+
36+
volumes:
37+
postgres_data:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @ts-check
2+
import eslint from '@eslint/js';
3+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4+
import globals from 'globals';
5+
import tseslint from 'typescript-eslint';
6+
7+
export default tseslint.config(
8+
{
9+
ignores: ['eslint.config.mjs'],
10+
},
11+
eslint.configs.recommended,
12+
...tseslint.configs.recommendedTypeChecked,
13+
eslintPluginPrettierRecommended,
14+
{
15+
languageOptions: {
16+
globals: {
17+
...globals.node,
18+
...globals.jest,
19+
},
20+
sourceType: 'commonjs',
21+
parserOptions: {
22+
projectService: true,
23+
tsconfigRootDir: import.meta.dirname,
24+
},
25+
},
26+
},
27+
{
28+
rules: {
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
'@typescript-eslint/no-floating-promises': 'warn',
31+
'@typescript-eslint/no-unsafe-argument': 'warn',
32+
'prettier/prettier': ['error', { endOfLine: 'auto' }],
33+
},
34+
},
35+
);

0 commit comments

Comments
 (0)