feat(paykit): add Stripe currency support

Merged
MA
5mo ago
+1985-20

Summary

  • add global Stripe currency support for usd and eur
  • persist product price currency and backfill existing paid products to usd
  • create a new Stripe Price when amount, interval, or currency changes
  • add focused unit coverage and EUR product-sync E2E coverage

Tests

  • pnpm --filter paykitjs typecheck
  • pnpm test:unit
  • pnpm --filter paykitjs build
  • pnpm format:check
  • pnpm lint
  • PAYKIT_ALLOW_UNSIGNED_PAYLOADS=1 E2E_STRIPE_WHSEC=whsec_dummy pnpm --filter e2e exec vitest run --project=cli cli/push.test.ts
  • full Stripe E2E earlier: 19 files / 21 tests passed

No release/changset in this PR; release will happen separately.


Summary by cubic

Adds global Stripe currency support for usd and eur. Products now store priceCurrency, plan hashes include currency, syncing/subscriptions handle currency changes, and the CLI formats EUR prices.

  • New Features

    • Add stripe.currency option (usd or eur, default usd) with strict lowercase 3-letter validation.
    • Normalize paid plans with the configured currency and include it in plan hashes; persist priceCurrency on products and backfill existing paid plans to usd.
    • Create a new Stripe Price when amount, interval, or currency changes; provider uses the plan’s currency for price creation and the configured currency for invoices.
    • Handle cross-currency paid plan changes by creating a new checkout-backed subscription.
    • Improve CLI formatPrice to localize currency and support EUR.
    • Resolve stored products by semantic plan match when only the hash changed to avoid unnecessary churn.
  • Migration

    • Run DB migration 0002_add-product-price-currency.
    • Re-run product sync (e.g., paykitjs push) to create currency-specific Stripe Prices (set stripe.currency to eur if needed, then push).

Summary by CodeRabbit

Release Notes

  • New Features
    • Added multi-currency product pricing with support for USD and EUR.
    • Plans now carry a currency setting where applicable, affecting hashing and product matching.
    • Switching between paid plans of different currencies now uses checkout flow.
  • Improvements
    • Price display uses locale-aware currency formatting.
    • Product sync now tracks and syncs the plan’s currency.
  • Validation
    • Stripe currency input is now strictly validated (lowercase 3-letter, supported set).
  • Database
    • Added price_currency to products and initialized existing records.
  • Tests
    • Expanded formatting, schema, and end-to-end sync coverage (including EUR).