Back to docs
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_region metadata
  • 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

  1. Extract region. Read tax_region from the license key's metadata payload (ISO 3166-2 or ZIP).
  2. Check cache. Query Upstash KV with key tax:{region}. Return cached rate on hit.
  3. Fetch live rate. Call the tax provider's /rates endpoint with the region and cart subtotal.
  4. 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.