Poseidonas

payload shipping rates

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Adds a shipping zones collection, a quote endpoint and a shipping group on orders and carts to shops built on the official Payload ecommerce plugin. Zones match by country and postcode with a documented precedence rule, and methods include flat, free over threshold, weight bands, price bands and local pickup. Requires Payload 3.88 or newer and the official ecommerce plugin; it has no runtime dependencies.

Features

  • Shipping zones matched by country and postcode patterns with priority and specificity rules
  • Flat rate, free over threshold, weight band, price band and local pickup methods
  • Quote endpoint that reads subtotal, weight and shipping classes from a cart or the request body
  • Withdraws methods with a stated reason instead of quoting zero
  • Records the chosen method and amount on orders and carts
  • Pure quoteShipping function usable server-side without HTTP

Use cases

  • Offer customers shipping options and costs by destination address at checkout
  • Charge delivery by order value or cart weight bands across regions
  • Provide free shipping over a threshold or local pickup alongside paid methods

From the author

Shipping zones, methods and rate calculation for Payload ecommerce, in integer minor units.

Installation

npm i payload-shipping-rates

2

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

14

Weekly Downloads

v1.0.1

npm Version

49.2 KB

Unpacked Size

0

Dependencies

GitHub stars

2+1 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20262
Dec 5, 20262
Dec 4, 20262
Dec 3, 20262
Dec 2, 20262
Dec 1, 20262
Nov 30, 20262
Nov 29, 20262
Nov 28, 20262
Nov 27, 20262
Nov 26, 20262
Nov 25, 20262
Nov 24, 20262
Nov 23, 20262
Nov 22, 20262
Nov 21, 20262
Nov 20, 20262
Nov 19, 20262
Nov 18, 20262
Nov 17, 20262
Nov 16, 20262
Nov 15, 20262
Nov 14, 20262
Nov 13, 20262
Nov 12, 20262
Nov 11, 20262
Nov 10, 20262
Nov 9, 20262
Nov 8, 20262
Nov 7, 20262
Nov 6, 20262
Nov 5, 20262
Nov 4, 20262
Nov 3, 20262
Nov 2, 20262
Nov 1, 20262
Oct 31, 20262
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20262
Oct 26, 20262
Oct 25, 20262
Oct 24, 20262
Oct 23, 20262
Oct 22, 20262
Oct 21, 20262
Oct 20, 20262
Oct 19, 20262
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20261
Oct 10, 20261
Oct 9, 20261
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20261
Oct 3, 20261
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20261
Sep 26, 20261
Sep 25, 20261
Sep 24, 20261
Sep 23, 20261
Sep 22, 20261
Sep 21, 20261
Sep 20, 20261
Sep 19, 20261
Sep 18, 20261
Sep 17, 20261
Sep 16, 20261
Sep 15, 20261
Sep 14, 20261
Sep 13, 20261
Sep 12, 20261
Sep 11, 20261
Sep 10, 20261
Sep 9, 20261
Sep 8, 20261
Sep 7, 20261
npm weekly downloads

21+8 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202621
Dec 5, 202616
Dec 4, 202616
Dec 3, 202618
Dec 2, 202620
Dec 1, 202621
Nov 30, 202621
Nov 29, 202617
Nov 28, 202628
Nov 27, 202636
Nov 26, 2026221
Nov 25, 2026218
Nov 24, 2026215
Nov 23, 2026214
Nov 22, 2026211
Nov 21, 2026199
Nov 20, 2026189
Nov 19, 20263
Nov 18, 20263
Nov 17, 20263
Nov 16, 20264
Nov 15, 20265
Nov 14, 20266
Nov 13, 20267
Nov 12, 20267
Nov 11, 20269
Nov 10, 20269
Nov 9, 20269
Nov 8, 20268
Nov 7, 20268
Nov 6, 20266
Nov 5, 20267
Nov 4, 20265
Nov 3, 20265
Nov 2, 20268
Nov 1, 20268
Oct 31, 20267
Oct 30, 20267
Oct 29, 20265
Oct 28, 20265
Oct 27, 20266
Oct 26, 20263
Oct 25, 20262
Oct 24, 20263
Oct 23, 20263
Oct 22, 20264
Oct 21, 20264
Oct 20, 20263
Oct 19, 20262
Oct 18, 20262
Oct 17, 20262
Oct 16, 20262
Oct 15, 20263
Oct 14, 20263
Oct 13, 20263
Oct 12, 20263
Oct 11, 20264
Oct 10, 20263
Oct 9, 20263
Oct 8, 20263
Oct 7, 20263
Oct 6, 20264
Oct 5, 20264
Oct 4, 20264
Oct 3, 20265
Oct 2, 20268
Oct 1, 20266
Sep 30, 20267
Sep 29, 20267
Sep 28, 20267
Sep 27, 20267
Sep 26, 20269
Sep 25, 20266
Sep 24, 20266
Sep 23, 20266
Sep 22, 20266
Sep 21, 20267
Sep 20, 20268
Sep 19, 20265
Sep 18, 20265
Sep 17, 20266
Sep 16, 202611
Sep 15, 202611
Sep 14, 202614
Sep 13, 202612
Sep 12, 202616
Sep 11, 202618
Sep 10, 202617
Sep 9, 202613
Sep 8, 202614
Sep 7, 202613

Each point is npm's rolling 7-day download count.

Health Score

73/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1340410589-root.svg)](https://payloaddirectory.dev/plugins/1340410589-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340410589-root"><img src="https://payloaddirectory.dev/badge/1340410589-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-shipping-rates

npm node license payload

Gives a Payload shop shipping zones and shipping methods, an endpoint that says what a delivery to a given address costs, and a place on the order to record which method the customer chose.

  • Zones matched by country and, optionally, by postcode, with one documented rule for deciding between them
  • Flat rate, free over a threshold, weight bands, price bands and local pickup
  • Every amount an integer in minor units, the same units @payloadcms/plugin-ecommerce stores prices in
  • When nothing can be costed it says so and why, and never falls back to a cost of zero
  • No runtime dependencies
  • No admin components, so it survives minor releases

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-shipping-rates
import { shippingRatesPlugin } from 'payload-shipping-rates'

export default buildConfig({
  plugins: [
    shippingRatesPlugin({
      weightUnit: 'kg',
    }),
  ],
})

A Shipping zones collection appears in the admin panel, a shipping group appears on orders and carts, and POST /api/shipping-rates/quote starts answering.

What was measured

Measured on 19 August 2026 against the published contents of @payloadcms/[email protected].

The official plugin does not calculate shipping. Every occurrence of the word in the published package, in full:

WhereWhat it is
ordersone shippingAddress group, built from the address fields, on a tab labelled shipping
initiatePayment and the Stripe adapterthat same address read from the request and handed to the payment provider
two doc commentsthe word shipping, describing that address

That is the whole of it. zone occurs zero times. carrier occurs zero times. parcel occurs zero times. rate never occurs as a shipping rate, only inside words such as separate and generated. A cart carries no shipping address at all, so nothing before checkout even knows where the order is going. The plugin collects a destination and then charges the cart subtotal.

Amounts are integers in minor units. dist/ui/utilities.js converts a typed price with Math.round(value * Math.pow(10, currency.decimals)), and EUR, USD and GBP are all declared with decimals: 2. So 4.90 is stored as 490. Every amount in this package is the same kind of integer, and nothing here divides.

The address fields the plugin generates are title, firstName, lastName, company, addressLine1, addressLine2, city, state, postalCode, country and phone. This package reads two of them, country and postalCode.

Order status options are processing, which is the default, completed, cancelled and refunded. Recording a chosen shipping method does not touch any of them.

Zone precedence

Several zones can cover one address. Exactly one of them serves it, and its methods are the only methods offered. The winner is chosen by three rules, applied in this order and no other:

  1. The higher priority. An explicit number always wins, so a shop can force an answer without rearranging anything. A missing priority counts as 0.
  2. The higher specificity. A zone that matched through one of its postcode patterns scores 2. A zone that listed the destination country by name scores 1 more than one that matched through the wildcard *. So a postcode match beats a country match, and a named country beats *.
  3. The lower zone id. A final tie is broken by id, so the same cart and the same address always get the same answer.
ZoneCountriesPostcodesPriorityScore for GB, SW1A 1AA
LondonGBSW1*03, and it wins
United KingdomGBnone01
Rest of world*none00

A zone whose country list is empty covers nothing. A zone that restricts postcodes and whose patterns do not match is out of the running entirely; it does not fall back to a country match.

Postcode patterns

The destination postcode is uppercased and stripped of everything that is not a letter or a digit, so sw1a 1aa, SW1A-1AA and SW1A1AA are one postcode. Each pattern is then read in this order:

FormExampleMatches
numeric range1000...1999any all digit postcode from 1000 to 1999, both ends included
prefix wildcardSW1*any postcode starting SW1, including SW1 itself
everything*every postcode, including an absent one
exactSW1A 1AAthat postcode only

A range is compared as a number, so 900...1100 covers 1000. A range never applies to a postcode containing a letter.

Methods

Each zone holds any number of methods. Every amount is in minor units.

TypeFields it usesCost
flatamountamount, always
free_overthreshold0 at or above the subtotal threshold. Below it, the method is withdrawn
weight_bandsbandsthe band the cart weight falls into
price_bandsbandsthe band the cart subtotal falls into
local_pickupamountamount, or 0 when none is set

A band has a from, an optional to and an amount. from is inclusive, to is exclusive, so bands of 0 to 1, 1 to 5 and 5 upwards leave neither a gap nor an overlap. A band with no to runs without an upper bound. Bands are sorted by from before they are read, so the order they were entered in never changes the answer.

Weight band boundaries are written in the configured weightUnit and converted to whole grams with the same rounding payload-shipping-classes uses when it stores a weight, so a boundary of 5 lb and a product of 5 lb both become 2268 g and land on the same side of the line. Price band boundaries are already minor units and are not converted.

When a method cannot be costed

It is withdrawn with a reason. It is never quoted at zero.

ReasonMeaning
below_thresholda free_over method whose threshold the subtotal has not reached
class_excludedthe cart carries a shipping class the method refuses
misconfiguredthe method is missing a value it cannot work without, such as a flat rate with no amount
no_bandthe bands leave a gap and the cart falls in it
subtotal_unknownno subtotal was supplied and the method needs one
weight_unknownno weight was supplied and the method needs one

And when no zone covers the address at all, the answer is available: false with reason: 'no_matching_zone' and an empty method list. A shop that would rather charge something than nothing must configure a zone with * in its country list; this package will not invent one.

The endpoint

POST /api/shipping-rates/quote
{
  "address": { "country": "GB", "postalCode": "SW1A 1AA" },
  "cartID": "68f0c4c2b1a3d90012ab34cd",
  "secret": "the guest cart secret, when there is one"
}

Given a cartID the endpoint reads the subtotal, the currency, the weight and the shipping classes from the cart. Any of those four given in the body directly wins over what the cart says, and a request that supplies them all needs no cartID:

{
  "address": { "country": "GB", "postalCode": "SW1A 1AA" },
  "subtotal": 4990,
  "weightGrams": 1250,
  "shippingClasses": ["bulky"]
}

The answer:

{
  "available": true,
  "reason": null,
  "zone": { "id": 2, "name": "London", "priority": 0 },
  "methods": [
    { "code": "standard", "label": "Standard", "type": "flat", "amount": 490 },
    { "code": "next-day", "label": "Next day", "type": "flat", "amount": 990 }
  ],
  "unavailable": [
    { "code": "free-shipping", "label": "Free shipping", "type": "free_over", "reason": "below_threshold" }
  ],
  "subtotal": 4990,
  "weightGrams": 1250,
  "shippingClasses": ["bulky"],
  "currency": "GBP",
  "destination": { "country": "GB", "postalCode": "SW1A 1AA" }
}

Methods come back cheapest first, ties broken by the order they were entered in the zone. The request returns 400 when no destination country was given and 404 when a cartID cannot be read; every other answer is 200, including the one that says no zone matched.

The cart is read through the request that is already open, so it joins the transaction Payload started for that request rather than taking a second connection from the pool.

Options

OptionDefaultMeaning
cartsSlug'carts'Slug of the carts collection
disabledfalseStops the endpoint being registered but keeps the collection and the fields, so the database keeps its shape
endpointPath'/shipping-rates/quote'Path of the quote endpoint, relative to the API route
fieldName'shipping'Group holding the chosen method on orders and carts
ordersSlug'orders'Slug of the orders collection
shippingClassFieldName'shippingClass'Field on products and variants holding the class
weightFieldName'weightGrams'Field on products and variants holding the weight in whole grams
weightUnit'kg'Unit weight band boundaries are written in. One of g, kg, oz, lb
zonesOverrides{}Merged over the generated zones collection, applied last
zonesSlug'shipping-zones'Collection holding the zones

An unusable value is replaced by its default rather than applied. An unknown weight unit falls back to kg, a name given as an empty string falls back to its default name, and an endpoint path given without a leading slash gets one.

What it adds to your database

CollectionFieldTypeNotes
shipping-zonesnametextrequired
shipping-zonescountriestext, manyrequired. Two letter codes, or *
shipping-zonespostcodestext, manyoptional. Empty covers every postcode in those countries
shipping-zonesprioritynumberindexed, defaults to 0
shipping-zonesmethodsarraylabel, code, type, amount, threshold, bands, excludedShippingClasses
your orders collectionshippinggroupmethod, label, type, zone, amount
your carts collectionshippinggroupthe same five, added only when the collection exists

shipping.method is indexed. shipping.amount is minor units, so 490 is 4.90.

The shipping-zones collection is readable by anyone and writable by any authenticated user. Pass zonesOverrides with your own access to narrow that to your administrators.

Without payload-shipping-classes

The two packages are built to be used together and neither requires the other. This one reads weightGrams and shippingClass off products and variants, by those names, which are the names payload-shipping-classes writes. It does not import it, does not declare it, and does not check for it.

With no weights anywhere in the catalogue:

Method typeBehaviour
flatworks
free_overworks
price_bandsworks
local_pickupworks
weight_bandswithdrawn with weight_unknown, unless the caller supplies weightGrams in the request body

So a shop that never weighed anything can still charge by order value, and a shop that stores weights some other way can supply weightGrams itself.

Using the calculation without the endpoint

quoteShipping is pure. It reads nothing, writes nothing, and given the same input always returns the same answer, so a checkout can price a cart on the server without going through HTTP.

import { quoteShipping } from 'payload-shipping-rates'

const zones = await payload.find({ collection: 'shipping-zones', pagination: false, req })

const quote = quoteShipping({
  destination: { country: 'GB', postalCode: 'SW1A 1AA' },
  subtotal: 4990,
  weightGrams: 1250,
  shippingClasses: ['bulky'],
  weightUnit: 'kg',
  zones: zones.docs,
})

matchZones, selectZone, quoteMethods, matchesPostcode and readCartShipping are exported too, for a shop that needs one step of it rather than all of them.

Honest limits

The cost recorded on an order is not enforced. The shipping group is a record of what the customer chose. The amount actually charged is decided by the payment adapter, which sets the order's own amount and knows nothing about this package. A checkout that means to charge for delivery must add the quoted amount to the payment intent itself, and should quote again on the server before it does, rather than trusting a figure that came back from the browser.

Nothing is added to the order total. This package does not modify amount on orders or subtotal on carts. Those belong to the official plugin, and fighting it over them would break on its next release.

One zone serves an address. The methods of a second matching zone are never merged in. If a shop wants a courier from one zone and a pickup point from another, both belong in the winning zone.

Countries are compared as text. A zone lists GB and an address says GB. Nothing validates the code against ISO 3166, expands UK to GB, or knows that Jersey is not the United Kingdom. Whatever the address collection stores is what has to be listed.

No per class pricing. A method can refuse a shipping class through excludedShippingClasses, and that is all. There is no per class surcharge and no per item handling fee, because both need per line pricing and this package prices a cart, not a line.

No dimensions. Volumetric weight, girth and box packing are not calculated. A weight band is the only physical measure used.

No carrier integration. No live rates, no label printing, no tracking. The zones are what a shop typed in, and the answer is arithmetic over them.

Free shipping is a method, not a discount. free_over withdraws itself below its threshold rather than falling back to a paid rate. A shop that wants a flat rate below the threshold and nothing above it configures both methods, and both appear once the threshold is passed, cheapest first.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins