feat: fix billing

This commit is contained in:
Nevo David 2025-02-04 23:16:22 +07:00
parent 296f3f15af
commit 1ffcb5c545
2 changed files with 25 additions and 6 deletions

View File

@ -76,7 +76,7 @@ export class SubscriptionService {
billing: 'FREE' | 'STANDARD' | 'PRO'
) {
if (!customerId) {
return ;
return false;
}
const getOrgByCustomerId =
@ -90,7 +90,7 @@ export class SubscriptionService {
))!;
if (getCurrentSubscription.isLifetime) {
return ;
return false;
}
const from = pricing[getCurrentSubscription?.subscriptionTier || 'FREE'];
@ -123,6 +123,8 @@ export class SubscriptionService {
);
}
return true;
// if (to.faq < from.faq) {
// await this._faqRepository.deleteFAQs(getCurrentSubscription?.organizationId, from.faq - to.faq);
// }
@ -152,7 +154,18 @@ export class SubscriptionService {
org?: string
) {
if (!code) {
await this.modifySubscription(customerId, totalChannels, billing);
try {
const load = await this.modifySubscription(
customerId,
totalChannels,
billing
);
if (!load) {
return {};
}
} catch (e) {
return {};
}
}
return this._subscriptionRepository.createOrUpdateSubscription(
identifier,

View File

@ -104,7 +104,9 @@ export class StripeService {
try {
await stripe.paymentMethods.detach(paymentMethods.data[0].id);
await stripe.subscriptions.cancel(event.data.object.id as string);
} catch (err) {/*dont do anything*/}
} catch (err) {
/*dont do anything*/
}
return false;
}
}
@ -122,8 +124,12 @@ export class StripeService {
uniqueId: string;
} = event.data.object.metadata;
const check = await this.checkValidCard(event);
if (!check) {
try {
const check = await this.checkValidCard(event);
if (!check) {
return { ok: false };
}
} catch (err) {
return { ok: false };
}