Skip to content

Commit d684bc5

Browse files
authored
Merge pull request #603 from code-corps/602-terms-of-use
Add tos_acceptance parameters to account create
2 parents 8be9316 + 5a17df5 commit d684bc5

24 files changed

Lines changed: 218 additions & 59 deletions

lib/code_corps/conn_utils.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule CodeCorps.ConnUtils do
2+
def extract_ip(%Plug.Conn{} = conn) do
3+
conn.remote_ip |> Tuple.to_list |> Enum.join(".")
4+
end
5+
6+
def extract_user_agent(%Plug.Conn{} = conn) do
7+
conn |> Plug.Conn.get_req_header("user-agent") |> List.first
8+
end
9+
end

lib/code_corps/stripe_service/adapters/stripe_connect_account.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ defmodule CodeCorps.StripeService.Adapters.StripeConnectAccountAdapter do
5151
{:support_email, [:support_email]},
5252
{:support_phone, [:support_phone]},
5353
{:support_url, [:support_url]},
54+
{:tos_acceptance_date, [:tos_acceptance, :date]},
55+
{:tos_acceptance_ip, [:tos_acceptance, :ip]},
56+
{:tos_acceptance_user_agent, [:tos_acceptance, :user_agent]},
5457
{:transfers_enabled, [:transfers_enabled]},
5558
{:verification_disabled_reason, [:verification, :disabled_reason]},
5659
{:verification_due_by, [:verification, :due_by]},

lib/code_corps/stripe_service/stripe_connect_account.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ defmodule CodeCorps.StripeService.StripeConnectAccountService do
44

55
@api Application.get_env(:code_corps, :stripe)
66

7-
def create(%{"country" => country_code, "organization_id" => _} = attributes) do
8-
with {:ok, %Stripe.Account{} = account} <- @api.Account.create(%{country: country_code, managed: true}),
7+
def create(attributes) do
8+
with {:ok, from_params} <- StripeConnectAccountAdapter.from_params(attributes),
9+
{:ok, %Stripe.Account{} = account} <- @api.Account.create(from_params),
910
{:ok, params} <- StripeConnectAccountAdapter.to_params(account, attributes)
1011
do
1112
%StripeConnectAccount{}

lib/code_corps/stripe_testing/account.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
defmodule CodeCorps.StripeTesting.Account do
2-
def create(_map) do
3-
{:ok, create_stripe_record(%{})}
2+
def create(attributes) do
3+
{:ok, create_stripe_record(attributes)}
44
end
55

66
def retrieve(id) do
77
{:ok, create_stripe_record(%{"id" => id})}
88
end
99

1010
def update(id, attributes) do
11-
attributes =
11+
{:ok, create_stripe_record(attributes |> Map.merge(%{id: id}))}
12+
end
13+
14+
defp create_stripe_record(attributes) do
15+
transformed_attributes =
1216
attributes
1317
|> CodeCorps.MapUtils.keys_to_string
14-
|> Map.merge(%{"id" => id})
18+
|> Map.merge(account_fixture)
19+
|> add_nestings
1520

16-
{:ok, create_stripe_record(attributes)}
17-
end
1821

19-
defp create_stripe_record(attributes) do
20-
with attributes <- account_fixture |> Map.merge(attributes) |> add_nestings
21-
do
22-
Stripe.Account |> Stripe.Converter.stripe_map_to_struct(attributes)
23-
end
22+
Stripe.Account |> Stripe.Converter.stripe_map_to_struct(transformed_attributes)
2423
end
2524

2625
defp account_fixture do

lib/code_corps/stripe_testing/customer.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ defmodule CodeCorps.StripeTesting.Customer do
1212
end
1313

1414
defp do_create(_) do
15-
{:ok, created} = DateTime.from_unix(1479472835)
16-
1715
%Stripe.Customer{
1816
id: "cus_9aMOFmqy1esIRE",
1917
account_balance: 0,
20-
created: created,
18+
created: 1479472835,
2119
currency: "usd",
2220
default_source: nil,
2321
delinquent: false,
@@ -29,12 +27,10 @@ defmodule CodeCorps.StripeTesting.Customer do
2927
end
3028

3129
defp do_update(id, map) do
32-
{:ok, created} = DateTime.from_unix(1479472835)
33-
3430
%Stripe.Customer{
3531
id: id,
3632
account_balance: 0,
37-
created: created,
33+
created: 1479472835,
3834
currency: "usd",
3935
default_source: nil,
4036
delinquent: false,

lib/code_corps/stripe_testing/event.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ defmodule CodeCorps.StripeTesting.Event do
77
end
88

99
defp do_retrieve(_) do
10-
{:ok, created} = DateTime.from_unix(1479472835)
1110

1211
%Stripe.Event{
1312
api_version: "2016-07-06",
14-
created: created,
13+
created: 1479472835,
1514
id: "evt_123",
1615
livemode: false,
1716
object: "event",
@@ -22,11 +21,9 @@ defmodule CodeCorps.StripeTesting.Event do
2221
end
2322

2423
defp do_retrieve_connect(_) do
25-
{:ok, created} = DateTime.from_unix(1479472835)
26-
2724
%Stripe.Event{
2825
api_version: "2016-07-06",
29-
created: created,
26+
created: 1479472835,
3027
id: "evt_123",
3128
livemode: false,
3229
object: "event",

lib/code_corps/stripe_testing/plan.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ defmodule CodeCorps.StripeTesting.Plan do
44
end
55

66
defp do_create(_) do
7-
{:ok, created} = DateTime.from_unix(1479472835)
8-
97
%Stripe.Plan{
108
id: "plan_9aMOFmqy1esIRE",
119
amount: 5000,
12-
created: created,
10+
created: 1479472835,
1311
currency: "usd",
1412
interval: "month",
1513
interval_count: 1,

lib/code_corps/stripe_testing/subscription.ex

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ defmodule CodeCorps.StripeTesting.Subscription do
88
end
99

1010
defp do_create(%{quantity: quantity}) do
11-
{:ok, date} = DateTime.from_unix(1479472835)
12-
1311
{:ok, plan} = CodeCorps.StripeTesting.Plan.create(%{}, [])
1412

1513
%Stripe.Subscription{
1614
application_fee_percent: 5.0,
1715
cancel_at_period_end: false,
1816
canceled_at: nil,
19-
created: date,
20-
current_period_end: date,
21-
current_period_start: date,
17+
created: 1479472835,
18+
current_period_end: 1479472835,
19+
current_period_start: 1479472835,
2220
customer: "cus_123",
2321
ended_at: nil,
2422
id: "sub_123",
@@ -27,7 +25,7 @@ defmodule CodeCorps.StripeTesting.Subscription do
2725
plan: plan,
2826
quantity: quantity,
2927
source: nil,
30-
start: date,
28+
start: 1479472835,
3129
status: "active",
3230
tax_percent: nil,
3331
trial_end: nil,
@@ -36,17 +34,15 @@ defmodule CodeCorps.StripeTesting.Subscription do
3634
end
3735

3836
defp do_retrieve(_) do
39-
{:ok, date} = DateTime.from_unix(1479472835)
40-
4137
{:ok, plan} = CodeCorps.StripeTesting.Plan.create(%{}, [])
4238

4339
%Stripe.Subscription{
4440
application_fee_percent: 5.0,
4541
cancel_at_period_end: false,
4642
canceled_at: nil,
47-
created: date,
48-
current_period_end: date,
49-
current_period_start: date,
43+
created: 1479472835,
44+
current_period_end: 1479472835,
45+
current_period_start: 1479472835,
5046
customer: "cus_123",
5147
ended_at: nil,
5248
id: "sub_123",
@@ -55,7 +51,7 @@ defmodule CodeCorps.StripeTesting.Subscription do
5551
plan: plan,
5652
quantity: 1000,
5753
source: nil,
58-
start: date,
54+
start: 1479472835,
5955
status: "canceled",
6056
tax_percent: nil,
6157
trial_end: nil,

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"segment": {:hex, :segment, "0.1.1", "47bf9191590e7a533c105d1e21518e0d6da47c91e8d98ebb649c624db5dfc359", [:mix], [{:httpoison, "~> 0.8", [hex: :httpoison, optional: false]}, {:poison, "~> 1.3 or ~> 2.0", [hex: :poison, optional: false]}]},
5757
"sentry": {:hex, :sentry, "2.1.0", "51e7ca261b519294ac73b30763893c4a7ad2005205514aefa5bf37ccb83e44ea", [:mix], [{:hackney, "~> 1.6.1", [hex: :hackney, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: true]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}, {:uuid, "~> 1.0", [hex: :uuid, optional: false]}]},
5858
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:make, :rebar], []},
59-
"stripity_stripe": {:git, "https://github.com/code-corps/stripity_stripe.git", "88698ce6582574d5c7070db3551099c2439248c9", [branch: "add-update-changesets"]},
59+
"stripity_stripe": {:git, "https://github.com/code-corps/stripity_stripe.git", "bffefa3195d4fc75dafece4094d697506dc72c07", [branch: "2.0"]},
6060
"sweet_xml": {:hex, :sweet_xml, "0.6.3", "814265792baeb163421811c546581c522dfdcb9d1767b1e59959c52906414e80", [:mix], []},
6161
"timber": {:hex, :timber, "0.4.7", "df3fcd79bcb4eb4b53874d906ef5f3a212937b4bc7b7c5b244745202cc389443", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, optional: true]}, {:phoenix, "~> 1.2", [hex: :phoenix, optional: true]}, {:plug, "~> 1.2", [hex: :plug, optional: true]}, {:poison, "~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
6262
"timex": {:hex, :timex, "3.1.5", "413d6d8d6f0162a5d47080cb8ca520d790184ac43e097c95191c7563bf25b428", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmodule CodeCorps.Repo.Migrations.AddTosAcceptanceFieldsToStripeConnectAccounts do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:stripe_connect_accounts) do
6+
add :tos_acceptance_date, :datetime
7+
add :tos_acceptance_ip, :string
8+
add :tos_acceptance_user_agent, :string
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)