diff --git a/config/dev.exs b/config/dev.exs index 15877c2..62a6996 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -21,6 +21,10 @@ config :berrypod, Berrypod.Repo, config :berrypod, BerrypodWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + url: [ + host: System.get_env("PHX_HOST") || "localhost", + port: String.to_integer(System.get_env("PORT") || "4000") + ], http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")], check_origin: false, code_reloader: true, diff --git a/lib/berrypod/stripe/setup.ex b/lib/berrypod/stripe/setup.ex index 811f4a8..460c247 100644 --- a/lib/berrypod/stripe/setup.ex +++ b/lib/berrypod/stripe/setup.ex @@ -79,12 +79,25 @@ defmodule Berrypod.Stripe.Setup do end @doc """ - Returns true if the app is running on localhost (Stripe can't reach it). + Returns true if the app URL is unreachable from Stripe's servers + (localhost, loopback, or private/LAN IPs). """ def localhost? do url = BerrypodWeb.Endpoint.url() uri = URI.parse(url) - uri.host in ["localhost", "127.0.0.1", "0.0.0.0", "::1"] + unreachable_host?(uri.host) + end + + defp unreachable_host?(host) when host in ["localhost", "0.0.0.0", "::1"], do: true + + defp unreachable_host?(host) do + case :inet.parse_address(String.to_charlist(host)) do + {:ok, {127, _, _, _}} -> true + {:ok, {10, _, _, _}} -> true + {:ok, {172, b, _, _}} when b >= 16 and b <= 31 -> true + {:ok, {192, 168, _, _}} -> true + _ -> false + end end defp maybe_create_webhook(api_key) do diff --git a/lib/berrypod_web/live/setup/onboarding.ex b/lib/berrypod_web/live/setup/onboarding.ex index 583ca3e..39ce190 100644 --- a/lib/berrypod_web/live/setup/onboarding.ex +++ b/lib/berrypod_web/live/setup/onboarding.ex @@ -150,12 +150,7 @@ defmodule BerrypodWeb.Setup.Onboarding do case Products.create_provider_connection(params) do {:ok, connection} -> Products.enqueue_sync(connection) - - setup = %{ - socket.assigns.setup - | provider_connected: true, - provider_type: type - } + setup = Setup.setup_status() {:noreply, socket @@ -183,14 +178,7 @@ defmodule BerrypodWeb.Setup.Onboarding do case StripeSetup.connect(api_key) do {:ok, _result} -> - setup = %{socket.assigns.setup | stripe_connected: true} - - setup = - if setup.admin_created and setup.provider_connected do - %{setup | setup_complete: true} - else - setup - end + setup = Setup.setup_status() {:noreply, socket