Fix broken billing portal when subscription canceled (#5082)
Fix billing portal link for canceled subscription
This commit is contained in:
@ -86,6 +86,13 @@ export const SettingsBilling = () => {
|
||||
const billingPortalButtonDisabled =
|
||||
loading || !isDefined(data) || !isDefined(data.billingPortalSession.url);
|
||||
|
||||
const switchIntervalButtonDisabled =
|
||||
onboardingStatus !== OnboardingStatus.Completed;
|
||||
|
||||
const cancelPlanButtonDisabled =
|
||||
billingPortalButtonDisabled ||
|
||||
onboardingStatus !== OnboardingStatus.Completed;
|
||||
|
||||
const displayPaymentFailInfo =
|
||||
onboardingStatus === OnboardingStatus.PastDue ||
|
||||
onboardingStatus === OnboardingStatus.Unpaid;
|
||||
@ -176,6 +183,7 @@ export const SettingsBilling = () => {
|
||||
title="View billing details"
|
||||
variant="secondary"
|
||||
onClick={openBillingPortal}
|
||||
disabled={billingPortalButtonDisabled}
|
||||
/>
|
||||
</Section>
|
||||
<Section>
|
||||
@ -188,7 +196,7 @@ export const SettingsBilling = () => {
|
||||
title={`Switch ${switchingInfo.to}`}
|
||||
variant="secondary"
|
||||
onClick={openSwitchingIntervalModal}
|
||||
disabled={billingPortalButtonDisabled}
|
||||
disabled={switchIntervalButtonDisabled}
|
||||
/>
|
||||
</Section>
|
||||
<Section>
|
||||
@ -202,7 +210,7 @@ export const SettingsBilling = () => {
|
||||
variant="secondary"
|
||||
accent="danger"
|
||||
onClick={openBillingPortal}
|
||||
disabled={billingPortalButtonDisabled}
|
||||
disabled={cancelPlanButtonDisabled}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
|
||||
@ -96,6 +96,14 @@ export class BillingService {
|
||||
return notCanceledSubscriptions?.[0];
|
||||
}
|
||||
|
||||
async getStripeCustomerId(workspaceId: string) {
|
||||
const subscriptions = await this.billingSubscriptionRepository.find({
|
||||
where: { workspaceId },
|
||||
});
|
||||
|
||||
return subscriptions?.[0]?.stripeCustomerId;
|
||||
}
|
||||
|
||||
async getBillingSubscriptionItem(
|
||||
workspaceId: string,
|
||||
stripeProductId = this.environmentService.get(
|
||||
@ -131,11 +139,9 @@ export class BillingService {
|
||||
workspaceId: string,
|
||||
returnUrlPath?: string,
|
||||
) {
|
||||
const billingSubscription = await this.getCurrentBillingSubscription({
|
||||
workspaceId,
|
||||
});
|
||||
const stripeCustomerId = await this.getStripeCustomerId(workspaceId);
|
||||
|
||||
if (!billingSubscription) {
|
||||
if (!stripeCustomerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +151,7 @@ export class BillingService {
|
||||
: frontBaseUrl;
|
||||
|
||||
const session = await this.stripeService.createBillingPortalSession(
|
||||
billingSubscription.stripeCustomerId,
|
||||
stripeCustomerId,
|
||||
returnUrl,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user