Framework
When a sales document needs a delivery price or a payment option, a sales provider can supply it. Register the provider under a stable identifier, then check the method available to an operator on a quote or order.
The sales module now discovers shipping and payment providers so modules can plug in custom pricing and checkout flows without forking core logic.
Providers are registered at module load time and exposed on both the backend (for calculations) and the admin UI (for configuration forms).
// src/modules/your-module/index.ts
import { registerPaymentProvider } from '@open-mercato/core/modules/sales/lib/providers'
registerPaymentProvider({
key: 'your-gateway',
label: 'Your Gateway',
description: 'Redirects buyers to your hosted checkout.',
settings: {
// Optional UI schema rendered in admin forms
fields: [
{ key: 'checkoutUrl', label: 'Checkout URL', type: 'url', required: true },
{ key: 'apiKey', label: 'API key', type: 'secret' },
],
// Optional validation for providerSettings
schema: z.object({
checkoutUrl: z.string().url(),
apiKey: z.string().min(1).optional(),
}),
},
// Optional hook: return surcharge adjustments (kind defaults to "surcharge")
async calculate({ document, context, settings }) {
const fee = Number(settings.applicationFee ?? 0)
if (!fee) return { adjustments: [] }
return {
adjustments: [
{
amountNet: fee,
amountGross: fee,
currencyCode: context.currencyCode,
metadata: { applied: true },
},
],
}
},
})
Shipping providers follow the same shape via registerShippingProvider and can emit shipping adjustments.
// src/modules/your-module/index.ts
import { registerShippingProvider } from '@open-mercato/core/modules/sales/lib/providers'
registerShippingProvider({
key: 'priority-courier',
label: 'Priority courier',
description: 'Weight-based express shipping.',
settings: {
fields: [
{ key: 'base', label: 'Base fee', type: 'number', required: true },
{ key: 'perKg', label: 'Per-kg rate', type: 'number', required: true },
],
},
async calculate({ metrics, settings, context, method }) {
const base = Number(settings.base ?? method.baseRateNet ?? 0)
const perKg = Number(settings.perKg ?? 0)
const amount = base + metrics.totalWeight * perKg
if (!amount) return { adjustments: [] }
return {
adjustments: [
{
amountNet: amount,
amountGross: amount,
currencyCode: context.currencyCode,
metadata: { applied: true, weight: metrics.totalWeight },
},
],
}
},
})
calculateDocumentTotals for quotes and orders.metadata.providerSettings on the sales_shipping_methods and sales_payment_methods rows, and exposed in the CRUD APIs as providerSettings.sales.shipping.adjustments.apply.before|after and sales.payment.adjustments.apply.before|after, letting you mutate or override the calculated adjustments before they are merged into the document totals.Out of the box the sales module registers:
wire-transfer) – offline payment with optional instructions.cash-on-delivery) – optional flat/percent fee.flat-rate) – tiered rates by item count, weight, volume, or subtotal; optional base-rate toggle.Stripe is available as an opt-in helper:
import { registerStripeProvider } from '@open-mercato/core/modules/sales/lib/providers'
registerStripeProvider()
You can extend or replace these by registering providers in your own modules; registry calls are idempotent, so re-registering a key overwrites the previous handler.
The sales settings page (/backend/config/sales) now includes Shipping Methods and Payment Methods sections built with the provider registry:
providerSettings.settings.schema, keeping saved rows aligned with the hooks that consume them.These settings drive the provider calculations during quote/order creation and updates, ensuring shipping costs and payment fees stay in sync with the configured provider rules.