@@ -12,6 +12,7 @@ defmodule Algora.Admin do
12
12
alias Algora.Github
13
13
alias Algora.Parser
14
14
alias Algora.Payments
15
+ alias Algora.Payments.Transaction
15
16
alias Algora.Repo
16
17
alias Algora.Util
17
18
alias Algora.Workspace
@@ -21,6 +22,48 @@ defmodule Algora.Admin do
21
22
22
23
require Logger
23
24
25
+ def release_payment ( tx_id ) do
26
+ Repo . transact ( fn ->
27
+ { _ , [ tx ] } =
28
+ Repo . update_all ( from ( t in Transaction , where: t . id == ^ tx_id , select: t ) ,
29
+ set: [ status: :succeeded , succeeded_at: DateTime . utc_now ( ) ]
30
+ )
31
+
32
+ Repo . update_all ( from ( b in Bounty , where: b . id == ^ tx . bounty_id ) , set: [ status: :paid ] )
33
+
34
+ activities_result = Repo . insert_activity ( tx , % { type: :transaction_succeeded , notify_users: [ tx . user_id ] } )
35
+
36
+ jobs_result =
37
+ case Payments . fetch_active_account ( tx . user_id ) do
38
+ { :ok , _account } ->
39
+ % { credit_id: tx . id }
40
+ |> Payments.Jobs.ExecutePendingTransfer . new ( )
41
+ |> Oban . insert ( )
42
+
43
+ { :error , :no_active_account } ->
44
+ Logger . warning ( "No active account for user #{ tx . user_id } " )
45
+
46
+ % { credit_id: tx . id }
47
+ |> Bounties.Jobs.PromptPayoutConnect . new ( )
48
+ |> Oban . insert ( )
49
+ end
50
+
51
+ with { :ok , _ } <- activities_result ,
52
+ { :ok , _ } <- jobs_result do
53
+ Payments . broadcast ( )
54
+ { :ok , nil }
55
+ else
56
+ { :error , reason } ->
57
+ Logger . error ( "Failed to update transactions: #{ inspect ( reason ) } " )
58
+ { :error , :failed_to_update_transactions }
59
+
60
+ error ->
61
+ Logger . error ( "Failed to update transactions: #{ inspect ( error ) } " )
62
+ { :error , :failed_to_update_transactions }
63
+ end
64
+ end )
65
+ end
66
+
24
67
def refresh_bounty ( url ) do
25
68
with % { owner: owner , repo: repo , number: number } <- parse_ticket_url ( url ) ,
26
69
{ :ok , ticket } <- Workspace . ensure_ticket ( token_for ( owner ) , owner , repo , number ) do
0 commit comments