Recipe
Recipe: Tax rate lookup for cart
NOT tax advice — consult a qualified professional for your jurisdiction.
Overview
This recipe demonstrates how to resolve a cart-level tax rate using Meridian's license-key metadata and a third-party tax API. The pattern is idempotent, cacheable, and safe for server-side rendering.
Ingredients
- Meridian license key with
tax_regionmetadata - Upstash KV for rate caching (TTL 24h)
- TaxJar or Avalara API key (stored in Vercel env vars)
- Next.js 14 App Router route handler
Steps
- Extract region. Read
tax_regionfrom the license key's metadata payload (ISO 3166-2 or ZIP). - Check cache. Query Upstash KV with key
tax:{region}. Return cached rate on hit. - Fetch live rate. Call the tax provider's
/ratesendpoint with the region and cart subtotal. - Populate cache. Write the response into KV with a 24-hour TTL and return the rate to the client.
Important
Tax rates vary by product type, customer exemption status, and nexus thresholds. This recipe provides a lookup pattern only. Always validate rates with a licensed tax professional before charging customers.