Skip to content

Commit

Permalink
feat: Adding fetching user to check payment status. #1
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Dec 26, 2022
1 parent 990444e commit 0bfea37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,10 @@ defmodule UsersTable do
Pockets.put(@table, person_id, %{stripe_id: stripe_id, status: status})
end

def fetch_user(person_id) do
Pockets.get(@table, person_id)
end

end
```

Expand All @@ -1182,6 +1186,8 @@ If the file already exists, we open the file.
- `create_user/3` receives a `stripe_id`, `person_id` and `status`
(pertaining to whether the payment has been made or not)
and creates a user object.
- `fetch_user/1` retrieves the persisted user
according to the given` person_id`.

Let's make use of some of these functions.
We want to setup the `DETS` table on the process startup.
Expand All @@ -1199,6 +1205,12 @@ UsersTable.init()

Awesome!



# todo
ver todo no checkout_session_controller.ex
remove swoosh, mailer, postgres, ecto

# Thanks!

Thanks for learning about payment processing with us!
Expand Down
4 changes: 4 additions & 0 deletions lib/app/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ defmodule UsersTable do
Pockets.put(@table, person_id, %{stripe_id: stripe_id, status: status})
end

def fetch_user(person_id) do
Pockets.get(@table, person_id)
end

end
12 changes: 9 additions & 3 deletions lib/app_web/controllers/app_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ defmodule AppWeb.AppController do
use AppWeb, :controller

def home(conn, _params) do
# The home page is often custom made,
# so skip the default app layout.
render(conn, :app, layout: false)

person_id = conn.assigns.person.id
case UsersTable.fetch_user(person_id) do
nil ->
conn |> redirect(to: ~p"/")

_ ->
render(conn, :app, layout: false)
end
end
end
8 changes: 5 additions & 3 deletions lib/app_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ defmodule AppWeb.PageController do
use AppWeb, :controller

def home(conn, _params) do
# The home page is often custom made,
# so skip the default app layout.
render(conn, :home, layout: false)
end

def success(conn, %{"session_id" => session_id}) do

case Stripe.Session.retrieve(session_id) do
{:ok, _session} ->
{:ok, session} ->

person_id = conn.assigns.person.id
UsersTable.create_user(%{person_id: person_id, stripe_id: session.customer, status: true})

render(conn, :success, layout: false)

{:error, _error} ->
Expand Down

0 comments on commit 0bfea37

Please sign in to comment.