Workflows
createOrderReturnRequestWorkflow
This documentation provides a reference to thecreateOrderReturnRequestWorkflow. It belongs to the @mercurjs/requests package.
This workflow creates an order return request from a customer. It validates that no return request already exists for the order, verifies that line items and return reasons are valid, creates the request, and links it to both the seller and the order. It exposes a hook for custom extensions.
Source code
Examples
- API Route
packages/modules/requests/src/api/store/return-request/route.ts
Steps
- validateOrderReturnRequestStep: Validates that no return request exists, line items are valid, and return reasons exist.
- createOrderReturnRequestStep: Creates the return request record.
- createRemoteLinkStep: Creates links between the return request and the seller, and between the return request and the order.
Hooks
- orderReturnRequestCreated: Hook that fires after a return request is created, providing the
requestId.
Input
The return request creation details.
Output
The created order return request.
proceedReturnRequestWorkflow
This documentation provides a reference to theproceedReturnRequestWorkflow. It belongs to the @mercurjs/requests package.
This workflow processes the actual return after a return request has been approved (status set to “refunded”). It begins the return order process, requests the item returns, and confirms the return. This workflow is nested within the updateOrderReturnRequestWorkflow.
Source code
Examples
- Update Workflow
packages/modules/requests/src/workflows/order-return-request/workflows/update-return-request.ts
Steps
- retrieveOrderFromReturnRequestStep: Retrieves the order and return request details.
- beginReturnOrderWorkflow: Begins the return order process using Medusa’s core workflow.
- requestItemReturnWorkflow: Requests the specific items to be returned using Medusa’s core workflow.
- confirmReturnRequestWorkflow: Confirms the return request using Medusa’s core workflow.
Input
The return request update details (must have status “refunded”).
Output
updateOrderReturnRequestWorkflow
This documentation provides a reference to theupdateOrderReturnRequestWorkflow. It belongs to the @mercurjs/requests package.
This workflow updates an order return request. When the status is set to “refunded”, it automatically triggers the return processing workflow. After updating, it links any created returns to the seller. It exposes a hook for custom extensions.
Source code
Examples
- API Route
packages/modules/requests/src/api/vendor/return-request/[id]/route.ts
Steps
- updateOrderReturnRequestStep: Updates the return request status and reviewer details.
- proceedReturnRequestWorkflow: Processes the return (only when status is “refunded”).
- useQueryGraphStep: Retrieves order and return details for linking.
- createRemoteLinkStep: Links any created returns to the seller.
Hooks
- orderReturnRequestUpdated: Hook that fires after a return request is updated, providing the
requestId.
Input
The return request update details.
Output
The updated order return request.
Steps
createOrderReturnRequestStep
Creates an order return request record in the database. Source codeInput
The return request creation details.
Output
The created return request.
retrieveOrderFromReturnRequestStep
Retrieves the order and complete return request details including line items and seller information. Used to prepare data for return processing. Source codeInput
The return request with the ID to retrieve.
Output
updateOrderReturnRequestStep
Updates an order return request record. This step includes a compensation function that restores the previous request state if a subsequent step in the workflow fails. Source codeInput
The return request update details.
Output
The updated return request.
validateOrderReturnRequestStep
Validates a return request creation by checking:- No return request already exists for the order
- All line item IDs belong to the order
- All return reason IDs are valid
Input
The return request data to validate.
Output
Returns true if validation passes. Throws an
INVALID_ARGUMENT error if:- A return request already exists for the order
- Any line item ID is invalid
- Any return reason ID is invalid