Skip to content

Commit f70211a

Browse files
committed
feat: implement create_tip_intent function and refactor do_create_tip_intent in bounties module; enhance safe redirect handling in util module; update tip controller for streamlined redirection; improve layout in dashboard live view
1 parent b05bb29 commit f70211a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/algora/admin/admin.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ defmodule Algora.Admin do
2121

2222
require Logger
2323

24+
def create_tip_intent(recipient, amount, ticket_ref) do
25+
with installation_id when not is_nil(installation_id) <- Workspace.get_installation_id_by_owner(ticket_ref.owner) do
26+
Bounties.do_create_tip_intent(
27+
%{
28+
recipient: recipient,
29+
amount: amount,
30+
ticket_ref: ticket_ref
31+
},
32+
installation_id: installation_id
33+
)
34+
end
35+
end
36+
2437
def add_label(url, amount) do
2538
%{owner: owner, repo: repo, number: number} = parse_ticket_url(url)
2639

lib/algora/bounties/bounties.ex

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ defmodule Algora.Bounties do
639639
|> Oban.insert()
640640
end
641641

642-
@spec create_tip_intent(
642+
@spec do_create_tip_intent(
643643
%{
644644
recipient: String.t() | nil,
645645
amount: Money.t() | nil,
@@ -648,7 +648,7 @@ defmodule Algora.Bounties do
648648
opts :: [installation_id: integer()]
649649
) ::
650650
{:ok, String.t()} | {:error, atom()}
651-
def create_tip_intent(
651+
def do_create_tip_intent(
652652
%{recipient: recipient, amount: amount, ticket_ref: %{owner: owner, repo: repo, number: number}},
653653
opts \\ []
654654
) do
@@ -682,12 +682,25 @@ defmodule Algora.Bounties do
682682
"Please visit [Algora](#{url}) to complete your tip via Stripe."
683683
end
684684

685-
%{
685+
Jobs.NotifyTipIntent.new(%{
686686
body: body,
687687
ticket_ref: %{owner: owner, repo: repo, number: number},
688688
installation_id: opts[:installation_id]
689-
}
690-
|> Jobs.NotifyTipIntent.new()
689+
})
690+
end
691+
692+
@spec create_tip_intent(
693+
params :: %{
694+
recipient: String.t() | nil,
695+
amount: Money.t() | nil,
696+
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()}
697+
},
698+
opts :: [installation_id: integer()]
699+
) ::
700+
{:ok, String.t()} | {:error, atom()}
701+
def create_tip_intent(params, opts \\ []) do
702+
params
703+
|> do_create_tip_intent(opts)
691704
|> Oban.insert()
692705
end
693706

0 commit comments

Comments
 (0)