Skip to content

Commit 1ffb3dd

Browse files
committed
add prompt payout connect job
1 parent c3a5a7f commit 1ffb3dd

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

config/config.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ config :algora, Oban,
3434
notify_bounty: 1,
3535
notify_tip_intent: 1,
3636
notify_claim: 1,
37+
prompt_payout_connect: 10,
3738
transfers: 1,
3839
activity_notifier: 1,
3940
activity_mailer: 1
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
defmodule Algora.Bounties.Jobs.PromptPayoutConnect do
2+
@moduledoc false
3+
use Oban.Worker, queue: :prompt_payout_connect
4+
5+
alias Algora.Github
6+
7+
require Logger
8+
9+
# TODO: confirm these urls
10+
defp signup_url, do: "#{AlgoraWeb.Endpoint.url()}"
11+
defp connect_url, do: "#{AlgoraWeb.Endpoint.url()}/user/transactions"
12+
defp body, do: "💵 To receive payouts, [sign up on Algora](#{signup_url()}) and [connect with Stripe](#{connect_url()})."
13+
14+
@impl Oban.Worker
15+
def perform(%Oban.Job{args: %{"ticket_ref" => ticket_ref, "installation_id" => nil}}) do
16+
if Github.pat_enabled() do
17+
Github.create_issue_comment(
18+
Github.pat(),
19+
ticket_ref["owner"],
20+
ticket_ref["repo"],
21+
ticket_ref["number"],
22+
body()
23+
)
24+
else
25+
Logger.info("""
26+
Github.create_issue_comment(Github.pat(), "#{ticket_ref["owner"]}", "#{ticket_ref["repo"]}", #{ticket_ref["number"]},
27+
\"\"\"
28+
#{body()}
29+
\"\"\")
30+
""")
31+
end
32+
end
33+
34+
@impl Oban.Worker
35+
def perform(%Oban.Job{args: %{"ticket_ref" => ticket_ref, "installation_id" => installation_id}}) do
36+
ticket_ref = %{
37+
owner: ticket_ref["owner"],
38+
repo: ticket_ref["repo"],
39+
number: ticket_ref["number"]
40+
}
41+
42+
with {:ok, token} <- Github.get_installation_token(installation_id) do
43+
Github.create_issue_comment(
44+
token,
45+
ticket_ref["owner"],
46+
ticket_ref["repo"],
47+
ticket_ref["number"],
48+
body()
49+
)
50+
end
51+
end
52+
end

lib/algora_web/controllers/webhooks/stripe_controller.ex

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule AlgoraWeb.Webhooks.StripeController do
44
import Ecto.Changeset
55
import Ecto.Query
66

7+
alias Algora.Bounties
78
alias Algora.Payments
89
alias Algora.Payments.Customer
910
alias Algora.Payments.Jobs.ExecutePendingTransfers
@@ -40,15 +41,24 @@ defmodule AlgoraWeb.Webhooks.StripeController do
4041
case Payments.fetch_active_account(user_id) do
4142
{:ok, _account} ->
4243
case %{user_id: user_id}
43-
|> ExecutePendingTransfers.new()
44+
|> Payments.Jobs.ExecutePendingTransfers.new()
4445
|> Oban.insert() do
4546
{:ok, _job} -> {:cont, :ok}
4647
error -> {:halt, error}
4748
end
4849

4950
{:error, :not_found} ->
50-
# TODO: notify user to connect payout account
51-
{:cont, :ok}
51+
# TODO:
52+
installation_id = 0
53+
# TODO:
54+
ticket_ref = %{"owner" => "", "repo" => "", "number" => 0}
55+
56+
case %{installation_id: installation_id, ticket_ref: ticket_ref}
57+
|> Bounties.Jobs.PromptPayoutConnect.new()
58+
|> Oban.insert() do
59+
{:ok, _job} -> {:cont, :ok}
60+
error -> {:halt, error}
61+
end
5262
end
5363
end)
5464

0 commit comments

Comments
 (0)