Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent downgrading an org when a coupon/credit is applied #1718

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/routes/(console)/apply-credit/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
WizardSecondaryContent,
WizardSecondaryFooter
} from '$lib/layout';
import { type PaymentList } from '$lib/sdk/billing';
import { type PaymentList, type Plan } from '$lib/sdk/billing';
import { app } from '$lib/stores/app';
import { isOrganization } from '$lib/stores/billing.js';
import { addNotification } from '$lib/stores/notifications';
Expand Down Expand Up @@ -72,6 +72,12 @@
let couponData = data?.couponData;
let campaign = data?.campaign;
let billingPlan = BillingPlan.PRO;
let currentPlan: Plan;

function isUpgrade() {
const newPlan = $page.data.plansInfo.get(billingPlan);
return currentPlan && newPlan && currentPlan.order < newPlan.order;
}

onMount(async () => {
await loadPaymentMethods();
Expand Down Expand Up @@ -132,7 +138,7 @@
}

// Upgrade existing org
else if (selectedOrg?.billingPlan !== billingPlan) {
else if (selectedOrg?.billingPlan !== billingPlan && isUpgrade()) {
org = await sdk.forConsole.billing.updatePlan(
selectedOrg.$id,
billingPlan,
Expand Down Expand Up @@ -216,6 +222,14 @@
selectedOrg?.billingPlan === BillingPlan.SCALE
? BillingPlan.SCALE
: (campaign?.plan ?? BillingPlan.PRO);

$: {
if (selectedOrgId) {
(async () => {
currentPlan = await sdk.forConsole.billing.getOrganizationPlan(selectedOrgId);
})();
}
}
</script>

<svelte:head>
Expand Down