B2B Second Inventory Returns and Refunds API Reference
Endpoint reference for the bb phase 5 admin returns and refunds API — open and process a return, inspect it into stock, draft and settle refunds, the refund a cancel leaves, with permissions, throttles, idempotency, error codes and known limits.
B2B Second Inventory (bb) — Returns and Refunds API Reference
Audience: Admin engineers integrating with the bb phase 5 backend. A refund is a record of money owed. No gateway exists: staff pay the customer outside the system, then record that they did.
All endpoints are prefixed with /api, need a JWT, and need the listed permission. Superadmin passes every permission check. Every response uses the ResponseDto envelope (message, errorCode, data); lists add pagination metadata. Every :publicId is a UUID (a malformed one is a 400). Money is integer paisa; Admin #2 shows it as NPR.
Routes
| Method and path | Permission | Throttle (per 60 s) |
|---|---|---|
GET /api/admin/bb/returns (list) | BB_Returns_READ | 30, per IP (ADMIN_READ) |
GET /api/admin/bb/returns/:publicId (detail) | BB_Returns_READ | 30, per IP (ADMIN_READ) |
POST /api/admin/bb/returns (open) | BB_Returns_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/returns/:publicId/decide | BB_Returns_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/returns/:publicId/receive | BB_Returns_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/returns/:publicId/inspect | BB_Returns_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/returns/:publicId/cancel (close) | BB_Returns_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
GET /api/admin/bb/refunds (list) | BB_Refunds_READ | 30, per IP (ADMIN_READ) |
POST /api/admin/bb/orders/:publicId/refunds (draft) | BB_Refunds_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/refunds/:publicId/approve | BB_Refunds_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/refunds/:publicId/reject | BB_Refunds_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/refunds/:publicId/not-owed | BB_Refunds_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
POST /api/admin/bb/refunds/:publicId/settle | BB_Refunds_UPDATE | 30, per user (BB_RETURN_REFUND_WRITE) |
There is no refund detail route. A refund list row carries its lines, and the order detail lists the order's refunds. The only refund create route is the goodwill draft; the other refunds come from a cancel or an inspection.
The seed and permissions:sync create five codes per module, BB_Returns_* and BB_Refunds_*: CREATE, READ, UPDATE, DELETE and RESTORE. These routes check only READ and UPDATE. Money-moving routes sit behind BB_Refunds_UPDATE, separate from BB_Orders_UPDATE, so being able to cancel orders does not give the right to approve money.
How a return and a refund fit together
A return is by units: no request carries an amount. A line is worth its units times the sold unit price.
| Return status | Meaning |
|---|---|
requested | Opened. Its units are claimed against the order line. |
approved | Staff approved it. |
rejected | Staff refused it. The units are claimed no more. |
received | Staff recorded that the goods came back. No stock has moved. |
completed | Inspected: accepted units went back into stock. |
cancelled | Staff closed an approved return. The units are claimed no more. |
| Refund status | Meaning |
|---|---|
requested | Waiting for a decision. |
awaiting_settlement | Approved with a method. The order's refundedPaisa has risen by its amount. |
settled | Staff recorded the payout reference. |
rejected | Refused. Its units are free again. |
not_owed | Closed: no money ever moved. Cancellation refunds only. |
Refund origin is cancellation, return or goodwill. Only an inspection moves stock; a refund never does.
Legal moves:
- Return:
requestedtoapprovedorrejected(decide);approvedtoreceived(receive) orcancelled(close);receivedtocompleted(inspect). Any other move answers 409BB_RETURN_TRANSITION_NOT_ALLOWEDand changes nothing. - Refund:
requestedtoawaiting_settlement(approve),rejected(reject) ornot_owed;awaiting_settlementtosettled. Any other move answers 409BB_REFUND_TRANSITION_NOT_ALLOWEDand changes nothing.
Returns
Open
POST /api/admin/bb/returns opens a return on a paid order and answers 201.
- Body:
orderPublicId,reason(one ofwrong_item,damaged,defective,missing_parts,incorrect_size,no_longer_needed,changed_mind,not_as_described,other), optionalnote(1 to 1000 characters, no NUL; blank becomes null), andlines(1 to 50; eachorderItemPublicIdandquantityfrom 1 to 1,000,000). Idempotency-Keyis required; without it the answer is 400IDEMPOTENCY_KEY_REQUIRED. The same key and request again replays the first answer; the same key with a different request is 409IDEMPOTENCY_KEY_CONFLICT; the same key while the first is running is 409IDEMPOTENCY_REQUEST_IN_PROGRESS.- The answer holds the return's identifiers and status only, with no note: the idempotency layer stores the answer in Redis, and a note can hold anything. Read the text from the detail route.
- Errors: 400
VALIDATION_FAILED,BB_RETURN_DUPLICATE_LINE(a line named twice); 404BB_ORDER_NOT_FOUND; 409BB_RETURN_NOT_ELIGIBLE(the order is cancelled),BB_RETURN_LINE_NOT_ON_ORDERandBB_RETURN_QUANTITY_UNAVAILABLE(both withdetails.lines, naming every line at fault),BB_CATALOG_BUSY. - A line not on the order is reported before a quantity that is too high. Units already claimed by a return or a live refund are not available.
Decide
POST :publicId/decide takes { approve: boolean, reason } (reason 1 to 500 characters, required for an approval and a refusal alike) and answers 200 with the return detail. Only a requested return can be decided. A refusal gives the units back.
Receive
POST :publicId/receive takes no body and answers 200 with the return detail. Only an approved return can be received. No stock moves.
Inspect
POST :publicId/inspect decides every line, restocks what was accepted and, when money is still owed, proposes a refund, all in one transaction. Body: lines, one entry for every line of the return exactly once, each with returnItemPublicId, acceptedQuantity (0 up to the requested units) and optional rejectionReason (1 to 500 characters). The reason is required when fewer units are accepted than were requested, and refused when all were. Only a received return can be inspected. The answer is the return detail, with refund filled when one was proposed.
A failure anywhere rolls back all of it: stock, line outcomes, counters and the refund. There is no compensation step. Inspecting twice answers 409 and stock rises once.
- Errors: 400
VALIDATION_FAILED,BB_RETURN_INSPECTION_INVALID(not every line once, accepted above requested, reason missing or not allowed),BB_INVENTORY_QUANTITY_LIMIT(restocking would pass the variant's stock cap;details.variantPublicIdanddetails.orderItemPublicIdname the line, and the whole inspection is refused); 404BB_RETURN_NOT_FOUND,BB_INVENTORY_NOT_FOUND; 409BB_RETURN_TRANSITION_NOT_ALLOWED,BB_REFUND_DECISION_REQUIRED,BB_REFUND_EXCEEDS_REMAINING,BB_REFUND_ORDER_TOTAL_EXCEEDED,BB_CATALOG_BUSY. BB_REFUND_DECISION_REQUIREDmeans arequestedrefund covers a line this inspection would net against, and that refund may still be rejected. Nothing was written.detailsholdsrefunds([{ refundNumber }]) andlines([{ orderItemPublicId }]). Approve or reject that refund first, then inspect.- A variant deleted since the sale still takes its units back; the return detail marks the line
variantDeleted.
Close
POST :publicId/cancel takes { reason } (1 to 500 characters), closes an approved return and releases its units. It answers 200 with the return detail.
List and detail
GET /api/admin/bb/returns takes search, status, reason, order (asc or desc, default desc), page and size. No query answers page 1, size 20. An empty size= reads as 20. size above 100 or page above 1,000,000 answers 400, as does an unsupported query key. search is at most 100 characters and matches the return number, the order number, or the customer name, phone or company as stored on the order.
GET :publicId returns the return with its lines (product name, variant label, SKU, unitPricePaisa, requestedQuantity, acceptedQuantity, outcome, rejectionReason, refundableQuantity, refundablePaisa, variantDeleted, productDeleted) and its refund (publicId, refundNumber, status, amountPaisa), or null before one exists. A missing return answers 404 BB_RETURN_NOT_FOUND. Line outcome is pending, accepted, partially_accepted or rejected.
Refunds
Draft a goodwill refund
POST /api/admin/bb/orders/:publicId/refunds asks for money back on an order without a return, and answers 201.
- Body:
lines(1 to 50; eachorderItemPublicIdandquantityof units, 1 to 1,000,000) andreason(1 to 500 characters). There is no amount: the backend prices each line. Idempotency-Keyis required, with the same replay and conflict answers as opening a return.- Errors: 400
VALIDATION_FAILED,BB_REFUND_DUPLICATE_LINE; 404BB_ORDER_NOT_FOUND; 409BB_REFUND_LINE_NOT_ON_ORDER,BB_REFUND_ZERO_VALUEandBB_REFUND_EXCEEDS_REMAINING(each withdetails.lines),BB_REFUND_ORDER_TOTAL_EXCEEDED,BB_CATALOG_BUSY. - When one draft has both a worthless line and an over-remaining line,
BB_REFUND_ZERO_VALUEanswers first.
Approve, reject, not owed, settle
All four answer 200 with the refund row and take no idempotency key. A repeat answers 409 BB_REFUND_TRANSITION_NOT_ALLOWED and moves nothing.
| Route | Body | Does |
|---|---|---|
approve | { method }: cash, qr, bank_transfer, cheque, card or other | requested to awaiting_settlement; raises the order's refundedPaisa. 409 BB_REFUND_ORDER_TOTAL_EXCEEDED if it would pass the order total. |
reject | { reason }, 1 to 500 characters | requested to rejected. The units are free again. |
not-owed | { reason }, 1 to 500 characters | requested to not_owed. A return or goodwill refund answers 409 BB_REFUND_NOT_OWED_NOT_ALLOWED. |
settle | { settlementReference }, 1 to 200 characters | awaiting_settlement to settled; stores the reference. |
A missing refund answers 404 BB_REFUND_NOT_FOUND. Every route can also answer 409 BB_CATALOG_BUSY. The reason of reject and not-owed is stored as decisionReason.
List
GET /api/admin/bb/refunds takes search, status, origin, order, page and size, with the same defaults and limits as the returns list. search matches the refund number, the order number, or the customer name, phone or company as stored on the order.
Each row carries status, origin, amountPaisa, currency (NPR), method, decisionReason, settlementReference, the order (orderPublicId, orderStatus, orderPaymentMethod, orderCancelReason, orderTotalPaisa, orderRefundedPaisa, orderAttributedPaisa), the customer as stored on the order, returnPublicId and returnNumber when it came from a return, lines (orderItemPublicId, names, SKU, unitPricePaisa, quantity, amountPaisa), and the actors and times of approval, settlement and closing.
orderRefundedPaisa counts approved refunds only. orderAttributedPaisa counts every refund that is not rejected and not marked not owed, so a requested refund is in the second figure and not the first.
What cancelling an order now does
POST /api/admin/bb/orders/:publicId/cancel (see Orders API reference) now also asks for the money back. After the restock, the response carries refund: a requested cancellation refund (publicId, refundNumber, status, amountPaisa) for every line value and unit no live refund already holds, or null when nothing is owed. One cancellation refund exists per order.
Cancel is refused, with nothing written, when:
| Status | Code | Trigger |
|---|---|---|
| 409 | BB_ORDER_HAS_RETURN | A return holds pending units, or units were returned. Finish or close the return instead. |
| 409 | BB_REFUND_DECISION_REQUIRED | A requested refund covers a line the cancel would net against. details as under Inspect. |
| 409 | BB_REFUND_ORDER_TOTAL_EXCEEDED | The cancellation refund would pass the order total. |
The order detail (GET /api/admin/bb/orders/:publicId) now also returns refunds and returns (the newest 100 each, with refundsTruncated and returnsTruncated), refundSummary (requestedPaisa, awaitingSettlementPaisa, settledPaisa, notOwedPaisa), refundedPaisa, and per line returnPendingQuantity, returnedQuantity, refundedUnits, returnableUnits and refundableUnits.
Audit, events and stock ledger
- Every return and refund write writes a
bb_auditrow in the same transaction; a failed audit write rolls the operation back. Audit rows carry statuses, amounts and the method, never reasons, notes or settlement references. - Order events record refund and return steps with identifiers, numbers, amounts and, for approval and settlement, the method.
- An inspection writes one stock movement with reason
returnper restocked line, carrying the return's UUID as its correlation id. - Return and refund numbers come from sequences. A rolled-back write burns a number; a refused request draws none.
Known limits
- Idempotency covers open and draft only. The transitions and the inspection take no key. A repeat is a 409 and changes nothing; recover a lost response by reading the detail or list.
- No gateway.
settlerecords a reference typed by staff and checks it against nothing. - No customer-facing route. Staff close a return.
- No refund detail route.
- The request shapes above were read from the DTO classes and controllers. They were not captured from a running server.
B2B Second Inventory Orders Deploy Notes
Deploy order, migrations 0065 and 0066, the required permissions:sync, the SUPERADMIN_PASSWORD seed requirement, the pre-deploy check list and rollback limits for bb phase 4. Phase 4 ships together with phase 5.
B2B Second Inventory Returns and Refunds Deploy Notes
Deploy order, migrations 0067 and 0068, the locks they take, the required permissions:sync, the manual grant step and rollback limits for bb phase 5. Phase 5 ships together with phase 4.