Documentation Index Fetch the complete documentation index at: https://docs.mercurjs.com/llms.txt
Use this file to discover all available pages before exploring further.
Workflows
processPayoutWebhookActionWorkflow
This documentation provides a reference to the processPayoutWebhookActionWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow processes webhook events from the payout provider (e.g., Stripe Connect) and takes appropriate actions based on the webhook type. Currently, it handles account authorization events by updating the payout account status to active.
Source code
Examples
packages/modules/b2c-core/src/subscribers/payout-webhook.ts
import { SubscriberArgs , SubscriberConfig } from "@medusajs/framework" ;
import {
PayoutWebhookActionPayload ,
PayoutWebhookEvents ,
} from "@mercurjs/framework" ;
import { PAYOUT_MODULE } from "../modules/payout" ;
import { PayoutModuleService } from "../modules/payout" ;
import { processPayoutWebhookActionWorkflow } from "../workflows/payout/workflows" ;
export default async function payoutWebhookHandler ({
event ,
container ,
} : SubscriberArgs < PayoutWebhookActionPayload >) {
const payoutService : PayoutModuleService = container . resolve ( PAYOUT_MODULE );
const input = event . data ;
// Parse webhook data
const actionAndData = await payoutService . getWebhookActionAndData ( input );
if ( ! actionAndData ) {
return ;
}
await processPayoutWebhookActionWorkflow ( container ). run ({
input: {
action: actionAndData . action ,
data: actionAndData . data ,
},
});
}
export const config : SubscriberConfig = {
event: PayoutWebhookEvents . ACCOUNT_WEBHOOK_RECEIVED ,
context: {
subscriberId: "payout-account-webhook-handler" ,
},
};
Steps
The webhook action and data. action
PayoutWebhookAction
required
The webhook action type. Available actions:
account_authorized - Account has been authorized and is ready to receive payouts
account_deauthorized - Account has been deauthorized
account_requires_action - Account requires additional action from the seller
The webhook payload data. The ID of the payout account.
Output
This workflow does not return a value.
Steps
createPayoutReversalStep
Creates a reversal (refund) for a payout that was previously processed. This is typically used when an order is canceled after the seller has already been paid out. The step handles errors gracefully and returns both the reversal result and error status.
Source code
Examples
packages/modules/b2c-core/src/workflows/order/workflows/cancel-order.ts
import { createPayoutReversalStep } from '../../payout/steps'
// ... inside cancelOrderWorkflow
const payoutId = transform ({ order }, ({ order }) => {
return order . payouts && order . payouts [ 0 ] ? order . payouts [ 0 ]. id : null
})
parallelize (
// ... other steps
createPayoutReversalStep ({
payout_id: payoutId ,
amount: order . split_order_payment . captured_amount ,
currency_code: order . currency_code
})
)
The payout reversal details. The ID of the payout to reverse. If null, the step does nothing.
The currency code (e.g., “usd”).
Output
The created payout reversal, or null if creation failed or payout_id was null.
Whether an error occurred during reversal creation.
updatePayoutAccountStep
Updates a payout account’s details. This step includes a compensation function that restores the previous account state if a subsequent step in the workflow fails, ensuring data consistency.
Source code
Examples
packages/modules/b2c-core/src/workflows/payout/workflows/process-payout-webhook-action.ts
import { PayoutAccountStatus , PayoutWebhookAction } from "@mercurjs/framework" ;
import { updatePayoutAccountStep } from '../steps'
// ... inside processPayoutWebhookActionWorkflow
when (
{ action: input . action },
({ action }) => action === PayoutWebhookAction . ACCOUNT_AUTHORIZED
). then (() => {
updatePayoutAccountStep ({
id: input . data . account_id ,
status: PayoutAccountStatus . ACTIVE
})
})
input
UpdatePayoutAccountDTO
required
The payout account updates. The ID of the payout account to update.
The new status of the payout account. Available statuses:
pending - Account is pending authorization
active - Account is active and can receive payouts
disabled - Account is disabled
The external reference ID from the payment provider.
Additional data about the payout account.
Output
The updated payout account. The ID of the payout account.
The external reference ID from the payment provider.
The status of the payout account.
Additional provider-specific data.
The date the account was created.
The date the account was last updated.