mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-11-24 00:07:27 +01:00
70 lines
2.1 KiB
Diff
70 lines
2.1 KiB
Diff
--- template/app/src/analytics/stats.ts
|
|
+++ opensaas-sh/app/src/analytics/stats.ts
|
|
@@ -2,7 +2,6 @@
|
|
import { type DailyStatsJob } from 'wasp/server/jobs';
|
|
import Stripe from 'stripe';
|
|
import { stripe } from '../payment/stripe/stripeClient';
|
|
-import { listOrders } from '@lemonsqueezy/lemonsqueezy.js';
|
|
import { getDailyPageViews, getSources } from './providers/plausibleAnalyticsUtils';
|
|
// import { getDailyPageViews, getSources } from './providers/googleAnalyticsUtils';
|
|
import { paymentProcessor } from '../payment/paymentProcessor';
|
|
@@ -42,17 +41,7 @@
|
|
paidUserDelta -= yesterdaysStats.paidUserCount;
|
|
}
|
|
|
|
- let totalRevenue;
|
|
- switch (paymentProcessor.id) {
|
|
- case 'stripe':
|
|
- totalRevenue = await fetchTotalStripeRevenue();
|
|
- break;
|
|
- case 'lemonsqueezy':
|
|
- totalRevenue = await fetchTotalLemonSqueezyRevenue();
|
|
- break;
|
|
- default:
|
|
- throw new Error(`Unsupported payment processor: ${paymentProcessor.id}`);
|
|
- }
|
|
+ let totalRevenue = await fetchTotalStripeRevenue()
|
|
|
|
const { totalViews, prevDayViewsChangePercent } = await getDailyPageViews();
|
|
|
|
@@ -163,39 +152,3 @@
|
|
// Revenue is in cents so we convert to dollars (or your main currency unit)
|
|
return totalRevenue / 100;
|
|
}
|
|
-
|
|
-async function fetchTotalLemonSqueezyRevenue() {
|
|
- try {
|
|
- let totalRevenue = 0;
|
|
- let hasNextPage = true;
|
|
- let currentPage = 1;
|
|
-
|
|
- while (hasNextPage) {
|
|
- const { data: response } = await listOrders({
|
|
- filter: {
|
|
- storeId: process.env.LEMONSQUEEZY_STORE_ID,
|
|
- },
|
|
- page: {
|
|
- number: currentPage,
|
|
- size: 100,
|
|
- },
|
|
- });
|
|
-
|
|
- if (response?.data) {
|
|
- for (const order of response.data) {
|
|
- totalRevenue += order.attributes.total;
|
|
- }
|
|
- }
|
|
-
|
|
- hasNextPage = !response?.meta?.page.lastPage;
|
|
- currentPage++;
|
|
- }
|
|
-
|
|
- // Revenue is in cents so we convert to dollars (or your main currency unit)
|
|
- return totalRevenue / 100;
|
|
- } catch (error) {
|
|
- console.error('Error fetching Lemon Squeezy revenue:', error);
|
|
- throw error;
|
|
- }
|
|
-}
|
|
-
|