Workflows
cancelOrderWorkflow
This documentation provides a reference to thecancelOrderWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow cancels an order and handles all associated cleanup including inventory reservation deletion, payment refunds, and payout reversals. It validates that all fulfillments are canceled before proceeding and ensures data consistency across the marketplace.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/vendor/orders/[id]/cancel/route.ts
Steps
- useQueryGraphStep: Fetches the order with fulfillments, payment, and payout details.
- cancelValidateOrder: Validates that the order can be canceled (not already canceled, all fulfillments canceled).
- deleteReservationsByLineItemsStep: Removes inventory reservations for the order items.
- cancelOrdersStep: Marks the order as canceled.
- refundSplitOrderPaymentWorkflow: Refunds the payment to the customer.
- createPayoutReversalStep: Creates a reversal for any payout that was already processed.
- emitEventStep: Emits the
order.canceledevent.
Input
The order cancellation details.
Output
The ID of the canceled order.
getVendorOrdersListWorkflow
This documentation provides a reference to thegetVendorOrdersListWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow retrieves a list of orders with aggregated payment and fulfillment status. It enhances the standard order data by computing the fulfillment status based on the order’s fulfillments and their states.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/vendor/orders/route.ts
Steps
- useRemoteQueryStep: Fetches the orders with specified fields including items, fulfillments, and split payment data.
Input
The order list query parameters.
Output
Array of orders with aggregated statuses.
processPayoutForOrderWorkflow
This documentation provides a reference to theprocessPayoutForOrderWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow processes a payout for a completed order by calculating the amount after commissions, creating the payout via the payment provider, and linking it to the order. It handles both success and failure scenarios, emitting appropriate events.
Source code
Examples
- Subscriber
packages/modules/b2c-core/src/subscribers/payout-order.ts
Steps
- validateNoExistingPayoutForOrderStep: Ensures no payout has already been created for this order.
- useQueryGraphStep: Fetches the order with seller, payment, and commission details.
- validateSellerPayoutAccountStep: Validates that the seller has an active payout account.
- calculatePayoutForOrderStep: Calculates the payout amount after deducting commissions and refunds.
- createPayoutStep: Creates the payout via the payment provider.
- createRemoteLinkStep: Links the payout to the order (on success).
- emitEventStep: Emits either
payout.succeededorpayout.failedevent based on the outcome.
Input
The payout processing details.
Output
This workflow does not return a value.Steps
calculatePayoutForOrderStep
Calculates the payout amount for an order by subtracting total commissions and refunds from the captured payment amount. Source codeInput
Output
The calculated payout amount (captured_amount - refunded_amount - total_commission).
calculateTotalCommissionStep
Calculates the total commission amount for an order by summing all commission lines associated with the order’s line items. Source codeInput
Output
cancelValidateOrder
Validates that an order can be canceled. It checks that the order is not already canceled and that all fulfillments have been canceled first. Source codeInput
Output
Throws an error if validation fails.
createPayoutStep
Creates a payout via the payment provider. This step handles errors gracefully and returns both the payout result and error status. Source codeInput
The payout creation details.
Output
validateNoExistingPayoutForOrderStep
Validates that no payout has already been created for the given order. Throws an error if a payout already exists. Source codeInput
The order ID to check for existing payouts.
Output
Throws a
DUPLICATE_ERROR if a payout already exists for the order.validateSellerPayoutAccountStep
Validates that a seller has a payout account and that the account is active. Throws an error if the seller has no payout account or if the account is not active. Source codeInput
The seller to validate, including payout account details.
Output
Throws an
INVALID_DATA error if validation fails.