34 lines
943 B
Elixir
34 lines
943 B
Elixir
defmodule RecycledCloudWeb.BillingController do
|
|
use RecycledCloudWeb, :controller
|
|
|
|
alias RecycledCloud.Billing.Partner
|
|
alias RecycledCloud.Repo
|
|
|
|
def current_partner(conn) do
|
|
user = conn.assigns.current_user
|
|
Partner.get_or_create(user)
|
|
end
|
|
|
|
def index(conn, _params) do
|
|
partner = conn |> current_partner
|
|
changeset = partner |> Partner.changeset(%{})
|
|
|
|
render(conn, "index.html", partner: partner, partner_changeset: changeset)
|
|
end
|
|
|
|
def update(conn, %{"partner" => changes} = params) do
|
|
partner = conn |> current_partner
|
|
changeset = partner |> Partner.changeset(changes)
|
|
|
|
case Partner.apply(changeset) do
|
|
{:ok, _} ->
|
|
conn
|
|
|> put_flash(:info, "Billing Partner has been updated")
|
|
|> redirect(to: Routes.billing_path(conn, :index))
|
|
{:error, changeset} ->
|
|
render(conn, "index.html", partner: partner, partner_changeset:
|
|
changeset)
|
|
end
|
|
end
|
|
end
|