readConfig required all Dodo values, so the console could not start before the railyard Dodo brand and products exist (owner item Y-2), although Railyard is sold inside the Scribase add-on (bridge orgs need no checkout). Dodo values are now optional: billingReady is true only when the key, the webhook secret and the three product ids are all set. Without them checkout, pause and cancel redirect with 'card payments open soon', the webhook answers 503, and everything else runs. Scribase project and session secret stay required. 4 new tests; console 158/158, tsc clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
import { setPaused } from "../../../../lib/billing.ts";
|
|
import { sessionFromRequest } from "../../../../lib/current.ts";
|
|
import { deps } from "../../../../lib/deps.ts";
|
|
import { sameOrigin } from "../../../../lib/http.ts";
|
|
|
|
export async function POST(req: Request) {
|
|
const d = deps();
|
|
const s = await sessionFromRequest(req);
|
|
if (!s) return new Response(null, { status: 303, headers: { location: `${d.cfg.consoleUrl}/` } });
|
|
if (!sameOrigin(req, d.cfg.consoleUrl)) return new Response("Forbidden", { status: 403 });
|
|
if (!d.cfg.billingReady) return new Response(null, { status: 303, headers: { location: `${d.cfg.consoleUrl}/billing?error=arriving` } });
|
|
const paused = (await req.formData()).get("paused") === "1";
|
|
try {
|
|
await setPaused(d, s.org, paused, new Date());
|
|
return new Response(null, { status: 303, headers: { location: `${d.cfg.consoleUrl}/billing` } });
|
|
} catch (err) {
|
|
console.error(`pause failed for org ${s.org}: ${(err as Error).message}`);
|
|
return new Response(null, { status: 303, headers: { location: `${d.cfg.consoleUrl}/billing?error=pause` } });
|
|
}
|
|
}
|