Core Subscribers Reference
Subscribers are functions that handle events emitted in the Medusa application, allowing you to execute custom logic in response to system events. They enable event-driven architecture by reacting to changes in your commerce system, such as order placements, payment captures, or data updates. Learn more about subscribers in the Medusa documentation.Payout Subscribers
payout-order-handler
Processes payouts for orders when a payout event is received. Event:payout.received (PayoutWorkflowEvents.RECEIVED)Source:
packages/modules/b2c-core/src/subscribers/payout-order.ts
Functionality
When thepayout.received event is triggered, this subscriber:
- Receives the order ID from the event payload
- Executes the
processPayoutForOrderWorkflowto create and process the payout - Uses the order ID as a transaction ID for idempotency
Event Payload
Use Cases
- Automated payout processing triggered by scheduled jobs
- Manual payout retries for failed orders
- Catch-up processing for orders missing payouts
payout-webhook-handler
Handles webhook events from payment providers for payout account updates. Event:payout_account.webhook_received (PayoutWebhookEvents.ACCOUNT_WEBHOOK_RECEIVED)Source:
packages/modules/b2c-core/src/subscribers/payout-webhook.ts
Functionality
When webhook events are received from payment providers, this subscriber:- Deserializes the webhook data (handles Buffer serialization)
- Uses the payout service to parse and validate the webhook
- Determines the appropriate action (account authorized, deauthorized, requires action)
- Executes the
processPayoutWebhookActionWorkflowwith the parsed data
Event Payload
Use Cases
- Stripe Connect account status updates
- Payment provider webhook processing
- Payout account authorization changes
- Account requirement notifications
Order and Payment Subscribers
order-set-placed-payment-capture
Captures payment when an order set is placed with multiple seller orders. Event:order_set.placed (OrderSetWorkflowEvents.PLACED)Source:
packages/modules/b2c-core/src/subscribers/order-set-placed-payment-capture.ts
Functionality
When an order set is placed, this subscriber:- Retrieves the order set and associated payment collection
- Validates that payment exists
- Executes the
capturePaymentWorkflowto capture the payment - Marks all split order payments as captured via
markSplitOrderPaymentsAsCapturedWorkflow - Throws an error if payment capture fails
Event Payload
Use Cases
- Multi-seller order payment capture
- Split payment processing
- Payment validation and error handling
split-payment-payment-captured
Updates split order payment status when a payment is captured. Event:payment.captured (PaymentEvents.CAPTURED)Source:
packages/modules/b2c-core/src/subscribers/split-payment-payment-captured.ts
Functionality
When a payment is captured, this subscriber:- Retrieves the payment and its associated payment collection
- Executes the
markSplitOrderPaymentsAsCapturedWorkflowto update all related split order payments
Event Payload
Use Cases
- Synchronizing split payment statuses
- Tracking payment capture across multiple seller orders
- Maintaining payment consistency
Notification Subscribers
notification-seller-new-order
Sends notifications to sellers when they receive a new order. Event:order.placed (OrderWorkflowEvents.PLACED)Source:
packages/modules/b2c-core/src/subscribers/notification-seller-new-order.ts
Functionality
When an order is placed, this subscriber:- Retrieves order details including seller and customer information
- Validates that the order and seller email exist
- Creates a notification in the seller feed
- Includes order ID and customer name in the notification
Event Payload
Use Cases
- Seller order notifications
- In-app notification feed updates
- Email notifications to sellers
- Order management alerts
notification-admin-new-order-set
Notifies admins when a customer places an order from multiple sellers. Event:order_set.placed (OrderSetWorkflowEvents.PLACED)Source:
packages/modules/b2c-core/src/subscribers/notification-admin-new-order-set.ts
Functionality
When an order set is placed, this subscriber:- Retrieves the order set and counts the number of orders
- Only proceeds if the order set contains 2 or more orders (multi-seller)
- Creates an admin UI notification
- Includes a redirect link to the orders page
Event Payload
Use Cases
- Admin dashboard notifications
- Multi-seller order monitoring
- Order management alerts
- Administrative oversight
Seller Management Subscribers
seller-creation-request-accepted
Creates a seller account when a seller registration request is accepted. Event:requests.seller.accepted (SellerAccountRequestUpdatedEvent.ACCEPTED)Source:
packages/modules/b2c-core/src/subscribers/seller-creation-request-accepted.ts
Functionality
When a seller creation request is accepted, this subscriber:- Extracts seller, member, and authentication data from the request
- Executes the
createSellerWorkflowto create the seller account - Logs the successful creation with seller and request IDs
Event Payload
Use Cases
- Automated seller onboarding
- Request approval workflow completion
- Seller account provisioning
seller-status-changed
Updates product search indexes when a seller’s status changes. Event:seller.store_status_changed (SellerEvents.STORE_STATUS_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/seller-status-changed.ts
Functionality
When a seller’s store status changes, this subscriber:- Retrieves all products associated with the seller
- Emits an
algolia.products.changedevent with the product IDs - Skips processing if the seller has no products
Event Payload
Use Cases
- Search index synchronization
- Product visibility updates
- Store status propagation
- Marketplace product filtering
Algolia Search Index Subscribers
These subscribers maintain search index synchronization by listening to intermediate events and triggering Algolia product updates.algolia-fulfillment-set-changed
Updates product indexes when fulfillment set configurations change. Event:algolia.intermediate.fulfillment_set.changed (IntermediateEvents.FULFULLMENT_SET_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/algolia-fulfillment-set-changed.ts
Functionality
- Retrieves the seller associated with the fulfillment set
- Fetches all products belonging to that seller
- Emits
algolia.products.changedevent to update product indexes
algolia-inventory-item-changed
Updates product indexes when inventory levels change. Event:algolia.intermediate.inventory_item.changed (IntermediateEvents.INVENTORY_ITEM_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/algolia-inventory-item.changed.ts
Functionality
- Retrieves inventory items and their associated product variants
- Extracts unique product IDs from variants
- Emits
algolia.products.changedevent to update product indexes
algolia-service-zone-changed
Updates product indexes when service zone configurations change. Event:algolia.intermediate.service_zone.changed (IntermediateEvents.SERVICE_ZONE_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/algolia-service-zone-changed.ts
Functionality
- Retrieves the seller associated with the service zone
- Fetches all products belonging to that seller
- Emits
algolia.products.changedevent to update product indexes
algolia-shipping-option-changed
Updates product indexes when shipping option configurations change. Event:algolia.intermediate.shipping_option.changed (IntermediateEvents.SHIPPING_OPTION_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/algolia-shipping-option-changed.ts
Functionality
- Retrieves the seller associated with the shipping option
- Fetches all products belonging to that seller
- Emits
algolia.products.changedevent to update product indexes
algolia-stock-location-changed
Updates product indexes when stock location configurations change. Event:algolia.intermediate.stock_location.changed (IntermediateEvents.STOCK_LOCATION_CHANGED)Source:
packages/modules/b2c-core/src/subscribers/algolia-stock-location-changed.ts
Functionality
- Retrieves the seller associated with the stock location
- Fetches all products belonging to that seller
- Emits
algolia.products.changedevent to update product indexes
Notes
Event-Driven Architecture
Subscribers implement an event-driven architecture pattern:- Decoupling: Workflows emit events without knowing who will handle them
- Scalability: Multiple subscribers can react to the same event
- Reliability: Event bus handles retries and delivery guarantees
- Extensibility: New subscribers can be added without modifying existing code
Subscriber Configuration
Each subscriber exports a configuration object with:- event: The event name to listen for
- subscriberId: A unique identifier for the subscriber
- context: Optional metadata for the subscriber
Error Handling
Subscribers should implement appropriate error handling:- Failed subscribers are automatically retried based on event bus configuration
- Critical failures should be logged for monitoring
- Validation errors should return early to avoid unnecessary processing
Algolia Synchronization Pattern
The Algolia subscribers use an intermediate events pattern:- Intermediate Events: Emitted when shipping, inventory, or fulfillment data changes
- Subscriber Processing: Identifies affected products
- Product Events: Emits consolidated
algolia.products.changedevents - Index Updates: Separate Algolia module subscriber handles actual index updates
Performance Considerations
- Subscribers run asynchronously and don’t block the main application flow
- Heavy operations should be delegated to workflows for better error recovery
- Batch operations where possible (e.g., processing multiple product IDs at once)
- Use early returns to skip unnecessary processing