SwapService
Handles swaps
constructor
Parameters
__namedParameters
InjectedPropsRequiredProperties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "swap.created"
Events.FULFILLMENT_CREATED
stringRequiredDefault: "swap.fulfillment_created"
Events.PAYMENT_CAPTURED
stringRequiredDefault: "swap.payment_captured"
Events.PAYMENT_CAPTURE_FAILED
stringRequiredDefault: "swap.payment_capture_failed"
Events.PAYMENT_COMPLETED
stringRequiredDefault: "swap.payment_completed"
Events.PROCESS_REFUND_FAILED
stringRequiredDefault: "swap.process_refund_failed"
Events.RECEIVED
stringRequiredDefault: "swap.received"
Events.REFUND_PROCESSED
stringRequiredDefault: "swap.refund_processed"
Events.SHIPMENT_CREATED
stringRequiredDefault: "swap.shipment_created"
Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
areReturnItemsValid
Parameters
Returns
Promise
Promise<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
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
Promise<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
swapId
stringRequiredReturns
cancelFulfillment
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentId
stringRequiredReturns
create
Creates a swap from an order, with given return items, additional items and an optional return shipping method.
Parameters
additionalItems
Pick<LineItem, "variant_id" | "quantity">[]returnShipping
objectreturnShipping.option_id
stringRequiredreturnShipping.price
numbercustom
objectRequiredcustom.allow_backorder
booleancustom.idempotency_key
stringcustom.location_id
stringcustom.no_notification
booleanReturns
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
swapId
stringRequiredcustomShippingOptions
object[]RequiredDefault: []
context
objectRequiredDefault: {}
context.sales_channel_id
stringReturns
createFulfillment
Fulfills the additional items associated with the swap. Will call the fulfillment providers associated with the shipping methods.
Parameters
swapId
stringRequiredconfig
CreateShipmentConfigRequiredReturns
createShipment
Marks a fulfillment as shipped and attaches tracking numbers.
Parameters
swapId
stringRequiredfulfillmentId
stringRequiredtrackingLinks
object[]config
CreateShipmentConfigRequiredReturns
deleteMetadata
Dedicated method to delete metadata for a swap.
Parameters
swapId
stringRequiredkey
stringRequiredReturns
list
List swaps.
Parameters
Returns
listAndCount
List swaps.
Parameters
Returns
processDifference
Process difference for the requested swap.
Parameters
swapId
stringRequiredReturns
registerCartCompletion
Register a cart completion
Parameters
swapId
stringRequiredReturns
registerReceived
Registers the swap return items as received so that they cannot be used as a part of other swaps/returns.
Parameters
id
anyRequiredReturns
retrieve
Retrieves a swap with the given id.
Parameters
swapId
stringRequiredDefault: {}
Returns
retrieveByCartId
Retrieves a swap based on its associated cart id
Parameters
cartId
stringRequiredrelations
undefined | string[]RequiredDefault: []
Returns
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleantransformQueryForCart
Transform find config object for retrieval.
Parameters
Returns
Omit<FindConfig<Swap>, "select"> & object & object
Omit<FindConfig<Swap>, "select"> & object & objectupdate
Update the swap record.
Parameters
swapId
stringRequiredReturns
withTransaction
Parameters
transactionManager
EntityManagerReturns
SwapService
objectRequired