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!

Remove manual payment logging

Blue Mousec56df4fda3ac
diff --git a/backend/apps/cloud/src/analytics/analytics.controller.ts b/backend/apps/cloud/src/analytics/analytics.controller.ts
index 91a1d5d85..afc4a8029 100644
--- a/backend/apps/cloud/src/analytics/analytics.controller.ts
+++ b/backend/apps/cloud/src/analytics/analytics.controller.ts
@@ -97,17 +97,8 @@ import { LiveVisitorsDto } from './dto/live-visitors.dto'
import { GetHeartbeatStatsDto } from './dto/get-heartbeat-stats'
import { GetKeywordsDto } from './dto/get-keywords.dto'
import { GSCService } from '../project/gsc.service'
-import {
- GetProfileIdDto,
- GetSessionIdDto,
- LogPaymentDto,
-} from '../revenue/dto/payment-log.dto'
+import { GetProfileIdDto, GetSessionIdDto } from './dto/get-id.dto'
import { RevenueService } from '../revenue/revenue.service'
-import {
- RevenueType,
- RevenueStatus,
- RevenueProvider,
-} from '../revenue/interfaces/revenue.interface'
dayjs.extend(utc)
dayjs.extend(dayjsTimezone)
@@ -2367,68 +2358,4 @@ export class AnalyticsController {
return { sessionId: null }
}
}
-
- @Post('payment')
- @Public()
- async logPayment(
- @Body() dto: LogPaymentDto,
- @Headers() headers,
- @Ip() reqIP,
- ): Promise<{ success: boolean }> {
- const { 'user-agent': userAgent, origin } = headers
-
- try {
- const ip = getIPFromHeaders(headers, true) || reqIP || ''
-
- // Validate the project exists
- await this.analyticsService.validate({ pid: dto.pid } as any, origin, ip)
-
- // Generate profileId and sessionId if not provided
- let profileId = dto.profileId
- let sessionId = dto.sessionId
-
- if (!profileId) {
- profileId = await this.analyticsService.generateProfileId(
- dto.pid,
- userAgent,
- ip,
- )
- }
-
- if (!sessionId) {
- const { psid } = await this.analyticsService.getSessionId(
- dto.pid,
- userAgent,
- ip,
- )
- sessionId = psid || undefined
- }
-
- // Insert the payment event into ClickHouse
- await this.revenueService.insertTransaction({
- pid: dto.pid,
- transactionId: dto.transactionId || `manual_${Date.now()}`,
- provider: RevenueProvider.PADDLE, // Default to paddle for now
- type: RevenueType.SALE,
- status: RevenueStatus.COMPLETED,
- amount: dto.amount || 0,
- originalAmount: dto.amount || 0,
- originalCurrency: dto.currency || 'USD',
- currency: dto.currency || 'USD',
- profileId: profileId || null,
- sessionId: sessionId || null,
- customerEmail: null,
- productId: null,
- productName: null,
- metadata: dto.metadata || {},
- created: new Date(),
- syncedAt: new Date(),
- })
-
- return { success: true }
- } catch (error) {
- this.logger.error({ error, pid: dto.pid }, 'Error logging payment')
- return { success: false }
- }
- }
}
diff --git a/backend/apps/cloud/src/analytics/dto/get-id.dto.ts b/backend/apps/cloud/src/analytics/dto/get-id.dto.ts
new file mode 100644
index 000000000..539c70999
--- /dev/null
+++ b/backend/apps/cloud/src/analytics/dto/get-id.dto.ts
@@ -0,0 +1,25 @@
+import { ApiProperty } from '@nestjs/swagger'
+import { IsNotEmpty, Matches } from 'class-validator'
+import { PID_REGEX } from '../../common/constants'
+
+export class GetProfileIdDto {
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
+ @IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid: string
+}
+
+export class GetSessionIdDto {
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
+ @IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid: string
+}
diff --git a/backend/apps/cloud/src/revenue/dto/payment-log.dto.ts b/backend/apps/cloud/src/revenue/dto/payment-log.dto.ts
index 81a6fffab..64a1e178a 100644
--- a/backend/apps/cloud/src/revenue/dto/payment-log.dto.ts
+++ b/backend/apps/cloud/src/revenue/dto/payment-log.dto.ts
@@ -1,20 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsNotEmpty, IsString, IsOptional, IsNumber } from 'class-validator'
-export class GetProfileIdDto {
- @ApiProperty({ description: 'Project ID' })
- @IsNotEmpty()
- @IsString()
- pid: string
-}
-
-export class GetSessionIdDto {
- @ApiProperty({ description: 'Project ID' })
- @IsNotEmpty()
- @IsString()
- pid: string
-}
-
export class LogPaymentDto {
@ApiProperty({ description: 'Project ID' })
@IsNotEmpty()