manicanldes-backend/docs/b2b-samples-api.md

30 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# B2B sample requests (Phase 3E)
All endpoints are under `/api/v1/b2b/samples` and require a bearer session. Every request is scoped to the caller's organization. Request fields and event history are immutable; status changes are checked in the database.
| Method | Path | Permission | Purpose |
| ------ | --------------- | --------------------- | ------------------------------------------------------- |
| GET | `/` | `b2b.sample.read` | List; optional `accountId`, `status`, `limit`, `offset` |
| GET | `/:id` | `b2b.sample.read` | Read request and ordered events |
| POST | `/` | `b2b.sample.request` | Request samples for a verified business account |
| POST | `/:id/decision` | `b2b.sample.review` | Approve or reject, by a different staff member |
| POST | `/:id/dispatch` | `b2b.sample.dispatch` | Record manual dispatch of an approved request |
Request body example:
```json
{
"accountId": "b92c23e5-794d-47e7-a7f4-428b84543fa1",
"variantId": "842b4658-2c2c-4626-8feb-1842ecf8726a",
"quantity": 4,
"purpose": "Fragrance evaluation",
"idempotencyKey": "10fc5585-34a6-4ead-b5ce-d83418eb50df"
}
```
Quantity is 1–100. The variant must be active and its product published. The request stores the variant SKU and name at creation. A decision body contains `decision` (`APPROVED` or `REJECTED`), `note`, and `idempotencyKey`. An approval rechecks business verification. A dispatch body contains `dispatchReference`, `note`, and `idempotencyKey`. Notes and purpose require 3–500 characters; dispatch reference requires 3–100 characters.
The lifecycle is `REQUESTED → APPROVED → DISPATCHED` or `REQUESTED → REJECTED`. Duplicate requests with the same key and payload return the current request; a changed payload returns a distinct 409 error. Event retries work the same way. The event response includes actor, time, and dispatch reference where applicable. Authorization and tenant boundaries apply to reads as well as writes.
`DISPATCHED` is a staff-recorded dispatch claim. This phase does not reserve or deduct stock, purchase postage, verify carrier delivery, or bill the partner. Those steps require later inventory/shipping and receivables integration. Operators should only record dispatch after a real handoff.