SwapService
Handles swaps
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredEvents.FULFILLMENT_CREATED
stringRequiredEvents.PAYMENT_CAPTURED
stringRequiredEvents.PAYMENT_CAPTURE_FAILED
stringRequiredEvents.PAYMENT_COMPLETED
stringRequiredEvents.PROCESS_REFUND_FAILED
stringRequiredEvents.RECEIVED
stringRequiredEvents.REFUND_PROCESSED
stringRequiredEvents.SHIPMENT_CREATED
stringRequiredAccessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
areReturnItemsValid
Protected
areReturnItemsValid(returnItems
): Promise
<boolean
>
Parameters
Returns
Promise
<boolean
>
Promise
Promise<boolean>Required
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>RequiredInherited from
TransactionBaseService.atomicPhase_
cancel
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
>
the canceled swap.
cancelFulfillment
cancelFulfillment(fulfillmentId
): Promise
<Swap
>
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentId
stringRequiredReturns
Promise
<Swap
>
updated 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
objectcustom.allow_backorder
booleancustom.idempotency_key
stringcustom.location_id
stringcustom.no_notification
booleanReturns
Promise
<Swap
>
the newly created 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 }[]context
objectcontext.sales_channel_id
stringReturns
Promise
<Swap
>
the swap with its cart_id prop set to the id of the new cart.
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
stringRequiredconfig
CreateShipmentConfigReturns
Promise
<Swap
>
the updated swap with new status and fulfillments.
createShipment
createShipment(swapId
, fulfillmentId
, trackingLinks?
, config?
): Promise
<Swap
>
Marks a fulfillment as shipped and attaches tracking numbers.
Parameters
swapId
stringRequiredfulfillmentId
stringRequiredtrackingLinks
{ tracking_number: string }[]config
CreateShipmentConfigReturns
Promise
<Swap
>
the updated swap with new fulfillments and status.
deleteMetadata
deleteMetadata(swapId
, key
): Promise
<Swap
>
Dedicated method to delete metadata for a swap.
Parameters
swapId
stringRequiredkey
stringRequiredReturns
Promise
<Swap
>
resolves to the updated result.
list
list(selector
, config?
): Promise
<Swap
[]>
List swaps.
Parameters
config
FindConfig<Swap>Returns
Promise
<Swap
[]>
the result of the find operation
listAndCount
listAndCount(selector
, config?
): Promise
<[Swap
[], number
]>
List swaps.
Parameters
config
FindConfig<Swap>Returns
Promise
<[Swap
[], number
]>
the result of the find operation
processDifference
processDifference(swapId
): Promise
<Swap
>
Process difference for the requested swap.
Parameters
swapId
stringRequiredReturns
Promise
<Swap
>
processed swap
registerCartCompletion
registerCartCompletion(swapId
): Promise
<Swap
>
Register a cart completion
Parameters
swapId
stringRequiredReturns
Promise
<Swap
>
swap related to the cart
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
>
the resulting order
retrieve
retrieve(swapId
, config?
): Promise
<Swap
>
Retrieves a swap with the given id.
Parameters
swapId
stringRequiredconfig
Omit<FindConfig<Swap>, "select"> & { select?: string[] }Returns
Promise
<Swap
>
the swap
retrieveByCartId
retrieveByCartId(cartId
, relations?
): Promise
<Swap
>
Retrieves a swap based on its associated cart id
Parameters
cartId
stringRequiredrelations
string[]Returns
Promise
<Swap
>
the swap
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited from
TransactionBaseService.shouldRetryTransaction_
transformQueryForCart
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/js-client/admin_auth/modules/admin_auth.internal#omit)<[`FindConfig`](/references/js-client/internal/interfaces/admin_discounts.internal.internal.FindConfig)<[`Swap`](/references/js-client/internal/classes/admin_collections.internal.Swap)\>, ``"select"``\> & { `select?`: `string`[] } & { `cartRelations`: `undefined` \| `string`[] ; `cartSelects`: `undefined` \| keyof [`Cart`](/references/js-client/internal/classes/admin_collections.internal.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
>
updated swap record
withTransaction
withTransaction(transactionManager?
): SwapService
Parameters
transactionManager
EntityManager