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