@vynxc/better-stripe 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,321 @@
1
+ # better-stripe
2
+
3
+ Extended Stripe plugin for [Better Auth](https://better-auth.com) with **one-time payment** support.
4
+
5
+ Fork of `@better-auth/stripe` v1.5.6 with one-time payment functionality adapted from [better-auth#4892](https://github.com/better-auth/better-auth/pull/4892).
6
+
7
+ ## Features
8
+
9
+ - All existing `@better-auth/stripe` subscription features (upgrade, cancel, restore, billing portal, seat-based billing, organizations)
10
+ - **One-time payments** — create checkout sessions for single purchases, track payment status, list payment history
11
+ - Per-product `onPaymentComplete` callbacks
12
+ - Promotion codes and automatic tax support
13
+ - 16 automated tests including integration tests with real Stripe webhook signature verification
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install better-stripe stripe
19
+ ```
20
+
21
+ Peer dependencies: `better-auth`, `@better-auth/core`, `better-call`, `stripe` (v18-20)
22
+
23
+ ## Quick Start
24
+
25
+ ### Server
26
+
27
+ ```ts
28
+ import { betterAuth } from "better-auth";
29
+ import Stripe from "stripe";
30
+ import { stripe } from "better-stripe";
31
+
32
+ const auth = betterAuth({
33
+ // ...your config
34
+ plugins: [
35
+ stripe({
36
+ stripeClient: new Stripe(process.env.STRIPE_SECRET_KEY!),
37
+ stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
38
+ createCustomerOnSignUp: true,
39
+
40
+ // One-time payments
41
+ payments: {
42
+ enabled: true,
43
+ products: [
44
+ {
45
+ name: "lifetime-access",
46
+ priceId: "price_xxx", // from Stripe dashboard
47
+ onPaymentComplete: async ({ payment, product }) => {
48
+ console.log(`Payment ${payment.id} completed for ${product.name}`);
49
+ // Grant access, send email, etc.
50
+ },
51
+ },
52
+ ],
53
+ successUrl: "/thank-you",
54
+ cancelUrl: "/pricing",
55
+ },
56
+
57
+ // Subscriptions (optional, same as @better-auth/stripe)
58
+ subscription: {
59
+ enabled: true,
60
+ plans: [
61
+ { name: "starter", priceId: "price_starter" },
62
+ { name: "pro", priceId: "price_pro" },
63
+ ],
64
+ },
65
+ }),
66
+ ],
67
+ });
68
+ ```
69
+
70
+ ### Client
71
+
72
+ ```ts
73
+ import { createAuthClient } from "better-auth/client";
74
+ import { stripeClient } from "better-stripe/client";
75
+
76
+ const client = createAuthClient({
77
+ plugins: [
78
+ stripeClient({
79
+ subscription: true,
80
+ payments: true,
81
+ }),
82
+ ],
83
+ });
84
+ ```
85
+
86
+ ### Webhook Endpoint
87
+
88
+ Add the webhook route to your Stripe dashboard or use the CLI for local development:
89
+
90
+ ```
91
+ https://your-app.com/api/auth/stripe/webhook
92
+ ```
93
+
94
+ ```bash
95
+ # Local development
96
+ stripe listen --forward-to http://localhost:3000/api/auth/stripe/webhook
97
+ ```
98
+
99
+ ## API Reference
100
+
101
+ ### Payment Endpoints
102
+
103
+ #### `POST /payment/create-session`
104
+
105
+ Create a Stripe Checkout session for a one-time payment.
106
+
107
+ ```ts
108
+ const { data } = await client.payment.createSession({
109
+ productName: "lifetime-access",
110
+ successUrl: "/thank-you", // optional, uses plugin default
111
+ cancelUrl: "/pricing", // optional, uses plugin default
112
+ quantity: 1, // optional, default 1
113
+ metadata: { coupon: "SAVE10" }, // optional
114
+ disableRedirect: false, // optional, default false
115
+ });
116
+
117
+ // data.url — Stripe Checkout URL (redirect user here)
118
+ // data.sessionId — Stripe session ID
119
+ // data.paymentId — database payment record ID
120
+ // data.redirect — whether to auto-redirect
121
+ ```
122
+
123
+ #### `GET /payment/status`
124
+
125
+ Get the status of a payment. Automatically syncs with Stripe if the payment hasn't succeeded yet.
126
+
127
+ ```ts
128
+ const { data } = await client.payment.status({
129
+ query: { paymentId: "xxx" },
130
+ });
131
+ // or by session ID:
132
+ const { data } = await client.payment.status({
133
+ query: { sessionId: "cs_test_xxx" },
134
+ });
135
+
136
+ // data.status — "requires_payment_method" | "succeeded" | "canceled" | ...
137
+ // data.amount — amount in cents
138
+ // data.currency — "usd"
139
+ // data.stripePaymentIntentId — Stripe PaymentIntent ID
140
+ ```
141
+
142
+ #### `GET /payment/list`
143
+
144
+ List payments for the authenticated user.
145
+
146
+ ```ts
147
+ const { data } = await client.payment.list({
148
+ query: {
149
+ status: "succeeded", // optional filter
150
+ limit: 10, // optional, default 10
151
+ offset: 0, // optional, default 0
152
+ },
153
+ });
154
+
155
+ // data — array of Payment objects
156
+ ```
157
+
158
+ ### Subscription Endpoints
159
+
160
+ All subscription endpoints from `@better-auth/stripe` are preserved:
161
+
162
+ | Endpoint | Method | Description |
163
+ |----------|--------|-------------|
164
+ | `/subscription/upgrade` | POST | Create or upgrade a subscription |
165
+ | `/subscription/cancel` | POST | Cancel a subscription |
166
+ | `/subscription/restore` | POST | Restore a canceled subscription |
167
+ | `/subscription/list` | GET | List active subscriptions |
168
+ | `/subscription/billing-portal` | POST | Create a billing portal session |
169
+ | `/subscription/success` | GET | Handle post-checkout redirect |
170
+ | `/stripe/webhook` | POST | Handle Stripe webhook events |
171
+
172
+ ## Configuration
173
+
174
+ ### Plugin Options
175
+
176
+ ```ts
177
+ stripe({
178
+ // Required
179
+ stripeClient: Stripe, // Stripe SDK instance
180
+ stripeWebhookSecret: string, // Webhook signing secret
181
+
182
+ // Customer management
183
+ createCustomerOnSignUp?: boolean, // Auto-create Stripe customer on signup
184
+ onCustomerCreate?: (data, ctx) => Promise<void>,
185
+ getCustomerCreateParams?: (user, ctx) => Promise<Partial<Stripe.CustomerCreateParams>>,
186
+
187
+ // One-time payments
188
+ payments?: {
189
+ enabled: boolean,
190
+ products: StripeProduct[] | (() => StripeProduct[] | Promise<StripeProduct[]>),
191
+ requireEmailVerification?: boolean, // default false
192
+ successUrl?: string,
193
+ cancelUrl?: string,
194
+ allowPromotionCodes?: boolean, // default false
195
+ automaticTax?: boolean, // default false
196
+ authorizeReference?: (data, ctx) => Promise<boolean>,
197
+ getCheckoutSessionParams?: (data, ctx) => Promise<{ params?, options? }>,
198
+ },
199
+
200
+ // Subscriptions
201
+ subscription?: {
202
+ enabled: boolean,
203
+ plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>),
204
+ requireEmailVerification?: boolean,
205
+ onSubscriptionComplete?: (data, ctx) => Promise<void>,
206
+ onSubscriptionUpdate?: (data) => Promise<void>,
207
+ onSubscriptionCancel?: (data) => Promise<void>,
208
+ onSubscriptionCreated?: (data) => Promise<void>,
209
+ onSubscriptionDeleted?: (data) => Promise<void>,
210
+ authorizeReference?: (data, ctx) => Promise<boolean>,
211
+ getCheckoutSessionParams?: (data, req, ctx) => Promise<{ params?, options? }>,
212
+ },
213
+
214
+ // Organizations (requires better-auth organization plugin)
215
+ organization?: {
216
+ enabled: true,
217
+ getCustomerCreateParams?: (org, ctx) => Promise<Partial<Stripe.CustomerCreateParams>>,
218
+ onCustomerCreate?: (data, ctx) => Promise<void>,
219
+ },
220
+
221
+ // Global
222
+ onEvent?: (event: Stripe.Event) => Promise<void>,
223
+ })
224
+ ```
225
+
226
+ ### Product Configuration
227
+
228
+ ```ts
229
+ {
230
+ name: "lifetime-access", // required — used to reference the product
231
+ priceId: "price_xxx", // Stripe price ID (use this or lookupKey)
232
+ lookupKey: "lifetime_key", // alternative to priceId
233
+ description: "One-time access", // optional
234
+ group: "premium", // optional — for categorizing products
235
+ metadata: { tier: "gold" }, // optional
236
+ onPaymentComplete: async ({ event, stripeSession, payment, product }, ctx) => {
237
+ // Called after successful payment
238
+ // payment.id, payment.amount, payment.currency, payment.referenceId
239
+ },
240
+ }
241
+ ```
242
+
243
+ ## Database Schema
244
+
245
+ The plugin adds a `payment` table (when `payments.enabled: true`):
246
+
247
+ | Column | Type | Description |
248
+ |--------|------|-------------|
249
+ | `id` | string | Primary key |
250
+ | `product` | string | Product name |
251
+ | `referenceId` | string | User ID or custom reference |
252
+ | `stripeCustomerId` | string | Stripe customer ID |
253
+ | `stripeSessionId` | string | Checkout session ID |
254
+ | `stripePaymentIntentId` | string | Payment intent ID (set after payment) |
255
+ | `priceId` | string | Stripe price ID |
256
+ | `status` | string | Payment status |
257
+ | `amount` | number | Amount in cents (set after payment) |
258
+ | `currency` | string | Currency code (default: "usd") |
259
+ | `metadata` | string | JSON metadata |
260
+
261
+ The existing `subscription` and `user` tables from `@better-auth/stripe` are also included when their respective features are enabled.
262
+
263
+ ## Webhook Events
264
+
265
+ The plugin handles these Stripe webhook events:
266
+
267
+ | Event | Handler |
268
+ |-------|---------|
269
+ | `checkout.session.completed` | Updates payment/subscription records, calls `onPaymentComplete` or `onSubscriptionComplete` |
270
+ | `customer.subscription.created` | Creates subscription record |
271
+ | `customer.subscription.updated` | Updates subscription, handles cancellations and trial transitions |
272
+ | `customer.subscription.deleted` | Marks subscription as canceled |
273
+
274
+ All other events are passed to `onEvent` if configured.
275
+
276
+ ## Testing
277
+
278
+ ### Run Tests
279
+
280
+ ```bash
281
+ npm run test:run
282
+ ```
283
+
284
+ The test suite includes:
285
+ - **Unit tests** (`test/payment.test.ts`) — 11 tests with mocked Stripe client
286
+ - **Integration tests** (`test/integration.test.ts`) — 5 tests with real Stripe webhook signature verification using `generateTestHeaderString`
287
+
288
+ ### Dev Server
289
+
290
+ For manual testing with the Stripe CLI:
291
+
292
+ ```bash
293
+ STRIPE_SECRET_KEY=sk_test_... \
294
+ STRIPE_WEBHOOK_SECRET=whsec_... \
295
+ STRIPE_PRICE_ID=price_... \
296
+ npm run dev:server
297
+ ```
298
+
299
+ Then in another terminal:
300
+
301
+ ```bash
302
+ stripe listen --forward-to http://localhost:3333/api/auth/stripe/webhook
303
+ ```
304
+
305
+ ## Differences from `@better-auth/stripe`
306
+
307
+ | Feature | `@better-auth/stripe` | `better-stripe` |
308
+ |---------|----------------------|-----------------|
309
+ | Subscriptions | Yes | Yes |
310
+ | One-time payments | No | Yes |
311
+ | `POST /payment/create-session` | - | Yes |
312
+ | `GET /payment/status` | - | Yes |
313
+ | `GET /payment/list` | - | Yes |
314
+ | `payment` table | - | Yes |
315
+ | `onPaymentComplete` callback | - | Yes |
316
+ | Promotion codes (payments) | - | Yes |
317
+ | Automatic tax (payments) | - | Yes |
318
+
319
+ ## License
320
+
321
+ MIT
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/error-codes.ts
8
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
9
+ var STRIPE_ERROR_CODES = defineErrorCodes({
10
+ UNAUTHORIZED: "Unauthorized access",
11
+ INVALID_REQUEST_BODY: "Invalid request body",
12
+ SUBSCRIPTION_NOT_FOUND: "Subscription not found",
13
+ SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found",
14
+ ALREADY_SUBSCRIBED_PLAN: "You're already subscribed to this plan",
15
+ REFERENCE_ID_NOT_ALLOWED: "Reference id is not allowed",
16
+ CUSTOMER_NOT_FOUND: "Stripe customer not found for this user",
17
+ UNABLE_TO_CREATE_CUSTOMER: "Unable to create customer",
18
+ UNABLE_TO_CREATE_BILLING_PORTAL: "Unable to create billing portal session",
19
+ STRIPE_SIGNATURE_NOT_FOUND: "Stripe signature not found",
20
+ STRIPE_WEBHOOK_SECRET_NOT_FOUND: "Stripe webhook secret not found",
21
+ STRIPE_WEBHOOK_ERROR: "Stripe webhook error",
22
+ FAILED_TO_CONSTRUCT_STRIPE_EVENT: "Failed to construct Stripe event",
23
+ FAILED_TO_FETCH_PLANS: "Failed to fetch plans",
24
+ EMAIL_VERIFICATION_REQUIRED: "Email verification is required before you can subscribe to a plan",
25
+ SUBSCRIPTION_NOT_ACTIVE: "Subscription is not active",
26
+ /**
27
+ * @deprecated Use `SUBSCRIPTION_NOT_PENDING_CHANGE` instead.
28
+ */
29
+ SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: "Subscription is not scheduled for cancellation",
30
+ SUBSCRIPTION_NOT_PENDING_CHANGE: "Subscription has no pending cancellation or scheduled plan change",
31
+ ORGANIZATION_NOT_FOUND: "Organization not found",
32
+ ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: "Organization subscription is not enabled",
33
+ AUTHORIZE_REFERENCE_REQUIRED: "Organization subscriptions require authorizeReference callback to be configured",
34
+ ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: "Cannot delete organization with active subscription",
35
+ ORGANIZATION_REFERENCE_ID_REQUIRED: "Reference ID is required. Provide referenceId or set activeOrganizationId in session",
36
+ PRODUCT_NOT_FOUND: "Product not found",
37
+ PAYMENT_NOT_FOUND: "Payment not found"
38
+ });
39
+
40
+ export {
41
+ __export,
42
+ STRIPE_ERROR_CODES
43
+ };
44
+ //# sourceMappingURL=chunk-4KHAYSFO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const STRIPE_ERROR_CODES = defineErrorCodes({\n\tUNAUTHORIZED: \"Unauthorized access\",\n\tINVALID_REQUEST_BODY: \"Invalid request body\",\n\tSUBSCRIPTION_NOT_FOUND: \"Subscription not found\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"Subscription plan not found\",\n\tALREADY_SUBSCRIBED_PLAN: \"You're already subscribed to this plan\",\n\tREFERENCE_ID_NOT_ALLOWED: \"Reference id is not allowed\",\n\tCUSTOMER_NOT_FOUND: \"Stripe customer not found for this user\",\n\tUNABLE_TO_CREATE_CUSTOMER: \"Unable to create customer\",\n\tUNABLE_TO_CREATE_BILLING_PORTAL: \"Unable to create billing portal session\",\n\tSTRIPE_SIGNATURE_NOT_FOUND: \"Stripe signature not found\",\n\tSTRIPE_WEBHOOK_SECRET_NOT_FOUND: \"Stripe webhook secret not found\",\n\tSTRIPE_WEBHOOK_ERROR: \"Stripe webhook error\",\n\tFAILED_TO_CONSTRUCT_STRIPE_EVENT: \"Failed to construct Stripe event\",\n\tFAILED_TO_FETCH_PLANS: \"Failed to fetch plans\",\n\tEMAIL_VERIFICATION_REQUIRED:\n\t\t\"Email verification is required before you can subscribe to a plan\",\n\tSUBSCRIPTION_NOT_ACTIVE: \"Subscription is not active\",\n\t/**\n\t * @deprecated Use `SUBSCRIPTION_NOT_PENDING_CHANGE` instead.\n\t */\n\tSUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION:\n\t\t\"Subscription is not scheduled for cancellation\",\n\tSUBSCRIPTION_NOT_PENDING_CHANGE:\n\t\t\"Subscription has no pending cancellation or scheduled plan change\",\n\tORGANIZATION_NOT_FOUND: \"Organization not found\",\n\tORGANIZATION_SUBSCRIPTION_NOT_ENABLED:\n\t\t\"Organization subscription is not enabled\",\n\tAUTHORIZE_REFERENCE_REQUIRED:\n\t\t\"Organization subscriptions require authorizeReference callback to be configured\",\n\tORGANIZATION_HAS_ACTIVE_SUBSCRIPTION:\n\t\t\"Cannot delete organization with active subscription\",\n\tORGANIZATION_REFERENCE_ID_REQUIRED:\n\t\t\"Reference ID is required. Provide referenceId or set activeOrganizationId in session\",\n\tPRODUCT_NOT_FOUND: \"Product not found\",\n\tPAYMENT_NOT_FOUND: \"Payment not found\",\n});\n"],"mappings":";;;;;;;AAAA,SAAS,wBAAwB;AAE1B,IAAM,qBAAqB,iBAAiB;AAAA,EAClD,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,6BAA6B;AAAA,EAC7B,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,oBAAoB;AAAA,EACpB,2BAA2B;AAAA,EAC3B,iCAAiC;AAAA,EACjC,4BAA4B;AAAA,EAC5B,iCAAiC;AAAA,EACjC,sBAAsB;AAAA,EACtB,kCAAkC;AAAA,EAClC,uBAAuB;AAAA,EACvB,6BACC;AAAA,EACD,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAIzB,6CACC;AAAA,EACD,iCACC;AAAA,EACD,wBAAwB;AAAA,EACxB,uCACC;AAAA,EACD,8BACC;AAAA,EACD,sCACC;AAAA,EACD,oCACC;AAAA,EACD,mBAAmB;AAAA,EACnB,mBAAmB;AACpB,CAAC;","names":[]}
@@ -0,0 +1,88 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { stripe } from './index.js';
3
+ import 'better-auth/plugins/organization';
4
+ import 'stripe';
5
+ import 'zod';
6
+ import 'better-call';
7
+
8
+ declare const STRIPE_ERROR_CODES: {
9
+ UNAUTHORIZED: better_auth.RawError<"UNAUTHORIZED">;
10
+ INVALID_REQUEST_BODY: better_auth.RawError<"INVALID_REQUEST_BODY">;
11
+ SUBSCRIPTION_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_NOT_FOUND">;
12
+ SUBSCRIPTION_PLAN_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_PLAN_NOT_FOUND">;
13
+ ALREADY_SUBSCRIBED_PLAN: better_auth.RawError<"ALREADY_SUBSCRIBED_PLAN">;
14
+ REFERENCE_ID_NOT_ALLOWED: better_auth.RawError<"REFERENCE_ID_NOT_ALLOWED">;
15
+ CUSTOMER_NOT_FOUND: better_auth.RawError<"CUSTOMER_NOT_FOUND">;
16
+ UNABLE_TO_CREATE_CUSTOMER: better_auth.RawError<"UNABLE_TO_CREATE_CUSTOMER">;
17
+ UNABLE_TO_CREATE_BILLING_PORTAL: better_auth.RawError<"UNABLE_TO_CREATE_BILLING_PORTAL">;
18
+ STRIPE_SIGNATURE_NOT_FOUND: better_auth.RawError<"STRIPE_SIGNATURE_NOT_FOUND">;
19
+ STRIPE_WEBHOOK_SECRET_NOT_FOUND: better_auth.RawError<"STRIPE_WEBHOOK_SECRET_NOT_FOUND">;
20
+ STRIPE_WEBHOOK_ERROR: better_auth.RawError<"STRIPE_WEBHOOK_ERROR">;
21
+ FAILED_TO_CONSTRUCT_STRIPE_EVENT: better_auth.RawError<"FAILED_TO_CONSTRUCT_STRIPE_EVENT">;
22
+ FAILED_TO_FETCH_PLANS: better_auth.RawError<"FAILED_TO_FETCH_PLANS">;
23
+ EMAIL_VERIFICATION_REQUIRED: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED">;
24
+ SUBSCRIPTION_NOT_ACTIVE: better_auth.RawError<"SUBSCRIPTION_NOT_ACTIVE">;
25
+ SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: better_auth.RawError<"SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION">;
26
+ SUBSCRIPTION_NOT_PENDING_CHANGE: better_auth.RawError<"SUBSCRIPTION_NOT_PENDING_CHANGE">;
27
+ ORGANIZATION_NOT_FOUND: better_auth.RawError<"ORGANIZATION_NOT_FOUND">;
28
+ ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: better_auth.RawError<"ORGANIZATION_SUBSCRIPTION_NOT_ENABLED">;
29
+ AUTHORIZE_REFERENCE_REQUIRED: better_auth.RawError<"AUTHORIZE_REFERENCE_REQUIRED">;
30
+ ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: better_auth.RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
31
+ ORGANIZATION_REFERENCE_ID_REQUIRED: better_auth.RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
32
+ PRODUCT_NOT_FOUND: better_auth.RawError<"PRODUCT_NOT_FOUND">;
33
+ PAYMENT_NOT_FOUND: better_auth.RawError<"PAYMENT_NOT_FOUND">;
34
+ };
35
+
36
+ declare const stripeClient: <O extends {
37
+ subscription: boolean;
38
+ payments?: boolean;
39
+ }>(options?: O | undefined) => {
40
+ id: "stripe-client";
41
+ $InferServerPlugin: ReturnType<typeof stripe<{
42
+ stripeClient: any;
43
+ stripeWebhookSecret: string;
44
+ } & (O["subscription"] extends true ? {
45
+ subscription: {
46
+ enabled: true;
47
+ plans: StripePlan[];
48
+ };
49
+ } : {}) & (O["payments"] extends true ? {
50
+ payments: {
51
+ enabled: true;
52
+ products: [];
53
+ };
54
+ } : {})>>;
55
+ pathMethods: {
56
+ "/subscription/billing-portal": "POST";
57
+ "/subscription/restore": "POST";
58
+ };
59
+ $ERROR_CODES: {
60
+ UNAUTHORIZED: better_auth.RawError<"UNAUTHORIZED">;
61
+ INVALID_REQUEST_BODY: better_auth.RawError<"INVALID_REQUEST_BODY">;
62
+ SUBSCRIPTION_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_NOT_FOUND">;
63
+ SUBSCRIPTION_PLAN_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_PLAN_NOT_FOUND">;
64
+ ALREADY_SUBSCRIBED_PLAN: better_auth.RawError<"ALREADY_SUBSCRIBED_PLAN">;
65
+ REFERENCE_ID_NOT_ALLOWED: better_auth.RawError<"REFERENCE_ID_NOT_ALLOWED">;
66
+ CUSTOMER_NOT_FOUND: better_auth.RawError<"CUSTOMER_NOT_FOUND">;
67
+ UNABLE_TO_CREATE_CUSTOMER: better_auth.RawError<"UNABLE_TO_CREATE_CUSTOMER">;
68
+ UNABLE_TO_CREATE_BILLING_PORTAL: better_auth.RawError<"UNABLE_TO_CREATE_BILLING_PORTAL">;
69
+ STRIPE_SIGNATURE_NOT_FOUND: better_auth.RawError<"STRIPE_SIGNATURE_NOT_FOUND">;
70
+ STRIPE_WEBHOOK_SECRET_NOT_FOUND: better_auth.RawError<"STRIPE_WEBHOOK_SECRET_NOT_FOUND">;
71
+ STRIPE_WEBHOOK_ERROR: better_auth.RawError<"STRIPE_WEBHOOK_ERROR">;
72
+ FAILED_TO_CONSTRUCT_STRIPE_EVENT: better_auth.RawError<"FAILED_TO_CONSTRUCT_STRIPE_EVENT">;
73
+ FAILED_TO_FETCH_PLANS: better_auth.RawError<"FAILED_TO_FETCH_PLANS">;
74
+ EMAIL_VERIFICATION_REQUIRED: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED">;
75
+ SUBSCRIPTION_NOT_ACTIVE: better_auth.RawError<"SUBSCRIPTION_NOT_ACTIVE">;
76
+ SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: better_auth.RawError<"SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION">;
77
+ SUBSCRIPTION_NOT_PENDING_CHANGE: better_auth.RawError<"SUBSCRIPTION_NOT_PENDING_CHANGE">;
78
+ ORGANIZATION_NOT_FOUND: better_auth.RawError<"ORGANIZATION_NOT_FOUND">;
79
+ ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: better_auth.RawError<"ORGANIZATION_SUBSCRIPTION_NOT_ENABLED">;
80
+ AUTHORIZE_REFERENCE_REQUIRED: better_auth.RawError<"AUTHORIZE_REFERENCE_REQUIRED">;
81
+ ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: better_auth.RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
82
+ ORGANIZATION_REFERENCE_ID_REQUIRED: better_auth.RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
83
+ PRODUCT_NOT_FOUND: better_auth.RawError<"PRODUCT_NOT_FOUND">;
84
+ PAYMENT_NOT_FOUND: better_auth.RawError<"PAYMENT_NOT_FOUND">;
85
+ };
86
+ };
87
+
88
+ export { STRIPE_ERROR_CODES, stripeClient };
package/dist/client.js ADDED
@@ -0,0 +1,21 @@
1
+ import {
2
+ STRIPE_ERROR_CODES
3
+ } from "./chunk-4KHAYSFO.js";
4
+
5
+ // src/client.ts
6
+ var stripeClient = (options) => {
7
+ return {
8
+ id: "stripe-client",
9
+ $InferServerPlugin: {},
10
+ pathMethods: {
11
+ "/subscription/billing-portal": "POST",
12
+ "/subscription/restore": "POST"
13
+ },
14
+ $ERROR_CODES: STRIPE_ERROR_CODES
15
+ };
16
+ };
17
+ export {
18
+ STRIPE_ERROR_CODES,
19
+ stripeClient
20
+ };
21
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport { STRIPE_ERROR_CODES } from \"./error-codes\";\nimport type { StripePlan, stripe } from \"./index\";\nexport const stripeClient = <\n\tO extends {\n\t\tsubscription: boolean;\n\t\tpayments?: boolean;\n\t},\n>(\n\toptions?: O | undefined,\n) => {\n\treturn {\n\t\tid: \"stripe-client\",\n\t\t$InferServerPlugin: {} as ReturnType<\n\t\t\ttypeof stripe<\n\t\t\t\t{\n\t\t\t\t\tstripeClient: any;\n\t\t\t\t\tstripeWebhookSecret: string;\n\t\t\t\t} & (O[\"subscription\"] extends true\n\t\t\t\t\t? { subscription: { enabled: true; plans: StripePlan[] } }\n\t\t\t\t\t: {}) &\n\t\t\t\t\t(O[\"payments\"] extends true\n\t\t\t\t\t\t? { payments: { enabled: true; products: [] } }\n\t\t\t\t\t\t: {})\n\t\t\t>\n\t\t>,\n\t\tpathMethods: {\n\t\t\t\"/subscription/billing-portal\": \"POST\",\n\t\t\t\"/subscription/restore\": \"POST\",\n\t\t},\n\t\t$ERROR_CODES: STRIPE_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\nexport * from \"./error-codes\";\n"],"mappings":";;;;;AAGO,IAAM,eAAe,CAM3B,YACI;AACJ,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAarB,aAAa;AAAA,MACZ,gCAAgC;AAAA,MAChC,yBAAyB;AAAA,IAC1B;AAAA,IACA,cAAc;AAAA,EACf;AACD;","names":[]}