Shipping
Onfleet local delivery for GoCommerce
A Go package that turns a shipment into an Onfleet task for the store’s own drivers. Not a carrier: no label, no waybill — a delivery task with the order on it, and a note to collect money when the order is unpaid.
- Shipping module
- 6 settings
- 8 tests
- ext/fulfill-onfleet
What it does
The module registers “onfleet” as a fulfillment provider. An operator ships through the engine’s own POST /api/admin/create-fulfillment with the provider onfleet — the engine keeps the order’s state and its events, and the module only talks to Onfleet.
The package is plain about what Onfleet is not: it carries nothing. It dispatches a task to the store’s own drivers, so the tracking number recorded is Onfleet’s shortId — what finds the task in the dashboard — the carrier is “onfleet”, and there is no label, because a driver going to an address does not need one. It suits same-day and local delivery and, in the package’s words, it is the wrong module for anything that goes in the post.
In the admin it describes itself as “Dispatches your own drivers through Onfleet: every shipment becomes a delivery task.” One setting is required, the API key. No SDK: REST over Go’s standard library.
Configuration
Only the API key is required. Set it in Config from your own main(), or leave Config empty and type it under Settings › Shipping providers.
| Setting | Environment variable | Required | What it does |
|---|---|---|---|
APIKeyAPI key | ONFLEET_API_KEY | Yes | An Onfleet API key, sent as the username of HTTP Basic auth with an empty password — which is how Onfleet authenticates. |
AutoAssignAuto-assign a driver | — | No | Asks Onfleet to pick a driver, by distance, as the task is created. Off by default: assigning somebody’s next two hours is a decision. |
TeamIDTeam ID | — | No | Scopes auto-assignment to one team. Only meaningful with AutoAssign. |
ServiceTimeMinutesService time (minutes) | — | No | How long the driver is expected at the door. Zero leaves Onfleet’s own default. |
BaseURLAPI base URL | — | No | Overrides https://onfleet.com/api/v2, for tests. Empty for production. |
Client | — | No | Replaces the HTTP client, which otherwise times out after 30 seconds. Go only; not in the panel. |
The module reads its Config struct, not the environment. The variable names are the ones the package’s own example or the reference binary uses; in your own main() you choose where each value comes from. Where a setting has a panel label, the admin’s settings drawer can hold it too, and a value typed there wins over Config.
Setting it up
- Get an API keyFrom Onfleet’s dashboard, under API & Webhooks, as the plugin’s own help text says.
- Install the moduleImport it and pass onfleet.New to gocommerce.New, as below — or run the reference binary with -carriers, which installs every carrier module idle.
- Decide on assignmentLeave auto-assign off to dispatch by hand in Onfleet, or switch it on, optionally for one team. Settings live in Config or under Settings › Shipping providers.
- Ship an orderPOST /api/admin/create-fulfillment with the order id and the provider onfleet. The task’s shortId is recorded as the tracking number; meta notes adds a line for the driver.
main.go
import (
"os"
"github.com/itswadesh/gocommerce/core"
onfleet "github.com/itswadesh/gocommerce/ext/fulfill-onfleet"
)
app, err := gocommerce.New(cfg,
onfleet.New(onfleet.Config{APIKey: os.Getenv("ONFLEET_API_KEY")}),
) The package doc’s own example, with its imports; cfg is your gocommerce.Config. With an empty onfleet.Config the module installs idle and waits for the panel. Import path github.com/itswadesh/gocommerce/ext/fulfill-onfleet.
How it works
-
An address in parts
The engine holds the address as parts, so the module sends them as parts — street, apartment, city, state, postcode, country. Onfleet’s house-number field is left out rather than guessed, since “Flat 2, 14 High Street” has two numbers in it.
-
What the driver reads
The task notes say “Order” and its number, then what is in this parcel, one entry per line with its quantity. Meta notes adds a further line.
-
Collect, at the top
When the order is unpaid, the notes begin with COLLECT, the currency and the amount — because the driver is the one who will be asked for money, or will forget to ask.
-
Found by the store’s own ids
The task carries order_number, order_id and the unit count as metadata visible to the store and its drivers, not to the recipient.
-
The recipient’s link is Onfleet’s
Onfleet texts the recipient its own tracking link. The module logs that URL rather than storing it, and the engine has no tracking URL for the onfleet carrier on purpose: a link built from the task id would not resolve.
-
Settings without a restart
Before each shipment the panel’s values are laid over Config. With nothing in Config the module installs idle; with a key in Config it starts switched on.
What it does not do
Read these before an order depends on it. No store is known to run GoCommerce in production yet, so these come from the code, not from anyone’s experience.
- Not for the postNo label, no waybill and no carrier: the module is for the store’s own drivers, and nothing else.
- No task updatesNo webhook: a task completed or failed in Onfleet does not mark the order delivered. That is still the operator’s job.
- Collect means the whole orderThe COLLECT line is the order’s total, even on a parcel carrying part of it, and it is written with two decimals — wrong for a currency without them.
- No cancel callThere is no call to delete a task. Deleting the fulfillment in GoCommerce leaves the task in Onfleet.
- Assignment by distance onlyAuto-assign asks Onfleet for its distance mode. Any other assignment rule is set up by hand in Onfleet, with auto-assign off.
FAQ
Questions about the Onfleet module
What does the customer see?
Whatever Onfleet sends them: it texts the recipient its own tracking link. The store’s own order.shipped message still goes out through whichever notifier is installed, with the task’s shortId as the tracking number.
Does it handle cash on delivery?
It tells the driver. When the order is not paid, the task notes open with COLLECT, the currency and the order total. Marking the order paid afterwards is done in GoCommerce, as for any cash-on-delivery order.
Can I use it without writing Go?
Yes. The reference binary’s -carriers flag installs every carrier module with an empty Config. Switch Onfleet on under Settings › Shipping providers and paste the API key there.
Is this an Onfleet partnership?
No. The module calls Onfleet’s public API with a key you supply. Onfleet does not endorse GoCommerce, and no store is known to run this module in production yet.
Source
Everything on this page is read from ext/fulfill-onfleet in the GoCommerce repository, MIT licensed. When this page and the code disagree, the code is right and this page is out of date.Onfleet is a trademark of its owner; this module talks to its public API and implies no endorsement. See trademarks.
Try it against a store of your own
The one-command stack gives you GoCommerce’s API and admin on your own machine in minutes. Add this module to it and try it on test orders before a real one depends on it.