manicanldes-backend/docs/b2b-partner-orders-api.md

2.3 KiB

B2B partner purchase orders (Phase 3G)

All endpoints are under /api/v1/b2b/partner-orders and require a bearer session. Staff record a partner purchase order only from an accepted, unexpired quotation for a verified business account. The order copies the quotation's account profile snapshot, currency, merchandise total, and every line's variant, SKU, name, quantity, minimum quantity, unit price, and line total. Those records are immutable.

Method Path Permission Purpose
GET / b2b.order.read List; optional accountId, limit, offset
GET /:id b2b.order.read Read order, lines, and cancellation
POST / b2b.order.manage Record purchase order from a quote
POST /:id/cancel b2b.order.manage Record one reasoned cancellation

Create example:

{
  "quoteId": "b92c23e5-794d-47e7-a7f4-428b84543fa1",
  "partnerReference": "CUSTOMER-PO-123",
  "note": "Requested by purchasing team",
  "idempotencyKey": "10fc5585-34a6-4ead-b5ce-d83418eb50df"
}

The partner reference is required and unique within the business account; note may be omitted or null. One quotation can produce only one order. An identical retry returns the existing order, while reuse of an idempotency key for different content returns a distinct 409 error. A cancellation body is { "reason": "Partner withdrew purchase order", "idempotencyKey": "<uuid>" }. Cancellation is append-only and changes the computed response status from RECEIVED to CANCELLED; an identical retry returns the current order.

These are merchandise-only purchase-order records. Recording one does not reserve inventory, schedule production or delivery, calculate tax or shipping, charge a payment method, or draw on a credit policy. The order number and its snapshot can be used as stable inputs to later fulfillment and receivables workflows. Those workflows must explicitly validate a non-cancelled order and define their own financial and stock transitions.

Phase 3H adds manual partial payment records. Cancellation now requires reversing any active receipt first.