This commit is contained in:
Emily
2024-09-12 16:16:19 +02:00
parent 6a9a698b7a
commit 525a371a6e
20 changed files with 746 additions and 365 deletions

View File

@@ -4,6 +4,8 @@ import type Event from 'stripe';
import { ProjectModel } from '@schema/ProjectSchema';
import { PREMIUM_DATA, PREMIUM_PLAN, getPlanFromId, getPlanFromPrice, getPlanFromTag } from '@data/PREMIUM';
import { ProjectLimitModel } from '@schema/ProjectsLimits';
import EmailService from '@services/EmailService'
import { UserModel } from '@schema/UserSchema';
@@ -87,6 +89,14 @@ async function onPaymentOnetimeSuccess(event: Event.PaymentIntentSucceededEvent)
await addSubscriptionToProject(project._id.toString(), PLAN, subscription.id, subscription.current_period_start, subscription.current_period_end)
const user = await UserModel.findOne({ _id: project.owner });
if (!user) return { ok: false, error: 'USER NOT EXIST FOR PROJECT' + project.id }
setTimeout(() => {
EmailService.sendPurchaseEmail(user.email);
}, 1);
return { ok: true };
}
@@ -125,6 +135,13 @@ async function onPaymentSuccess(event: Event.InvoicePaidEvent) {
await addSubscriptionToProject(project._id.toString(), PLAN, subscription_id, currentSubscription.current_period_start, currentSubscription.current_period_end)
const user = await UserModel.findOne({ _id: project.owner });
if (!user) return { ok: false, error: 'USER NOT EXIST FOR PROJECT' + project.id }
setTimeout(() => {
EmailService.sendPurchaseEmail(user.email);
}, 1);
return { ok: true };