Skip to content

Commit

Permalink
feat: fix billing
Browse files Browse the repository at this point in the history
  • Loading branch information
nevo-david committed Feb 4, 2025
1 parent 296f3f1 commit 1ffcb5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class SubscriptionService {
billing: 'FREE' | 'STANDARD' | 'PRO'
) {
if (!customerId) {
return ;
return false;
}

const getOrgByCustomerId =
Expand All @@ -90,7 +90,7 @@ export class SubscriptionService {
))!;

if (getCurrentSubscription.isLifetime) {
return ;
return false;
}

const from = pricing[getCurrentSubscription?.subscriptionTier || 'FREE'];
Expand Down Expand Up @@ -123,6 +123,8 @@ export class SubscriptionService {
);
}

return true;

// if (to.faq < from.faq) {
// await this._faqRepository.deleteFAQs(getCurrentSubscription?.organizationId, from.faq - to.faq);
// }
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions libraries/nestjs-libraries/src/services/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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 };
}

Expand Down

0 comments on commit 1ffcb5c

Please sign in to comment.