Overview
Icon for Zone Rate Shipping

Zone Rate Shipping

Weight-based zone rates with tracking

medusa-fulfillment-zone-rate

Calculated shipping for Medusa v2: price per kilogram by destination zone on the chargeable weight (the larger of actual and volumetric), plus shipment tracking with own tracking numbers, a status timeline, a public tracking page, a mobile-first Admin and A6 labels. Built and used in production by Haus Kayu.
Ongkir terhitung untuk Medusa v2: tarif per kg menurut zona tujuan, dari berat tagih (yang lebih besar antara berat aktual dan berat volume), plus pelacakan kiriman. Dibuat dan dipakai sendiri oleh Haus Kayu.

Compatibility

Plugin Medusa Node Tested in CI on 0.3.x 2.19.0 or newer 2.x (Copy to clipboard^2.19.0) 20.19+ or 22.12+ Medusa 2.19.0 and 2.22.2

Quick start

npm install medusa-fulfillment-zone-rate
npx medusa db:migrate
// medusa-config.ts
import shipping from "./shipping.config" // services, zones, rates: see Config below
plugins: [{ resolve: "medusa-fulfillment-zone-rate", options: {} }],
modules: [
{
resolve: "@medusajs/medusa/fulfillment",
options: {
providers: [
{ resolve: "medusa-fulfillment-zone-rate/providers/zone-rate", id: "zone-rate", options: shipping },
],
},
},
],

In the Admin, add the zone-rate provider to your stock location and create one shipping option per service with price type Calculated. Full steps: Install · Config · Tracking.

Checkout Admin (phone) Tracking page A6 label Packing slip International checkout

English · Bahasa Indonesia

English

What it does

  • Fulfillment provider with calculated prices (Copy to clipboardzone-rate_zone-rate): the price comes from the cart and the shipping address, never a flat amount.
  • One config file holds every service, zone, rate, divisor and estimate. Each service (e.g. domestic, air, sea) is one fulfillment option, so one shipping option in Medusa.
  • Chargeable weight, the same for every service: Integer arithmetic only (milligrams, 0.01 mm steps, whole currency units), so floats never push a parcel into the next kilogram. The divisor defaults to 6000 and can be set per service. Units default to grams and centimetres.
actual = Σ (variant weight × qty) grams, from variant.weight
volumetric = Σ (L × W × H / divisor × qty) cm, from variant.length/width/height
chargeable = max(actual, volumetric) in kg, rounded UP to a whole kg, at least 1 kg
1.1 kg → 2 kg · 0.3 kg → 1 kg · 2.0 kg → 2 kg
price = chargeable × rate per kg of the zone
  • Product fallback: a variant without weight or dimensions uses its product's values (option, on by default).
  • Never 0: shipping is refused with a clear message (English/Indonesian) when the destination is unknown or a line has no weight or misses a dimension. Checkout shows the message and the option cannot be added.
  • Rejection log in the Admin (time, cart, reason, the province as typed, the variants at fault), with repeats for the same cart counted on one row.
  • Incomplete variants report in the Admin: every variant without weight or a dimension, with a link to edit it and a CSV export.
  • Tolerant province matching for Indonesia: the 38 provinces by ISO 3166-2 code (Copy to clipboardID-JT, Copy to clipboardJT), official and English names, common abbreviations (Jabar, Jateng, DIY, NTB, Kaltim, Sulsel, Kepri, Babel …), old and new spellings (Sumatra/Sumatera, Jogja), with or without "Provinsi"/"Prov.", any case and spacing.
  • Fixed exchange rate for carts in another currency: rates stay in your base currency, the price is converted and rounded up to a whole unit. The rate and the date you set it are shown in the Admin.
  • Admin pages in English and Indonesian; a small "by Haus Kayu" credit you can turn off.

Tracking

  • Shipment per order, created when the payment is captured (option Copy to clipboardtracking.autoCreate: Copy to clipboard"payment.captured", Copy to clipboard"order.placed" or Copy to clipboardfalse), or from the order page in the Admin. Automatic creation happens once per order: never for canceled, archived or draft orders, never again after a shipment existed (also a canceled one), so replayed events are harmless; an admin can re-issue one after a cancellation.
  • Tracking numbers like Copy to clipboardHK-261103-7K3QX9: prefix, ship date (store time zone), five random symbols and a check symbol that catches every single-symbol typo; unique in the database. A third-party carrier's name, number and link can be added alongside.
  • Statuses Copy to clipboarddiproses → Copy to clipboarddikemas → Copy to clipboarddiserahkan_ke_kurir / Copy to clipboarddikirim → Copy to clipboardtransit → Copy to clipboardtiba_di_kota_tujuan → Copy to clipboarddalam_pengantaran → Copy to clipboardterkirim, plus Copy to clipboardgagal_kirim, Copy to clipboarddikembalikan, Copy to clipboarddibatalkan (labels in English and Indonesian). Add or relabel statuses with Copy to clipboardtracking.statuses; other transitions are refused.
  • Medusa in step: a shipped status creates the Medusa fulfillment and shipment (label = our tracking number), Copy to clipboardterkirim marks it delivered, Copy to clipboarddibatalkan cancels an unshipped fulfillment.
  • Payment before shipping (optional, off by default): with Copy to clipboardtracking.requirePaidBeforeShipping: true the shipped statuses (Copy to clipboarddiserahkan_ke_kurir, Copy to clipboarddikirim, or your own with Copy to clipboardmedusa: "shipped") are refused while the order still has an outstanding amount (total minus captured payments), for stores that bill in parts (deposit + balance). Other statuses are not affected. Authorized-but-not-captured payments count as outstanding.
  • Timeline (append-only): status, note, location, time, admin, shown-to-buyer, up to 5 proof photos per update (compressed on the server to WebP, longest side 1600 px, EXIF/GPS removed; stored in the database, not public).
  • Live: open tracking pages and Admin pages update over Server-Sent Events (Redis pub/sub across processes when Redis is configured), with 30-second polling as fallback.
  • Events Copy to clipboardshipment.created and Copy to clipboardshipment.status_updated for your own subscribers (WhatsApp, Slack …).
  • E-mails to the buyer for every status shown to them, through the Notification Module (English/Indonesian templates you can replace, one e-mail per event); skipped quietly without a provider.
  • Admin (sidebar → Shipments): counts per status, late and shipped today; search by tracking number, order number, name or e-mail; filters; bulk update; one screen per shipment with big status buttons and camera upload; A6 label (Code 128 + QR to the tracking page) and packing slip; widget on the order page.
  • Storefront: public lookup (status, city and times only, rate limited per IP) and the customer's own order timeline with notes and photos. See examples/dtc-starter.

Plugin options (Copy to clipboardplugins: [{ resolve: "medusa-fulfillment-zone-rate", options }]):

{
showCredit: true,
// brand: { logoUrl: "https://shop.example/brand/logo.png" }, // printed on the A6 label + packing slip; default: store name as text
tracking: {
prefix: "HK",
timeZone: "Asia/Jakarta",
autoCreate: "payment.captured",
// requirePaidBeforeShipping: true, // refuse "shipped" statuses while money is outstanding
lookupsPerIpPerMinute: 30,
trustedProxySecret: process.env.ZONE_RATE_PROXY_SECRET, // same value in the storefront
label: { senderName: "My Store" }, // default: store name + stock location address
notifications: {
storeName: "My Store",
trackingUrl: { id: "https://shop.example/lacak/{tracking_number}", en: "https://shop.example/us/track/{tracking_number}" },
// templates: { id: { subject, text, html? }, en: { … } }
},
// statuses: [{ id: "ditahan_bea_cukai", label: { en: "Held at customs", id: "Ditahan bea cukai" }, next: ["transit"] }],
},
}

Install

npm install medusa-fulfillment-zone-rate
npx medusa db:migrate

Copy to clipboardmedusa-config.ts:

import shipping from "./shipping.config"
module.exports = defineConfig({
// …
plugins: [{ resolve: "medusa-fulfillment-zone-rate", options: { showCredit: true } }],
modules: [
{
resolve: "@medusajs/medusa/fulfillment",
options: {
providers: [
// keep Medusa's manual provider if you still use it
{ resolve: "@medusajs/medusa/fulfillment-manual", id: "manual" },
{ resolve: "medusa-fulfillment-zone-rate/providers/zone-rate", id: "zone-rate", options: shipping },
],
},
},
],
})

Then, in the Admin (Settings → Locations & Shipping):

  1. Add the provider zone-rate to your stock location.
  2. Create one shipping option per service with price type "Calculated" and pick the service (e.g. "domestic") as the fulfillment option. The option's Copy to clipboarddata.id is the service id.
Note for pnpm without hoisting or a locally linked copy: the Admin build picks up this plugin's Tailwind classes through Copy to clipboardrequire.resolve("medusa-fulfillment-zone-rate/admin") from Copy to clipboard@medusajs/admin-bundler; if the bundler cannot resolve the package (pnpm with Copy to clipboardhoist=false, or a plugin symlinked from outside the project), the plugin's Admin pages lose their layout. npm, Yarn and pnpm's defaults are fine; otherwise install from npm (or Copy to clipboardnpm pack) next to the bundler, or add Copy to clipboardhoist-pattern[]=medusa-fulfillment-zone-rate to Copy to clipboard.npmrc.

Config

A complete example, Haus Kayu's own: Copy to clipboardexamples/shipping.config.haus-kayu.ts.

import type { ZoneRateConfig } from "medusa-fulfillment-zone-rate/types"
const config: ZoneRateConfig = {
currency: "idr", // currency of every rate below
exchange_rates: { usd: { rate: 16500, updated_at: "2026-11-03" } }, // IDR per 1 USD
units: { weight: "g", dimension: "cm" }, // g | kg | lb | oz, mm | cm | m | in
volumetric_divisor: 6000,
product_fallback: true,
locale: "auto", // "auto" | "en" | "id" for the refusal messages
services: [
{
id: "domestic",
name: { en: "Standard shipping", id: "Pengiriman reguler" },
destination: "province", // zone by province (one country)…
country: "id",
estimate: { min: 2, max: 7, unit: "day" },
zones: [
{ id: "jawa", name: "Java", rate_per_kg: 30000, provinces: ["ID-JK", "Jawa Barat", "Jateng"] },
// …
],

The config is checked when Medusa starts: a rate of 0 or with decimals, an unknown province, a province in two zones or a duplicate id stops the server with a clear error instead of quoting a wrong price.

Adding a zone: add an entry to the service's Copy to clipboardzones with a new Copy to clipboardid, a Copy to clipboardrate_per_kg and its provinces or countries, then restart Medusa. A destination may belong to only one zone per service.

Another country by province: Copy to clipboarddestination: "province" matches Indonesian provinces today. For other countries use Copy to clipboarddestination: "country", or open an issue to add a province list.

Per-line package (e.g. a custom item on a draft order, which has no variant): set Copy to clipboardline_item.metadata.zone_rate_package = { weight, length, width, height } (per unit, in the config's units). Values given there win over the variant's; missing or invalid ones fall through to the variant/product. The tracking snapshot (zone, chargeable kg) reads the same values.

Refusals

Reason When Copy to clipboardunknown_province the province is empty or not recognised, or no zone lists it Copy to clipboardunsupported_country the address is outside the service's country/countries Copy to clipboardincomplete_items a line has no weight or misses length, width or height (0 counts as missing) Copy to clipboardno_exchange_rate the cart's currency is not the base currency and has no rate Copy to clipboardno_address, Copy to clipboardno_items, Copy to clipboardunknown_service as named

Medusa answers Copy to clipboardPOST /store/shipping-options/:id/calculate and Copy to clipboardPOST /store/carts/:id/shipping-methods with an error carrying the message, in the cart's locale (Copy to clipboardid… → Indonesian, Copy to clipboarden… → English), else Indonesian for Indonesian addresses and English otherwise.

Admin

Sidebar → Shipping rates: rates and zones as configured, the exchange rate and its date, the incomplete variants report (CSV export) and the rejection log.

Admin API (logged-in admin): Copy to clipboardGET /admin/zone-rate/config, Copy to clipboardGET /admin/zone-rate/incomplete-variants (Copy to clipboard?format=csv), Copy to clipboardGET /admin/zone-rate/rejections (Copy to clipboard?reason=&service_id=&limit=&offset=).

Development

See CONTRIBUTING.md. Copy to clipboardnpm test runs the unit tests; Copy to clipboardnode integration-tests/e2e.mjs runs the provider in a real Medusa app against a throwaway Postgres.

Bahasa Indonesia

Fitur

  • Provider fulfillment dengan harga terhitung (Copy to clipboardzone-rate_zone-rate): ongkir dihitung dari keranjang dan alamat tujuan, bukan harga flat.
  • Satu file config berisi semua layanan, zona, tarif, pembagi volume, dan estimasi. Tiap layanan (mis. domestik, udara, laut) jadi satu shipping option di Medusa.
  • Berat tagih (sama untuk semua layanan): Copy to clipboardmax(berat aktual, berat volume) dalam kg, dibulatkan ke atas ke kg penuh, minimal 1 kg (1,1 kg → 2 kg; 0,3 kg → 1 kg; 2,0 kg → 2 kg). Ongkir = berat tagih × tarif per kg zona. Hitungan pakai bilangan bulat, jadi tidak ada salah bulat karena float.
  • Fallback ke produk: varian tanpa berat/ukuran memakai nilai produknya (bisa dimatikan).
  • Tidak pernah Rp0: ongkir ditolak dengan pesan jelas (Indonesia/Inggris) kalau provinsi/negara tidak dikenal atau ada barang tanpa berat atau salah satu ukuran.
  • Log penolakan dan laporan varian belum lengkap (link ke produk + export CSV) di Admin.
  • Pencocokan provinsi toleran: 38 provinsi, kode ISO (Copy to clipboardID-JT, Copy to clipboardJT), nama resmi dan Inggris, singkatan (Jabar, Jateng, DIY, NTB, Kaltim, Sulsel, Kepri, Babel, …), ejaan lama/baru (Sumatra/Sumatera, Jogja), dengan atau tanpa "Provinsi"/"Prov.", huruf besar/kecil dan spasi bebas.
  • Kurs tetap untuk keranjang mata uang lain: tarif tetap dalam mata uang dasar, hasilnya dikonversi dan dibulatkan ke atas ke satuan penuh. Kurs dan tanggal update tampil di Admin.
  • Lunas sebelum dikirim (opsional, default mati): Copy to clipboardtracking.requirePaidBeforeShipping: true menolak status kirim (Copy to clipboarddiserahkan_ke_kurir, Copy to clipboarddikirim) selama order masih punya sisa tagihan, untuk toko yang menagih bertahap (DP + pelunasan).
  • Admin dua bahasa (en/id) dan credit kecil "by Haus Kayu" yang bisa dimatikan (Copy to clipboardshowCredit: false).

Pasang

Lihat bagian Install dan Config di atas; contoh lengkap ada di Copy to clipboardexamples/shipping.config.haus-kayu.ts. Setelah itu, di Admin: tambahkan provider zone-rate ke lokasi stok, lalu buat satu shipping option per layanan dengan tipe harga Calculated.

Menambah zona: tambahkan entri di Copy to clipboardzones dengan Copy to clipboardid baru, Copy to clipboardrate_per_kg, dan daftar provinsi/negaranya, lalu restart Medusa. Satu tujuan hanya boleh ada di satu zona per layanan; config dicek saat start.

Catatan untuk pnpm tanpa hoisting atau plugin yang di-symlink lokal: build Admin mengambil class Tailwind plugin ini lewat Copy to clipboardrequire.resolve("medusa-fulfillment-zone-rate/admin") dari Copy to clipboard@medusajs/admin-bundler; kalau bundler tidak bisa me-resolve paketnya (pnpm dengan Copy to clipboardhoist=false, atau plugin di-symlink dari luar proyek), halaman Admin plugin kehilangan layout-nya. npm, Yarn, dan pnpm bawaan aman; selain itu pasang dari npm (atau Copy to clipboardnpm pack) di sebelah bundler, atau tambahkan Copy to clipboardhoist-pattern[]=medusa-fulfillment-zone-rate di Copy to clipboard.npmrc.

About Haus Kayu

Teak furniture and crafts, made to order in Jepara, Indonesia — hauskayu.com.

Other plugins by Haus Kayu: medusa-payment-doit (QRIS and virtual accounts through doit.id) and medusa-payment-manual-transfer (bank transfer with proof upload).

License

MIT

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?