SwapService
Handles swaps
Constructors
constructor
new SwapService(«destructured»
)
Parameters
Properties
__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_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
areReturnItemsValid
Protected
areReturnItemsValid(returnItems
): Promise
<boolean
>
Parameters
Returns
Promise
<boolean
>
Promise
Promise<boolean>RequiredatomicPhase_
Protected
atomicPhase_<TResult
, TError
>(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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
<TResult
>
Promise
Promise<TResult>Requiredcancel
cancel(swapId
): Promise
<Swap
>
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
Promise
<Swap
>
cancelFulfillment
cancelFulfillment(fulfillmentId
): Promise
<Swap
>
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentId
stringRequiredReturns
Promise
<Swap
>
create
create(order
, returnItems
, additionalItems?
, returnShipping?
, custom?
): Promise
<Swap
>
Creates a swap from an order, with given return items, additional items and an optional return shipping method.
Parameters
returnShipping
objectreturnShipping.option_id
stringRequiredreturnShipping.price
numbercustom
objectRequiredcustom.allow_backorder
booleancustom.idempotency_key
stringcustom.location_id
stringcustom.no_notification
booleanReturns
Promise
<Swap
>
createCart
createCart(swapId
, customShippingOptions?
, context?
): Promise
<Swap
>
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
{ option_id: string ; price: number }[]RequiredDefault: []
context
objectRequiredDefault: {}
context.sales_channel_id
stringReturns
Promise
<Swap
>
createFulfillment
createFulfillment(swapId
, config?
): Promise
<Swap
>
Fulfills the additional items associated with the swap. Will call the fulfillment providers associated with the shipping methods.
Parameters
swapId
stringRequiredReturns
Promise
<Swap
>
createShipment
createShipment(swapId
, fulfillmentId
, trackingLinks?
, config?
): Promise
<Swap
>
Marks a fulfillment as shipped and attaches tracking numbers.
Parameters
swapId
stringRequiredfulfillmentId
stringRequiredtrackingLinks
{ tracking_number: string }[]Returns
Promise
<Swap
>
deleteMetadata
deleteMetadata(swapId
, key
): Promise
<Swap
>
Dedicated method to delete metadata for a swap.
Parameters
swapId
stringRequiredkey
stringRequiredReturns
Promise
<Swap
>
list
list(selector
, config?
): Promise
<Swap
[]>
List swaps.
Parameters
Returns
Promise
<Swap
[]>
listAndCount
listAndCount(selector
, config?
): Promise
<[Swap
[], number
]>
List swaps.
Parameters
Returns
Promise
<[Swap
[], number
]>
processDifference
processDifference(swapId
): Promise
<Swap
>
Process difference for the requested swap.
Parameters
swapId
stringRequiredReturns
Promise
<Swap
>
registerCartCompletion
registerCartCompletion(swapId
): Promise
<Swap
>
Register a cart completion
Parameters
swapId
stringRequiredReturns
Promise
<Swap
>
registerReceived
registerReceived(id
): Promise
<Swap
>
Registers the swap return items as received so that they cannot be used as a part of other swaps/returns.
Parameters
id
anyRequiredReturns
Promise
<Swap
>
retrieve
retrieve(swapId
, config?
): Promise
<Swap
>
Retrieves a swap with the given id.
Parameters
swapId
stringRequiredDefault: {}
Returns
Promise
<Swap
>
retrieveByCartId
retrieveByCartId(cartId
, relations?
): Promise
<Swap
>
Retrieves a swap based on its associated cart id
Parameters
cartId
stringRequiredrelations
undefined | string[]RequiredDefault: []
Returns
Promise
<Swap
>
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleantransformQueryForCart
Protected
transformQueryForCart(config
): Omit
<FindConfig
<Swap
>, "select"
> & { select?
: string
[] } & { cartRelations
: undefined
| string
[] ; cartSelects
: undefined
| keyof Cart
[] }
Transform find config object for retrieval.
Parameters
Returns
Omit
<FindConfig
<Swap
>, "select"
> & { select?
: string
[] } & { cartRelations
: undefined
| string
[] ; cartSelects
: undefined
| keyof Cart
[] }
[`Omit`](/references/services/types/Omit)<[`FindConfig`](/references/services/interfaces/FindConfig)<[`Swap`](/references/services/classes/Swap)\>, ``"select"``\> & { `select?`: `string`[] } & { `cartRelations`: `undefined` \| `string`[] ; `cartSelects`: `undefined` \| keyof [`Cart`](/references/services/classes/Cart)[] }
Omit<FindConfig<Swap>, "select"> & { select?: string[] } & { cartRelations: undefined | string[] ; cartSelects: undefined | keyof Cart[] }update
update(swapId
, update
): Promise
<Swap
>
Update the swap record.
Parameters
Returns
Promise
<Swap
>
withTransaction
withTransaction(transactionManager?
): SwapService
Parameters
transactionManager
EntityManager