Initial commit on Forgejo
All checks were successful
CI and deploy / Test (push) Successful in 4m52s
CI and deploy / Deploy production (push) Successful in 23s

Fresh repository history for elektrine/tarakan hosted at
https://git.elektrine.com/elektrine/tarakan.
This commit is contained in:
Maxfield Luke 2026-07-29 04:43:40 -04:00
commit af6077b9c3
455 changed files with 78366 additions and 0 deletions

View file

@ -0,0 +1,40 @@
defmodule TarakanWeb.BillingController do
@moduledoc """
Stripe exit points for subscription billing.
Plain POST endpoints (authenticated) that create a Checkout or Billing
Portal session and 303-redirect to Stripe. LiveViews use the same
`Tarakan.Billing` functions directly; these exist for non-LiveView pages
like /pricing.
"""
use TarakanWeb, :controller
alias Tarakan.Billing
def checkout(conn, %{"plan" => plan}) do
case Billing.ensure_checkout(conn.assigns.current_scope, plan) do
{:ok, checkout_url} ->
redirect(conn, external: checkout_url)
{:error, _reason} ->
conn
|> put_flash(:error, "Checkout could not be started. Try again shortly.")
|> redirect(to: ~p"/pricing")
end
end
def checkout(conn, _params), do: checkout(conn, %{"plan" => "enterprise"})
def portal(conn, _params) do
case Billing.portal_session(conn.assigns.current_scope.account) do
{:ok, portal_url} ->
redirect(conn, external: portal_url)
{:error, _reason} ->
conn
|> put_flash(:error, "The billing portal is unavailable for this account.")
|> redirect(to: ~p"/accounts/billing")
end
end
end