@better-auth/stripe 1.2.2-beta.6 → 1.2.3-beta.1

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.
@@ -1,15 +1,15 @@
1
1
 
2
- > @better-auth/stripe@1.2.2-beta.6 build /home/runner/work/better-auth/better-auth/packages/stripe
2
+ > @better-auth/stripe@1.2.3-beta.1 build /home/runner/work/better-auth/better-auth/packages/stripe
3
3
  > unbuild
4
4
 
5
5
  [info] Automatically detected entries: src/index, src/client [esm] [cjs] [dts]
6
6
  [info] Building stripe
7
7
  [success] Build succeeded for stripe
8
- [log] dist/index.cjs (total size: 30.6 kB, chunk size: 30.6 kB, exports: stripe)
8
+ [log] dist/index.cjs (total size: 30.8 kB, chunk size: 30.8 kB, exports: stripe)
9
9
 
10
10
  [log] dist/client.cjs (total size: 160 B, chunk size: 160 B, exports: stripeClient)
11
11
 
12
- [log] dist/index.mjs (total size: 30.4 kB, chunk size: 30.4 kB, exports: stripe)
12
+ [log] dist/index.mjs (total size: 30.5 kB, chunk size: 30.5 kB, exports: stripe)
13
13
 
14
14
  [log] dist/client.mjs (total size: 133 B, chunk size: 133 B, exports: stripeClient)
15
15
 
package/dist/index.cjs CHANGED
@@ -107,12 +107,19 @@ async function onSubscriptionUpdated(ctx, options, event) {
107
107
  where: [{ field: "stripeCustomerId", value: customerId }]
108
108
  });
109
109
  if (subs.length > 1) {
110
- betterAuth.logger.warn(
111
- `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no referenceId or subscriptionId is provided`
110
+ const activeSub = subs.find(
111
+ (sub) => sub.status === "active" || sub.status === "trialing"
112
112
  );
113
- return;
113
+ if (!activeSub) {
114
+ betterAuth.logger.warn(
115
+ `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no active subscription is found`
116
+ );
117
+ return;
118
+ }
119
+ subscription = activeSub;
120
+ } else {
121
+ subscription = subs[0];
114
122
  }
115
- subscription = subs[0];
116
123
  }
117
124
  const seats = subscriptionUpdated.items.data[0].quantity;
118
125
  await ctx.context.adapter.update({
@@ -132,8 +139,8 @@ async function onSubscriptionUpdated(ctx, options, event) {
132
139
  },
133
140
  where: [
134
141
  {
135
- field: "referenceId",
136
- value: subscription.referenceId
142
+ field: "id",
143
+ value: subscription.id
137
144
  }
138
145
  ]
139
146
  });
package/dist/index.mjs CHANGED
@@ -105,12 +105,19 @@ async function onSubscriptionUpdated(ctx, options, event) {
105
105
  where: [{ field: "stripeCustomerId", value: customerId }]
106
106
  });
107
107
  if (subs.length > 1) {
108
- logger.warn(
109
- `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no referenceId or subscriptionId is provided`
108
+ const activeSub = subs.find(
109
+ (sub) => sub.status === "active" || sub.status === "trialing"
110
110
  );
111
- return;
111
+ if (!activeSub) {
112
+ logger.warn(
113
+ `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no active subscription is found`
114
+ );
115
+ return;
116
+ }
117
+ subscription = activeSub;
118
+ } else {
119
+ subscription = subs[0];
112
120
  }
113
- subscription = subs[0];
114
121
  }
115
122
  const seats = subscriptionUpdated.items.data[0].quantity;
116
123
  await ctx.context.adapter.update({
@@ -130,8 +137,8 @@ async function onSubscriptionUpdated(ctx, options, event) {
130
137
  },
131
138
  where: [
132
139
  {
133
- field: "referenceId",
134
- value: subscription.referenceId
140
+ field: "id",
141
+ value: subscription.id
135
142
  }
136
143
  ]
137
144
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
3
  "author": "Bereket Engida",
4
- "version": "1.2.2-beta.6",
4
+ "version": "1.2.3-beta.1",
5
5
  "main": "dist/index.cjs",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "zod": "^3.24.1",
38
- "better-auth": "^1.2.2-beta.6"
38
+ "better-auth": "^1.2.3-beta.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/better-sqlite3": "^7.6.12",
package/src/hooks.ts CHANGED
@@ -43,7 +43,6 @@ export async function onCheckoutSessionCompleted(
43
43
  periodEnd: new Date(subscription.current_period_end * 1000),
44
44
  stripeSubscriptionId: checkoutSession.subscription as string,
45
45
  seats,
46
-
47
46
  ...trial,
48
47
  },
49
48
  where: [
@@ -110,12 +109,19 @@ export async function onSubscriptionUpdated(
110
109
  where: [{ field: "stripeCustomerId", value: customerId }],
111
110
  });
112
111
  if (subs.length > 1) {
113
- logger.warn(
114
- `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no referenceId or subscriptionId is provided`,
112
+ const activeSub = subs.find(
113
+ (sub) => sub.status === "active" || sub.status === "trialing",
115
114
  );
116
- return;
115
+ if (!activeSub) {
116
+ logger.warn(
117
+ `Stripe webhook error: Multiple subscriptions found for customerId: ${customerId} and no active subscription is found`,
118
+ );
119
+ return;
120
+ }
121
+ subscription = activeSub;
122
+ } else {
123
+ subscription = subs[0];
117
124
  }
118
- subscription = subs[0];
119
125
  }
120
126
 
121
127
  const seats = subscriptionUpdated.items.data[0].quantity;
@@ -138,8 +144,8 @@ export async function onSubscriptionUpdated(
138
144
  },
139
145
  where: [
140
146
  {
141
- field: "referenceId",
142
- value: subscription.referenceId,
147
+ field: "id",
148
+ value: subscription.id,
143
149
  },
144
150
  ],
145
151
  });