Skip to content

Commit 16fba4d

Browse files
committed
adapt line items based on contract type
1 parent a5b014d commit 16fba4d

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,8 @@ defmodule Algora.Bounties do
828828
bounty: Bounty.t(),
829829
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()},
830830
claims: [Claim.t()],
831-
recipient: User.t()
831+
recipient: User.t(),
832+
contract_type: Bounty.contract_type()
832833
]
833834
) ::
834835
[LineItem.t()]
@@ -841,51 +842,62 @@ defmodule Algora.Bounties do
841842
description = if(ticket_ref, do: "#{ticket_ref[:repo]}##{ticket_ref[:number]}")
842843

843844
platform_fee_pct =
844-
if bounty && Date.before?(bounty.inserted_at, ~D[2025-04-16]) do
845+
if bounty && Date.before?(bounty.inserted_at, ~D[2025-04-16]) && is_nil(bounty.contract_type) do
845846
Decimal.div(owner.fee_pct_prev, 100)
846847
else
847848
Decimal.div(owner.fee_pct, 100)
848849
end
849850

850851
transaction_fee_pct = Payments.get_transaction_fee_pct()
851852

852-
payouts =
853-
if recipient do
853+
case opts[:contract_type] do
854+
:marketplace ->
854855
[
855856
%LineItem{
856-
amount: amount,
857-
title: "Payment to @#{recipient.provider_login}",
858-
description: description,
857+
amount: Money.mult!(amount, Decimal.add(1, Decimal.add(platform_fee_pct, transaction_fee_pct))),
858+
title: "Contract payment - @#{recipient.provider_login}",
859+
description: "(includes all platform and payment processing fees)",
859860
image: recipient.avatar_url,
860861
type: :payout
861862
}
862863
]
863-
else
864-
Enum.map(claims, fn claim ->
865-
%LineItem{
866-
# TODO: ensure shares are normalized
867-
amount: Money.mult!(amount, claim.group_share),
868-
title: "Payment to @#{claim.user.provider_login}",
869-
description: description,
870-
image: claim.user.avatar_url,
871-
type: :payout
872-
}
873-
end)
874-
end
875864

876-
payouts ++
877-
[
878-
%LineItem{
879-
amount: Money.mult!(amount, platform_fee_pct),
880-
title: "Algora platform fee (#{Util.format_pct(platform_fee_pct)})",
881-
type: :fee
882-
},
883-
%LineItem{
884-
amount: Money.mult!(amount, transaction_fee_pct),
885-
title: "Transaction fee (#{Util.format_pct(transaction_fee_pct)})",
886-
type: :fee
887-
}
888-
]
865+
_ ->
866+
if recipient do
867+
[
868+
%LineItem{
869+
amount: amount,
870+
title: "Payment to @#{recipient.provider_login}",
871+
description: description,
872+
image: recipient.avatar_url,
873+
type: :payout
874+
}
875+
]
876+
else
877+
Enum.map(claims, fn claim ->
878+
%LineItem{
879+
# TODO: ensure shares are normalized
880+
amount: Money.mult!(amount, claim.group_share),
881+
title: "Payment to @#{claim.user.provider_login}",
882+
description: description,
883+
image: claim.user.avatar_url,
884+
type: :payout
885+
}
886+
end)
887+
end ++
888+
[
889+
%LineItem{
890+
amount: Money.mult!(amount, platform_fee_pct),
891+
title: "Algora platform fee (#{Util.format_pct(platform_fee_pct)})",
892+
type: :fee
893+
},
894+
%LineItem{
895+
amount: Money.mult!(amount, transaction_fee_pct),
896+
title: "Transaction fee (#{Util.format_pct(transaction_fee_pct)})",
897+
type: :fee
898+
}
899+
]
900+
end
889901
end
890902

891903
@spec create_payment_session(

lib/algora_web/live/contract_live.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ defmodule AlgoraWeb.ContractLive do
793793
},
794794
bounty: socket.assigns.bounty,
795795
ticket_ref: socket.assigns.ticket_ref,
796-
recipient: socket.assigns.contractor
796+
recipient: socket.assigns.contractor,
797+
contract_type: socket.assigns.bounty.contract_type
797798
)
798799

799800
assign(socket, :line_items, line_items)

0 commit comments

Comments
 (0)