Brand Studio docs
Engineering manualAPI route source

/api/credits/checkout

Exact current route handler: hosted-app/app/api/credits/checkout/route.js

Methods: GET, POST. Input signals: query parameters. Literal response-status signals: none detected.

Source: hosted-app/app/api/credits/checkout/route.js. Imports: ../../../../lib/bounded-http.mjs, ../../../../lib/comprehensive-pull.mjs, ../../../../lib/stripe-checkout-attempts.mjs, ../../../../lib/stripe-credit-checkout.mjs, ../../../../lib/supabase-rest.mjs, next/server. Exact source is shown for inspection; its presence does not prove authentication, validation or live behavior.

All API routes · API and execution contract

import { readBoundedJsonRequest } from "../../../../lib/bounded-http.mjs";
import { NextResponse } from "next/server";
import { supabaseConfigFromEnv } from "../../../../lib/supabase-rest.mjs";
import { resolveAuthContext, bearerTokenFromHeader } from "../../../../lib/comprehensive-pull.mjs";
import { creditBillingSessionRefusal } from "../../../../lib/stripe-credit-checkout.mjs";
import { startCreditCheckout, recoverCreditCheckout } from "../../../../lib/stripe-checkout-attempts.mjs";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(request) {
  const config = supabaseConfigFromEnv(process.env);
  const auth = await resolveAuthContext({ token: bearerTokenFromHeader(request.headers.get("authorization")), ...config });
  const refusal = creditBillingSessionRefusal(auth);
  if (refusal) {
    const { http, ...body } = refusal;
    return NextResponse.json(body, { status: http, headers: { "cache-control": "no-store" } });
  }
  const body = await readBoundedJsonRequest(request, 4096).catch(() => ({}));
  const result = await startCreditCheckout({ config, userId: auth.user.id, packId: body?.pack,
    attemptId: body?.attempt_id, afterAttemptId: body?.after_attempt_id });
  const { http, ...response } = result;
  return NextResponse.json(response, { status: http, headers: { "cache-control": "no-store" } });
}

export async function GET(request) {
  const config = supabaseConfigFromEnv(process.env);
  const auth = await resolveAuthContext({ token: bearerTokenFromHeader(request.headers.get("authorization")), ...config });
  const refusal = creditBillingSessionRefusal(auth);
  if (refusal) {
    const { http, ...body } = refusal;
    return NextResponse.json(body, { status: http, headers: { "cache-control": "no-store" } });
  }
  const params = new URL(request.url).searchParams;
  const result = await recoverCreditCheckout({ config, userId: auth.user.id, sessionId: params.get('session_id'),
    attemptId: params.get('attempt_id'), returnState: params.get('return_state') });
  const { http, ...body } = result;
  return NextResponse.json(body, { status: http, headers: { "cache-control": "no-store" } });
}