Overview
Refunds Admin API provides admin control over the refund lifecycle. Includes viewing pending refund queues, force-processing refunds (bypassing store approval), marking externally processed refunds, viewing refund analytics, and bulk deletion. All functions require admin authorization. Location:convex/admins/refundsAdmin.ts
Get Pending Refunds
Lists return requests awaiting refund processing (statuspicked_up). Returns enriched data including customer name, store name, order total, and days waiting.
Pagination options (numItems, cursor)
The
daysWaiting is calculated from the pickup completion date (or creation time if pickup date is missing) to now. The reason is extracted from the first item in the return request. totalPending reflects the total count of all pending refunds, not just the current page.Force Refund
Admin override to force-process a refund, bypassing the normal store approval workflow. Supports two modes: Stripe automated refund or manual marking.Return request ID to process
Admin notes explaining the forced refund
When
true, schedules a Stripe refund via processStripeRefundInternal. When false, marks the refund as completed manually with a generated reference ID.When
processViaStripe is true, the refund is scheduled asynchronously via ctx.scheduler.runAfter and the return request stays in picked_up status until Stripe confirms. When false, the status is immediately set to refunded with a reference ID formatted as manual_{timestamp}_{adminUserId}.Mark Refund Processed
Marks a return request as refunded for refunds processed externally (bank transfer, cash, store credit, etc.). Creates an admin notification for audit tracking.Return request ID to mark as processed
Method used for the refund, e.g.
bank_transfer, cash, store_creditExternal reference number (e.g., bank transaction ID). If omitted, a generated ID is used.
Admin notes about the refund processing
Throws an error if the return request is already in
refunded status. A notification is created via adminNotifications.createNotification for audit tracking. If no externalRefundId is provided, a reference ID is generated as external_{refundMethod}_{timestamp}.Get Refund Statistics
Returns refund analytics for the admin dashboard, including totals, amounts, and a breakdown by reason category.Optional date range filter with
startDate and endDate (timestamps in milliseconds)Pending refunds are those with
picked_up status. Completed refunds are those with refunded status. The averageRefundAmount is calculated only from completed refunds. Reason categorization is based on keyword matching in the return item reasons: “damaged”, “wrong”, “not as described”, and “changed mind”. Reasons not matching any category fall into other.Bulk Delete Refunds
Permanently deletes multiple return request records. Processes in batches of 50 using internal mutations.Array of return request IDs to delete
This is a Convex action that delegates to internal mutations in batches of 50. Returns zero count if an empty array is passed. Silently skips already-deleted records.
