createAndCompleteReturnOrderWorkflow - Medusa Core Workflows Reference

This documentation provides a reference to the createAndCompleteReturnOrderWorkflow. It belongs to the @medusajs/medusa/core-flows package.

This workflow creates and completes a return from the storefront. The admin would receive the return and process it from the dashboard. This workflow is used by the Create Return Store API Route.

You can use this workflow within your customizations or your own custom workflows, allowing you to create a return for an order in your custom flow.

Source Code

Examples#

Steps#

Input#

CreateOrderReturnWorkflowInput & AdditionalDataCreateOrderReturnWorkflowInput & AdditionalData
CreateOrderReturnWorkflowInputobject
The details to create a return order.
AdditionalDataobject
Additional data, passed through the additional_data property accepted in HTTP requests, that allows passing custom data and handle them in hooks. Learn more in this documentation.

Output#

ReturnDTOReturnDTO
The return details.
idstring
The ID of the return.
The status of the return.
order_idstring
The associated order's ID.
The items of the return
display_idnumber
The return's display ID.
metadatanull | Record<string, unknown>
Holds custom data in key-value pairs.
refund_amountBigNumberValueOptional
The refund amount of the return.
raw_refund_amountBigNumberValueOptional
The raw refund amount of the return.
orderOrderDTOOptional
The associated order.
exchange_idstringOptional
The associated exchange's ID.
exchangeOrderExchangeDTOOptional
The associated exchange.
claim_idstringOptional
The associated claim's ID.
claimOrderClaimDTOOptional
The associated claim.
location_idstringOptional
The ID of the location to return the items to.
no_notificationbooleanOptional
Whether the customer should receive notifications related to updates on the return.
created_bynull | stringOptional
The id of the user that created the return
shipping_methodsOrderShippingMethodDTO[]Optional
The shipping methods used to receive the returned items.
transactionsOrderTransactionDTO[]Optional
The return's transactions if refund is required.
created_atstring | DateOptional
The creation date of the return.
updated_atstring | DateOptional
The update date of the return.
deleted_atstring | DateOptional
The deletion date of the return.
canceled_atstring | DateOptional
The cancelation date of the return.
requested_atstring | DateOptional
The request date of the return.
received_atstring | DateOptional
The receival date of the return.

Hooks#

Hooks allow you to inject custom functionalities into the workflow. You'll receive data from the workflow, as well as additional data sent through an HTTP request.

Learn more about Hooks and Additional Data.

setPricingContext#

This hook is executed before the return's shipping method is created. You can consume this hook to return any custom context useful for the prices retrieval of the shipping method's option.

For example, assuming you have the following custom pricing rule:

Code
1{2  "attribute": "location_id",3  "operator": "eq",4  "value": "sloc_123",5}

You can consume the setPricingContext hook to add the location_id context to the prices calculation:

Code
1import { createAndCompleteReturnOrderWorkflow } from "@medusajs/medusa/core-flows";2import { StepResponse } from "@medusajs/workflows-sdk";3
4createAndCompleteReturnOrderWorkflow.hooks.setPricingContext((5  { order, additional_data }, { container }6) => {7  return new StepResponse({8    location_id: "sloc_123", // Special price for in-store purchases9  });10});

The price of the shipping method's option will now be retrieved using the context you return.

Note: Learn more about prices calculation context in the Prices Calculation documentation.

Example

Code
1import { createAndCompleteReturnOrderWorkflow } from "@medusajs/medusa/core-flows"2
3createAndCompleteReturnOrderWorkflow.hooks.setPricingContext(4  (async ({ order, additional_data }, { container }) => {5    //TODO6  })7)

Input

Handlers consuming this hook accept the following input.

inputinput
The input data for the hook.
The order details.
additional_dataRecord<string, unknown> | undefined
Additional data that can be passed through the additional_data property in HTTP requests. Learn more in this documentation.

Emitted Events#

This section lists the events that are either triggered by the emitEventStep in the workflow, or by another workflow executed within this workflow.

You can listen to these events in a subscriber, as explained in the Subscribers documentation.

Event

Description

Payload

Action

order.return_requested

Emitted when a return request is confirmed.

{
  order_id, // The ID of the order
  return_id, // The ID of the return
}

order.return_received

Emitted when a return is marked as received.

{
  order_id, // The ID of the order
  return_id, // The ID of the return
}
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break