Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

⚡ PayPulse API

Production-grade B2B Payment Gateway — built for high concurrency, financial integrity, and zero double-spending.

Repos: github.com/aldoprogrammer/PayPulse-API

Demo

PayPulse Demo Video

Screenshots & UI preview

Full gallery (card checkout, PulsePay wallet, payment success): docs/preview/PLATFORM_PREVIEW.md

Used by: travel marketplace VoyageX — hotel/package checkout redirects to a PayPulse Checkout page (TEST MODE, card / PulsePay wallet UI), then confirms payment via this API and webhooks VoyageX to mark the order PAID.

PayPulse API is a fintech backend that handles wallet balances, ledger transactions, checkout payments, and merchant webhooks at scale. Deposits are queued asynchronously via RabbitMQ so the HTTP layer stays fast under burst traffic, while balance writes are processed safely by a background consumer. Checkout payments are created as PENDING, then confirmed (demo pay) with HTTP webhook delivery to merchants such as VoyageX.


🔗 VoyageX Integration

Sister repo: VoyageX · UI/flow doc: VoyageX-PayPulse-Integration-v1.0.md

VoyageX uses PayPulse for hotel/package checkout only (flights stay instant-PAID).

End-to-end flow

Hotel/package checkout → Create order (UNPAID)
  → VoyageX booking creates PayPulse payment (PENDING)
  → Redirect to VoyageX FE /paypulse/checkout?orderId=…&returnUrl=/dashboard
  → Customer pays in hosted UI (TEST MODE · card / PulsePay wallet — demo only)
  → VoyageX booking POST /api/v1/orders/:id/pay
  → PayPulse POST /api/v1/payments/:id/confirm
  → Order PAID in VoyageX (+ HTTP webhook payment.completed as backup)

The browser never calls PayPulse directly; VoyageX booking-service is the B2B client (X-API-Key).

Local setup

  1. Start PayPulse: npm run dev (API 4100).
  2. Bootstrap merchant: npm run bootstrap:voyagex → copy apiKey.
  3. In VoyageX .env (booking-service):
PAYPULSE_ENABLED=true
PAYPULSE_API_URL=http://host.docker.internal:4100
PAYPULSE_API_KEY=<apiKey from bootstrap>
PAYPULSE_CALLBACK_URL=http://host.docker.internal:4000/api/v1/webhooks/paypulse
  1. Recreate VoyageX booking: docker compose up -d --force-recreate booking-service. Open http://localhost:3000.

Without PAYPULSE_API_KEY, VoyageX disables PayPulse and hotel/package orders default to PAID (offline demo).

Default webhook URL (PayPulse container → VoyageX booking on host):
http://host.docker.internal:4000/api/v1/webhooks/paypulse

See Payments contract (VoyageX) below for create / confirm / webhook payloads.

🏗️ Tech Stack

Layer Technology
Framework NestJS (TypeScript)
Database PostgreSQL + Prisma ORM
Cache / Idempotency Redis
Message Broker RabbitMQ
API Docs Swagger (/docs)
Dev Infra Docker Compose + hot-reload (ts-node-dev)

💡 Why This Project Stands Out

  • Async Deposit Pipeline — POST /deposit returns 202 QUEUED instantly; RabbitMQ consumer handles balance + ledger writes off the HTTP thread.
  • Checkout Payments — create PENDING payments, confirm to credit wallet + ledger, deliver payment.completed over HTTP.
  • Idempotency Engine — Redis-backed X-Idempotency-Key locks prevent duplicate processing on retries or double-clicks.
  • ACID Wallet Transfers — Prisma $transaction blocks guarantee atomic balance deduction, credit, and ledger entry.
  • Reliable Webhooks — notifications are published to RabbitMQ, then HTTP-delivered by a dedicated consumer with WebhookLog status tracking.
  • Zero-Friction DevEx — Docker volume mounts + auto prisma db push on container boot. Edit code, save, reload — no manual DB sync.

🔄 Request Flow

Client / VoyageX
  │
  ├─ POST /payments
  │     ├─ Redis idempotency check
  │     └─ Create Payment PENDING
  │
  ├─ POST /payments/:id/confirm
  │     ├─ Redis idempotency check
  │     ├─ Prisma $transaction (wallet credit + ledger DEPOSIT + Payment COMPLETED)
  │     └─ Publish → RabbitMQ (paypulse.webhooks)
  │
  ├─ POST /wallets/:id/deposit
  │     ├─ Redis idempotency check
  │     ├─ Publish → RabbitMQ (paypulse.deposits)
  │     └─ Return 202 QUEUED
  │
  └─ POST /transfers
        ├─ Redis idempotency check
        ├─ Prisma $transaction (balance + ledger)
        └─ Publish → RabbitMQ (paypulse.webhooks)

RabbitMQ Consumer (paypulse.deposits)
  └─ Prisma $transaction → balance update + ledger insert

RabbitMQ Consumer (paypulse.webhooks)
  └─ HTTP POST → merchant webhookUrl / payment.callbackUrl

📡 API Endpoints

Method Endpoint Auth Description
POST /api/v1/merchants — Register merchant, get API key
POST /api/v1/wallets X-API-Key Create wallet
GET /api/v1/wallets X-API-Key List wallets
POST /api/v1/wallets/:id/deposit X-API-Key + X-Idempotency-Key Queue async deposit
POST /api/v1/transfers X-API-Key + X-Idempotency-Key ACID balance transfer
POST /api/v1/payments X-API-Key + X-Idempotency-Key Create PENDING payment
GET /api/v1/payments/:id X-API-Key Get payment
POST /api/v1/payments/:id/confirm X-API-Key + X-Idempotency-Key Confirm payment (demo pay)
GET /api/v1/health — Health check

Payments contract (VoyageX)

Create

POST /api/v1/payments
X-API-Key: <merchant api key>
X-Idempotency-Key: <unique key>
Content-Type: application/json

{
  "amount": 149.99,
  "currency": "USD",
  "externalReference": "<VoyageX orderId>",
  "description": "optional",
  "callbackUrl": "optional override",
  "metadata": {}
}

Response: { id, status, amount, currency, externalReference, createdAt }

Confirm

POST /api/v1/payments/:id/confirm
X-API-Key: <merchant api key>
X-Idempotency-Key: <unique key>

Response includes status: COMPLETED, paidAt, ledgerTransactionId.

Webhook (PayPulse → VoyageX)

POST <callbackUrl | merchant.webhookUrl>
Content-Type: application/json
X-PayPulse-Event: payment.completed

{
  "event": "payment.completed",
  "paymentId": "...",
  "externalReference": "<orderId>",
  "amount": "149.99",
  "currency": "USD",
  "status": "COMPLETED",
  "timestamp": "..."
}

🛠️ How to Run

cp .env.example .env
npm run dev

Ports vs VoyageX

Service PayPulse (host) VoyageX (typical)
API 4100 4000 (booking)
Postgres 5433 → 5432 5432
Redis 6380 → 6379 6379
RabbitMQ AMQP 5673 → 5672 5672
RabbitMQ UI 15673 → 15672 15672
Service URL
API Gateway http://localhost:4100/api/v1
Swagger Docs http://localhost:4100/docs
RabbitMQ UI http://localhost:15673 (paypulse / paypulse_secret)
Prisma Studio http://localhost:5555 (npm run prisma:studio)

Note: .env uses localhost + remapped host ports for DB/Redis/RabbitMQ so host-side tools work. Docker app container overrides these to internal hostnames automatically.


🗄️ Prisma Studio

Stack must be running first (npm run dev), then:

npm run prisma:studio

Open http://localhost:5555

Stay on Prisma 6.x with Node 20. Do not upgrade to Prisma 7 unless you move to Node 22+.


⚙️ Core Scripts

Command Description
npm run dev Start full stack with logs
npm run dev:down Stop all containers
npm run dev:clean Stop + wipe DB/volume data
npm run bootstrap:voyagex Create VoyageX merchant + USD wallet, print apiKey
npm run test:load Run 5,000 deposit stress test (100/batch)

🧪 Stress Test (High-Volume Load)

simulate-traffic.ts automates a full blast test:

  1. Creates 1 merchant + retrieves API key
  2. Creates 1 IDR wallet
  3. Fires 5,000 deposit requests in batches of 100 (Promise.all per batch)
  4. Each request uses a unique X-Idempotency-Key and random amount (10,000–50,000 IDR)

Prerequisite: API must be running (npm run dev).

npm run test:load

Or directly:

npx ts-node simulate-traffic.ts

Verify async queuing in RabbitMQ UI:

http://localhost:15673 → Queues → paypulse.deposits

You should see message count spike during the blast, then drain as the consumer processes them.

Optional env overrides:

API_BASE_URL=http://localhost:4100 \
API_PREFIX=api/v1 \
LOAD_TOTAL_REQUESTS=5000 \
LOAD_BATCH_SIZE=100 \
npm run test:load

📂 Project Structure

src/
├── merchants/          # Merchant onboarding + API keys
├── wallets/            # Wallet CRUD + async deposit producer/consumer
├── payments/           # PENDING payments + confirm (checkout)
├── transfers/          # ACID balance transfers
├── webhooks/           # HTTP webhook delivery consumer
├── idempotency/        # Redis middleware (X-Idempotency-Key)
├── rabbitmq/           # Queue publisher + consumers
├── redis/              # Redis client + lock helpers
└── prisma/             # Database service
scripts/
└── bootstrap-voyagex-merchant.ts
simulate-traffic.ts     # High-volume stress test script
docker-compose.yml      # Full local infra

📄 License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages