Skip to content

Commit

Permalink
Merge branch 'bc-checkout' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
macifell committed May 21, 2024
2 parents 8ef8a93 + eb2b81b commit 436b6e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/recognizer/bigcommerce.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,21 @@ defmodule Recognizer.BigCommerce do

def login_redirect_uri(user), do: home_redirect_uri() <> config(:login_path) <> generate_login_jwt(user)

def checkout_redirect_uri(user), do: home_redirect_uri() <> config(:login_path) <> generate_checkout_login_jwt(user)

def logout_redirect_uri(), do: home_redirect_uri() <> config(:logout_path)

defp generate_checkout_login_jwt(user) do
{:ok, token, _claims} =
user
|> Recognizer.Repo.preload(:bigcommerce_user)
|> jwt_claims()
|> Map.put("redirect_to", "/checkout")
|> Token.generate_and_sign(jwt_signer())

token
end

defp generate_login_jwt(user) do
{:ok, token, _claims} =
user
Expand Down
3 changes: 3 additions & 0 deletions lib/recognizer_web/authentication.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ defmodule RecognizerWeb.Authentication do
"""
def login_redirect(conn, user) do
cond do
get_session(conn, :bc_checkout) ->
[external: BigCommerce.checkout_redirect_uri(user)]

get_session(conn, :bc) ->
[external: BigCommerce.login_redirect_uri(user)]

Expand Down
8 changes: 8 additions & 0 deletions lib/recognizer_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ defmodule RecognizerWeb.Router do
end
end

defp add_bc_to_session(%{query_params: %{"bc" => "true", "checkout" => "true"}} = conn, _opts) do
if Recognizer.BigCommerce.enabled?() do
put_session(conn, :bc_checkout, true)
else
conn
end
end

defp add_bc_to_session(conn, _opts) do
conn
end
Expand Down

0 comments on commit 436b6e1

Please sign in to comment.