SwapService
Handles swaps
constructor
Parameters
__namedParameters
InjectedPropsRequiredProperties
manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequired__container__
anyRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "swap.created"
Events.RECEIVED
stringRequiredDefault: "swap.received"
Events.SHIPMENT_CREATED
stringRequiredDefault: "swap.shipment_created"
Events.PAYMENT_COMPLETED
stringRequiredDefault: "swap.payment_completed"
Events.PAYMENT_CAPTURED
stringRequiredDefault: "swap.payment_captured"
Events.PAYMENT_CAPTURE_FAILED
stringRequiredDefault: "swap.payment_capture_failed"
Events.PROCESS_REFUND_FAILED
stringRequiredDefault: "swap.process_refund_failed"
Events.REFUND_PROCESSED
stringRequiredDefault: "swap.refund_processed"
Events.FULFILLMENT_CREATED
stringRequiredDefault: "swap.fulfillment_created"
__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
withTransaction
Parameters
transactionManager
EntityManagerReturns
this
thisRequiredshouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredatomicPhase_
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>RequiredtransformQueryForCart
Transform find config object for retrieval.
Parameters
Returns
cartRelations
undefined | string[]Requiredselect
string[]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
list
List swaps.
Parameters
Returns
listAndCount
List swaps.
Parameters
Returns
create
Creates a swap from an order, with given return items, additional items and an optional return shipping method.
Parameters
returnShipping.option_id
stringRequiredcustom
objectRequiredadditionalItems
Pick<LineItem, "variant_id" | "quantity">[]returnShipping
objectreturnShipping.price
numbercustom.no_notification
booleancustom.idempotency_key
stringcustom.allow_backorder
booleancustom.location_id
stringReturns
processDifference
Process difference for the requested swap.
Parameters
swapId
stringRequiredReturns
update
Update the swap record.
Parameters
swapId
stringRequiredReturns
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
registerCartCompletion
Register a cart completion
Parameters
swapId
stringRequiredReturns
cancel
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
createFulfillment
Fulfills the additional items associated with the swap. Will call the fulfillment providers associated with the shipping methods.
Parameters
swapId
stringRequiredconfig
CreateShipmentConfigRequiredReturns
cancelFulfillment
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentId
stringRequiredReturns
createShipment
Marks a fulfillment as shipped and attaches tracking numbers.
Parameters
swapId
stringRequiredfulfillmentId
stringRequiredconfig
CreateShipmentConfigRequiredtrackingLinks
object[]Returns
deleteMetadata
Dedicated method to delete metadata for a swap.
Parameters
swapId
stringRequiredkey
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
areReturnItemsValid
Parameters
Returns
Promise
Promise<boolean>Required