@better-auth/stripe 1.5.0-beta.1 → 1.5.0-beta.2
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/.turbo/turbo-build.log +7 -7
- package/dist/client.d.mts +2 -1
- package/dist/client.mjs +4 -1
- package/dist/{index-DpiQGYLJ.d.mts → index-SbT5j9k6.d.mts} +45 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +201 -59
- package/package.json +5 -5
- package/src/client.ts +1 -0
- package/src/hooks.ts +166 -17
- package/src/middleware.ts +1 -2
- package/src/routes.ts +126 -84
- package/src/schema.ts +12 -0
- package/src/stripe.test.ts +2434 -1291
- package/src/types.ts +30 -1
- package/src/utils.ts +25 -1
package/src/types.ts
CHANGED
|
@@ -154,9 +154,26 @@ export interface Subscription {
|
|
|
154
154
|
*/
|
|
155
155
|
periodEnd?: Date | undefined;
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Whether this subscription will (if status=active)
|
|
158
|
+
* or did (if status=canceled) cancel at the end of the current billing period.
|
|
158
159
|
*/
|
|
159
160
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* If the subscription is scheduled to be canceled,
|
|
163
|
+
* this is the time at which the cancellation will take effect.
|
|
164
|
+
*/
|
|
165
|
+
cancelAt?: Date | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* If the subscription has been canceled, this is the time when it was canceled.
|
|
168
|
+
*
|
|
169
|
+
* Note: If the subscription was canceled with `cancel_at_period_end`,
|
|
170
|
+
* this reflects the cancellation request time, not when the subscription actually ends.
|
|
171
|
+
*/
|
|
172
|
+
canceledAt?: Date | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* If the subscription has ended, the date the subscription ended.
|
|
175
|
+
*/
|
|
176
|
+
endedAt?: Date | undefined;
|
|
160
177
|
/**
|
|
161
178
|
* A field to group subscriptions so you can have multiple subscriptions
|
|
162
179
|
* for one reference id
|
|
@@ -257,6 +274,18 @@ export type SubscriptionOptions = {
|
|
|
257
274
|
subscription: Subscription;
|
|
258
275
|
}) => Promise<void>)
|
|
259
276
|
| undefined;
|
|
277
|
+
/**
|
|
278
|
+
* A callback to run when a subscription is created
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
onSubscriptionCreated?:
|
|
282
|
+
| ((data: {
|
|
283
|
+
event: Stripe.Event;
|
|
284
|
+
stripeSubscription: Stripe.Subscription;
|
|
285
|
+
subscription: Subscription;
|
|
286
|
+
plan: StripePlan;
|
|
287
|
+
}) => Promise<void>)
|
|
288
|
+
| undefined;
|
|
260
289
|
/**
|
|
261
290
|
* parameters for session create params
|
|
262
291
|
*
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import type { StripeOptions, Subscription } from "./types";
|
|
2
3
|
|
|
3
4
|
export async function getPlans(
|
|
4
5
|
subscriptionOptions: StripeOptions["subscription"],
|
|
@@ -33,3 +34,26 @@ export async function getPlanByName(options: StripeOptions, name: string) {
|
|
|
33
34
|
res?.find((plan) => plan.name.toLowerCase() === name.toLowerCase()),
|
|
34
35
|
);
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a subscription is in an available state (active or trialing)
|
|
40
|
+
*/
|
|
41
|
+
export function isActiveOrTrialing(
|
|
42
|
+
sub: Subscription | Stripe.Subscription,
|
|
43
|
+
): boolean {
|
|
44
|
+
return sub.status === "active" || sub.status === "trialing";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if a subscription is scheduled to be canceled (DB subscription object)
|
|
49
|
+
*/
|
|
50
|
+
export function isPendingCancel(sub: Subscription): boolean {
|
|
51
|
+
return !!(sub.cancelAtPeriodEnd || sub.cancelAt);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if a Stripe subscription is scheduled to be canceled (Stripe API response)
|
|
56
|
+
*/
|
|
57
|
+
export function isStripePendingCancel(stripeSub: Stripe.Subscription): boolean {
|
|
58
|
+
return !!(stripeSub.cancel_at_period_end || stripeSub.cancel_at);
|
|
59
|
+
}
|