Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(billing): cancel Cap Pro at period end via zero seats
Richie McIlroy81e701953592
diff --git a/apps/web/actions/organization/update-seat-quantity.ts b/apps/web/actions/organization/update-seat-quantity.tsindex d6343f339..91a0a248f 100644--- a/apps/web/actions/organization/update-seat-quantity.ts+++ b/apps/web/actions/organization/update-seat-quantity.ts@@ -155,11 +155,37 @@ export async function updateSeatQuantity(organizationId: Organisation.OrganisationId,newQuantity: number,) {- validateQuantity(newQuantity);+ if (+ !Number.isInteger(newQuantity) ||+ newQuantity < 0 ||+ newQuantity > MAX_SEATS+ ) {+ throw new Error(`Quantity must be an integer between 0 and ${MAX_SEATS}`);+ }const { subscription, subscriptionItem, proSeatsUsed, user } =await getOwnerSubscription(organizationId);const currentQuantity = subscriptionItem.quantity ?? 1;+ // Zero seats means canceling Cap Pro. The paid period stays active until+ // it expires (no refund); the deletion webhook then downgrades the account+ // and cancels any Signed BAA subscription.+ if (newQuantity === 0) {+ if (proSeatsUsed > 1) {+ throw new Error(+ "Remove Pro seats from your members before canceling the subscription",+ );+ }+ await stripe().subscriptions.update(subscription.id, {+ cancel_at_period_end: true,+ });+ revalidatePath("/dashboard/settings/organization");+ return {+ success: true,+ newQuantity: currentQuantity,+ cancelAtPeriodEnd: true,+ };+ }+if (newQuantity < proSeatsUsed) {throw new Error(`Cannot reduce below ${proSeatsUsed} seats (currently assigned)`,@@ -212,5 +238,5 @@ export async function updateSeatQuantity(revalidatePath("/dashboard/settings/organization");- return { success: true, newQuantity };+ return { success: true, newQuantity, cancelAtPeriodEnd: false };}