Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Pages/Projects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,8 @@ pricingUpdateH pid PricingUpdateForm{orderIdM, plan, isOnboarding} = do
Settings.notifyPlanChange envCfg project (ET.planUpgradedEmail productName)
_ -> addErrorToast "Something went wrong while fetching subscription id" Nothing
Nothing -> do
-- Free clears sub_id below; cancel first, or the provider keeps billing a sub nothing points at.
whenJustM (Projects.projectById pid) (Settings.cancelProjectSubscription envCfg)
_ <- updatePricing "Free" "" "" ""
auditPlan ("Free" :: Text)
handleOnboarding
Expand Down
8 changes: 8 additions & 0 deletions test/integration/Pages/BusinessFlowsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ stripeBillingTests = do
(reqs, _) <- runAsBaseRecordingHTTP tr $ atAuthToBase tr.trSessAndHeader $ CreateProject.deleteProjectGetH testPid
map fst reqs `shouldContain` ["https://api.stripe.com/v1/subscriptions/sub_test123"]

-- Choosing Free cleared sub_id but left the Stripe sub running, still billing the customer.
it "freePlanChoice_cancelsTheRunningStripeSubscription" \TestContext{tcResources = tr, tcProjectId = testPid} -> do
_ <- runQueryEffect tr $ Projects.updateStripeProjectBilling testPid (Projects.PlanName "GraduatedPricing") (Projects.SubId "sub_test123") (Projects.SubItemId "si_test") (Projects.CustomerId "cus_test")
session <- refreshSession tr.trPool tr.trATCtx.hasqlPool tr.trSessAndHeader
(reqs, _) <- runAsBaseRecordingHTTP tr $ atAuthToBase session $ CreateProject.pricingUpdateH testPid def
map fst reqs `shouldContain` ["https://api.stripe.com/v1/subscriptions/sub_test123"]
fmap (.paymentPlan) <$> runQueryEffect tr (Projects.projectById testPid) `shouldReturn` Just "Free"

it "deleteProject cancels the project's LemonSqueezy subscription" \TestContext{tcResources = tr, tcProjectId = testPid} -> do
_ <- runQueryEffect tr $ Projects.updateProjectPricing testPid (Projects.PlanName "GraduatedPricing") (Projects.SubId "987654") (Projects.SubItemId "si_test") (Projects.OrderId "ord_test")
(reqs, _) <- runAsBaseRecordingHTTP tr $ atAuthToBase tr.trSessAndHeader $ CreateProject.deleteProjectGetH testPid
Expand Down
Loading