[PR #5834] [CLOSED] fix(stripe): allow custom metadata in subscription_data without overwriting internal fields #6261

Closed
opened 2026-03-13 12:52:43 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5834
Author: @bytaesu
Created: 11/7/2025
Status: Closed

Base: canaryHead: 2025-11-08/fix/stripe-metadata


📝 Commits (7)

  • a362f94 fix(stripe): allow custom metadata in subscription_data without overwriting internal fields
  • 520e18b test: add metadata merge behavior test cases
  • 78fd9f1 fix: prevent param override and use camelcase
  • 373f965 test: clear unused code
  • b448a31 fix: extract only the fields we explicitly want to use
  • f9c9056 test: imporve test cases
  • ef666b8 fix: restore restParams

📊 Changes

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

View changed files

📝 packages/stripe/src/index.ts (+20 -5)
📝 packages/stripe/src/stripe.test.ts (+329 -0)

📄 Description

Allow passing metadata to Stripe subscription via subscription_data while preserving internal fields

Closes https://github.com/better-auth/better-auth/issues/4104


Summary by cubic

Allows custom metadata in Stripe checkout sessions via subscription_data and metadata, merging safely with internal fields and trial settings. Also passes through safe checkout session params while blocking overrides of protected fields.

  • Bug Fixes
    • Merge subscription_data with freeTrial to keep trial_period_days and preserve subscription_data.metadata.
    • Merge custom metadata with internal keys (userId, subscriptionId, referenceId); internal keys win.
    • Pass through non-protected params from getCheckoutSessionParams (e.g., allow_promotion_codes, tax_id_collection, custom_text) and options (e.g., idempotencyKey); block overrides of customer, customer_email, line_items, mode, client_reference_id, success_url, cancel_url.
    • Added tests for metadata merging, safe param passthrough, and idempotencyKey.

Written for commit ef666b830a. Summary will update automatically on new commits.


🔄 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/5834 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 11/7/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `2025-11-08/fix/stripe-metadata` --- ### 📝 Commits (7) - [`a362f94`](https://github.com/better-auth/better-auth/commit/a362f94aeee6f422383f9916c7d007e3e6d93d8f) fix(stripe): allow custom metadata in subscription_data without overwriting internal fields - [`520e18b`](https://github.com/better-auth/better-auth/commit/520e18b9f7e685fba108bf981375be34aa959071) test: add metadata merge behavior test cases - [`78fd9f1`](https://github.com/better-auth/better-auth/commit/78fd9f14f013b63632b4b6a91bae4ec034e26d8a) fix: prevent param override and use camelcase - [`373f965`](https://github.com/better-auth/better-auth/commit/373f9652776d65759d7643e3270e574a7b54e7a5) test: clear unused code - [`b448a31`](https://github.com/better-auth/better-auth/commit/b448a31be6c3026e00116c21df468165500d1299) fix: extract only the fields we explicitly want to use - [`f9c9056`](https://github.com/better-auth/better-auth/commit/f9c9056902eedea255ef011dc422abef078dc11a) test: imporve test cases - [`ef666b8`](https://github.com/better-auth/better-auth/commit/ef666b830adecde4038bfd417ff82ef72e13282c) fix: restore restParams ### 📊 Changes **2 files changed** (+349 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/index.ts` (+20 -5) 📝 `packages/stripe/src/stripe.test.ts` (+329 -0) </details> ### 📄 Description Allow passing metadata to Stripe subscription via `subscription_data` while preserving internal fields Closes https://github.com/better-auth/better-auth/issues/4104 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allows custom metadata in Stripe checkout sessions via subscription_data and metadata, merging safely with internal fields and trial settings. Also passes through safe checkout session params while blocking overrides of protected fields. - **Bug Fixes** - Merge subscription_data with freeTrial to keep trial_period_days and preserve subscription_data.metadata. - Merge custom metadata with internal keys (userId, subscriptionId, referenceId); internal keys win. - Pass through non-protected params from getCheckoutSessionParams (e.g., allow_promotion_codes, tax_id_collection, custom_text) and options (e.g., idempotencyKey); block overrides of customer, customer_email, line_items, mode, client_reference_id, success_url, cancel_url. - Added tests for metadata merging, safe param passthrough, and idempotencyKey. <sup>Written for commit ef666b830adecde4038bfd417ff82ef72e13282c. Summary will update automatically on new commits.</sup> <!-- 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-03-13 12:52:43 -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#6261