Skip to main content

Class: ReturnService

Handles Returns

Hierarchy

  • "medusa-interfaces"

    ReturnService

Constructors

constructor

new ReturnService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/return.js:9

Properties

inventoryService_

inventoryService_: any

Defined in

services/return.js:49


returnReasonService_

returnReasonService_: any

Defined in

services/return.js:47


taxProviderService_

taxProviderService_: any

Defined in

services/return.js:39

Methods

cancel

cancel(returnId): Promise<Return>

Cancels a return if possible. Returns can be canceled if it has not been received.

Parameters

NameTypeDescription
returnIdstringthe id of the return to cancel.

Returns

Promise<Return>

the updated Return

Defined in

services/return.js:134


create

create(data): Promise<Return>

Creates a return request for an order, with given items, and a shipping method. If no refund amount is provided the refund amount is calculated from the return lines and the shipping cost.

Parameters

NameTypeDescription
dataanydata to use for the return e.g. shipping_method, items or refund_amount

Returns

Promise<Return>

the created return

Defined in

services/return.js:307


fulfill

fulfill(returnId): any

Parameters

NameType
returnIdany

Returns

any

Defined in

services/return.js:450


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/return.js:89


list

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

Parameters

NameTypeDescription
selectoranythe query object for find
configanythe config object for find

Returns

Promise<any>

the result of the find operation

Defined in

services/return.js:120


receive

receive(return_id, received_items, refund_amount, allow_mismatch?): Promise<any>

Registers a previously requested return as received. 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

NameTypeDefault valueDescription
return_idstringundefinedthe orderId to return to
received_itemsItem[]undefinedthe items received after return.
refund_amountundefined | numberundefinedthe amount to return
allow_mismatchboolfalsewhether to ignore return/received product mismatch

Returns

Promise<any>

the result of the update operation

Defined in

services/return.js:524


retrieve

retrieve(id, config?): Return

Retrieves a return by its id.

Parameters

NameTypeDescription
idstringthe id of the return to retrieve
configanythe config object

Returns

Return

the return

Defined in

services/return.js:229


retrieveBySwap

retrieveBySwap(swapId, relations?): Promise<any>

Parameters

NameTypeDefault value
swapIdanyundefined
relationsany[][]

Returns

Promise<any>

Defined in

services/return.js:248


update

update(returnId, update): Promise<any>

Parameters

NameType
returnIdany
updateany

Returns

Promise<any>

Defined in

services/return.js:271


validateReturnLineItem_

validateReturnLineItem_(item, quantity, additional): LineItem

Checks that a given quantity of a line item can be returned. Fails if the item is undefined or if the returnable quantity of the item is lower, than the quantity that is requested to be returned.

Parameters

NameTypeDescription
itemanythe line item to check has sufficient returnable quantity.
quantitynumberthe quantity that is requested to be returned.
additionalanythe quantity that is requested to be returned.

Returns

LineItem

a line item where the quantity is set to the requested return quantity.

Defined in

services/return.js:191


validateReturnStatuses_

validateReturnStatuses_(order): void

Checks that an order has the statuses necessary to complete a return. fulfillment_status cannot be not_fulfilled or returned. payment_status must be captured.

throws when statuses are not sufficient for returns.

Parameters

NameTypeDescription
orderOrderthe order to check statuses on

Returns

void

Defined in

services/return.js:161


withTransaction

withTransaction(transactionManager): ReturnService

Parameters

NameType
transactionManagerany

Returns

ReturnService

Defined in

services/return.js:55