# completeOrderWorkflow - Medusa Core Workflows Reference

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

This workflow marks one or more orders as completed. It's used by the [Complete Cart Admin API Route](https://docs.medusajs.com/api/admin#orders_postordersidcomplete).

This workflow has a hook that allows you to perform custom actions on the completed orders. For example, you can pass under `additional_data` custom data that
allows you to update custom data models linked to the orders.

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

[Source code](https://github.com/medusajs/medusa/blob/ad4437b298d499d1a51e54decad6de3f5ebd2181/packages/core/core-flows/src/order/workflows/complete-orders.ts#L49)

## Examples

### API Route

```ts title="src/api/workflow/route.ts"
import type {
  MedusaRequest,
  MedusaResponse,
} from "@medusajs/framework/http"
import { completeOrderWorkflow } from "@medusajs/medusa/core-flows"

export async function POST(
  req: MedusaRequest,
  res: MedusaResponse
) {
  const { result } = await completeOrderWorkflow(req.scope)
    .run({
      input: {
        orderIds: ["order_1", "order_2"],
        additional_data: {
          send_webhook: true,
        }
      }
    })

  res.send(result)
}
```

### Subscriber

```ts title="src/subscribers/order-placed.ts"
import {
  type SubscriberConfig,
  type SubscriberArgs,
} from "@medusajs/framework"
import { completeOrderWorkflow } from "@medusajs/medusa/core-flows"

export default async function handleOrderPlaced({
  event: { data },
  container,
}: SubscriberArgs < { id: string } > ) {
  const { result } = await completeOrderWorkflow(container)
    .run({
      input: {
        orderIds: ["order_1", "order_2"],
        additional_data: {
          send_webhook: true,
        }
      }
    })

  console.log(result)
}

export const config: SubscriberConfig = {
  event: "order.placed",
}
```

### Scheduled Job

```ts title="src/jobs/message-daily.ts"
import { MedusaContainer } from "@medusajs/framework/types"
import { completeOrderWorkflow } from "@medusajs/medusa/core-flows"

export default async function myCustomJob(
  container: MedusaContainer
) {
  const { result } = await completeOrderWorkflow(container)
    .run({
      input: {
        orderIds: ["order_1", "order_2"],
        additional_data: {
          send_webhook: true,
        }
      }
    })

  console.log(result)
}

export const config = {
  name: "run-once-a-day",
  schedule: "0 0 * * *",
}
```

### Another Workflow

```ts title="src/workflows/my-workflow.ts"
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { completeOrderWorkflow } from "@medusajs/medusa/core-flows"

const myWorkflow = createWorkflow(
  "my-workflow",
  () => {
    const result = completeOrderWorkflow
      .runAsStep({
        input: {
          orderIds: ["order_1", "order_2"],
          additional_data: {
            send_webhook: true,
          }
        }
      })
  }
)
```

## Steps

- [completeOrdersStep](../../../Steps_Order/functions/core_flows.Order.Steps_Order.completeOrdersStep/page.mdx): This step completes one or more orders.
- [emitEventStep](../../../../Common/Steps_Common/functions/core_flows.Common.Steps_Common.emitEventStep/page.mdx): This step emits an event, which you can listen to in a \[subscriber]\(https://docs.medusajs.com/learn/fundamentals/events-and-subscribers). You can pass data to the
  subscriber by including it in the \`data\` property.

  The event is only emitted after the workflow has finished successfully. So, even if it's executed in the middle of the workflow, it won't actually emit the event until the workflow has completed successfully.&#x20;
  If the workflow fails, it won't emit the event at all.
- [ordersCompleted](#ordersCompleted): This hook is executed after the orders are completed. You can consume this hook to perform custom actions on the completed orders.

## Input

- CompleteOrdersWorkflowInput: (\[CompleteOrdersWorkflowInput]\(../../../../types/core\_flows.CompleteOrdersWorkflowInput/page.mdx)) The orders to complete, along with custom data that's passed to the workflow's hooks.

  - orderIds: (\`string\`\[]) The IDs of the orders to complete.

  - additional\_data: (\`Record\<string, unknown>\`) Additional data that can be passed through the \`additional\_data\` property in HTTP requests.

    Learn more in \[this documentation]\(https://docs.medusajs.com/learn/fundamentals/api-routes/additional-data).

## Output

- OrderDTO\[]: (\[OrderDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderDTO/page.mdx)\[])

  - id: (\`string\`) The ID of the order.

  - version: (\`number\`) The version of the order.

  - display\_id: (\`number\`) The order's display ID.

  - status: (\[OrderStatus]\(../../../../../fulfillment/types/fulfillment.OrderStatus/page.mdx)) The status of the order.

  - currency\_code: (\`string\`) The currency of the order

  - created\_at: (\`string\` \\| \`Date\`) When the order was created.

  - updated\_at: (\`string\` \\| \`Date\`) When the order was updated.

  - original\_item\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original item total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_item\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original item subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_item\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original item tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - item\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - item\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - item\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - item\_discount\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item discount total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The subtotal of the order. (Excluding taxes)

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - discount\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - discount\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - discount\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - credit\_line\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The credit line total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - gift\_card\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The gift card total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - gift\_card\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The gift card tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - shipping\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The shipping total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - shipping\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The shipping subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - shipping\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The shipping tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - shipping\_discount\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The shipping discount total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_shipping\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original shipping total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_shipping\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original shipping subtotal of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - original\_shipping\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original shipping tax total of the order.

    - numeric: (\`number\`)

    - raw: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - bigNumber: (\`BigNumber\`)

  - raw\_original\_item\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original item total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_item\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original item subtotal of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_item\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original item tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_item\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw item total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_item\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw item subtotal of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_item\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw item tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original subtotal of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw subtotal of the order. (Excluding taxes)

    - value: (\`string\` \\| \`number\`)

  - raw\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_discount\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw discount total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_discount\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw discount tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_credit\_line\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw credit line total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_gift\_card\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw gift card total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_gift\_card\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw gift card tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_shipping\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw shipping total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_shipping\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw shipping subtotal of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_shipping\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw shipping tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_shipping\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original shipping total of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_shipping\_subtotal: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original shipping subtotal of the order.

    - value: (\`string\` \\| \`number\`)

  - raw\_original\_shipping\_tax\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx)) The raw original shipping tax total of the order.

    - value: (\`string\` \\| \`number\`)

  - custom\_display\_id: (\`string\`) The order's custom display ID.

  - order\_change: (\[OrderChangeDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderChangeDTO/page.mdx)) The active order change, if any.

    - id: (\`string\`) The ID of the order change

    - version: (\`number\`) The version of the order change

    - order\_id: (\`string\`) The ID of the associated order

    - return\_id: (\`string\`) The ID of the associated return order

    - exchange\_id: (\`string\`) The ID of the associated exchange order

    - claim\_id: (\`string\`) The ID of the associated claim order

    - order: (\[OrderDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderDTO/page.mdx)) The associated order

    - return\_order: (\[ReturnDTO]\(../../../../../fulfillment/interfaces/fulfillment.ReturnDTO/page.mdx)) The associated return order

    - exchange: (\[OrderExchangeDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderExchangeDTO/page.mdx)) The associated exchange order

    - claim: (\[OrderClaimDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderClaimDTO/page.mdx)) The associated claim order

    - actions: (\[OrderChangeActionDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderChangeActionDTO/page.mdx)\[]) The actions of the order change

    - status: (\[OrderChangeStatus]\(../../../../../fulfillment/types/fulfillment.OrderChangeStatus/page.mdx)) The status of the order change

    - requested\_by: (\`null\` \\| \`string\`) The requested by of the order change

    - requested\_at: (\`null\` \\| \`string\` \\| \`Date\`) When the order change was requested

    - confirmed\_by: (\`null\` \\| \`string\`) The confirmed by of the order change

    - confirmed\_at: (\`null\` \\| \`string\` \\| \`Date\`) When the order change was confirmed

    - declined\_by: (\`null\` \\| \`string\`) The declined by of the order change

    - declined\_reason: (\`null\` \\| \`string\`) The declined reason of the order change

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) The metadata of the order change

    - declined\_at: (\`null\` \\| \`string\` \\| \`Date\`) When the order change was declined

    - canceled\_by: (\`null\` \\| \`string\`) The canceled by of the order change

    - canceled\_at: (\`null\` \\| \`string\` \\| \`Date\`) When the order change was canceled

    - created\_at: (\`string\` \\| \`Date\`) When the order change was created

    - updated\_at: (\`string\` \\| \`Date\`) When the order change was updated

    - change\_type: (\`"return"\` \\| \`"exchange"\` \\| \`"claim"\` \\| \`"edit"\` \\| \`"transfer"\`) The type of the order change

    - carry\_over\_promotions: (\`null\` \\| \`boolean\`) Whether to carry over promotions (apply promotions to outbound exchange items).

  - region\_id: (\`string\`) The ID of the region the order belongs to.

  - customer\_id: (\`string\`) The ID of the customer on the order.

  - sales\_channel\_id: (\`string\`) The ID of the sales channel the order belongs to.

  - email: (\`string\`) The email of the order.

  - shipping\_address: (\[OrderAddressDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderAddressDTO/page.mdx)) The associated shipping address.

    - id: (\`string\`) The ID of the address.

    - created\_at: (\`string\` \\| \`Date\`) When the address was created.

    - updated\_at: (\`string\` \\| \`Date\`) When the address was updated.

    - customer\_id: (\`string\`) The customer ID of the address.

    - first\_name: (\`string\`) The first name of the address.

    - last\_name: (\`string\`) The last name of the address.

    - phone: (\`string\`) The phone number of the address.

    - company: (\`string\`) The company of the address.

    - address\_1: (\`string\`) The first address line of the address.

    - address\_2: (\`string\`) The second address line of the address.

    - city: (\`string\`) The city of the address.

    - country\_code: (\`string\`) The country code of the address.

    - province: (\`string\`) The lower-case \[ISO 3166-2]\(https://en.wikipedia.org/wiki/ISO\\\_3166-2) province/state of the address.

    - postal\_code: (\`string\`) The postal code of the address.

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) Holds custom data in key-value pairs.

  - billing\_address: (\[OrderAddressDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderAddressDTO/page.mdx)) The associated billing address.

    - id: (\`string\`) The ID of the address.

    - created\_at: (\`string\` \\| \`Date\`) When the address was created.

    - updated\_at: (\`string\` \\| \`Date\`) When the address was updated.

    - customer\_id: (\`string\`) The customer ID of the address.

    - first\_name: (\`string\`) The first name of the address.

    - last\_name: (\`string\`) The last name of the address.

    - phone: (\`string\`) The phone number of the address.

    - company: (\`string\`) The company of the address.

    - address\_1: (\`string\`) The first address line of the address.

    - address\_2: (\`string\`) The second address line of the address.

    - city: (\`string\`) The city of the address.

    - country\_code: (\`string\`) The country code of the address.

    - province: (\`string\`) The lower-case \[ISO 3166-2]\(https://en.wikipedia.org/wiki/ISO\\\_3166-2) province/state of the address.

    - postal\_code: (\`string\`) The postal code of the address.

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) Holds custom data in key-value pairs.

  - items: (\[OrderLineItemDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderLineItemDTO/page.mdx)\[]) The associated order details / line items.

    - original\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original total of the order line item.

    - original\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original subtotal of the order line item.

    - original\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original tax total of the order line item.

    - item\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item total of the order line item.

    - item\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item subtotal of the order line item.

    - item\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The item tax total of the order line item.

    - total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The total of the order line item.

    - subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The subtotal of the order line item.

    - tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The tax total of the order line item.

    - discount\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount total of the order line item.

    - discount\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount tax total of the order line item.

    - refundable\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The refundable total of the order line item.

    - refundable\_total\_per\_unit: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The refundable total per unit of the order line item.

    - id: (\`string\`) The ID of the line item.

    - title: (\`string\`) The title of the line item.

    - requires\_shipping: (\`boolean\`) Indicates whether the line item requires shipping.

    - is\_discountable: (\`boolean\`) Indicates whether the line item is discountable.

    - is\_giftcard: (\`boolean\`) Indicates whether the line item is a gift card.

    - is\_tax\_inclusive: (\`boolean\`) Indicates whether the line item price is tax inclusive.

    - unit\_price: (\`number\`) The unit price of the line item.

    - quantity: (\`number\`) The quantity of the line item.

    - detail: (\[OrderItemDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderItemDTO/page.mdx)) The details of the item

    - created\_at: (\`Date\`) The date when the line item was created.

    - updated\_at: (\`Date\`) The date when the line item was last updated.

    - subtitle: (\`null\` \\| \`string\`) The subtitle of the line item.

    - thumbnail: (\`null\` \\| \`string\`) The thumbnail of the line item.

    - variant\_id: (\`null\` \\| \`string\`) The ID of the variant associated with the line item.

    - product\_id: (\`null\` \\| \`string\`) The ID of the product associated with the line item.

    - product\_title: (\`null\` \\| \`string\`) The title of the product associated with the line item.

    - product\_description: (\`null\` \\| \`string\`) The description of the product associated with the line item.

    - product\_subtitle: (\`null\` \\| \`string\`) The subtitle of the product associated with the line item.

    - product\_type\_id: (\`null\` \\| \`string\`) The ID of the type of the product associated with the line item.

    - product\_type: (\`null\` \\| \`string\`) The type of the product associated with the line item.

    - product\_collection: (\`null\` \\| \`string\`) The collection of the product associated with the line item.

    - product\_handle: (\`null\` \\| \`string\`) The handle of the product associated with the line item.

    - variant\_sku: (\`null\` \\| \`string\`) The SKU (stock keeping unit) of the variant associated with the line item.

    - variant\_barcode: (\`null\` \\| \`string\`) The barcode of the variant associated with the line item.

    - variant\_title: (\`null\` \\| \`string\`) The title of the variant associated with the line item.

    - variant\_option\_values: (\`null\` \\| \`Record\<string, unknown>\`) The option values of the variant associated with the line item.

    - compare\_at\_unit\_price: (\`number\`) The compare at unit price of the line item.

    - tax\_lines: (\[OrderLineItemTaxLineDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderLineItemTaxLineDTO/page.mdx)\[]) The associated tax lines.

    - adjustments: (\[OrderLineItemAdjustmentDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderLineItemAdjustmentDTO/page.mdx)\[]) The associated adjustments.

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) Holds custom data in key-value pairs.

  - shipping\_methods: (\[OrderShippingMethodDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderShippingMethodDTO/page.mdx)\[]) The associated shipping methods

    - id: (\`string\`) The ID of the shipping method.

    - order\_id: (\`string\`) The ID of the associated order.

    - name: (\`string\`) The name of the shipping method.

    - amount: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The price of the shipping method.

    - is\_tax\_inclusive: (\`boolean\`) Whether the shipping method price is tax inclusive or not.

    - created\_at: (\`string\` \\| \`Date\`) When the shipping method was created.

    - updated\_at: (\`string\` \\| \`Date\`) When the shipping method was updated.

    - original\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original total of the order shipping method.

    - original\_subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original subtotal of the order shipping method.

    - original\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The original tax total of the order shipping method.

    - total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The total of the order shipping method.

    - subtotal: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The subtotal of the order shipping method.

    - tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The tax total of the order shipping method.

    - discount\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount total of the order shipping method.

    - discount\_tax\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The discount tax total of the order shipping method.

    - description: (\`string\`) The description of the shipping method.

    - shipping\_option\_id: (\`string\`) The ID of the shipping option the method was created from.

    - data: (\`Record\<string, unknown>\`) Additional data needed for fulfillment.

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) Holds custom data in key-value pairs.

    - tax\_lines: (\[OrderShippingMethodTaxLineDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderShippingMethodTaxLineDTO/page.mdx)\[]) The associated tax lines.

    - adjustments: (\[OrderShippingMethodAdjustmentDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderShippingMethodAdjustmentDTO/page.mdx)\[]) The associated adjustments.

  - transactions: (\[OrderTransactionDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderTransactionDTO/page.mdx)\[]) The tramsactions associated with the order

    - id: (\`string\`) The ID of the transaction

    - order\_id: (\`string\`) The ID of the associated order

    - version: (\`number\`) The associated order version

    - order: (\[OrderDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderDTO/page.mdx)) The associated order

    - amount: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The amount of the transaction

    - currency\_code: (\`string\`) The currency code of the transaction

    - reference: (\`string\`) The reference of the transaction

    - reference\_id: (\`string\`) The ID of the reference

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) The metadata of the transaction

    - created\_at: (\`string\` \\| \`Date\`) When the transaction was created

    - updated\_at: (\`string\` \\| \`Date\`) When the transaction was updated

  - credit\_lines: (\[OrderCreditLineDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderCreditLineDTO/page.mdx)\[]) The credit lines for an order

    - id: (\`string\`) The ID of the order credit line.

    - order\_id: (\`string\`) The ID of the order that the credit line belongs to.

    - order: (\[OrderDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderDTO/page.mdx)) The associated order

    - amount: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx)) The amount of the credit line.

    - reference: (\`null\` \\| \`string\`) The reference model name that the credit line is generated from

    - reference\_id: (\`null\` \\| \`string\`) The reference model id that the credit line is generated from

    - metadata: (\`null\` \\| \`Record\<string, unknown>\`) The metadata of the order detail

    - created\_at: (\`Date\`) The date when the order credit line was created.

    - updated\_at: (\`Date\`) The date when the order credit line was last updated.

  - summary: (\[OrderSummaryDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderSummaryDTO/page.mdx)) The summary of the order totals.

    - pending\_difference: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - current\_order\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - original\_order\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - transaction\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - paid\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - refunded\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - credit\_line\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - accounting\_total: (\[BigNumberValue]\(../../../../../fulfillment/types/fulfillment.BigNumberValue/page.mdx))

    - raw\_pending\_difference: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_current\_order\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_original\_order\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_transaction\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_paid\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_refunded\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_credit\_line\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

    - raw\_accounting\_total: (\[BigNumberRawValue]\(../../../../../fulfillment/types/fulfillment.BigNumberRawValue/page.mdx))

  - is\_draft\_order: (\`boolean\`) Whether the order is a draft order.

  - locale: (\`string\`) The locale of the order.

  - metadata: (\`null\` \\| \`Record\<string, unknown>\`) Holds custom data in key-value pairs.

  - canceled\_at: (\`string\` \\| \`Date\`) When the order was canceled.

  - deleted\_at: (\`string\` \\| \`Date\`) When the order was deleted.

## 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](https://docs.medusajs.com/learn/fundamentals/workflows/workflow-hooks) and [Additional Data](https://docs.medusajs.com/learn/fundamentals/api-routes/additional-data).

### ordersCompleted

This hook is executed after the orders are completed. You can consume this hook to perform custom actions on the completed orders.

#### Example

```ts
import { completeOrderWorkflow } from "@medusajs/medusa/core-flows"

completeOrderWorkflow.hooks.ordersCompleted(
  (async ({ orders, additional_data }, { container }) => {
    //TODO
  })
)
```

#### Input

Handlers consuming this hook accept the following input.

- input: (\[input]\(../../../core\_flows.Order.Workflows\_Order/page.mdx#\_\_type-4)) The input data for the hook.

  - orders: (\[OrderDTO]\(../../../../../fulfillment/interfaces/fulfillment.OrderDTO/page.mdx)\[])

  - additional\_data: (\`Record\<string, unknown> | undefined\`) Additional data that can be passed through the \`additional\_data\` property in HTTP requests.
    Learn more in \[this documentation]\(https://docs.medusajs.com/learn/fundamentals/api-routes/additional-data).

## 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.

:::note

The `emitEventStep` only emits the event after the workflow has finished successfully. So, even if it's executed in the middle of the workflow, it won't actually emit the event until the workflow has completed successfully. If the workflow fails, it won't emit the event at all.

:::

You can listen to these events in a subscriber, as explained in the [Subscribers](https://docs.medusajs.com/learn/fundamentals/events-and-subscribers) documentation.

|Event|Description|Payload|Action|
|---|---|---|---|
|\`order.completed\`|Emitted when orders are completed.|\`\`\`ts
\{
&#x20; id, // The ID of the order
}
\`\`\`||


---

The best way to deploy Medusa is through Medusa Cloud where you get autoscaling production infrastructure fine tuned for Medusa. Create an account by signing up at cloud.medusajs.com/signup.
