Skip to content

Commit ebb3177

Browse files
committed
collect billing details
1 parent dfa6267 commit ebb3177

File tree

4 files changed

+146
-8
lines changed

4 files changed

+146
-8
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ defmodule Algora.Accounts.User do
8383
field :login_token, :string, virtual: true
8484
field :signup_token, :string, virtual: true
8585

86+
field :billing_name, :string
87+
field :billing_address, :string
88+
field :executive_name, :string
89+
field :executive_role, :string
90+
8691
has_many :identities, Identity
8792
has_many :memberships, Member, foreign_key: :user_id
8893
has_many :members, Member, foreign_key: :org_id

lib/algora/admin/admin.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule Algora.Admin do
22
@moduledoc false
3+
import Ecto.Changeset
34
import Ecto.Query
45

56
alias Algora.Accounts
@@ -10,6 +11,7 @@ defmodule Algora.Admin do
1011
alias Algora.Bounties.Bounty
1112
alias Algora.Bounties.Claim
1213
alias Algora.Github
14+
alias Algora.Jobs.JobPosting
1315
alias Algora.Parser
1416
alias Algora.Payments
1517
alias Algora.Payments.Transaction
@@ -22,6 +24,23 @@ defmodule Algora.Admin do
2224

2325
require Logger
2426

27+
def seed_job(opts \\ %{}) do
28+
with {:ok, user} <- Repo.fetch_by(User, handle: opts.org.handle),
29+
{:ok, user} <- user |> change(opts.org) |> Repo.update(),
30+
{:ok, job} <-
31+
Repo.insert(%JobPosting{
32+
id: Nanoid.generate(),
33+
user_id: user.id,
34+
company_name: user.name,
35+
company_url: user.website_url,
36+
title: opts.title,
37+
description: opts.description,
38+
tech_stack: opts.tech_stack || Enum.take(user.tech_stack, 1)
39+
}) do
40+
dbg("#{AlgoraWeb.Endpoint.url()}/#{user.handle}/jobs/#{job.id}")
41+
end
42+
end
43+
2544
def sync_contributions(opts \\ []) do
2645
query =
2746
User

lib/algora_web/live/org/job_live.ex

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,35 @@ defmodule AlgoraWeb.Org.JobLive do
44

55
alias Algora.Accounts.User
66
alias Algora.Jobs
7+
alias Algora.Repo
78
alias Algora.Settings
89
alias AlgoraWeb.Forms.BountyForm
910
alias AlgoraWeb.Forms.ContractForm
1011
alias AlgoraWeb.Forms.TipForm
1112

1213
require Logger
1314

15+
defmodule WirePaymentForm do
16+
@moduledoc false
17+
use Ecto.Schema
18+
19+
import Ecto.Changeset
20+
21+
embedded_schema do
22+
field :billing_name, :string
23+
field :billing_address, :string
24+
field :executive_name, :string
25+
field :executive_role, :string
26+
field :payment_date, :date
27+
end
28+
29+
def changeset(form, attrs \\ %{}) do
30+
form
31+
|> cast(attrs, [:billing_name, :billing_address, :executive_name, :executive_role, :payment_date])
32+
|> validate_required([:billing_name, :billing_address, :executive_name, :executive_role, :payment_date])
33+
end
34+
end
35+
1436
defp subscribe(job) do
1537
Phoenix.PubSub.subscribe(Algora.PubSub, "job:#{job.id}")
1638
end
@@ -45,6 +67,21 @@ defmodule AlgoraWeb.Org.JobLive do
4567
# Map of github_handle => %{status: :loading/:done, user: nil/User}
4668
|> assign(:importing_users, %{})
4769
|> assign(:loading_contribution_handle, nil)
70+
|> assign(
71+
:wire_form,
72+
to_form(
73+
WirePaymentForm.changeset(
74+
%WirePaymentForm{
75+
payment_date: Date.utc_today(),
76+
billing_name: socket.assigns.current_org.billing_name,
77+
billing_address: socket.assigns.current_org.billing_address,
78+
executive_name: socket.assigns.current_org.executive_name,
79+
executive_role: socket.assigns.current_org.executive_role
80+
},
81+
%{}
82+
)
83+
)
84+
)
4885
|> assign_applicants()}
4986

5087
_ ->
@@ -649,12 +686,31 @@ defmodule AlgoraWeb.Org.JobLive do
649686
end
650687

651688
@impl true
652-
def handle_event("process_payment", %{"payment" => %{"payment_type" => "wire"}}, socket) do
653-
# Mock successful wire initiation
654-
{:noreply,
655-
socket
656-
|> put_flash(:info, "Wire transfer details have been sent to your email")
657-
|> assign(:show_payment_drawer, false)}
689+
def handle_event("process_payment", %{"payment" => %{"payment_type" => "wire"}} = params, socket) do
690+
case WirePaymentForm.changeset(%WirePaymentForm{}, params["wire_payment_form"]) do
691+
%{valid?: true} = changeset ->
692+
# Update user billing info
693+
{:ok, _user} =
694+
socket.assigns.current_org
695+
|> Ecto.Changeset.change(%{
696+
billing_name: changeset.changes.billing_name,
697+
billing_address: changeset.changes.billing_address,
698+
executive_name: changeset.changes.executive_name,
699+
executive_role: changeset.changes.executive_role
700+
})
701+
|> Repo.update()
702+
703+
{:noreply,
704+
socket
705+
|> put_flash(:info, "Wire transfer details have been sent to your email")
706+
|> assign(:show_payment_drawer, false)}
707+
708+
%{valid?: false} = changeset ->
709+
{:noreply,
710+
socket
711+
|> assign(:wire_form, to_form(changeset))
712+
|> put_flash(:error, "Please fill in all required fields")}
713+
end
658714
end
659715

660716
@impl true
@@ -1587,9 +1643,48 @@ defmodule AlgoraWeb.Org.JobLive do
15871643
{Money.to_string!(@current_org.subscription_price)}
15881644
</span>
15891645
</div>
1646+
1647+
<div class="border-t pt-4">
1648+
<h4 class="font-medium mb-4">Billing Information</h4>
1649+
<div class="space-y-4">
1650+
<.input
1651+
type="text"
1652+
label="Billing Name"
1653+
field={@wire_form[:billing_name]}
1654+
value={
1655+
@current_org.billing_name || @current_org.display_name ||
1656+
@current_org.handle
1657+
}
1658+
/>
1659+
<.input
1660+
type="textarea"
1661+
label="Billing Address"
1662+
field={@wire_form[:billing_address]}
1663+
value={@current_org.billing_address}
1664+
/>
1665+
<.input
1666+
type="text"
1667+
label="Executive Name"
1668+
field={@wire_form[:executive_name]}
1669+
value={@current_org.executive_name}
1670+
/>
1671+
<.input
1672+
type="text"
1673+
label="Executive Role"
1674+
field={@wire_form[:executive_role]}
1675+
value={@current_org.executive_role}
1676+
/>
1677+
<.input
1678+
type="date"
1679+
label="Payment Date"
1680+
field={@wire_form[:payment_date]}
1681+
value={Date.utc_today()}
1682+
/>
1683+
</div>
1684+
</div>
15901685
</div>
15911686
<p class="text-sm text-muted-foreground pt-4">
1592-
You will receive an invoice and receipt via email once you confirm
1687+
You will receive an invoice via email once you confirm
15931688
</p>
15941689
</.card_content>
15951690
</.card>
@@ -1599,7 +1694,7 @@ defmodule AlgoraWeb.Org.JobLive do
15991694
Cancel
16001695
</.button>
16011696
<.button type="submit">
1602-
I have wired
1697+
Generate invoice
16031698
</.button>
16041699
</div>
16051700
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule Algora.Repo.Migrations.AddBillingInfoToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :billing_name, :string
7+
add :billing_address, :string
8+
add :executive_name, :string
9+
add :executive_role, :string
10+
end
11+
12+
# Set billing_name for existing users
13+
execute """
14+
UPDATE users
15+
SET billing_name = COALESCE(display_name, handle)
16+
WHERE billing_name IS NULL
17+
"""
18+
end
19+
end

0 commit comments

Comments
 (0)