[PR #3351] [CLOSED] Stripe: resolve lookupKey → price-ID so subscriptions validate correctly #30377

Closed
opened 2026-04-17 21:29:31 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3351
Author: @tinkerer-shubh
Created: 7/12/2025
Status: Closed

Base: mainHead: fix/stripe-lookupkey-3337


📝 Commits (2)

  • c500b2e fix(stripe): resolve price IDs from lookup keys with caching
  • ffa4396 fix(stripe): cache priceId lookups in secondaryStorage

📊 Changes

2 files changed (+103 additions, -5 deletions)

View changed files

📝 packages/stripe/src/types.ts (+9 -0)
📝 packages/stripe/src/utils.ts (+94 -5)

📄 Description

closes https://github.com/better-auth/better-auth/issues/3337

Key Changes

  1. Price ID Caching Mechanism:

    • Introduces a priceIdCache (a Map) to store up to 100 lookupKey-to-price-ID mappings, improving performance by preventing repeated Stripe API calls for the same keys.
    • Adds cacheSet and uses the cache in the new resolution logic.
  2. New Price ID Resolution Logic:

    • Implements an async resolvePriceId function that, given a Stripe client and a lookupKey, fetches the corresponding price ID from Stripe (if not in the cache) and caches it.
    • Handles errors gracefully, logging any Stripe API call failures.
  3. Enhanced Plan Lookup:

    • Updates getPlanByPriceId to first check for direct priceId matches as before.
    • If no direct match is found, it gathers all lookup keys from available plans, resolves them to price IDs (using the cache and the new resolver), and attempts to match the resolved IDs to the provided priceId.
    • This ensures that plans defined using lookupKey (instead of priceId) are correctly matched and validated for subscriptions.

Impact

  • Subscriptions now validate correctly, whether the plan uses a direct priceId or a lookupKey.
  • Stripe API calls are minimized due to caching, boosting efficiency.

Summary by cubic

Fixed subscription validation by resolving Stripe plan lookup keys to price IDs, with caching to improve performance.

  • Bug Fixes
    • Subscriptions now validate correctly when plans use lookupKey instead of priceId.
    • Added a cache to avoid repeated Stripe API calls for the same lookup keys.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3351 **Author:** [@tinkerer-shubh](https://github.com/tinkerer-shubh) **Created:** 7/12/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/stripe-lookupkey-3337` --- ### 📝 Commits (2) - [`c500b2e`](https://github.com/better-auth/better-auth/commit/c500b2e4c5fd5bb07285725d1e5f66329a6ef145) fix(stripe): resolve price IDs from lookup keys with caching - [`ffa4396`](https://github.com/better-auth/better-auth/commit/ffa4396aeec6cf5d1702c1492c3edc2ff198a7cf) fix(stripe): cache priceId lookups in secondaryStorage ### 📊 Changes **2 files changed** (+103 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/types.ts` (+9 -0) 📝 `packages/stripe/src/utils.ts` (+94 -5) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/3337 ### Key Changes 1. **Price ID Caching Mechanism**: - Introduces a `priceIdCache` (a Map) to store up to 100 lookupKey-to-price-ID mappings, improving performance by preventing repeated Stripe API calls for the same keys. - Adds `cacheSet` and uses the cache in the new resolution logic. 2. **New Price ID Resolution Logic**: - Implements an async `resolvePriceId` function that, given a Stripe client and a lookupKey, fetches the corresponding price ID from Stripe (if not in the cache) and caches it. - Handles errors gracefully, logging any Stripe API call failures. 3. **Enhanced Plan Lookup**: - Updates `getPlanByPriceId` to first check for direct priceId matches as before. - If no direct match is found, it gathers all lookup keys from available plans, resolves them to price IDs (using the cache and the new resolver), and attempts to match the resolved IDs to the provided priceId. - This ensures that plans defined using lookupKey (instead of priceId) are correctly matched and validated for subscriptions. ### Impact - Subscriptions now validate correctly, whether the plan uses a direct priceId or a lookupKey. - Stripe API calls are minimized due to caching, boosting efficiency. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed subscription validation by resolving Stripe plan lookup keys to price IDs, with caching to improve performance. - **Bug Fixes** - Subscriptions now validate correctly when plans use lookupKey instead of priceId. - Added a cache to avoid repeated Stripe API calls for the same lookup keys. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:29:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#30377