SwapService
Handles swaps
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>manager_EntityManagerRequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredEvents.FULFILLMENT_CREATEDstringRequiredEvents.PAYMENT_CAPTUREDstringRequiredEvents.PAYMENT_CAPTURE_FAILEDstringRequiredEvents.PAYMENT_COMPLETEDstringRequiredEvents.PROCESS_REFUND_FAILEDstringRequiredEvents.RECEIVEDstringRequiredEvents.REFUND_PROCESSEDstringRequiredEvents.SHIPMENT_CREATEDstringRequiredAccessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
areReturnItemsValid
Protected areReturnItemsValid(returnItems): Promise<boolean>
Parameters
Returns
Promise<boolean>
PromisePromise<boolean>Required
PromisePromise<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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<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
swapIdstringRequiredReturns
Promise<Swap>
the canceled swap.
cancelFulfillment
cancelFulfillment(fulfillmentId): Promise<Swap>
Cancels a fulfillment (if related to a swap)
Parameters
fulfillmentIdstringRequiredReturns
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
returnShippingobjectreturnShipping.option_idstringRequiredreturnShipping.pricenumbercustomobjectcustom.allow_backorderbooleancustom.idempotency_keystringcustom.location_idstringcustom.no_notificationbooleanReturns
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
swapIdstringRequiredcustomShippingOptions{ option_id: string ; price: number }[]contextobjectcontext.sales_channel_idstringReturns
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
swapIdstringRequiredconfigCreateShipmentConfigReturns
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
swapIdstringRequiredfulfillmentIdstringRequiredtrackingLinks{ tracking_number: string }[]configCreateShipmentConfigReturns
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
swapIdstringRequiredkeystringRequiredReturns
Promise<Swap>
resolves to the updated result.
list
list(selector, config?): Promise<Swap[]>
List swaps.
Parameters
configFindConfig<Swap>Returns
Promise<Swap[]>
the result of the find operation
listAndCount
listAndCount(selector, config?): Promise<[Swap[], number]>
List swaps.
Parameters
configFindConfig<Swap>Returns
Promise<[Swap[], number]>
the result of the find operation
processDifference
processDifference(swapId): Promise<Swap>
Process difference for the requested swap.
Parameters
swapIdstringRequiredReturns
Promise<Swap>
processed swap
registerCartCompletion
registerCartCompletion(swapId): Promise<Swap>
Register a cart completion
Parameters
swapIdstringRequiredReturns
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
idanyRequiredReturns
Promise<Swap>
the resulting order
retrieve
retrieve(swapId, config?): Promise<Swap>
Retrieves a swap with the given id.
Parameters
swapIdstringRequiredconfigOmit<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
cartIdstringRequiredrelationsstring[]Returns
Promise<Swap>
the swap
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanInherited 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
transactionManagerEntityManager