mercurjs/mercur
repository·main·Indexed 23 days ago
https://github.com/mercurjs/mercurAn open-source, headless marketplace platform built on top of Medusa. It provides primitives for multi-vendor commerce, including vendor onboarding, commissions, and automated payouts, to support the development of B2B or B2C marketplaces.
What's inside mercur
- Medusa is a collection of open-source commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build advanced ecommerce stores, marketplaces, and other commerce-driven applications without having to implement core commerce logic from scratch. All modules are available via npm.
What is the Split Order Payment Module?
mainThe Split Order Payment Module is a standalone package in Mercur designed for multi-vendor marketplaces. It enables tracking of payment amounts (authorized, captured, refunded) separately for each seller's portion of a multi-vendor order.
Key features include:
- Payment Tracking per Seller: Separate tracking for each seller's portion of a single cart.
- Payment Collection Association: Linking split payments to the main payment collection.
- Automatic Status Updates: Syncing split payment status with the main payment.
- Refund Management: Handling partial refunds specific to individual sellers.
- Financial Reconciliation: Accurate records for commission and payout processing.
What is Mercur
mainMercur is an open-core marketplace platform built on top of the Medusa Framework. While Medusa provides the core commerce engine (products, pricing, carts, orders, fulfillment, and events), Mercur adds a marketplace domain layer including:
- Marketplace Entities & Workflows: Sellers, onboarding, product requests, commissions, reviews, return escalations, order splitting, and vendor payouts.
- Dedicated APIs: Separate APIs for Admin, Vendor, and Storefront.
- Optional Interfaces:
- Admin Panel: For marketplace operators.
- Vendor Portal: For seller teams.
- Storefront: For marketplace consumers.
Overview of the Payout Module
mainThe Payout Module is a standalone package in Mercur that provides out-of-the-box seller payout features. It is designed to handle the lifecycle of marketplace funds moving from the platform to sellers.
Key Features:
- Payout Account Management: Create and manage seller accounts integrated with providers like Stripe Connect.
- Seller Onboarding: Manage the process for sellers to connect bank accounts.
- Automated Payouts: Automatically process payouts based on completed orders.
- Payout Reversals: Handle refunds and chargebacks.
- Webhook Integration: Process asynchronous events from payment providers to update account statuses.
Overview of the Vendor Panel features
mainThe Vendor Panel is a platform for vendors to manage their online store operations. Key functional areas include:
- Dashboard: Monitor store performance and key metrics.
- Company Profile: Manage business and company details.
- Orders Management: Track order status, fulfillment, and process order updates.
- Product Management: Create listings, organize collections/categories, and manage pricing and descriptions.
- Inventory Control: Track stock levels and manage inventory reservations.
- Customer Management: View customer history, manage groups, and monitor reviews.
- Promotions and Marketing: Create campaigns, special offers, discounts, and segment-specific price lists.
- Messaging: A TalkJS-based system for communicating with customers and tracking conversation history.
Compare Mercur vs Mirakl
mainMercur is an open-source (MIT licensed) marketplace platform designed as an alternative to closed-source SaaS providers like Mirakl.
Key differentiators include:
- Ownership: Mercur provides full source code access and data ownership, whereas Mirakl is proprietary and vendor-controlled.
- Pricing: Mercur has no GMV (Gross Merchandise Volume) fees or per-transaction cuts. Mirakl typically charges a percentage of GMV plus platform fees.
- Hosting: Mercur can be self-hosted on any infrastructure (including on-prem or air-gapped networks) or used via fully managed services (Medusa Cloud or Rigby-hosted). Mirakl is vendor-hosted SaaS only.
- Extensibility: Mercur is built on a composable architecture (TypeScript, Node.js, React, PostgreSQL) allowing for deep customization of workflows, APIs, and UI. Mirakl is limited to configuration within platform constraints.
- Speed to Market: Mercur can be initialized in minutes using
bun create mercur-app.
Identify the correct Mercur API surface
mainMercur exposes three distinct HTTP surfaces on the Medusa server. Choose the surface based on your target audience and required permissions:
- Admin API (
/admin/*): For marketplace operators. Requires Medusa admin authentication (session or bearer token). - Vendor API (
/vendor/*): For sellers. Requires member authentication and is scoped to a specific seller via thex-seller-idheader or a session-selected seller. This surface automatically filters all queries and mutations to the selected seller. - Store API (
/store/*): For storefronts. Mostly public. Customer authentication is required for/store/order-groupsand optional for routes like/store/offers,/store/products, and/store/searchto enrich pricing context.
All requests and responses use JSON. It is highly recommended to use the typed
@mercurjs/clientfor all calls.- Admin API (
Use the Marketplace Module for multi-vendor order management
mainThe Marketplace Module provides out-of-the-box features for managing multi-vendor commerce. Key features include:
- Order Set Management: Grouping multiple vendor orders from a single customer checkout into an
OrderSetfor unified tracking. - Multi-Vendor Order Tracking: Associating multiple orders with a single cart and payment collection.
- Order Aggregation: Calculating aggregated totals, status, and fulfillment information across all orders in a set.
- Unified Customer View: Providing customers with a single view of multi-vendor orders while maintaining individual records per seller.
In Mercur, you interact with these features by building Workflows using pre-built workflows provided in the
@mercurjs/b2c-corepackage.- Order Set Management: Grouping multiple vendor orders from a single customer checkout into an
Project Structure of the Mercur Basic Template
mainThe Mercur Basic Template is a monorepo managed by Turborepo. The core structure is as follows:
apps/admin/: Admin dashboard extensions.apps/vendor/: Vendor portal extensions.packages/api/: The core backend (based on Medusa) containing:src/api/: Custom API routes.src/jobs/: Background jobs.src/links/: Module links.src/modules/: Custom modules.src/scripts/: CLI scripts.src/subscribers/: Event subscribers.src/workflows/: Business workflows.medusa-config.ts: Backend configuration.
blocks.json: Configuration for Mercur blocks.turbo.json: Turborepo configuration.
├── apps/ │ ├── admin/ # Admin dashboard extensions │ └── vendor/ # Vendor portal extensions ├── packages/ │ └── api/ # Medusa backend │ ├── src/ │ │ ├── api/ # Custom API routes │ │ ├── jobs/ # Background jobs │ │ ├── links/ # Module links │ │ ├── modules/ # Custom modules │ │ ├── scripts/ # CLI scripts │ │ ├── subscribers/ # Event subscribers │ │ └── workflows/ # Business workflows │ └── medusa-config.ts ├── blocks.json # Mercur blocks configuration ├── package.json └── turbo.jsonUnderstand Medusa commerce modules
mainMedusa is a collection of open-source commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build advanced ecommerce stores, marketplaces, or other commerce-driven applications without having to reimplement core commerce logic. All modules are available via npm and can be customized to fit specific business needs.Use ICommissionModuleService for complex customizations
mainThe
ICommissionModuleServiceinterface provides low-level access to the Commission Module's functionalities. It is intended for developers implementing complex customizations. For standard use cases, you should use the available built-in workflows instead.The interface is organized into several method groups:
Commission Rule Methods
Methods for managing rules:
createCommissionRules,updateCommissionRules,deleteCommissionRules,retrieveCommissionRule,listCommissionRules,listAndCountCommissionRules,softDeleteCommissionRules, andrestoreCommissionRules.Commission Rate Methods
Methods for managing rates:
createCommissionRates,updateCommissionRates,deleteCommissionRates,retrieveCommissionRate,listCommissionRates,listAndCountCommissionRates,softDeleteCommissionRates, andrestoreCommissionRates.Commission Line Methods
Methods for managing lines:
createCommissionLines,updateCommissionLines,deleteCommissionLines,retrieveCommissionLine,listCommissionLines,listAndCountCommissionLines,softDeleteCommissionLines, andrestoreCommissionLines.Custom Methods
Includes specialized logic like
selectCommissionForProductLine.Summary of Seller Module links
mainThe Seller Module maintains several stored links to other Commerce Modules to associate sellers with their respective data models. These include:
Second Data Model Type Description Product Stored - one-to-many Associates a seller with their products Order Stored - one-to-many Associates a seller with their orders Return Stored - one-to-many Associates a seller with order returns PayoutAccount Stored - one-to-one Associates a seller with their payout account StockLocation Stored - one-to-many Associates a seller with their stock locations FulfillmentSet Stored - one-to-many Associates a seller with their fulfillment sets ServiceZone Stored - one-to-many Associates a seller with their service zones ShippingOption Stored - one-to-many Associates a seller with their shipping options ShippingProfile Stored - one-to-many Associates a seller with their shipping profiles InventoryItem Stored - one-to-many Associates a seller with their inventory items CustomerGroup Stored - one-to-many Associates a seller with their customer groups PriceList Stored - one-to-many Associates a seller with their price lists Promotion Stored - one-to-many Associates a seller with their promotions Campaign Stored - one-to-many Associates a seller with their campaigns