From fb6a2a8af90b55f9b0b59a2165c26e22125d20e1 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 14 Feb 2026 00:46:49 -0700 Subject: [PATCH] Update APIs --- docs/Plugin API/shipping.md | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/docs/Plugin API/shipping.md b/docs/Plugin API/shipping.md index 5c5691d..c0a2474 100644 --- a/docs/Plugin API/shipping.md +++ b/docs/Plugin API/shipping.md @@ -15,6 +15,7 @@ Add custom carrier and rates, and adjust markup. * [.getServiceName(serviceId, carrier)](#shipping.getServiceName) ⇒ string * [.registerRateEndpoint(getRates, purchase, idPrefix)](#shipping.registerRateEndpoint) * [.registerMarkupCalculator(markupFn)](#shipping.registerMarkupCalculator) + * [.registerInsuranceProvider(id, name, cardText, maxValue, getQuote, insure)](#shipping.registerInsuranceProvider) @@ -241,3 +242,57 @@ global.apis.shipping.registerMarkupCalculator( } ); ``` + + +### shipping.registerInsuranceProvider(id, name, cardText, maxValue, getQuote, insure) +Add a shipping insurance provider. + +**Kind**: static method of [shipping](#shipping) + +| Param | Type | Description | +| --- | --- | --- | +| id | string \| null | Unique ID for the provider. Will be autogenerated if null. | +| name | string | Human-readable name for the provider. Shown as the card heading on the Insurance section of the Ship screen. | +| cardText | string | Text or HTML to display on the Ship screen card for this provider. | +| maxValue | number | The largest number that will be accepted for the "Insured for" value. | +| getQuote | function | Returns the cost and retail price for insuring the parcel, or a Promise that resolves into the same. See the example for details. | +| insure | function | Insure the parcel and add the insurance details to the receipt. See example. | + +**Example** +```js +async function getQuote(value, parcel, carrier, service) { + // Do math, etc + var cost = value / 100; + + return { + cost: cost, + retail: cost * 2 + }; + // Or, to remove this shipping rate from the list, + // because the shipment/carrier/service combination + // is not eligible for insurance: + return false; +} + +async function insure(value, parcel, carrier = "USPS", service = "Priority", trackingNumber = "94055...") { + // Purchase the insurance + var cost = value / 100; + var retailPrice = cost * 2; + var costPrice = cost; + + var receiptitem = new global.apis.pos.ReceiptItem(`sampleinsurance_${trackingNumber}`, + "Sample Insurance", + "Insured for " + global.apis.i18n.moneyString(value), + retailPrice, 1, costPrice, 0 + ); + receiptitem.merch = true; + receiptitem.category = "Shipping Insurance"; + receiptitem.barcode = trackingNumber; + global.apis.pos.addReceiptItem(receiptitem); +} + +global.apis.shipping.registerInsuranceProvider( + "sampleproviderid", "Sample Insurance", + "Insurance coverage from Sample Insurance. $1 per $100 of value.", + 5000, getQuote, insure); +```