Skip to main content

Class: SwapService

Handles swaps

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    SwapServiceCopy to Clipboard

Constructors

constructor

new SwapService(__namedParametersCopy to Clipboard)

Parameters

NameType
__namedParametersCopy to ClipboardInjectedPropsCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

medusa/src/services/swap.ts:91

Properties

__configModule__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __configModule__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__configModule__

Defined in

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


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

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


__moduleDeclaration__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __moduleDeclaration__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

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


cartService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard cartService_: CartServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:77


customShippingOptionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard customShippingOptionService_: CustomShippingOptionServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:87


eventBus_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventBus_: EventBusServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:78


fulfillmentService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard fulfillmentService_: FulfillmentServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:83


lineItemAdjustmentService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard lineItemAdjustmentService_: LineItemAdjustmentServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:86


lineItemService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard lineItemService_: LineItemServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:82


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.manager_

Defined in

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


orderService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard orderService_: OrderServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:79


paymentProviderService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard paymentProviderService_: PaymentProviderServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:85


productVariantInventoryService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productVariantInventoryService_: ProductVariantInventoryServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:89


returnService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard returnService_: ReturnServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:80


shippingOptionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard shippingOptionService_: ShippingOptionServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:84


swapRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard swapRepository_: RepositoryCopy to Clipboard<SwapCopy to Clipboard>

Defined in

medusa/src/services/swap.ts:75


totalsService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard totalsService_: TotalsServiceCopy to Clipboard

Defined in

medusa/src/services/swap.ts:81


transactionManager_

ProtectedCopy to Clipboard transactionManager_: undefinedCopy to Clipboard | EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.transactionManager_

Defined in

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


Events

StaticCopy to Clipboard Events: ObjectCopy to Clipboard

Type declaration

NameType
CREATEDCopy to ClipboardstringCopy to Clipboard
FULFILLMENT_CREATEDCopy to ClipboardstringCopy to Clipboard
PAYMENT_CAPTUREDCopy to ClipboardstringCopy to Clipboard
PAYMENT_CAPTURE_FAILEDCopy to ClipboardstringCopy to Clipboard
PAYMENT_COMPLETEDCopy to ClipboardstringCopy to Clipboard
PROCESS_REFUND_FAILEDCopy to ClipboardstringCopy to Clipboard
RECEIVEDCopy to ClipboardstringCopy to Clipboard
REFUND_PROCESSEDCopy to ClipboardstringCopy to Clipboard
SHIPMENT_CREATEDCopy to ClipboardstringCopy to Clipboard

Defined in

medusa/src/services/swap.ts:63

Accessors

activeManager_

ProtectedCopy to Clipboard getCopy to Clipboard activeManager_(): EntityManagerCopy to Clipboard

Returns

EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.activeManager_

Defined in

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

Methods

areReturnItemsValid

ProtectedCopy to Clipboard areReturnItemsValid(returnItemsCopy to Clipboard): PromiseCopy to Clipboard<booleanCopy to Clipboard>

Parameters

NameType
returnItemsCopy to ClipboardWithRequiredPropertyCopy to Clipboard<PartialCopy to Clipboard<ReturnItemCopy to Clipboard>, "item_id"Copy to Clipboard>[]

Returns

PromiseCopy to Clipboard<booleanCopy to Clipboard>

Defined in

medusa/src/services/swap.ts:1245


atomicPhase_

ProtectedCopy to Clipboard atomicPhase_<TResultCopy to Clipboard, TErrorCopy to Clipboard>(workCopy to Clipboard, isolationOrErrorHandler?Copy to Clipboard, maybeErrorHandlerOrDontFail?Copy to Clipboard): PromiseCopy to Clipboard<TResultCopy to Clipboard>

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
TResultCopy to Clipboard
TErrorCopy to Clipboard

Parameters

NameTypeDescription
workCopy to Clipboard(transactionManagerCopy to Clipboard: EntityManagerCopy to Clipboard) => PromiseCopy to Clipboard<TResultCopy to Clipboard>the transactional work to be done
isolationOrErrorHandler?Copy to ClipboardIsolationLevelCopy to Clipboard | (errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?Copy to Clipboard(errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>Potential error handler

Returns

PromiseCopy to Clipboard<TResultCopy to Clipboard>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

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


cancel

cancel(swapIdCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

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
swapIdCopy to ClipboardstringCopy to Clipboardthe id of the swap to cancel.

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the canceled swap.

Defined in

medusa/src/services/swap.ts:860


cancelFulfillment

cancelFulfillment(fulfillmentIdCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Cancels a fulfillment (if related to a swap)

Parameters

NameTypeDescription
fulfillmentIdCopy to ClipboardstringCopy to Clipboardthe ID of the fulfillment to cancel

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

updated swap

Defined in

medusa/src/services/swap.ts:1064


create

create(orderCopy to Clipboard, returnItemsCopy to Clipboard, additionalItems?Copy to Clipboard, returnShipping?Copy to Clipboard, custom?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

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

Parameters

NameTypeDescription
orderCopy to ClipboardOrderCopy to Clipboardthe order to base the swap off
returnItemsCopy to ClipboardWithRequiredPropertyCopy to Clipboard<PartialCopy to Clipboard<ReturnItemCopy to Clipboard>, "item_id"Copy to Clipboard>[]the items to return in the swap
additionalItems?Copy to ClipboardPickCopy to Clipboard<LineItemCopy to Clipboard, "variant_id"Copy to Clipboard | "quantity"Copy to Clipboard>[]the items to send to the customer
returnShipping?Copy to ClipboardObjectCopy to Clipboardan optional shipping method for returning the returnItems
returnShipping.option_idCopy to ClipboardstringCopy to Clipboard-
returnShipping.price?Copy to ClipboardnumberCopy to Clipboard-
customCopy to ClipboardObjectCopy to Clipboardcontains 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
custom.allow_backorder?Copy to ClipboardbooleanCopy to Clipboard-
custom.idempotency_key?Copy to ClipboardstringCopy to Clipboard-
custom.location_id?Copy to ClipboardstringCopy to Clipboard-
custom.no_notification?Copy to ClipboardbooleanCopy to Clipboard-

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the newly created swap

Defined in

medusa/src/services/swap.ts:321


createCart

createCart(swapIdCopy to Clipboard, customShippingOptions?Copy to Clipboard, context?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Creates a cart from the given swap. 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
swapIdCopy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboardthe id of the swap to create the cart from
customShippingOptionsCopy to Clipboard{ option_idCopy to Clipboard: stringCopy to Clipboard ; priceCopy to Clipboard: numberCopy to Clipboard }[][]Copy to Clipboardthe shipping options
contextCopy to ClipboardObjectCopy to Clipboard{}Copy to Clipboard-
context.sales_channel_id?Copy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboard-

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

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

Defined in

medusa/src/services/swap.ts:577


createFulfillment

createFulfillment(swapIdCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

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

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardthe id of the swap to fulfill,
configCopy to ClipboardCreateShipmentConfigCopy to Clipboardoptional configurations, includes optional metadata to attach to the shipment, and a no_notification flag.

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the updated swap with new status and fulfillments.

Defined in

medusa/src/services/swap.ts:922


createShipment

createShipment(swapIdCopy to Clipboard, fulfillmentIdCopy to Clipboard, trackingLinks?Copy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Marks a fulfillment as shipped and attaches tracking numbers.

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardthe id of the swap that has been shipped.
fulfillmentIdCopy to ClipboardstringCopy to Clipboardthe id of the specific fulfillment that has been shipped
trackingLinks?Copy to Clipboard{ tracking_numberCopy to Clipboard: stringCopy to Clipboard }[]the tracking numbers associated with the shipment
configCopy to ClipboardCreateShipmentConfigCopy to Clipboardoptional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the updated swap with new fulfillments and status.

Defined in

medusa/src/services/swap.ts:1095


deleteMetadata

deleteMetadata(swapIdCopy to Clipboard, keyCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Dedicated method to delete metadata for a swap.

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardthe order to delete metadata from.
keyCopy to ClipboardstringCopy to Clipboardkey for metadata field

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

resolves to the updated result.

Defined in

medusa/src/services/swap.ts:1173


list

list(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard[]>

List swaps.

Parameters

NameTypeDescription
selectorCopy to ClipboardSelectorCopy to Clipboard<SwapCopy to Clipboard>the query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<SwapCopy to Clipboard>the configuration used to find the objects. contains relations, skip, and take.

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard[]>

the result of the find operation

Defined in

medusa/src/services/swap.ts:273


listAndCount

listAndCount(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<[SwapCopy to Clipboard[], numberCopy to Clipboard]>

List swaps.

Parameters

NameTypeDescription
selectorCopy to ClipboardSelectorCopy to Clipboard<SwapCopy to Clipboard>the query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<SwapCopy to Clipboard>the configuration used to find the objects. contains relations, skip, and take.

Returns

PromiseCopy to Clipboard<[SwapCopy to Clipboard[], numberCopy to Clipboard]>

the result of the find operation

Defined in

medusa/src/services/swap.ts:293


processDifference

processDifference(swapIdCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Process difference for the requested swap.

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardid of a swap being processed

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

processed swap

Defined in

medusa/src/services/swap.ts:421


registerCartCompletion

registerCartCompletion(swapIdCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Register a cart completion

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to ClipboardThe id of the swap

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

swap related to the cart

Defined in

medusa/src/services/swap.ts:727


registerReceived

registerReceived(idCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

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

Parameters

NameTypeDescription
idCopy to ClipboardanyCopy to Clipboardthe id of the order with the swap.

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the resulting order

Defined in

medusa/src/services/swap.ts:1211


retrieve

retrieve(swapIdCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Retrieves a swap with the given id.

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardthe id of the swap to retrieve
configCopy to ClipboardOmitCopy to Clipboard<FindConfigCopy to Clipboard<SwapCopy to Clipboard>, "select"Copy to Clipboard> & { select?Copy to Clipboard: stringCopy to Clipboard[] }the configuration to retrieve the swap

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the swap

Defined in

medusa/src/services/swap.ts:203


retrieveByCartId

retrieveByCartId(cartIdCopy to Clipboard, relations?Copy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Retrieves a swap based on its associated cart id

Parameters

NameTypeDefault valueDescription
cartIdCopy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboardthe cart id that the swap's cart has
relationsCopy to ClipboardundefinedCopy to Clipboard | stringCopy to Clipboard[][]Copy to Clipboardthe relations to retrieve swap

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

the swap

Defined in

medusa/src/services/swap.ts:246


shouldRetryTransaction_

ProtectedCopy to Clipboard shouldRetryTransaction_(errCopy to Clipboard): booleanCopy to Clipboard

Parameters

NameType
errCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> | { codeCopy to Clipboard: stringCopy to Clipboard }

Returns

booleanCopy to Clipboard

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

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


transformQueryForCart

ProtectedCopy to Clipboard transformQueryForCart(configCopy to Clipboard): OmitCopy to Clipboard<FindConfigCopy to Clipboard<SwapCopy to Clipboard>, "select"Copy to Clipboard> & { select?Copy to Clipboard: stringCopy to Clipboard[] } & { cartRelationsCopy to Clipboard: undefinedCopy to Clipboard | stringCopy to Clipboard[] ; cartSelectsCopy to Clipboard: undefinedCopy to Clipboard | keyof CartCopy to Clipboard[] }

Transform find config object for retrieval.

Parameters

NameTypeDescription
configCopy to ClipboardOmitCopy to Clipboard<FindConfigCopy to Clipboard<SwapCopy to Clipboard>, "select"Copy to Clipboard> & { select?Copy to Clipboard: stringCopy to Clipboard[] }parsed swap find config

Returns

OmitCopy to Clipboard<FindConfigCopy to Clipboard<SwapCopy to Clipboard>, "select"Copy to Clipboard> & { select?Copy to Clipboard: stringCopy to Clipboard[] } & { cartRelationsCopy to Clipboard: undefinedCopy to Clipboard | stringCopy to Clipboard[] ; cartSelectsCopy to Clipboard: undefinedCopy to Clipboard | keyof CartCopy to Clipboard[] }

transformed find swap config

Defined in

medusa/src/services/swap.ts:130


update

update(swapIdCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<SwapCopy to Clipboard>

Update the swap record.

Parameters

NameTypeDescription
swapIdCopy to ClipboardstringCopy to Clipboardid of a swap to update
updateCopy to ClipboardPartialCopy to Clipboard<SwapCopy to Clipboard>new data

Returns

PromiseCopy to Clipboard<SwapCopy to Clipboard>

updated swap record

Defined in

medusa/src/services/swap.ts:544


withTransaction

withTransaction(transactionManager?Copy to Clipboard): SwapServiceCopy to Clipboard

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

SwapServiceCopy to Clipboard

Inherited from

TransactionBaseService.withTransaction

Defined in

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

Was this page helpful?