Skip to content

Commit be93406

Browse files
authored
Merge pull request #702 from Dokploy/canary
v0.11.2
2 parents 8162dcf + 82fc989 commit be93406

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

apps/dokploy/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dokploy",
3-
"version": "v0.11.1",
3+
"version": "v0.11.2",
44
"private": true,
55
"license": "Apache-2.0",
66
"type": "module",

apps/dokploy/pages/api/stripe/webhook.ts

+46-20
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export default async function handler(
8888
.update(admins)
8989
.set({
9090
stripeSubscriptionId: newSubscription.id,
91-
serversQuantity: 0,
9291
stripeCustomerId: newSubscription.customer as string,
9392
})
9493
.where(eq(admins.stripeCustomerId, newSubscription.customer as string))
@@ -121,12 +120,6 @@ export default async function handler(
121120
}
122121
case "customer.subscription.updated": {
123122
const newSubscription = event.data.object as Stripe.Subscription;
124-
await db
125-
.update(admins)
126-
.set({
127-
serversQuantity: newSubscription?.items?.data?.[0]?.quantity ?? 0,
128-
})
129-
.where(eq(admins.stripeCustomerId, newSubscription.customer as string));
130123

131124
const admin = await findAdminByStripeCustomerId(
132125
newSubscription.customer as string,
@@ -136,8 +129,27 @@ export default async function handler(
136129
return res.status(400).send("Webhook Error: Admin not found");
137130
}
138131

139-
const newServersQuantity = admin.serversQuantity;
140-
await updateServersBasedOnQuantity(admin.adminId, newServersQuantity);
132+
if (newSubscription.status === "active") {
133+
await db
134+
.update(admins)
135+
.set({
136+
serversQuantity: newSubscription?.items?.data?.[0]?.quantity ?? 0,
137+
})
138+
.where(
139+
eq(admins.stripeCustomerId, newSubscription.customer as string),
140+
);
141+
142+
const newServersQuantity = admin.serversQuantity;
143+
await updateServersBasedOnQuantity(admin.adminId, newServersQuantity);
144+
} else {
145+
await disableServers(admin.adminId);
146+
await db
147+
.update(admins)
148+
.set({ serversQuantity: 0 })
149+
.where(
150+
eq(admins.stripeCustomerId, newSubscription.customer as string),
151+
);
152+
}
141153

142154
break;
143155
}
@@ -148,6 +160,13 @@ export default async function handler(
148160
newInvoice.subscription as string,
149161
);
150162

163+
if (suscription.status !== "active") {
164+
console.log(
165+
`Skipping invoice.payment_succeeded for subscription ${suscription.id} with status ${suscription.status}`,
166+
);
167+
break;
168+
}
169+
151170
await db
152171
.update(admins)
153172
.set({
@@ -168,22 +187,29 @@ export default async function handler(
168187
}
169188
case "invoice.payment_failed": {
170189
const newInvoice = event.data.object as Stripe.Invoice;
171-
await db
172-
.update(admins)
173-
.set({
174-
serversQuantity: 0,
175-
})
176-
.where(eq(admins.stripeCustomerId, newInvoice.customer as string));
177190

178-
const admin = await findAdminByStripeCustomerId(
179-
newInvoice.customer as string,
191+
const subscription = await stripe.subscriptions.retrieve(
192+
newInvoice.subscription as string,
180193
);
181194

182-
if (!admin) {
183-
return res.status(400).send("Webhook Error: Admin not found");
195+
if (subscription.status !== "active") {
196+
const admin = await findAdminByStripeCustomerId(
197+
newInvoice.customer as string,
198+
);
199+
200+
if (!admin) {
201+
return res.status(400).send("Webhook Error: Admin not found");
202+
}
203+
await db
204+
.update(admins)
205+
.set({
206+
serversQuantity: 0,
207+
})
208+
.where(eq(admins.stripeCustomerId, newInvoice.customer as string));
209+
210+
await disableServers(admin.adminId);
184211
}
185212

186-
await disableServers(admin.adminId);
187213
break;
188214
}
189215

apps/dokploy/pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default function Home({ IS_CLOUD }: Props) {
199199
) : (
200200
<Link
201201
className="hover:underline text-muted-foreground"
202-
href="https://docs.dokploy.com/docs/core/get-started/reset-password"
202+
href="https://docs.dokploy.com/docs/core/reset-password"
203203
target="_blank"
204204
>
205205
Lost your password?

0 commit comments

Comments
 (0)