cancelOrderWorkflow - Medusa Core Workflows Reference

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

This workflow cancels an order. An order can only be canceled if it doesn't have any fulfillments, or if all fulfillments are canceled. The workflow will also cancel any uncaptured payments, and refund any captured payments.

This workflow is used by the Cancel Order Admin API Route.

This workflow has a hook that allows you to perform custom actions on the canceled order. For example, you can make changes to custom models linked to the order.

You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around canceling an order.

Source Code

Examples#

Steps#

Input#

CancelOrderWorkflowInputCancelOrderWorkflowInput
order_idstring
The ID of the order to cancel.
no_notificationbooleanOptional
Whether to notify the customer of the cancelation.
canceled_bystringOptional
The ID of the user that canceled the order.

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.

orderCanceled#

This hook is executed after the order is canceled. You can consume this hook to perform custom actions on the canceled order.

Example

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

Input

Handlers consuming this hook accept the following input.

inputobject
The input data for the hook.
orderany
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