Skip to content

Commit f11e458

Browse files
committed
feat: update fees
1 parent eac872e commit f11e458

File tree

8 files changed

+52
-17
lines changed

8 files changed

+52
-17
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ defmodule Algora.Accounts.User do
3939
field :featured, :boolean, default: false
4040
field :priority, :integer, default: 0
4141
field :fee_pct, :integer, default: 9
42+
field :fee_pct_prev, :integer, default: 9
4243
field :seeded, :boolean, default: false
4344
field :activated, :boolean, default: false
4445
field :max_open_attempts, :integer, default: 3

lib/algora/bounties/bounties.ex

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -766,17 +766,17 @@ defmodule Algora.Bounties do
766766
%{
767767
owner: User.t(),
768768
amount: Money.t(),
769-
bounty_id: String.t(),
769+
bounty: Bounty.t(),
770770
claims: [Claim.t()]
771771
},
772772
opts :: [ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()}, recipient: User.t()]
773773
) ::
774774
{:ok, String.t()} | {:error, atom()}
775-
def reward_bounty(%{owner: owner, amount: amount, bounty_id: bounty_id, claims: claims}, opts \\ []) do
775+
def reward_bounty(%{owner: owner, amount: amount, bounty: bounty, claims: claims}, opts \\ []) do
776776
create_payment_session(
777777
%{owner: owner, amount: amount, description: "Bounty payment for OSS contributions"},
778778
ticket_ref: opts[:ticket_ref],
779-
bounty_id: bounty_id,
779+
bounty: bounty,
780780
claims: claims,
781781
recipient: opts[:recipient]
782782
)
@@ -785,20 +785,28 @@ defmodule Algora.Bounties do
785785
@spec generate_line_items(
786786
%{owner: User.t(), amount: Money.t()},
787787
opts :: [
788+
bounty: Bounty.t(),
788789
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()},
789790
claims: [Claim.t()],
790791
recipient: User.t()
791792
]
792793
) ::
793794
[LineItem.t()]
794795
def generate_line_items(%{owner: owner, amount: amount}, opts \\ []) do
796+
bounty = opts[:bounty]
795797
ticket_ref = opts[:ticket_ref]
796798
recipient = opts[:recipient]
797799
claims = opts[:claims] || []
798800

799801
description = if(ticket_ref, do: "#{ticket_ref[:repo]}##{ticket_ref[:number]}")
800802

801-
platform_fee_pct = Decimal.div(owner.fee_pct, 100)
803+
platform_fee_pct =
804+
if bounty && Date.before?(bounty.inserted_at, ~D[2025-04-16]) do
805+
Decimal.div(owner.fee_pct_prev, 100)
806+
else
807+
Decimal.div(owner.fee_pct, 100)
808+
end
809+
802810
transaction_fee_pct = Payments.get_transaction_fee_pct()
803811

804812
payouts =
@@ -845,7 +853,7 @@ defmodule Algora.Bounties do
845853
opts :: [
846854
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()},
847855
tip_id: String.t(),
848-
bounty_id: String.t(),
856+
bounty: Bounty.t(),
849857
claims: [Claim.t()],
850858
recipient: User.t()
851859
]
@@ -858,17 +866,20 @@ defmodule Algora.Bounties do
858866
generate_line_items(%{owner: owner, amount: amount},
859867
ticket_ref: opts[:ticket_ref],
860868
recipient: opts[:recipient],
861-
claims: opts[:claims]
869+
claims: opts[:claims],
870+
bounty: opts[:bounty]
862871
)
863872

864873
gross_amount = LineItem.gross_amount(line_items)
865874

875+
bounty_id = if bounty = opts[:bounty], do: bounty.id
876+
866877
Repo.transact(fn ->
867878
with {:ok, _charge} <-
868879
initialize_charge(%{
869880
id: Nanoid.generate(),
870881
user_id: owner.id,
871-
bounty_id: opts[:bounty_id],
882+
bounty_id: bounty_id,
872883
gross_amount: gross_amount,
873884
net_amount: amount,
874885
total_fee: Money.sub!(gross_amount, amount),
@@ -881,7 +892,7 @@ defmodule Algora.Bounties do
881892
claims: opts[:claims] || [],
882893
tip_id: opts[:tip_id],
883894
recipient_id: if(opts[:recipient], do: opts[:recipient].id),
884-
bounty_id: opts[:bounty_id],
895+
bounty_id: bounty_id,
885896
claim_id: nil,
886897
amount: amount,
887898
creator_id: owner.id,
@@ -902,7 +913,7 @@ defmodule Algora.Bounties do
902913
opts :: [
903914
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()},
904915
tip_id: String.t(),
905-
bounty_id: String.t(),
916+
bounty: Bounty.t(),
906917
claims: [Claim.t()],
907918
recipient: User.t()
908919
]
@@ -915,11 +926,14 @@ defmodule Algora.Bounties do
915926
generate_line_items(%{owner: owner, amount: amount},
916927
ticket_ref: opts[:ticket_ref],
917928
recipient: opts[:recipient],
918-
claims: opts[:claims]
929+
claims: opts[:claims],
930+
bounty: opts[:bounty]
919931
)
920932

921933
gross_amount = LineItem.gross_amount(line_items)
922934

935+
bounty_id = if bounty = opts[:bounty], do: bounty.id
936+
923937
Repo.transact(fn ->
924938
with {:ok, _charge} <-
925939
initialize_charge(%{
@@ -937,7 +951,7 @@ defmodule Algora.Bounties do
937951
claims: opts[:claims] || [],
938952
tip_id: opts[:tip_id],
939953
recipient_id: if(opts[:recipient], do: opts[:recipient].id),
940-
bounty_id: opts[:bounty_id],
954+
bounty_id: bounty_id,
941955
claim_id: nil,
942956
amount: amount,
943957
creator_id: owner.id,

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do
216216
repo: payload["repository"]["name"],
217217
number: payload["pull_request"]["number"]
218218
},
219-
bounty_id: autopayable_bounty.id,
219+
bounty: autopayable_bounty,
220220
claims: claims
221221
),
222222
{:ok, _invoice} <-

lib/algora_web/live/bounty_live.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ defmodule AlgoraWeb.BountyLive do
747747
owner: socket.assigns.bounty.owner,
748748
amount: amount
749749
},
750+
bounty: socket.assigns.bounty,
750751
ticket_ref: ticket_ref,
751752
recipient: recipient
752753
)
@@ -758,7 +759,7 @@ defmodule AlgoraWeb.BountyLive do
758759
final_amount = calculate_final_amount(changeset)
759760

760761
Bounties.reward_bounty(
761-
%{owner: bounty.owner, amount: final_amount, bounty_id: bounty.id, claims: []},
762+
%{owner: bounty.owner, amount: final_amount, bounty: bounty, claims: []},
762763
ticket_ref: socket.assigns.ticket_ref,
763764
recipient: socket.assigns.recipient
764765
)

lib/algora_web/live/claim_live.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,15 @@ defmodule AlgoraWeb.ClaimLive do
254254
end
255255

256256
defp assign_line_items(socket) do
257+
bounty = Enum.find(socket.assigns.available_bounties, &(&1.owner_id == socket.assigns.selected_context.id))
258+
257259
line_items =
258260
Bounties.generate_line_items(
259261
%{
260262
owner: socket.assigns.selected_context,
261263
amount: calculate_final_amount(socket.assigns.reward_bounty_form.source)
262264
},
265+
bounty: bounty,
263266
ticket_ref: ticket_ref(socket),
264267
claims: socket.assigns.claims
265268
)
@@ -299,7 +302,7 @@ defmodule AlgoraWeb.ClaimLive do
299302
%{
300303
owner: socket.assigns.selected_context,
301304
amount: final_amount,
302-
bounty_id: bounty.id,
305+
bounty: bounty,
303306
claims: socket.assigns.claims
304307
},
305308
ticket_ref: ticket_ref(socket)

lib/algora_web/live/contract_live.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ defmodule AlgoraWeb.ContractLive do
576576
owner: socket.assigns.bounty.owner,
577577
amount: calculate_final_amount(socket.assigns.reward_form.source)
578578
},
579+
bounty: socket.assigns.bounty,
579580
ticket_ref: socket.assigns.ticket_ref,
580581
recipient: socket.assigns.contractor
581582
)
@@ -587,7 +588,7 @@ defmodule AlgoraWeb.ContractLive do
587588
final_amount = calculate_final_amount(changeset)
588589

589590
Bounties.reward_bounty(
590-
%{owner: bounty.owner, amount: final_amount, bounty_id: bounty.id, claims: []},
591+
%{owner: bounty.owner, amount: final_amount, bounty: bounty, claims: []},
591592
ticket_ref: socket.assigns.ticket_ref,
592593
recipient: socket.assigns.contractor
593594
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Algora.Repo.Migrations.UpdateUserFeePct do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :fee_pct_prev, :integer, default: 9
7+
end
8+
9+
execute """
10+
UPDATE users
11+
SET fee_pct_prev = fee_pct,
12+
fee_pct = 9
13+
"""
14+
end
15+
end

test/algora/bounties_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule Algora.BountiesTest do
7575
%{
7676
owner: owner,
7777
amount: ~M[4000]usd,
78-
bounty_id: bounty.id,
78+
bounty: bounty,
7979
claims: claims
8080
},
8181
installation_id: installation.id
@@ -193,7 +193,7 @@ defmodule Algora.BountiesTest do
193193
Bounties.create_invoice(
194194
%{owner: owner, amount: amount, idempotency_key: "bounty-#{bounty.id}"},
195195
ticket_ref: ticket_ref,
196-
bounty_id: bounty.id,
196+
bounty: bounty,
197197
claims: [claim]
198198
)
199199

0 commit comments

Comments
 (0)