SwapService
Handles swaps
constructor
Parameters
__namedParametersInjectedPropsRequiredProperties
__container__anyRequiredmanager_EntityManagerRequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredDefault: "swap.created"
Events.FULFILLMENT_CREATEDstringRequiredDefault: "swap.fulfillment_created"
Events.PAYMENT_CAPTUREDstringRequiredDefault: "swap.payment_captured"
Events.PAYMENT_CAPTURE_FAILEDstringRequiredDefault: "swap.payment_capture_failed"
Events.PAYMENT_COMPLETEDstringRequiredDefault: "swap.payment_completed"
Events.PROCESS_REFUND_FAILEDstringRequiredDefault: "swap.process_refund_failed"
Events.RECEIVEDstringRequiredDefault: "swap.received"
Events.REFUND_PROCESSEDstringRequiredDefault: "swap.refund_processed"
Events.SHIPMENT_CREATEDstringRequiredDefault: "swap.shipment_created"
__configModule__Record<string, unknown>__moduleDeclaration__Record<string, unknown>Accessors
activeManager_
Returns
EntityManagerEntityManagerRequiredMethods
areReturnItemsValid
Parameters
Returns
PromisePromise<boolean>RequiredatomicPhase_
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
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
PromisePromise<TResult>Requiredcancel
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
swapIdstringRequiredReturns
cancelFulfillment
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentIdstringRequiredReturns
create
Creates a swap from an order, with given return items, additional items and an optional return shipping method.
Parameters
returnShipping.option_idstringRequiredcustomobjectRequiredadditionalItemsPick<LineItem, "variant_id" | "quantity">[]returnShippingobjectreturnShipping.pricenumbercustom.allow_backorderbooleancustom.idempotency_keystringcustom.location_idstringcustom.no_notificationbooleanReturns
createCart
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
swapIdstringRequiredcustomShippingOptionsobject[]RequiredDefault: []
contextobjectRequiredDefault: {}
context.sales_channel_idstringReturns
createFulfillment
Fulfills the additional items associated with the swap. Will call the fulfillment providers associated with the shipping methods.
Parameters
swapIdstringRequiredconfigCreateShipmentConfigRequiredReturns
createShipment
Marks a fulfillment as shipped and attaches tracking numbers.
Parameters
swapIdstringRequiredfulfillmentIdstringRequiredconfigCreateShipmentConfigRequiredtrackingLinksobject[]Returns
deleteMetadata
Dedicated method to delete metadata for a swap.
Parameters
swapIdstringRequiredkeystringRequiredReturns
list
List swaps.
Parameters
Returns
listAndCount
List swaps.
Parameters
Returns
processDifference
Process difference for the requested swap.
Parameters
swapIdstringRequiredReturns
registerCartCompletion
Register a cart completion
Parameters
swapIdstringRequiredReturns
registerReceived
Registers the swap return items as received so that they cannot be used as a part of other swaps/returns.
Parameters
idanyRequiredReturns
retrieve
Retrieves a swap with the given id.
Parameters
swapIdstringRequiredDefault: {}
Returns
retrieveByCartId
Retrieves a swap based on its associated cart id
Parameters
cartIdstringRequiredrelationsundefined | string[]RequiredDefault: []
Returns
shouldRetryTransaction_
Parameters
errRecord<string, unknown> | objectRequiredReturns
booleanbooleanRequiredtransformQueryForCart
Transform find config object for retrieval.
Parameters
Returns
cartRelationsundefined | string[]Requiredselectstring[]update
Update the swap record.
Parameters
swapIdstringRequiredReturns
withTransaction
Parameters
transactionManagerEntityManagerReturns
thisthisRequired