Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Update next bill date on payment

Blue Mouse1644d017b4eb
diff --git a/backend/apps/cloud/src/webhook/webhook.controller.ts b/backend/apps/cloud/src/webhook/webhook.controller.ts
index 8c14505c0..f2ad1806b 100644
--- a/backend/apps/cloud/src/webhook/webhook.controller.ts
+++ b/backend/apps/cloud/src/webhook/webhook.controller.ts
@@ -215,7 +215,7 @@ export class WebhookController {
}
case 'subscription_payment_succeeded': {
- const { subscription_id: subID } = body
+ const { subscription_id: subID, next_bill_date: nextBillDate } = body
const subscriber = await this.userService.findOne({
where: { subID },
@@ -232,13 +232,21 @@ export class WebhookController {
return
}
+ const updateParams: Record<string, any> = {}
+
+ if (nextBillDate) {
+ updateParams.nextBillDate = nextBillDate
+ }
+
if (
subscriber.dashboardBlockReason ===
DashboardBlockReason.payment_failed
) {
- await this.userService.updateBySubID(subID, {
- dashboardBlockReason: null,
- })
+ updateParams.dashboardBlockReason = null
+ }
+
+ if (Object.keys(updateParams).length > 0) {
+ await this.userService.updateBySubID(subID, updateParams)
await this.projectService.clearProjectsRedisCacheBySubId(subID)
}