Files
Zumri-Backend/Documentation/API_WHOLESALE_COMPLETION.md
Sathira Sri Sathara abb760cc19
CI / test (push) Successful in 10m23s
feat: Implement loyalty and wholesale services with models, routes, and validation
- Added models for loyalty points allocation, redemption, rewards, tiers, tier history, and referrals.
- Created business credit ledger entries, settlements, and settlement items models.
- Developed services for loyalty operations including account management, point allocation, redemption, and referral handling.
- Implemented wholesale credit management services for transactions and settlements.
- Established routes for loyalty and wholesale admin and customer operations with appropriate middleware for authentication and permission checks.
- Introduced validation schemas for loyalty and wholesale operations.
- Set up cron jobs for loyalty reconciliation tasks such as birthday rewards and point expirations.
- Created migration scripts to set up the database schema for loyalty and wholesale features.
- Added unit tests for validation and policy enforcement in loyalty and wholesale services.
2026-09-09 13:56:37 +05:30

1.7 KiB

Wholesale Completion API

Business endpoints require an authenticated, ACTIVE business_customer; organization identity is never accepted from the request.

Business account

  • GET /api/v1/business/dashboard
  • GET /api/v1/business/credit
  • POST /api/v1/business/orders/:id/use-credit with Idempotency-Key
  • GET /api/v1/business/settlements, GET /api/v1/business/settlements/:id
  • GET /api/v1/business/orders/recent

The dashboard uses paid Order snapshots for monthly/lifetime volume and discounts, existing BusinessTier for classification, the immutable credit ledger for utilization, and settlement records for next payment information.

Administration

  • POST /admin/wholesale/credit/transactions (wholesale.credit.manage)
  • GET /admin/wholesale/businesses/:businessId/credit (wholesale.credit.read)
  • Settlement list/generation/issue/mark-paid endpoints with settlement permissions.

Credit formula: available = creditLimit - ledger balance. Captures/authorizations increase utilization; payment, release, and refund entries decrease it. Every operation locks the existing BusinessCreditAccount, validates ACTIVE business/account status and currency, and uses a unique event ID. Credit-backed Order placement atomically captures credit, consumes reservations, records an INTERNAL_CREDIT Payment, marks the Order paid, and reuses invoice issuance.

Settlements snapshot ledger activity for a unique business/period. Due dates come from the existing SettlementTerm. Numbers use ReferenceNumber, and only explicit lifecycle actions are accepted.

Payment allocation storage exists as a foundation. External bank matching, general ledger, ERP, tax-authority integration, and document-worker validation remain outside this phase.