Skip to main content

Class: ReturnService

Hierarchy

  • TransactionBaseService

    ReturnService

Constructors

constructor

new ReturnService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/return.ts:67

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


fulfillmentProviderService_

Protected Readonly fulfillmentProviderService_: FulfillmentProviderService

Defined in

packages/medusa/src/services/return.ts:61


lineItemService_

Protected Readonly lineItemService_: LineItemService

Defined in

packages/medusa/src/services/return.ts:58


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/return.ts:52


orderService_

Protected Readonly orderService_: OrderService

Defined in

packages/medusa/src/services/return.ts:63


productVariantInventoryService_

Protected Readonly productVariantInventoryService_: ProductVariantInventoryService

Defined in

packages/medusa/src/services/return.ts:65


returnItemRepository_

Protected Readonly returnItemRepository_: typeof ReturnItemRepository

Defined in

packages/medusa/src/services/return.ts:57


returnReasonService_

Protected Readonly returnReasonService_: ReturnReasonService

Defined in

packages/medusa/src/services/return.ts:62


returnRepository_

Protected Readonly returnRepository_: typeof ReturnRepository

Defined in

packages/medusa/src/services/return.ts:56


shippingOptionService_

Protected Readonly shippingOptionService_: ShippingOptionService

Defined in

packages/medusa/src/services/return.ts:60


taxProviderService_

Protected Readonly taxProviderService_: TaxProviderService

Defined in

packages/medusa/src/services/return.ts:59


totalsService_

Protected Readonly totalsService_: TotalsService

Defined in

packages/medusa/src/services/return.ts:55


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/return.ts:53

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

packages/medusa/src/interfaces/transaction-base-service.ts:50


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

packages/medusa/src/services/return.ts:164


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

packages/medusa/src/services/return.ts:349


fulfill

fulfill(returnId): Promise<Return>

Parameters

NameType
returnIdstring

Returns

Promise<Return>

Defined in

packages/medusa/src/services/return.ts:495


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

packages/medusa/src/services/return.ts:106


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

packages/medusa/src/services/return.ts:146


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

packages/medusa/src/services/return.ts:566


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

packages/medusa/src/services/return.ts:262


retrieveBySwap

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

Parameters

NameTypeDefault value
swapIdstringundefined
relationsstring[][]

Returns

Promise<Return>

Defined in

packages/medusa/src/services/return.ts:290


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(returnId, update): Promise<Return>

Parameters

NameType
returnIdstring
updateUpdateReturnInput

Returns

Promise<Return>

Defined in

packages/medusa/src/services/return.ts:315


validateReturnLineItem

Protected validateReturnLineItem(item?, quantity?, additional?): Object

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

Object

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

NameType
adjustments?(undefined | { id?: string | undefined; item_id?: string | undefined; item?: { cart_id?: string | undefined; cart?: { readonly object?: "cart" | undefined; email?: string | undefined; billing_address_id?: string | undefined; ... 37 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 38 more ...; updated_at?: { ...; }...)[]
allow_discounts?boolean
cart?{ readonly object?: "cart" | undefined; email?: string | undefined; billing_address_id?: string | undefined; billing_address?: { customer_id?: string | null | undefined; customer?: { ...; } | ... 1 more ... | undefined; ... 15 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 36 more ...; updated_at?: ...
cart_id?string
claim_order?{ payment_status?: ClaimPaymentStatus | undefined; fulfillment_status?: ClaimFulfillmentStatus | undefined; claim_items?: ({ images?: ({ ...; } | undefined)[] | undefined; ... 14 more ...; updated_at?: { ...; } | undefined; } | undefined)[] | undefined; ... 17 more ...; id?: string | undefined; }
claim_order_id?string
created_at?{ toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; }
description?null | string
discount_total?null | number
fulfilled_quantity?null | number
gift_card_total?null | number
has_shipping?null | boolean
id?string
includes_tax?boolean
is_giftcard?boolean
is_return?boolean
metadata?{ [x: string]: unknown; }
order?{ readonly object?: "order" | undefined; status?: OrderStatus | undefined; fulfillment_status?: FulfillmentStatus | undefined; payment_status?: PaymentStatus | undefined; ... 49 more ...; updated_at?: { ...; } | undefined; }
order_edit?null | { order_id?: string | undefined; order?: { readonly object?: "order" | undefined; status?: OrderStatus | undefined; fulfillment_status?: FulfillmentStatus | undefined; ... 50 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 27 more ...; updated_at?: { ...; } | undefined; }
order_edit_id?null | string
order_id?null | string
original_item_id?null | string
original_tax_total?null | number
original_total?null | number
quantity?number
refundable?null | number
returned_quantity?null | number
shipped_quantity?null | number
should_merge?boolean
subtotal?null | number
swap?{ fulfillment_status?: SwapFulfillmentStatus | undefined; payment_status?: SwapPaymentStatus | undefined; order_id?: string | undefined; ... 20 more ...; updated_at?: { ...; } | undefined; }
swap_id?string
tax_lines?(undefined | { item_id?: string | undefined; item?: { cart_id?: string | undefined; cart?: { readonly object?: "cart" | undefined; email?: string | undefined; billing_address_id?: string | undefined; ... 37 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 38 more ...; updated_at?: { ...; } | undefined; } | undefin...)[]
tax_total?null | number
thumbnail?null | string
title?string
total?null | number
unit_price?number
updated_at?{ toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; }
variant?{ title?: string | undefined; product_id?: string | undefined; product?: { title?: string | undefined; subtitle?: string | null | undefined; description?: string | null | undefined; ... 30 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 23 more ...; updated_at?: { ...; } | undefined; }
variant_id?null | string

Defined in

packages/medusa/src/services/return.ts:220


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

packages/medusa/src/services/return.ts:190


withTransaction

withTransaction(transactionManager?): ReturnService

Parameters

NameType
transactionManager?EntityManager

Returns

ReturnService

Inherited from

TransactionBaseService.withTransaction

Defined in

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