Returns whether the requested date is available (if not, the next available
date plus reason) and the delivery fee the checkout will charge.
THE FEE DEPENDS ON THE CART AND THE CURRENCY — the city's base rate is not
what checkout charges. Sri Lankan customers (LKR) pay the city rate capped
by the cart value (25% of the item value, at least LKR 300; some remote
cities 50%), so a small cart to a far city pays far less than the rate.
Overseas customers (USD) pay a fixed USD fee per city, whatever the cart.
Pass `currency` and the `cart` you are about to order and the answer gives
the EXACT fee kapruka_create_order will charge ("Delivery fee for this
cart"). Without a cart, an LKR answer gives only the MOST the fee can be
("up to"). One shipment per order: the fee covers the whole cart.
Pass `product_id` whenever the customer has named a product: the answer then
also checks that ITEM's delivery scope (restaurant food, hotel cakes and
liquor only reach selected cities, typically the Colombo area). With a
product_id, `available` is true only if the date is open AND the item is
deliverable to that city. When `item_deliverable` is false, offer the
customer one of the returned `deliverable_cities` or an island-wide
alternative — do not attempt kapruka_create_order with the same city, it
will be rejected. An unknown product_id is silently ignored (no item fields
in the result), so check `item_deliverable` is present before relying on it.
product_id also selects the SAME-DAY rule the checkout applies to that item:
vendor-delivered items (restaurant food) can go today until late afternoon;
ordinary items move to the next date; ordinary same-day is only possible early
in the morning near Colombo. So a check without product_id can differ from one
with it — always pass it once an item is chosen. When `available` is false,
offer `next_available_date`. Do not interpret the `reason` text (it is the
website's wording and may say slots are full when the real cause is the cutoff).
ECONOMY DELIVERY (cheaper courier, a few days instead of a chosen date) is
worked out from the `cart` (and `gift_message`, which you should pass when
there is one). When the answer shows an economy option, offer it to the
customer as the cheaper choice, quoting its fee, promise wording and
"expected by" date as given; if they take it, call kapruka_create_order with
`delivery.type: "economy"` (the order is dated for you). When the answer says
the order goes by economy delivery, that is the ONLY option for these items:
tell the customer and order with `delivery.type: "economy"`. When economy is
not shown, do not mention it.
Perishable codes (CAKE*, FLOWER*, COMBO*) additionally get a freshness
warning when the chosen delivery date is more than 1 day out.
INTERNATIONAL GIFTS (store products from kapruka_gift_country_products): pass
product_id or cart (no city needed) and, for Australia / the UAE, `zone`. The
answer is that country's delivery: available or not, the fee for the whole order,
and the earliest date (3 days ahead; used when delivery_date is omitted).
Args:
params (CheckDeliveryInput):
- city (str): Canonical city name (e.g. 'Colombo 03', 'Galle'); not needed for
international gift store products
- zone (Optional[str]): international gifts in Australia / the UAE
- delivery_date (Optional[str]): YYYY-MM-DD; defaults to today (LK time)
- product_id (Optional[str]): Check the city against this item's delivery scope
- currency (Optional[str]): LKR (default) or USD/GBP/AUD/EUR (charged in USD)
- cart (Optional[list]): [{product_id, quantity, icing_text?}] for the exact fee
- other_items_total (Optional[float]): LKR value of items not in `cart` (custom cake quote)
- gift_message (Optional[str]): the order's gift message, for the economy rule
- response_format (str): 'markdown' (default) or 'json'
Returns:
str: Delivery feasibility + fee in the requested format.
JSON schema:
{
"city": str,
"now": str, # ISO timestamp, Sri Lanka time
"checked_date": str, # YYYY-MM-DD
"available": bool, # date open AND (if product_id) item deliverable
"delivery_fee": number, # what checkout charges (see fee_basis)
"fee_currency": "LKR" | "USD",
"fee_basis": "cart" | "max" | "fixed", # exact for the cart | LKR without a cart: the most it can be | USD: same for any cart
"fee_items_value": number, # LKR item value the fee was computed from (fee_basis=cart)
"fee_cart_error": str, # the cart could not be priced (fee falls back to max)
"rate": number, # the city's BASE rate (LKR) — not the checkout fee
"currency": "LKR",
"reason": str | null, # date-block message, else "This item is not delivered to <City>."
"next_available_date": str|null, # only for date blocks
"item_deliverable": bool, # only when product_id resolved to a real product
"deliverable_cities": [str], # only when item_deliverable=false (capped at 60)
"perishable_warning": str | null, # populated when product_id is perishable
"economy": { # only with `cart`
"available": bool, # false: say nothing about economy
"forced": bool, # true: economy is the ONLY option
"fee": number, "currency": "LKR",
"promise": str, # quote as given
"delivery_date": str, # "expected by" date; create_order uses it
"saving": number | null # vs the standard fee
}
}