Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

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 pathPermissionThrottle (per 60 s)
GET /api/admin/bb/returns (list)BB_Returns_READ30, per IP (ADMIN_READ)
GET /api/admin/bb/returns/:publicId (detail)BB_Returns_READ30, per IP (ADMIN_READ)
POST /api/admin/bb/returns (open)BB_Returns_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/returns/:publicId/decideBB_Returns_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/returns/:publicId/receiveBB_Returns_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/returns/:publicId/inspectBB_Returns_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/returns/:publicId/cancel (close)BB_Returns_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
GET /api/admin/bb/refunds (list)BB_Refunds_READ30, per IP (ADMIN_READ)
POST /api/admin/bb/orders/:publicId/refunds (draft)BB_Refunds_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/refunds/:publicId/approveBB_Refunds_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/refunds/:publicId/rejectBB_Refunds_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/refunds/:publicId/not-owedBB_Refunds_UPDATE30, per user (BB_RETURN_REFUND_WRITE)
POST /api/admin/bb/refunds/:publicId/settleBB_Refunds_UPDATE30, 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 statusMeaning
requestedOpened. Its units are claimed against the order line.
approvedStaff approved it.
rejectedStaff refused it. The units are claimed no more.
receivedStaff recorded that the goods came back. No stock has moved.
completedInspected: accepted units went back into stock.
cancelledStaff closed an approved return. The units are claimed no more.
Refund statusMeaning
requestedWaiting for a decision.
awaiting_settlementApproved with a method. The order's refundedPaisa has risen by its amount.
settledStaff recorded the payout reference.
rejectedRefused. Its units are free again.
not_owedClosed: 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: requested to approved or rejected (decide); approved to received (receive) or cancelled (close); received to completed (inspect). Any other move answers 409 BB_RETURN_TRANSITION_NOT_ALLOWED and changes nothing.
  • Refund: requested to awaiting_settlement (approve), rejected (reject) or not_owed; awaiting_settlement to settled. Any other move answers 409 BB_REFUND_TRANSITION_NOT_ALLOWED and changes nothing.

Returns

Open

POST /api/admin/bb/returns opens a return on a paid order and answers 201.

  • Body: orderPublicId, reason (one of wrong_item, damaged, defective, missing_parts, incorrect_size, no_longer_needed, changed_mind, not_as_described, other), optional note (1 to 1000 characters, no NUL; blank becomes null), and lines (1 to 50; each orderItemPublicId and quantity from 1 to 1,000,000).
  • Idempotency-Key is required; without it the answer is 400 IDEMPOTENCY_KEY_REQUIRED. The same key and request again replays the first answer; the same key with a different request is 409 IDEMPOTENCY_KEY_CONFLICT; the same key while the first is running is 409 IDEMPOTENCY_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); 404 BB_ORDER_NOT_FOUND; 409 BB_RETURN_NOT_ELIGIBLE (the order is cancelled), BB_RETURN_LINE_NOT_ON_ORDER and BB_RETURN_QUANTITY_UNAVAILABLE (both with details.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.variantPublicId and details.orderItemPublicId name the line, and the whole inspection is refused); 404 BB_RETURN_NOT_FOUND, BB_INVENTORY_NOT_FOUND; 409 BB_RETURN_TRANSITION_NOT_ALLOWED, BB_REFUND_DECISION_REQUIRED, BB_REFUND_EXCEEDS_REMAINING, BB_REFUND_ORDER_TOTAL_EXCEEDED, BB_CATALOG_BUSY.
  • BB_REFUND_DECISION_REQUIRED means a requested refund covers a line this inspection would net against, and that refund may still be rejected. Nothing was written. details holds refunds ([{ refundNumber }]) and lines ([{ 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; each orderItemPublicId and quantity of units, 1 to 1,000,000) and reason (1 to 500 characters). There is no amount: the backend prices each line.
  • Idempotency-Key is required, with the same replay and conflict answers as opening a return.
  • Errors: 400 VALIDATION_FAILED, BB_REFUND_DUPLICATE_LINE; 404 BB_ORDER_NOT_FOUND; 409 BB_REFUND_LINE_NOT_ON_ORDER, BB_REFUND_ZERO_VALUE and BB_REFUND_EXCEEDS_REMAINING (each with details.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_VALUE answers 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.

RouteBodyDoes
approve{ method }: cash, qr, bank_transfer, cheque, card or otherrequested 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 charactersrequested to rejected. The units are free again.
not-owed{ reason }, 1 to 500 charactersrequested to not_owed. A return or goodwill refund answers 409 BB_REFUND_NOT_OWED_NOT_ALLOWED.
settle{ settlementReference }, 1 to 200 charactersawaiting_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:

StatusCodeTrigger
409BB_ORDER_HAS_RETURNA return holds pending units, or units were returned. Finish or close the return instead.
409BB_REFUND_DECISION_REQUIREDA requested refund covers a line the cancel would net against. details as under Inspect.
409BB_REFUND_ORDER_TOTAL_EXCEEDEDThe 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_audit row 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 return per 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. settle records 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.