mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
adjustments for docker image
This commit is contained in:
@@ -42,12 +42,14 @@ async function onPaymentFailed(event: Event.InvoicePaymentFailedEvent) {
|
|||||||
if (!project) return { error: 'CUSTOMER NOT EXIST' }
|
if (!project) return { error: 'CUSTOMER NOT EXIST' }
|
||||||
|
|
||||||
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
|
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
|
||||||
|
if (!allSubscriptions) return;
|
||||||
|
|
||||||
for (const subscription of allSubscriptions.data) {
|
for (const subscription of allSubscriptions.data) {
|
||||||
await StripeService.deleteSubscription(subscription.id);
|
await StripeService.deleteSubscription(subscription.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const freeSub = await StripeService.createFreeSubscription(customer_id);
|
const freeSub = await StripeService.createFreeSubscription(customer_id);
|
||||||
|
if (!freeSub) return;
|
||||||
|
|
||||||
await addSubscriptionToProject(
|
await addSubscriptionToProject(
|
||||||
project._id.toString(),
|
project._id.toString(),
|
||||||
@@ -75,6 +77,7 @@ async function onPaymentSuccess(event: Event.InvoicePaidEvent) {
|
|||||||
const subscription_id = event.data.object.subscription as string;
|
const subscription_id = event.data.object.subscription as string;
|
||||||
|
|
||||||
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
|
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
|
||||||
|
if (!allSubscriptions) return;
|
||||||
|
|
||||||
const currentSubscription = allSubscriptions.data.find(e => e.id === subscription_id);
|
const currentSubscription = allSubscriptions.data.find(e => e.id === subscription_id);
|
||||||
if (!currentSubscription) return { error: 'SUBSCRIPTION NOT EXIST' }
|
if (!currentSubscription) return { error: 'SUBSCRIPTION NOT EXIST' }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
||||||
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
|
import { ProjectLimitModel } from "@schema/ProjectsLimits";
|
||||||
import { UserSettingsModel } from "@schema/UserSettings";
|
import { UserSettingsModel } from "@schema/UserSettings";
|
||||||
import StripeService from '~/server/services/StripeService';
|
import StripeService from '~/server/services/StripeService';
|
||||||
|
|
||||||
@@ -41,6 +42,16 @@ export default defineEventHandler(async event => {
|
|||||||
visits: 0
|
visits: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await ProjectLimitModel.updateOne({ project_id: project._id }, {
|
||||||
|
events: 0,
|
||||||
|
visits: 0,
|
||||||
|
ai_messages: 0,
|
||||||
|
limit: 10_000_000,
|
||||||
|
ai_limit: 1_000_000,
|
||||||
|
billing_start_at: Date.now(),
|
||||||
|
billing_expire_at: new Date(3000, 1, 1)
|
||||||
|
}, { upsert: true })
|
||||||
|
|
||||||
return project.toJSON() as TProject;
|
return project.toJSON() as TProject;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user