Skip to content

Commit

Permalink
Add redirect_uri to stripe_auth
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Nov 29, 2016
1 parent 1c5bf5f commit a3d510c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ config :code_corps, :analytics, CodeCorps.Analytics.InMemoryAPI
# Configures stripe for dev mode
config :code_corps, :stripe, Stripe
config :code_corps, :stripe_env, :dev
config :code_corps, :stripe_redirect_uri, "http://localhost:4200/oauth/stripe"

config :sentry,
environment_name: Mix.env || :dev
1 change: 1 addition & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ config :code_corps, :analytics, CodeCorps.Analytics.SegmentAPI
# Configures stripe for production
config :code_corps, :stripe, Stripe
config :code_corps, :stripe_env, :prod
config :code_corps, :stripe_redirect_uri, "http://www.codecorps.org/oauth/stripe"

config :sentry,
environment_name: Mix.env || :prod
Expand Down
1 change: 1 addition & 0 deletions config/remote-development.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ config :logger, level: :info
# Configures stripe for remote dev
config :code_corps, :stripe, Stripe
config :code_corps, :stripe_env, :remote_dev
config :code_corps, :stripe_redirect_uri, "http://www.pbqrpbecf-qri.org/oauth/stripe"

# ## SSL Support
#
Expand Down
1 change: 1 addition & 0 deletions config/staging.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ config :sentry,
# Configures stripe for staging
config :code_corps, :stripe, Stripe
config :code_corps, :stripe_env, :staging
config :code_corps, :stripe_redirect_uri, "http://www.pbqrpbecf.org/oauth/stripe"

# ## SSL Support
#
Expand Down
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ config :code_corps, :analytics, CodeCorps.Analytics.TestAPI
# Configures stripe for test mode
config :code_corps, :stripe, CodeCorps.StripeTesting
config :code_corps, :stripe_env, :test
config :code_corps, :stripe_redirect_uri, "http://localhost:4200/oauth/stripe"

config :code_corps, :icon_color_generator, CodeCorps.RandomIconColor.TestGenerator

Expand Down
13 changes: 13 additions & 0 deletions test/controllers/stripe_auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,18 @@ defmodule CodeCorps.StripeAuthControllerTest do
conn = get conn, stripe_auth_path(conn, :stripe_auth, project)
assert json_response(conn, 403)
end

@tag :authenticated
test "sets redirect_uri from environment", %{conn: conn, current_user: current_user} do
Application.put_env(:code_corps, :stripe_redirect_uri, "https://example.com")
organization = insert(:organization)
insert(:organization_membership, role: "owner", member: current_user, organization: organization)
project = insert(:project, organization: organization)

conn = get conn, stripe_auth_path(conn, :stripe_auth, project)
url = json_response(conn, 200)["data"]["attributes"]["url"]
query = url |> URI.decode_query
assert query["redirect_uri"] == "https://example.com"
end
end
end
1 change: 0 additions & 1 deletion web/controllers/stripe_auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule CodeCorps.StripeAuthController do
alias CodeCorps.Project
alias CodeCorps.Repo
alias CodeCorps.StripeAuth
alias CodeCorps.User

plug :load_and_authorize_resource, model: Project, only: [:stripe_auth]

Expand Down
5 changes: 5 additions & 0 deletions web/models/stripe_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule CodeCorps.StripeAuth do
defp url_params(organization, user, token) do
%{
state: token,
redirect_uri: redirect_uri,
stripe_user: %{
"business_name" => organization.name,
"email" => user.email,
Expand All @@ -47,4 +48,8 @@ defmodule CodeCorps.StripeAuth do
}
}
end

defp redirect_uri do
Application.get_env(:code_corps, :stripe_redirect_uri)
end
end

0 comments on commit a3d510c

Please sign in to comment.