---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# FulfillmentService
Handles Fulfillments
## Constructors
### constructor
`**new FulfillmentService**(«destructured»)`
#### Parameters
## Properties
`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__container__",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__moduleDeclaration__",
"type": "`Record`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "fulfillmentProviderService_",
"type": "[FulfillmentProviderService](FulfillmentProviderService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "fulfillmentRepository_",
"type": "Repository<[Fulfillment](Fulfillment.mdx)>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "lineItemRepository_",
"type": "Repository<[LineItem](LineItem.mdx)> & `{ findByReturn: Method findByReturn }`",
"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<[TrackingLink](TrackingLink.mdx)>",
"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
## Methods
### atomicPhase\_
`Protected **atomicPhase_**(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>`
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.
#### Parameters
Promise<TResult>",
"description": "the transactional work to be done",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "isolationOrErrorHandler",
"type": "`IsolationLevel` \\| (`error`: `TError`) => Promise<void \\| TResult>",
"description": "the isolation level to be used for the work.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "maybeErrorHandlerOrDontFail",
"type": "(`error`: `TError`) => Promise<void \\| TResult>",
"description": "Potential error handler",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise<TResult>
___
### cancelFulfillment
`**cancelFulfillment**(fulfillmentOrId): Promise<[Fulfillment](Fulfillment.mdx)>`
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
#### Returns
Promise<[Fulfillment](Fulfillment.mdx)>
___
### createFulfillment
`**createFulfillment**(order, itemsToFulfill, custom?): Promise<[Fulfillment](Fulfillment.mdx)[]>`
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
#### Returns
Promise<[Fulfillment](Fulfillment.mdx)[]>
___
### createShipment
`**createShipment**(fulfillmentId, trackingLinks?, config?): Promise<[Fulfillment](Fulfillment.mdx)>`
Creates a shipment by marking a fulfillment as shipped. Adds
tracking links and potentially more metadata.
#### Parameters
#### Returns
Promise<[Fulfillment](Fulfillment.mdx)>
___
### getFulfillmentItems\_
`**getFulfillmentItems_**(order, items): Promise<(`null` \| [LineItem](LineItem.mdx))[]>`
Retrieves the order line items, given an array of items.
#### Parameters
#### Returns
Promise<(`null` \| [LineItem](LineItem.mdx))[]>
___
### partitionItems\_
`**partitionItems_**(shippingMethods, items): [FulfillmentItemPartition](../types/FulfillmentItemPartition.mdx)[]`
#### Parameters
#### Returns
[FulfillmentItemPartition](../types/FulfillmentItemPartition.mdx)[]
___
### retrieve
`**retrieve**(fulfillmentId, config?): Promise<[Fulfillment](Fulfillment.mdx)>`
Retrieves a fulfillment by its id.
#### Parameters
#### Returns
Promise<[Fulfillment](Fulfillment.mdx)>
___
### shouldRetryTransaction\_
`Protected **shouldRetryTransaction_**(err): boolean`
#### Parameters
` \\| `{ code: string }`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`boolean`
___
### 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
#### Returns
``null`` \| [LineItem](LineItem.mdx)
___
### withTransaction
`**withTransaction**(transactionManager?): [FulfillmentService](FulfillmentService.mdx)`
#### Parameters
#### Returns
[FulfillmentService](FulfillmentService.mdx)