[PR #3327] [CLOSED] stripe metered billing with v2 metered events #30359

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3327
Author: @dagmawibabi
Created: 7/10/2025
Status: Closed

Base: mainHead: stripe-stable


📝 Commits (10+)

  • 034e219 stripe metered billing with v2 metered events
  • 779b070 stable stripe metered billing
  • f939d74 fixed formatting issue
  • 0ed0187 fixed some reviews
  • c5d50ea session check when listing metered-billing
  • 59908ea fixed security issue with listing metered billings
  • 5ba98c8 get session issue fix
  • 750fd89 use session middleware when listiing metered bills
  • ab8e1b9 sessions supported in test
  • afc5119 sessions supported in test

📊 Changes

3 files changed (+670 additions, -0 deletions)

View changed files

📝 packages/stripe/src/index.ts (+328 -0)
packages/stripe/src/metered.test.ts (+325 -0)
📝 packages/stripe/src/types.ts (+17 -0)

📄 Description

This PR implements the metered billing methods provided in https://docs.stripe.com/api/billing/meter/object

This can be used to make metered bills,
This pull request introduces a metered billing feature to the Stripe integration, including new endpoints, validation logic, and tests. The changes allow users to create, update, retrieve, list, deactivate, and reactivate meters for billing, as well as record meter events. Additionally, a new AggregationFormula enum has been added to define how meter events are aggregated.

Metered Billing Feature

  • New Endpoints for Metered Billing: Added endpoints for creating, updating, retrieving, listing, deactivating, and reactivating meters, as well as recording meter events. These endpoints include validation for required fields and error handling for invalid or missing data. (packages/stripe/src/index.ts, [1] [2]
  • Validation and Error Handling: Implemented checks for required fields, valid aggregation formulas, and the existence of users or meters before performing operations. (packages/stripe/src/index.ts, packages/stripe/src/index.tsR928-R1286)

Testing

  • Unit Tests for Metered Billing: Added comprehensive tests to validate the functionality of all metered billing endpoints, including edge cases like missing fields and invalid inputs. Mocked Stripe client responses to simulate real-world scenarios. (packages/stripe/src/metered.test.ts, packages/stripe/src/metered.test.tsR1-R296)

Supporting Changes

  • AggregationFormula Enum: Introduced an enum to specify aggregation methods (SUM, COUNT, LAST) for meter events. (packages/stripe/src/types.ts, packages/stripe/src/types.tsR5-R22)
  • Imports Update: Updated imports to include User and AggregationFormula for use in the new endpoints and tests. (packages/stripe/src/index.ts, [1] [2]

🔄 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/3327 **Author:** [@dagmawibabi](https://github.com/dagmawibabi) **Created:** 7/10/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `stripe-stable` --- ### 📝 Commits (10+) - [`034e219`](https://github.com/better-auth/better-auth/commit/034e2195bbaeb1e1527c78e5498907bd8b89de99) stripe metered billing with v2 metered events - [`779b070`](https://github.com/better-auth/better-auth/commit/779b070f4b4587a2b8247ff206810c3848f236d0) stable stripe metered billing - [`f939d74`](https://github.com/better-auth/better-auth/commit/f939d74e9919196c7e76fe663acde78e3ac100f7) fixed formatting issue - [`0ed0187`](https://github.com/better-auth/better-auth/commit/0ed01870eeb4f33cc9d9709aadc891c43710c14d) fixed some reviews - [`c5d50ea`](https://github.com/better-auth/better-auth/commit/c5d50ea6b0ad0eab72170665a7fd442dda7b6db4) session check when listing metered-billing - [`59908ea`](https://github.com/better-auth/better-auth/commit/59908ea459f565dc1e4c4a81ff4feadd40333d61) fixed security issue with listing metered billings - [`5ba98c8`](https://github.com/better-auth/better-auth/commit/5ba98c86d2fb2b0994e43d9951edfd4d8e304538) get session issue fix - [`750fd89`](https://github.com/better-auth/better-auth/commit/750fd89963ffa4a4470a44c9ad04956f252a64f7) use session middleware when listiing metered bills - [`ab8e1b9`](https://github.com/better-auth/better-auth/commit/ab8e1b9b0a6011217198735aa98c860af2f45cb6) sessions supported in test - [`afc5119`](https://github.com/better-auth/better-auth/commit/afc51190ebf258e2f6edf6f2830f131a1852ffc2) sessions supported in test ### 📊 Changes **3 files changed** (+670 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/index.ts` (+328 -0) ➕ `packages/stripe/src/metered.test.ts` (+325 -0) 📝 `packages/stripe/src/types.ts` (+17 -0) </details> ### 📄 Description This PR implements the metered billing methods provided in https://docs.stripe.com/api/billing/meter/object This can be used to make metered bills, This pull request introduces a metered billing feature to the Stripe integration, including new endpoints, validation logic, and tests. The changes allow users to create, update, retrieve, list, deactivate, and reactivate meters for billing, as well as record meter events. Additionally, a new `AggregationFormula` enum has been added to define how meter events are aggregated. ### Metered Billing Feature * **New Endpoints for Metered Billing**: Added endpoints for creating, updating, retrieving, listing, deactivating, and reactivating meters, as well as recording meter events. These endpoints include validation for required fields and error handling for invalid or missing data. (`packages/stripe/src/index.ts`, [[1]](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R928-R1286) [[2]](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R1353) * **Validation and Error Handling**: Implemented checks for required fields, valid aggregation formulas, and the existence of users or meters before performing operations. (`packages/stripe/src/index.ts`, [packages/stripe/src/index.tsR928-R1286](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R928-R1286)) ### Testing * **Unit Tests for Metered Billing**: Added comprehensive tests to validate the functionality of all metered billing endpoints, including edge cases like missing fields and invalid inputs. Mocked Stripe client responses to simulate real-world scenarios. (`packages/stripe/src/metered.test.ts`, [packages/stripe/src/metered.test.tsR1-R296](diffhunk://#diff-77fb30a111748d9614faf71ddbe81bcdc786d7542531eb9812e091ea5581f384R1-R296)) ### Supporting Changes * **`AggregationFormula` Enum**: Introduced an enum to specify aggregation methods (`SUM`, `COUNT`, `LAST`) for meter events. (`packages/stripe/src/types.ts`, [packages/stripe/src/types.tsR5-R22](diffhunk://#diff-34efa9c605b726e157bb1f56b408f03c2a1abceb7b49c3f60d86c60d8fd0e55dR5-R22)) * **Imports Update**: Updated imports to include `User` and `AggregationFormula` for use in the new endpoints and tests. (`packages/stripe/src/index.ts`, [[1]](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R5) [[2]](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R17) --- <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:28:37 -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#30359