Skip to main content

Class: ReturnService

Hierarchy

  • TransactionBaseService

    ReturnService

Constructors

constructor

new ReturnService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

medusa/src/services/return.ts:64

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

medusa/src/interfaces/transaction-base-service.ts:14


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

medusa/src/interfaces/transaction-base-service.ts:13


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

medusa/src/interfaces/transaction-base-service.ts:15


fulfillmentProviderService_

Protected Readonly fulfillmentProviderService_: FulfillmentProviderService

Defined in

medusa/src/services/return.ts:58


lineItemService_

Protected Readonly lineItemService_: LineItemService

Defined in

medusa/src/services/return.ts:55


manager_

Protected manager_: EntityManager

Inherited from

TransactionBaseService.manager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:5


orderService_

Protected Readonly orderService_: OrderService

Defined in

medusa/src/services/return.ts:60


productVariantInventoryService_

Protected Readonly productVariantInventoryService_: ProductVariantInventoryService

Defined in

medusa/src/services/return.ts:62


returnItemRepository_

Protected Readonly returnItemRepository_: Repository<ReturnItem>

Defined in

medusa/src/services/return.ts:54


returnReasonService_

Protected Readonly returnReasonService_: ReturnReasonService

Defined in

medusa/src/services/return.ts:59


returnRepository_

Protected Readonly returnRepository_: Repository<Return>

Defined in

medusa/src/services/return.ts:53


shippingOptionService_

Protected Readonly shippingOptionService_: ShippingOptionService

Defined in

medusa/src/services/return.ts:57


taxProviderService_

Protected Readonly taxProviderService_: TaxProviderService

Defined in

medusa/src/services/return.ts:56


totalsService_

Protected Readonly totalsService_: TotalsService

Defined in

medusa/src/services/return.ts:52


transactionManager_

Protected transactionManager_: undefined | EntityManager

Inherited from

TransactionBaseService.transactionManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:6

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

Inherited from

TransactionBaseService.activeManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:8

Methods

atomicPhase_

Protected atomicPhase_<TResult, TError>(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.

Type parameters

Name
TResult
TError

Parameters

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (error: TError) => Promise<void | TResult>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?(error: TError) => Promise<void | TResult>Potential error handler

Returns

Promise<TResult>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

medusa/src/interfaces/transaction-base-service.ts:56


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

medusa/src/services/return.ts:161


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
dataCreateReturnInputdata to use for the return e.g. shipping_method, items or refund_amount

Returns

Promise<Return>

the created return

Defined in

medusa/src/services/return.ts:346


fulfill

fulfill(returnId): Promise<Return>

Parameters

NameType
returnIdstring

Returns

Promise<Return>

Defined in

medusa/src/services/return.ts:490


getFulfillmentItems

Protected getFulfillmentItems(order, items, transformer): Promise<LineItem & { note?: string ; reason_id?: string }[]>

Retrieves the order line items, given an array of items

Parameters

NameTypeDescription
orderOrderthe order to get line items from
itemsOrdersReturnItem[]the items to get
transformerTransformera 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 & { note?: string ; reason_id?: string }[]>

the line items generated by the transformer.

Defined in

medusa/src/services/return.ts:101


list

list(selector, config?): Promise<Return[]>

Parameters

NameTypeDescription
selectorSelector<Return>the query object for find
configFindConfig<Return>the config object for find

Returns

Promise<Return[]>

the result of the find operation

Defined in

medusa/src/services/return.ts:141


receive

receive(returnId, receivedItems, refundAmount?, allowMismatch?, context?): Promise<Return>

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
returnIdstringundefinedthe orderId to return to
receivedItemsOrdersReturnItem[]undefinedthe items received after return.
refundAmount?numberundefinedthe amount to return
allowMismatchbooleanfalsewhether to ignore return/received product mismatch
contextObject{}-
context.locationId?stringundefined-

Returns

Promise<Return>

the result of the update operation

Defined in

medusa/src/services/return.ts:561


retrieve

retrieve(returnId, config?): Promise<Return>

Retrieves a return by its id.

Parameters

NameTypeDescription
returnIdstringthe id of the return to retrieve
configFindConfig<Return>the config object

Returns

Promise<Return>

the return

Defined in

medusa/src/services/return.ts:259


retrieveBySwap

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

Parameters

NameTypeDefault value
swapIdstringundefined
relationsstring[][]

Returns

Promise<Return>

Defined in

medusa/src/services/return.ts:287


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

NameType
errRecord<string, unknown> | { code: string }

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

medusa/src/interfaces/transaction-base-service.ts:37


update

update(returnId, update): Promise<Return>

Parameters

NameType
returnIdstring
updateUpdateReturnInput

Returns

Promise<Return>

Defined in

medusa/src/services/return.ts:312


validateReturnLineItem

Protected validateReturnLineItem(item?, quantity?, additional?): DeepPartial<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

NameTypeDefault valueDescription
item?LineItemundefinedthe line item to check has sufficient returnable quantity.
quantitynumber0the quantity that is requested to be returned.
additionalObject{}the quantity that is requested to be returned.
additional.note?stringundefined-
additional.reason_id?stringundefined-

Returns

DeepPartial<LineItem>

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

Defined in

medusa/src/services/return.ts:217


validateReturnStatuses

Protected 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

medusa/src/services/return.ts:187


withTransaction

withTransaction(transactionManager?): ReturnService

Parameters

NameType
transactionManager?EntityManager

Returns

ReturnService

Inherited from

TransactionBaseService.withTransaction

Defined in

medusa/src/interfaces/transaction-base-service.ts:20