[PR #5952] [CLOSED] feat(stripe): stripe customer for organization #6345

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

📋 Pull Request Information

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

Base: canaryHead: 2025-11-13/feat/stripe-customer-organization


📝 Commits (10+)

  • 995d6ce refactor: error codes
  • 6f0e3bb refactor: utils
  • 7d50e73 refactor: import types from core
  • 9068191 fix: imporve stripe error handling
  • 1f37481 test: adjust error expectation
  • e3bb049 feat(stripe): stripe customer for organization
  • 2c23601 test: edge cases
  • ed8b8d2 test: stripe-organization integration
  • b2126a8 chore: format
  • becde1d test: migrate to getTestInstance

📊 Changes

10 files changed (+4607 additions, -633 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+100 -3)
📝 packages/stripe/src/client.ts (+1 -1)
packages/stripe/src/error-codes.ts (+34 -0)
📝 packages/stripe/src/hooks.ts (+1 -1)
📝 packages/stripe/src/index.ts (+565 -178)
📝 packages/stripe/src/schema.ts (+22 -0)
packages/stripe/src/stripe-organization.test.ts (+2663 -0)
📝 packages/stripe/src/stripe.test.ts (+1100 -442)
📝 packages/stripe/src/types.ts (+39 -7)
📝 packages/stripe/src/utils.ts (+82 -1)

📄 Description

This PR is based on https://github.com/better-auth/better-auth/pull/2794 by @Cmion

Closes https://github.com/better-auth/better-auth/issues/2079
Closes https://github.com/better-auth/better-auth/issues/3772

Tasks

  • Refactor the Stripe plugin
  • Add a baseline for Stripe customer support at the organization level
  • Add new unit test cases
  • Test it in a real application
  • Migrate existing test cases to getTestInstance
  • Update docs

To-do (Not in this PR)

  • We need two API endpoints to fetch and update stripeAdminId since the admin can change in an organization.

Summary by cubic

Added organization Stripe customer support with automatic customer creation, syncing, and safer deletion checks. Also strengthened Stripe error handling and consolidated utilities for clear, consistent messages across subscription and webhook flows.

  • New Features

    • Added enableOrganizationCustomer to create and link Stripe customers to organizations.
    • Synced organization name changes to Stripe; deleted Stripe customer on org deletion.
    • Blocked organization deletion when active Stripe subscriptions exist.
    • Used activeOrganizationId to scope customer and subscription operations.
    • Extended schema with organization.stripeCustomerId and organization.stripeAdminUserId.
    • Added onOrganizationCustomerCreate callback to run after creating an organization customer.
  • Bug Fixes

    • Added strict webhook validation with explicit errors for missing signature/secret and invalid events.
    • Returned BAD_REQUEST with specific error codes for common failures (price, subscription, customer, request body), avoiding generic 500s.

Written for commit 8d1036799a. 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/5952 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 11/13/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `2025-11-13/feat/stripe-customer-organization` --- ### 📝 Commits (10+) - [`995d6ce`](https://github.com/better-auth/better-auth/commit/995d6ce4f4596fe0d4d155d3b082ea4e9768c553) refactor: error codes - [`6f0e3bb`](https://github.com/better-auth/better-auth/commit/6f0e3bba4e9e0b88581811202bda13e166a57fca) refactor: utils - [`7d50e73`](https://github.com/better-auth/better-auth/commit/7d50e736e95fecd351fc3d224c748aaa50bb7943) refactor: import types from core - [`9068191`](https://github.com/better-auth/better-auth/commit/90681913dab68d363ee812b0ba5b79144cfa29d7) fix: imporve stripe error handling - [`1f37481`](https://github.com/better-auth/better-auth/commit/1f37481d09fd2753039844d6bc344b4dc1430aa3) test: adjust error expectation - [`e3bb049`](https://github.com/better-auth/better-auth/commit/e3bb04948ddc32d2be8d2cda902de19e6b9adbc3) feat(stripe): stripe customer for organization - [`2c23601`](https://github.com/better-auth/better-auth/commit/2c236011a46dd553868170a744b8018735bbef2b) test: edge cases - [`ed8b8d2`](https://github.com/better-auth/better-auth/commit/ed8b8d2676f039326580148c906e70c7950b3253) test: stripe-organization integration - [`b2126a8`](https://github.com/better-auth/better-auth/commit/b2126a80774c4ee5e2073c9693ce09f0546df414) chore: format - [`becde1d`](https://github.com/better-auth/better-auth/commit/becde1debb15d16244045558a838a199084cd0e4) test: migrate to getTestInstance ### 📊 Changes **10 files changed** (+4607 additions, -633 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+100 -3) 📝 `packages/stripe/src/client.ts` (+1 -1) ➕ `packages/stripe/src/error-codes.ts` (+34 -0) 📝 `packages/stripe/src/hooks.ts` (+1 -1) 📝 `packages/stripe/src/index.ts` (+565 -178) 📝 `packages/stripe/src/schema.ts` (+22 -0) ➕ `packages/stripe/src/stripe-organization.test.ts` (+2663 -0) 📝 `packages/stripe/src/stripe.test.ts` (+1100 -442) 📝 `packages/stripe/src/types.ts` (+39 -7) 📝 `packages/stripe/src/utils.ts` (+82 -1) </details> ### 📄 Description This PR is based on https://github.com/better-auth/better-auth/pull/2794 by @Cmion Closes https://github.com/better-auth/better-auth/issues/2079 Closes https://github.com/better-auth/better-auth/issues/3772 ### Tasks - [x] Refactor the Stripe plugin - [x] Add a baseline for Stripe customer support at the organization level - [x] Add new unit test cases - [x] Test it in a real application - [x] Migrate existing test cases to getTestInstance - [x] Update docs ### To-do (Not in this PR) - We need two API endpoints to fetch and update `stripeAdminId` since the admin can change in an organization. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added organization Stripe customer support with automatic customer creation, syncing, and safer deletion checks. Also strengthened Stripe error handling and consolidated utilities for clear, consistent messages across subscription and webhook flows. - New Features - Added enableOrganizationCustomer to create and link Stripe customers to organizations. - Synced organization name changes to Stripe; deleted Stripe customer on org deletion. - Blocked organization deletion when active Stripe subscriptions exist. - Used activeOrganizationId to scope customer and subscription operations. - Extended schema with organization.stripeCustomerId and organization.stripeAdminUserId. - Added onOrganizationCustomerCreate callback to run after creating an organization customer. - Bug Fixes - Added strict webhook validation with explicit errors for missing signature/secret and invalid events. - Returned BAD_REQUEST with specific error codes for common failures (price, subscription, customer, request body), avoiding generic 500s. <sup>Written for commit 8d1036799a86d4c498103f64754df71a1864c96e. 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:55: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#6345