Build a Shipping Rates Plugin
End-to-end shipping plugin with rates and shipments.
Overview
Build a complete shipping plugin implementing shipping.get_rates and shipping.create_shipment.
Get Rates
Calculate shipping rates:
Get Rates Action
TypeScript
app.post("/actions/shipping/get-rates", (req, res) => {
verifyThreeUSignature(req);
const { origin, destination, weight } = req.body;
res.json({
success: true,
rates: [
{ id: "standard", name: "Standard",
price: calculateRate(weight, destination),
currency: "QAR", estimated_days: { min: 3, max: 7 } },
{ id: "express", name: "Express",
price: calculateExpressRate(weight, destination),
currency: "QAR", estimated_days: { min: 1, max: 2 } }
]
});
});Create Shipment
Create shipments:
Create Shipment
TypeScript
app.post("/actions/shipping/create-shipment", (req, res) => {
verifyThreeUSignature(req);
const { order_id, rate_id, origin, destination } = req.body;
const shipment = createWithCarrier({ rate_id, origin, destination });
res.json({
success: true,
shipment: {
id: shipment.id,
tracking_number: shipment.tracking_number,
tracking_url: shipment.tracking_url,
label_url: shipment.label_url
}
});
});