Skip to main content

Class: SwapService

Handles swaps

Hierarchy

  • "medusa-interfaces"

    SwapService

Constructors

constructor

new SwapService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/swap.js:21

Properties

Events

Static Events: Object

Type declaration

NameType
CREATEDstring
FULFILLMENT_CREATEDstring
PAYMENT_CAPTUREDstring
PAYMENT_CAPTURE_FAILEDstring
PAYMENT_COMPLETEDstring
PROCESS_REFUND_FAILEDstring
RECEIVEDstring
REFUND_PROCESSEDstring
SHIPMENT_CREATEDstring

Defined in

services/swap.js:9

Methods

cancel

cancel(swapId): Promise<Swap>

Cancels a given swap if possible. A swap can only be canceled if all related returns, fulfillments, and payments have been canceled. If a swap is associated with a refund, it cannot be canceled.

Parameters

NameTypeDescription
swapIdstringthe id of the swap to cancel.

Returns

Promise<Swap>

the canceled swap.

Defined in

services/swap.js:790


cancelFulfillment

cancelFulfillment(fulfillmentId): Swap

Cancels a fulfillment (if related to a swap)

Parameters

NameTypeDescription
fulfillmentIdstringthe ID of the fulfillment to cancel

Returns

Swap

updated swap

Defined in

services/swap.js:983


create

create(order, returnItems, additionalItems, returnShipping, custom?): Promise<Swap>

Creates a swap from an order, with given return items, additional items and an optional return shipping method.

Parameters

NameTypeDescription
orderOrderthe order to base the swap off.
returnItemsReturnItem[]the items to return in the swap.
additionalItemsundefined | PreliminaryLineItem[]the items to send to the customer.
returnShippinganyan optional shipping method for returning the returnItems.
customanycontains relevant custom information. This object may include no_notification which will disable sending notification when creating swap. If set, it overrules the attribute inherited from the order.

Returns

Promise<Swap>

the newly created swap.

Defined in

services/swap.js:313


createCart

createCart(swapId, customShippingOptions?): Promise<Swap>

Creates a cart from the given swap and order. The cart can be used to pay for differences associated with the swap. The swap represented by the swapId must belong to the order. Fails if there is already a cart on the swap.

Parameters

NameTypeDefault valueDescription
swapIdstringundefinedthe id of the swap to create the cart from
customShippingOptionsany[][]the shipping options

Returns

Promise<Swap>

the swap with its cart_id prop set to the id of the new cart.

Defined in

services/swap.js:544


createFulfillment

createFulfillment(swapId, config?): Promise<Swap>

Fulfills the addtional items associated with the swap. Will call the fulfillment providers associated with the shipping methods.

Parameters

NameTypeDescription
swapIdstringthe id of the swap to fulfill,
configanyoptional configurations, includes optional metadata to attach to the shipment, and a no_notification flag.

Returns

Promise<Swap>

the updated swap with new status and fulfillments.

Defined in

services/swap.js:848


createShipment

createShipment(swapId, fulfillmentId, trackingLinks, config?): Promise<Swap>

Marks a fulfillment as shipped and attaches tracking numbers.

Parameters

NameTypeDescription
swapIdstringthe id of the swap that has been shipped.
fulfillmentIdstringthe id of the specific fulfillment that has been shipped
trackingLinksundefined | TrackingLink[]the tracking numbers associated with the shipment
configanyoptional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.

Returns

Promise<Swap>

the updated swap with new fulfillments and status.

Defined in

services/swap.js:1016


deleteMetadata

deleteMetadata(swapId, key): Promise<any>

Dedicated method to delete metadata for a swap.

Parameters

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

Returns

Promise<any>

resolves to the updated result.

Defined in

services/swap.js:1089


list

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

Parameters

NameTypeDescription
selectoranythe query object for find
configanythe configuration used to find the objects. contains relations, skip, and take.

Returns

Promise<any>

the result of the find operation

Defined in

services/swap.js:238


processDifference

processDifference(swapId): Promise<any>

Parameters

NameType
swapIdany

Returns

Promise<any>

Defined in

services/swap.js:395


registerCartCompletion

registerCartCompletion(swapId): Promise<any>

Parameters

NameTypeDescription
swapIdstringThe id of the swap

Returns

Promise<any>

Defined in

services/swap.js:659


registerReceived

registerReceived(id): Promise<Order>

Registers the swap return items as received so that they cannot be used as a part of other swaps/returns.

Parameters

NameTypeDescription
idstringthe id of the order with the swap.

Returns

Promise<Order>

the resulting order

Defined in

services/swap.js:1114


retrieve

retrieve(id, config?): Promise<Swap>

Retrieves a swap with the given id.

Parameters

NameTypeDescription
idstringthe id of the swap to retrieve
configanythe configuration to retrieve the swap

Returns

Promise<Swap>

the swap

Defined in

services/swap.js:181


retrieveByCartId

retrieveByCartId(cartId, relations?): Promise<Swap>

Retrieves a swap based on its associated cart id

Parameters

NameTypeDefault valueDescription
cartIdstringundefinedthe cart id that the swap's cart has
relationsstring[][]the relations to retrieve swap

Returns

Promise<Swap>

the swap

Defined in

services/swap.js:216


transformQueryForCart_

transformQueryForCart_(config): any

Parameters

NameType
configany

Returns

any

Defined in

services/swap.js:114


update

update(swapId, update): Promise<any>

Parameters

NameType
swapIdany
updateany

Returns

Promise<any>

Defined in

services/swap.js:511


validateReturnItems_

validateReturnItems_(order, returnItems): ReturnItems[]

Goes through a list of return items to ensure that they exist on the original order. If the item exists it is verified that the quantity to return is not higher than the original quantity ordered.

Parameters

NameTypeDescription
orderOrderLikethe order to return from
returnItemsReturnItem[]the items to return

Returns

ReturnItems[]

the validated returnItems

Defined in

services/swap.js:269


withTransaction

withTransaction(transactionManager): SwapService

Parameters

NameType
transactionManagerany

Returns

SwapService

Defined in

services/swap.js:86