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!

added support for yearly billing

Blue Mouse8f4fe97c11fa
diff --git a/src/user/entities/user.entity.ts b/src/user/entities/user.entity.ts
index 34e3e9d27..e3b084f50 100644
--- a/src/user/entities/user.entity.ts
+++ b/src/user/entities/user.entity.ts
@@ -22,21 +22,24 @@ export const ACCOUNT_PLANS = {
displayName: 'Freelancer plan',
monthlyUsageLimit: 100000,
maxProjects: 20,
- pid: '752316',
+ pid: '752316', // Plan ID
+ ypid: '776469', // Plan ID - Yearly billing
},
[PlanCode.startup]: {
id: PlanCode.startup,
displayName: 'Startup plan',
- monthlyUsageLimit: 500000,
+ monthlyUsageLimit: 1000000,
maxProjects: 20,
pid: '752317',
+ ypid: '776470',
},
[PlanCode.enterprise]: {
id: PlanCode.enterprise,
displayName: 'Enterprise plan',
- monthlyUsageLimit: 1000000,
+ monthlyUsageLimit: 5000000,
maxProjects: 30,
pid: '752318',
+ ypid: '776471',
},
}
@@ -48,7 +51,12 @@ export enum UserType {
export enum ReportFrequency {
Never = 'never',
Weekly = 'weekly',
- Monthly = 'monthly'
+ Monthly = 'monthly',
+}
+
+export enum BillingFrequency {
+ Monthly = 'monthly',
+ Yearly = 'yearly',
}
export const MAX_EMAIL_REQUESTS = 4 // 1 confirmation email on sign up + 3 additional ones
@@ -131,4 +139,13 @@ export class User {
@OneToMany(() => ActionToken, actionToken => actionToken.user)
actionTokens: ActionToken[]
+
+ @Column({
+ type: 'enum',
+ enum: BillingFrequency,
+ })
+ billingFrequency: BillingFrequency
+
+ @Column({ type: 'date', nullable: true })
+ nextBillDate: Date
}
diff --git a/src/webhook/webhook.controller.ts b/src/webhook/webhook.controller.ts
index 91eed6d2e..bad15cf6e 100644
--- a/src/webhook/webhook.controller.ts
+++ b/src/webhook/webhook.controller.ts
@@ -6,7 +6,7 @@ import * as _isEmpty from 'lodash/isEmpty'
import * as _keys from 'lodash/keys'
import * as _find from 'lodash/find'
-import { PlanCode, ACCOUNT_PLANS } from '../user/entities/user.entity'
+import { PlanCode, ACCOUNT_PLANS, BillingFrequency } from '../user/entities/user.entity'
import { UserService } from '../user/user.service'
import { AppLoggerService } from '../logger/logger.service'
import { WebhookService } from './webhook.service'
@@ -33,7 +33,7 @@ export class WebhookController {
case 'subscription_created':
case 'subscription_updated': {
const {
- passthrough, email, subscription_id, subscription_plan_id, cancel_url, update_url,
+ passthrough, email, subscription_id, subscription_plan_id, cancel_url, update_url, next_bill_date,
} = body
let uid
@@ -43,7 +43,13 @@ export class WebhookController {
this.logger.error(`[${body.alert_name}] Cannot parse the uid: ${JSON.stringify(body)}`)
}
- const plan = _find(ACCOUNT_PLANS, (tier) => tier.pid === subscription_plan_id)
+ let monthlyBilling = true
+ let plan = _find(ACCOUNT_PLANS, ({ pid }) => pid === subscription_plan_id)
+
+ if (!plan) {
+ monthlyBilling = false
+ plan = _find(ACCOUNT_PLANS, ({ ypid }) => ypid === subscription_plan_id)
+ }
if (!plan) {
throw new NotFoundException(`The selected account plan (${subscription_plan_id}) is not available`)
@@ -54,6 +60,8 @@ export class WebhookController {
subID: subscription_id,
subUpdateURL: update_url,
subCancelURL: cancel_url,
+ nextBillDate: next_bill_date,
+ billingFrequency: monthlyBilling ? BillingFrequency.Monthly : BillingFrequency.Yearly,
}
if (uid) {
@@ -72,6 +80,7 @@ export class WebhookController {
await this.userService.updateBySubID(subscription_id, {
planCode: PlanCode.free,
+ billingFrequency: BillingFrequency.Monthly,
})
break