manicanldes-backend/docs/b2b-credit-policies-api.md

2.6 KiB
Raw Permalink Blame History

B2B credit policies (Phase 3D)

All endpoints are under /api/v1/b2b/credit-policies and require a bearer session. Policies belong to the caller's organization. The proposal and event history are append-only; a policy has at most one approval or rejection and, if approved, one later suspension.

Method Path Permission Purpose
GET / b2b.credit.read List policies; optional accountId, status, limit, offset
GET /:id b2b.credit.read Read one policy and its ordered decision events
POST / b2b.credit.propose Propose terms for a verified business account
POST /:id/decision b2b.credit.review Approve or reject a proposal
POST /:id/suspend b2b.credit.review Suspend an active policy

Proposal example:

{
  "accountId": "b92c23e5-794d-47e7-a7f4-428b84543fa1",
  "currency": "INR",
  "creditLimit": "10000.00",
  "netDays": 30,
  "rationale": "Established wholesale customer",
  "idempotencyKey": "10fc5585-34a6-4ead-b5ce-d83418eb50df"
}

creditLimit is a positive decimal string with exactly two fractional digits and at most fourteen integer digits; netDays is 1–180. Review body: { "decision": "APPROVED", "note": "Reviewed account documents", "idempotencyKey": "..." } (or REJECTED). Suspension body: { "note": "Temporary credit hold", "idempotencyKey": "..." }. Each key is a UUID, unique within the organization. Reusing it with different content returns 409. Retrying an identical request returns the policy's current representation.

The proposer cannot review their own terms. Approval rechecks business verification and allows only one active policy per account and currency. The database enforces immutable terms, transition and event sequencing, and the active-policy uniqueness constraint. API errors have distinct codes/messages for unverified accounts, self-review, state conflicts, active overlap, replay conflicts, and scoped not-found responses.

This phase records approved limits and payment terms. It does not grant credit at checkout or track utilization, balances, payments, delinquency, or holds against orders. Those require a separate B2B order and receivables workflow. Do not interpret ACTIVE as permission to bypass the existing checkout payment boundary.