---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# FulfillmentService

Handles Fulfillments

## Constructors

### constructor

`**new FulfillmentService**(«destructured»)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "[InjectedDependencies](../types/InjectedDependencies-11.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__container__",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__moduleDeclaration__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "fulfillmentProviderService_",
    "type": "[FulfillmentProviderService](FulfillmentProviderService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "fulfillmentRepository_",
    "type": "Repository&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "lineItemRepository_",
    "type": "Repository&#60;[LineItem](LineItem.mdx)&#62; & `&#123; findByReturn: Method findByReturn  &#125;`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "lineItemService_",
    "type": "[LineItemService](LineItemService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "EntityManager",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productVariantInventoryService_",
    "type": "[ProductVariantInventoryService](ProductVariantInventoryService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "shippingProfileService_",
    "type": "[ShippingProfileService](ShippingProfileService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "totalsService_",
    "type": "[TotalsService](TotalsService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "trackingLinkRepository_",
    "type": "Repository&#60;[TrackingLink](TrackingLink.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| EntityManager",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

## Accessors

### activeManager\_

`Protected get**activeManager_**(): EntityManager`

#### Returns

EntityManager

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "EntityManager",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

## Methods

### atomicPhase\_

`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;`

Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: EntityManager) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;TResult&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### cancelFulfillment

`**cancelFulfillment**(fulfillmentOrId): Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;`

Cancels a fulfillment with the fulfillment provider. Will decrement the
fulfillment\_quantity on the line items associated with the fulfillment.
Throws if the fulfillment has already been shipped.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "fulfillmentOrId",
    "type": "`string` \\| [Fulfillment](Fulfillment.mdx)",
    "description": "the fulfillment object or id.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the save operation",
    "expandable": false,
    "children": []
  }
]} />

___

### createFulfillment

`**createFulfillment**(order, itemsToFulfill, custom?): Promise&#60;[Fulfillment](Fulfillment.mdx)[]&#62;`

Creates an order fulfillment
If items needs to be fulfilled by different provider, we make
sure to partition those items, and create fulfillment for
those partitions.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "order",
    "type": "[CreateFulfillmentOrder](../types/CreateFulfillmentOrder.mdx)",
    "description": "order to create fulfillment for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "itemsToFulfill",
    "type": "[FulFillmentItemType](../types/FulFillmentItemType.mdx)[]",
    "description": "the items in the order to fulfill",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom",
    "type": "[Partial](../types/Partial.mdx)&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "description": "potential custom values to add",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Fulfillment](Fulfillment.mdx)[]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Fulfillment](Fulfillment.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the created fulfillments",
    "expandable": false,
    "children": []
  }
]} />

___

### createShipment

`**createShipment**(fulfillmentId, trackingLinks?, config?): Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;`

Creates a shipment by marking a fulfillment as shipped. Adds
tracking links and potentially more metadata.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "fulfillmentId",
    "type": "`string`",
    "description": "the fulfillment to ship",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "trackingLinks",
    "type": "`&#123; tracking_number: string  &#125;`[]",
    "description": "tracking links for the shipment",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[CreateShipmentConfig](../types/CreateShipmentConfig.mdx)",
    "description": "potential configuration settings, such as no\\_notification and metadata",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the shipped fulfillment",
    "expandable": false,
    "children": []
  }
]} />

___

### getFulfillmentItems\_

`**getFulfillmentItems_**(order, items): Promise&#60;(`null` \| [LineItem](LineItem.mdx))[]&#62;`

Retrieves the order line items, given an array of items.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "order",
    "type": "[CreateFulfillmentOrder](../types/CreateFulfillmentOrder.mdx)",
    "description": "the order to get line items from",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "items",
    "type": "[FulFillmentItemType](../types/FulFillmentItemType.mdx)[]",
    "description": "the items to get",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;(`null` \| [LineItem](LineItem.mdx))[]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;(`null` \\| [LineItem](LineItem.mdx))[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the line items generated by the transformer.",
    "expandable": false,
    "children": []
  }
]} />

___

### partitionItems\_

`**partitionItems_**(shippingMethods, items): [FulfillmentItemPartition](../types/FulfillmentItemPartition.mdx)[]`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "shippingMethods",
    "type": "[ShippingMethod](ShippingMethod.mdx)[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "items",
    "type": "[LineItem](LineItem.mdx)[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[FulfillmentItemPartition](../types/FulfillmentItemPartition.mdx)[]

<ParameterTypes parameters={[
  {
    "name": "FulfillmentItemPartition[]",
    "type": "[FulfillmentItemPartition](../types/FulfillmentItemPartition.mdx)[]",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

`**retrieve**(fulfillmentId, config?): Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;`

Retrieves a fulfillment by its id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "fulfillmentId",
    "type": "`string`",
    "description": "the id of the fulfillment to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "description": "optional values to include with fulfillmentRepository query",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Fulfillment](Fulfillment.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the fulfillment",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

`Protected **shouldRetryTransaction_**(err): boolean`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| `&#123; code: string  &#125;`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`boolean`

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### validateFulfillmentLineItem\_

`**validateFulfillmentLineItem_**(item, quantity): `null` \| [LineItem](LineItem.mdx)`

Checks that a given quantity of a line item can be fulfilled. Fails if the
fulfillable quantity is lower than the requested fulfillment quantity.
Fulfillable quantity is calculated by subtracting the already fulfilled
quantity from the quantity that was originally purchased.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "item",
    "type": "`undefined` \\| [LineItem](LineItem.mdx)",
    "description": "the line item to check has sufficient fulfillable quantity.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "the quantity that is requested to be fulfilled.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

``null`` \| [LineItem](LineItem.mdx)

<ParameterTypes parameters={[
  {
    "name": "`null` \\| LineItem",
    "type": "``null`` \\| [LineItem](LineItem.mdx)",
    "optional": true,
    "defaultValue": "",
    "description": "a line item that has the requested fulfillment quantity\n  set.",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

`**withTransaction**(transactionManager?): [FulfillmentService](FulfillmentService.mdx)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "EntityManager",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[FulfillmentService](FulfillmentService.mdx)

<ParameterTypes parameters={[
  {
    "name": "FulfillmentService",
    "type": "[FulfillmentService](FulfillmentService.mdx)",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />
