fix: prevent billingPortal creation if no active subscription (#9701)
Billing portal is created in settings/billing page even if subscription is canceled, causing server internal error. -> Skip back end request Bonus : display settings/billing page with disabled button even if subscription is canceled --------- Co-authored-by: etiennejouan <jouan.etienne@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -79,18 +79,16 @@ export class BillingPortalWorkspaceService {
|
||||
workspace: Workspace,
|
||||
returnUrlPath?: string,
|
||||
) {
|
||||
const currentSubscription =
|
||||
await this.billingSubscriptionService.getCurrentBillingSubscriptionOrThrow(
|
||||
{
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
);
|
||||
const lastSubscription = await this.billingSubscriptionRepository.findOne({
|
||||
where: { workspaceId: workspace.id },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
|
||||
if (!currentSubscription) {
|
||||
if (!lastSubscription) {
|
||||
throw new Error('Error: missing subscription');
|
||||
}
|
||||
|
||||
const stripeCustomerId = currentSubscription.stripeCustomerId;
|
||||
const stripeCustomerId = lastSubscription.stripeCustomerId;
|
||||
|
||||
if (!stripeCustomerId) {
|
||||
throw new Error('Error: missing stripeCustomerId');
|
||||
|
||||
Reference in New Issue
Block a user