Skip to main content

Class: OrderService

Hierarchy

  • "medusa-interfaces"

    OrderService

Constructors

constructor

new OrderService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/order.js:25

Properties

Events

Static Events: Object

Type declaration

NameType
CANCELEDstring
COMPLETEDstring
FULFILLMENT_CANCELEDstring
FULFILLMENT_CREATEDstring
GIFT_CARD_CREATEDstring
ITEMS_RETURNEDstring
PAYMENT_CAPTUREDstring
PAYMENT_CAPTURE_FAILEDstring
PLACEDstring
REFUND_CREATEDstring
REFUND_FAILEDstring
RETURN_ACTION_REQUIREDstring
RETURN_REQUESTEDstring
SHIPMENT_CREATEDstring
SWAP_CREATEDstring
UPDATEDstring

Defined in

services/order.js:6

Methods

addShippingMethod

addShippingMethod(orderId, optionId, data, config?): Promise<any>

Parameters

NameType
orderIdany
optionIdany
dataany
configObject

Returns

Promise<any>

Defined in

services/order.js:806


archive

archive(orderId): Promise<any>

Archives an order. It only alloved, if the order has been fulfilled and payment has been captured.

Parameters

NameTypeDescription
orderIdstringthe order to archive

Returns

Promise<any>

the result of the update operation

Defined in

services/order.js:1301


cancel

cancel(orderId): Promise<any>

Cancels an order. Throws if fulfillment process has been initiated. Throws if payment process has been initiated.

Parameters

NameTypeDescription
orderIdstringid of order to cancel.

Returns

Promise<any>

result of the update operation.

Defined in

services/order.js:952


cancelFulfillment

cancelFulfillment(fulfillmentId): Promise<any>

Cancels a fulfillment (if related to an order)

Parameters

NameTypeDescription
fulfillmentIdstringthe ID of the fulfillment to cancel

Returns

Promise<any>

updated order

Defined in

services/order.js:1242


capturePayment

capturePayment(orderId): Promise<any>

Captures payment for an order.

Parameters

NameTypeDescription
orderIdstringid of order to capture payment for.

Returns

Promise<any>

result of the update operation.

Defined in

services/order.js:1021


completeOrder

completeOrder(orderId): Promise<any>

Parameters

NameTypeDescription
orderIdstringid of the order to complete

Returns

Promise<any>

the result of the find operation

Defined in

services/order.js:429


create

create(data): Promise<any>

Creates an order

Parameters

NameTypeDescription
dataanythe data to create an order

Returns

Promise<any>

resolves to the creation result.

Defined in

services/order.js:723


createFromCart

createFromCart(cartId): Promise<any>

Creates an order from a cart

Parameters

NameTypeDescription
cartIdstringid of the cart to create an order from

Returns

Promise<any>

resolves to the creation result.

Defined in

services/order.js:465


createFulfillment

createFulfillment(orderId, itemsToFulfill, config?): Promise<any>

Creates fulfillments for an order. In a situation where the order has more than one shipping method, we need to partition the order items, such that they can be sent to their respective fulfillment provider.

Parameters

NameTypeDescription
orderIdstringid of order to cancel.
itemsToFulfillanyitems to fulfil.
configanythe config to cancel.

Returns

Promise<any>

result of the update operation.

Defined in

services/order.js:1121


createRefund

createRefund(orderId, refundAmount, reason, note, config?): Promise<any>

Refunds a given amount back to the customer.

Parameters

NameTypeDescription
orderIdstringid of the order to refund.
refundAmountfloatthe amount to refund.
reasonstringthe reason to refund.
noteundefined | stringnote for refund.
configanythe config for refund.

Returns

Promise<any>

the result of the refund operation.

Defined in

services/order.js:1328


createShipment

createShipment(orderId, fulfillmentId, trackingLinks, config?): order

Adds a shipment to the order to indicate that an order has left the warehouse. Will ask the fulfillment provider for any documents that may have been created in regards to the shipment.

Parameters

NameTypeDescription
orderIdstringthe id of the order that has been shipped
fulfillmentIdstringthe fulfillment that has now been shipped
trackingLinksundefined | TrackingLink[]array of tracking numebers associated with the shipment
configanythe config of the order that has been shipped

Returns

order

the resulting order following the update.

Defined in

services/order.js:643


decorateTotals_

decorateTotals_(order, totalsFields?): Promise<any>

Parameters

NameTypeDefault value
orderanyundefined
totalsFieldsany[][]

Returns

Promise<any>

Defined in

services/order.js:1377


deleteMetadata

deleteMetadata(orderId, key): Promise<any>

Dedicated method to delete metadata for an order.

Parameters

NameTypeDescription
orderIdstringthe order to delete metadata from.
keystringkey for metadata field

Returns

Promise<any>

resolves to the updated result.

Defined in

services/order.js:1550


existsByCartId

existsByCartId(cartId): Promise<Order>

Checks the existence of an order by cart id.

Parameters

NameTypeDescription
cartIdstringcart id to find order

Returns

Promise<Order>

the order document

Defined in

services/order.js:417


getFulfillmentItems_

getFulfillmentItems_(order, items, transformer): Promise<LineItem[]>

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

Parameters

NameTypeDescription
orderOrderthe order to get line items from
itemsObjectthe items to get
items.item_idstring-
items.quantitynumber-
transformerFunctiona function to apply to each of the items retrieved from the order, should return a line item. If the transformer returns an undefined value the line item will be filtered from the returned array.

Returns

Promise<LineItem[]>

the line items generated by the transformer.

Defined in

services/order.js:1284


list

list(selector, config?): Promise<any>

Parameters

NameTypeDescription
selectoranythe query object for find
configanythe config to be used for find

Returns

Promise<any>

the result of the find operation

Defined in

services/order.js:148


listAndCount

listAndCount(selector, config?): Promise<any[]>

Parameters

NameTypeDefault value
selectoranyundefined
configObjectundefined
config.orderObjectundefined
config.order.created_atstring"DESC"
config.skipnumber0
config.takenumber50

Returns

Promise<any[]>

Defined in

services/order.js:173


registerReturnReceived

registerReturnReceived(orderId, receivedReturn, customRefundAmount): Promise<any>

Handles receiving a return. This will create a refund to the customer. If the returned items don't match the requested items the return status will be updated to requires_action. This behaviour is useful in sitautions where a custom refund amount is requested, but the retuned items are not matching the requested items. Setting the allowMismatch argument to true, will process the return, ignoring any mismatches.

Parameters

NameTypeDescription
orderIdstringthe order to return.
receivedReturnanythe received return
customRefundAmountfloatthe custom refund amount return

Returns

Promise<any>

the result of the update operation

Defined in

services/order.js:1473


retrieve

retrieve(orderId, config?): Promise<Order>

Gets an order by id.

Parameters

NameTypeDescription
orderIdstringid of order to retrieve
configanyconfig of order to retrieve

Returns

Promise<Order>

the order document

Defined in

services/order.js:305


retrieveByCartId

retrieveByCartId(cartId, config?): Promise<Order>

Gets an order by cart id.

Parameters

NameTypeDescription
cartIdstringcart id to find order
configanythe config to be used to find order

Returns

Promise<Order>

the order document

Defined in

services/order.js:343


retrieveByExternalId

retrieveByExternalId(externalId, config?): Promise<Order>

Gets an order by id.

Parameters

NameTypeDescription
externalIdstringid of order to retrieve
configanyquery config to get order by

Returns

Promise<Order>

the order document

Defined in

services/order.js:380


transformQueryForTotals_

transformQueryForTotals_(config): { relations: any ; select: any ; totalsToSelect: never[] = [] } | { relations: any ; select: any[] = toSelect; totalsToSelect: any }

Parameters

NameType
configany

Returns

{ relations: any ; select: any ; totalsToSelect: never[] = [] } | { relations: any ; select: any[] = toSelect; totalsToSelect: any }

Defined in

services/order.js:234


update

update(orderId, update): Promise<any>

Updates an order. Metadata updates should use dedicated method, e.g. setMetadata etc. The function will throw errors if metadata updates are attempted.

Parameters

NameTypeDescription
orderIdstringthe id of the order. Must be a string that can be casted to an ObjectId
updateanyan object with the update values.

Returns

Promise<any>

resolves to the update result.

Defined in

services/order.js:864


updateBillingAddress_

updateBillingAddress_(order, address): Promise<any>

Updates the order's billing address.

Parameters

NameTypeDescription
orderanythe order to update
addressanythe value to set the billing address to

Returns

Promise<any>

the result of the update operation

Defined in

services/order.js:744


updateShippingAddress_

updateShippingAddress_(order, address): Promise<any>

Updates the order's shipping address.

Parameters

NameTypeDescription
orderanythe order to update
addressanythe value to set the shipping address to

Returns

Promise<any>

the result of the update operation

Defined in

services/order.js:779


validateFulfillmentLineItem_

validateFulfillmentLineItem_(item, quantity): LineItem

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

NameTypeDescription
itemLineItemthe line item to check has sufficient fulfillable quantity.
quantitynumberthe quantity that is requested to be fulfilled.

Returns

LineItem

a line item that has the requested fulfillment quantity set.

Defined in

services/order.js:1091


validateId_

validateId_(rawId): string

Used to validate order ids. Throws an error if the cast fails

Parameters

NameTypeDescription
rawIdstringthe raw order id to validate.

Returns

string

the validated id

Defined in

services/order.js:139


withTransaction

withTransaction(manager): OrderService

Parameters

NameType
managerany

Returns

OrderService

Defined in

services/order.js:102