The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
@mercurjs/magento2-connector-plugin
Server-side half of the Mercur Magento 2 connector. Pairs with the
mercurjs/magento2-connector Composer package installed in Magento.
It adds to a Mercur API:
- Outbound webhooks (
magento_webhookmodule): register endpoints under/admin/magento/webhooks, pick the events to receive, and Mercur POSTs each event with an HMAC-SHA256 signature inx-mercur-signature. Failed deliveries retry on a 1m / 5m / 30m / 2h / 12h ladder, then stop. - External payment provider (
pp_external_external): lets a storefront that already captured the customer's payment complete a Mercur cart with the captured amount, so split orders, commission lines, and payouts run on real numbers without Mercur charging anything. - External refunds:
POST /admin/magento/orders/:id/refunds/externalmirrors a refund that happened in the storefront onto the Mercur order.
Install
// medusa-config.ts
module.exports = withMercur({
plugins: [{ resolve: "@mercurjs/magento2-connector-plugin", options: {} }],
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "@mercurjs/magento2-connector-plugin/providers/payment-external",
id: "external",
},
],
},
},
],
})
Run medusa db:migrate afterwards.
Checkout from an external storefront
POST /store/cartswithregion_idandsales_channel_id.POST /store/carts/:id/line-itemswith{ offer_id, quantity }per line.POST /store/carts/:idwith email and addresses.GET /store/shipping-options?cart_id=then onePOST /store/carts/:id/shipping-methodsper seller.POST /store/payment-collectionsandPOST /store/payment-collections/:id/payment-sessionswith{ provider_id: "pp_external_external", data: { reference, channel } }. The session is authorized, not captured. Passcaptured_atonly when the storefront already settled the payment.POST /store/carts/:id/complete. Theorder_groupin the response lists its childorderswith each one'sseller, so the storefront can map its lines to seller orders without further calls.- When the storefront invoices the order,
POST /admin/magento/order-groups/:id/payments/capture(optional{ reference }). Mercur captures the cart payment once, splits it between the child orders, and emitsorder.payment_captured. Calling it again is a no-op. If the storefront cancels before invoicing,POST /admin/magento/order-groups/:id/payments/cancelcancels every child order and voids the authorization.
Put metadata.channel on the cart in step 1; it is copied onto the order
group and every child order.