Class: ReturnService
Handles Returns
Hierarchy
"medusa-interfaces"
↳
ReturnService
Constructors
constructor
• new ReturnService(__namedParameters
)
Parameters
Name | Type |
---|---|
__namedParameters | Object |
Overrides
BaseService.constructor
Defined in
Properties
inventoryService_
• inventoryService_: any
Defined in
returnReasonService_
• returnReasonService_: any
Defined in
taxProviderService_
• taxProviderService_: any
Defined in
Methods
cancel
▸ cancel(returnId
): Promise
<Return
>
Cancels a return if possible. Returns can be canceled if it has not been received.
Parameters
Name | Type | Description |
---|---|---|
returnId | string | the id of the return to cancel. |
Returns
Promise
<Return
>
the updated Return
Defined in
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
Name | Type | Description |
---|---|---|
data | any | data to use for the return e.g. shipping_method, items or refund_amount |
Returns
Promise
<Return
>
the created return
Defined in
fulfill
▸ fulfill(returnId
): any
Parameters
Name | Type |
---|---|
returnId | any |
Returns
any
Defined in
getFulfillmentItems_
▸ getFulfillmentItems_(order
, items
, transformer
): Promise
<LineItem
[]>
Retrieves the order line items, given an array of items
Parameters
Name | Type | Description |
---|---|---|
order | Order | the order to get line items from |
items | Object | the items to get |
items.item_id | string | - |
items.quantity | number | - |
transformer | Function | a 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
list
▸ list(selector
, config?
): Promise
<any
>
Parameters
Name | Type | Description |
---|---|---|
selector | any | the query object for find |
config | any | the config object for find |
Returns
Promise
<any
>
the result of the find operation
Defined in
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
Name | Type | Default value | Description |
---|---|---|---|
return_id | string | undefined | the orderId to return to |
received_items | Item [] | undefined | the items received after return. |
refund_amount | undefined | number | undefined | the amount to return |
allow_mismatch | bool | false | whether to ignore return/received product mismatch |
Returns
Promise
<any
>
the result of the update operation
Defined in
retrieve
▸ retrieve(id
, config?
): Return
Retrieves a return by its id.
Parameters
Name | Type | Description |
---|---|---|
id | string | the id of the return to retrieve |
config | any | the config object |
Returns
Return
the return
Defined in
retrieveBySwap
▸ retrieveBySwap(swapId
, relations?
): Promise
<any
>
Parameters
Name | Type | Default value |
---|---|---|
swapId | any | undefined |
relations | any [] | [] |
Returns
Promise
<any
>
Defined in
update
▸ update(returnId
, update
): Promise
<any
>
Parameters
Name | Type |
---|---|
returnId | any |
update | any |
Returns
Promise
<any
>
Defined in
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
Name | Type | Description |
---|---|---|
item | any | the line item to check has sufficient returnable quantity. |
quantity | number | the quantity that is requested to be returned. |
additional | any | the quantity that is requested to be returned. |
Returns
LineItem
a line item where the quantity is set to the requested return quantity.
Defined in
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
Name | Type | Description |
---|---|---|
order | Order | the order to check statuses on |
Returns
void
Defined in
withTransaction
▸ withTransaction(transactionManager
): ReturnService
Parameters
Name | Type |
---|---|
transactionManager | any |