--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # SwapService Handles swaps ## Constructors ### constructor `**new SwapService**(«destructured»)` #### Parameters ## Properties `", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__container__", "type": "`any`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__moduleDeclaration__", "type": "`Record`", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "cartService_", "type": "[CartService](CartService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customShippingOptionService_", "type": "[CustomShippingOptionService](CustomShippingOptionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "eventBus_", "type": "[EventBusService](EventBusService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "fulfillmentService_", "type": "[FulfillmentService](FulfillmentService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "lineItemAdjustmentService_", "type": "[LineItemAdjustmentService](LineItemAdjustmentService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "lineItemService_", "type": "[LineItemService](LineItemService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "manager_", "type": "EntityManager", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orderService_", "type": "[OrderService](OrderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "paymentProviderService_", "type": "[PaymentProviderService](PaymentProviderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "productVariantInventoryService_", "type": "[ProductVariantInventoryService](ProductVariantInventoryService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "returnService_", "type": "[ReturnService](ReturnService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shippingOptionService_", "type": "[ShippingOptionService](ShippingOptionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "swapRepository_", "type": "Repository<[Swap](Swap.mdx)>", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "totalsService_", "type": "[TotalsService](TotalsService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "transactionManager_", "type": "`undefined` \\| EntityManager", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "Events", "type": "`object`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "Events.CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.created\"", "expandable": false, "children": [] }, { "name": "Events.FULFILLMENT_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.fulfillment_created\"", "expandable": false, "children": [] }, { "name": "Events.PAYMENT_CAPTURED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.payment_captured\"", "expandable": false, "children": [] }, { "name": "Events.PAYMENT_CAPTURE_FAILED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.payment_capture_failed\"", "expandable": false, "children": [] }, { "name": "Events.PAYMENT_COMPLETED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.payment_completed\"", "expandable": false, "children": [] }, { "name": "Events.PROCESS_REFUND_FAILED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.process_refund_failed\"", "expandable": false, "children": [] }, { "name": "Events.RECEIVED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.received\"", "expandable": false, "children": [] }, { "name": "Events.REFUND_PROCESSED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.refund_processed\"", "expandable": false, "children": [] }, { "name": "Events.SHIPMENT_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"swap.shipment_created\"", "expandable": false, "children": [] } ]} /> ## Accessors ### activeManager\_ `Protected get**activeManager_**(): EntityManager` #### Returns EntityManager ## Methods ### areReturnItemsValid `Protected **areReturnItemsValid**(returnItems): Promise<boolean>` #### Parameters #### Returns Promise<boolean> ___ ### atomicPhase\_ `Protected **atomicPhase_**(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. #### Parameters Promise<TResult>", "description": "the transactional work to be done", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "isolationOrErrorHandler", "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise<void \\| TResult>", "description": "the isolation level to be used for the work.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "maybeErrorHandlerOrDontFail", "type": "(`error`: `TError`) => Promise<void \\| TResult>", "description": "Potential error handler", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns Promise<TResult> ___ ### cancel `**cancel**(swapId): Promise<[Swap](Swap.mdx)>` 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 #### Returns Promise<[Swap](Swap.mdx)> ___ ### cancelFulfillment `**cancelFulfillment**(fulfillmentId): Promise<[Swap](Swap.mdx)>` Cancels a fulfillment (if related to a swap) #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### create `**create**(order, returnItems, additionalItems?, returnShipping?, custom?): Promise<[Swap](Swap.mdx)>` Creates a swap from an order, with given return items, additional items and an optional return shipping method. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### createCart `**createCart**(swapId, customShippingOptions?, context?): Promise<[Swap](Swap.mdx)>` 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 #### Returns Promise<[Swap](Swap.mdx)> ___ ### createFulfillment `**createFulfillment**(swapId, config?): Promise<[Swap](Swap.mdx)>` Fulfills the additional items associated with the swap. Will call the fulfillment providers associated with the shipping methods. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### createShipment `**createShipment**(swapId, fulfillmentId, trackingLinks?, config?): Promise<[Swap](Swap.mdx)>` Marks a fulfillment as shipped and attaches tracking numbers. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### deleteMetadata `**deleteMetadata**(swapId, key): Promise<[Swap](Swap.mdx)>` Dedicated method to delete metadata for a swap. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### list `**list**(selector, config?): Promise<[Swap](Swap.mdx)[]>` List swaps. #### Parameters #### Returns Promise<[Swap](Swap.mdx)[]> ___ ### listAndCount `**listAndCount**(selector, config?): Promise<[[Swap](Swap.mdx)[], number]>` List swaps. #### Parameters #### Returns Promise<[[Swap](Swap.mdx)[], number]> ___ ### processDifference `**processDifference**(swapId): Promise<[Swap](Swap.mdx)>` Process difference for the requested swap. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### registerCartCompletion `**registerCartCompletion**(swapId): Promise<[Swap](Swap.mdx)>` Register a cart completion #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### registerReceived `**registerReceived**(id): Promise<[Swap](Swap.mdx)>` Registers the swap return items as received so that they cannot be used as a part of other swaps/returns. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### retrieve `**retrieve**(swapId, config?): Promise<[Swap](Swap.mdx)>` Retrieves a swap with the given id. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### retrieveByCartId `**retrieveByCartId**(cartId, relations?): Promise<[Swap](Swap.mdx)>` Retrieves a swap based on its associated cart id #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### shouldRetryTransaction\_ `Protected **shouldRetryTransaction_**(err): boolean` #### Parameters ` \\| `{ code: string }`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `boolean` ___ ### transformQueryForCart `Protected **transformQueryForCart**(config): [Omit](../types/Omit.mdx)<[FindConfig](../interfaces/FindConfig.mdx)<[Swap](Swap.mdx)>, `"select"`> & { select?: string[] } & { cartRelations: undefined \| string[] ; cartSelects: undefined \| keyof [Cart](Cart.mdx)[] }` Transform find config object for retrieval. #### Parameters #### Returns [Omit](../types/Omit.mdx)<[FindConfig](../interfaces/FindConfig.mdx)<[Swap](Swap.mdx)>, `"select"`> & `{ select?: string[] }` & `{ cartRelations: undefined \| string[] ; cartSelects: undefined \| keyof [Cart](Cart.mdx)[] }` ___ ### update `**update**(swapId, update): Promise<[Swap](Swap.mdx)>` Update the swap record. #### Parameters #### Returns Promise<[Swap](Swap.mdx)> ___ ### withTransaction `**withTransaction**(transactionManager?): [SwapService](SwapService.mdx)` #### Parameters #### Returns [SwapService](SwapService.mdx)