Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(billing): verify live Cap Pro status before BAA purchase
Richie McIlroy92ffd46075fb
diff --git a/apps/web/__tests__/unit/signed-baa.test.ts b/apps/web/__tests__/unit/signed-baa.test.tsindex 7044bdf67..b02480dd5 100644--- a/apps/web/__tests__/unit/signed-baa.test.ts+++ b/apps/web/__tests__/unit/signed-baa.test.ts@@ -214,6 +214,34 @@ describe("Signed BAA entitlement", () => {).rejects.toThrow("active Cap Pro subscription");expect(mockStripe.subscriptions.create).not.toHaveBeenCalled();});++ it("rejects purchase when Stripe says Cap Pro is no longer entitled", async () => {+ mockOwner({+ stripeCustomerId: "cus_1",+ stripeSubscriptionId: "sub_stale",+ stripeSubscriptionStatus: "active",+ });+ mockStripe.subscriptions.retrieve.mockResolvedValue({+ id: "sub_stale",+ status: "canceled",+ });+ const { purchaseSignedBaa } = await import(+ "@/actions/organization/signed-baa"+ );++ await expect(+ purchaseSignedBaa("org-1" as never, {+ entityName: "Acme Health, Inc.",+ entityType: "Delaware corporation",+ entityAddress: "123 Main St, San Francisco, CA 94105",+ signerName: "Jane Smith",+ signerTitle: "CEO",+ noticesEmail: "[email protected]",+ signatureDataUrl: `data:image/png;base64,${"A".repeat(200)}`,+ }),+ ).rejects.toThrow("active Cap Pro subscription");+ expect(mockStripe.subscriptions.create).not.toHaveBeenCalled();+ });});const VALID_INPUT = {@@ -243,6 +271,7 @@ async function setupPurchaseAttempt() {vi.mocked(sendEmail).mockResolvedValue(undefined as never);mockStripe.subscriptions.retrieve.mockResolvedValue({id: "sub_active",+ status: "active",default_payment_method: "pm_1",});}diff --git a/apps/web/actions/organization/signed-baa.ts b/apps/web/actions/organization/signed-baa.tsindex e25faa6c2..9387b882d 100644--- a/apps/web/actions/organization/signed-baa.ts+++ b/apps/web/actions/organization/signed-baa.ts@@ -293,7 +293,27 @@ export async function purchaseSignedBaa(const priceId = getBaaPriceId();const customerId = user.stripeCustomerId;- if (!customerId || !ownerCanPurchaseSignedBaa(user)) {+ if (+ !customerId ||+ !user.stripeSubscriptionId ||+ !ownerCanPurchaseSignedBaa(user)+ ) {+ throw new Error(+ "Your organization needs an active Cap Pro subscription before adding the Signed BAA add-on.",+ );+ }++ let liveProSubscription: Stripe.Subscription;+ try {+ liveProSubscription = await stripe().subscriptions.retrieve(+ user.stripeSubscriptionId,+ );+ } catch {+ throw new Error(+ "Your organization needs an active Cap Pro subscription before adding the Signed BAA add-on.",+ );+ }+ if (!CAP_PRO_STATUSES.has(liveProSubscription.status)) {throw new Error("Your organization needs an active Cap Pro subscription before adding the Signed BAA add-on.",);