Skip to content

Commit

Permalink
Add login link creation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 20, 2017
1 parent 3917b5a commit 2e9116e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 8 additions & 0 deletions lib/stripe/connect/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,12 @@ defmodule Stripe.Account do
|> cast_to_id([:ending_before, :starting_after])
|> make_request()
end

@doc """
Create a login link.
"""
@spec create_login_link(Stripe.id | t, map, Stripe.options) :: {:ok, t} | {:error, Stripe.Error.t}
def create_login_link(id, params, opts \\ []) do
Stripe.LoginLink.create(id, params, opts)
end
end
18 changes: 14 additions & 4 deletions lib/stripe/connect/login_link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ defmodule Stripe.LoginLink do
"""

use Stripe.Entity
import Stripe.Request

@type t :: %__MODULE__{
object: String.t,
created: Stripe.timestamp,
url: String.t
}
object: String.t,
created: Stripe.timestamp,
url: String.t
}

defstruct [
:object,
:created,
:url
]

@spec create(Stripe.id | Stripe.Account.t, map, Stripe.options) :: {:ok, t} | {:error, Stripe.Error.t}
def create(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint("accounts/#{get_id!(id)}")
|> put_params(params)
|> put_method(:post)
|> make_request()
end
end
21 changes: 9 additions & 12 deletions test/stripe/connect/account_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
defmodule Stripe.AccountTest do
use Stripe.StripeCase, async: true

test "is listable" do
assert {:ok, %Stripe.List{data: accounts}} = Stripe.Account.list()
assert_stripe_requested :get, "/v1/accounts"
assert is_list(accounts)
assert %Stripe.Account{} = hd(accounts)
end

test "is retrievable using singular endpoint" do
assert {:ok, %Stripe.Account{}} = Stripe.Account.retrieve()
assert_stripe_requested :get, "/v1/account"
Expand All @@ -33,6 +26,13 @@ defmodule Stripe.AccountTest do
assert_stripe_requested :delete, "/v1/accounts/acct_123"
end

test "is listable" do
assert {:ok, %Stripe.List{data: accounts}} = Stripe.Account.list()
assert_stripe_requested :get, "/v1/accounts"
assert is_list(accounts)
assert %Stripe.Account{} = hd(accounts)
end

test "is rejectable" do
{:ok, account} = Stripe.Account.create(%{metadata: %{}, type: "standard"})
assert {:ok, %Stripe.Account{} = rejected_account} =
Expand All @@ -43,11 +43,8 @@ defmodule Stripe.AccountTest do
refute rejected_account.charges_enabled
end

test "additional_owners is handled correctly" do
flunk "todo: test this"
end

test "can create a login link" do
flunk "todo: test this"
assert {:ok, _login_link} = Stripe.Account.create_login_link("acct_123", %{})
assert_stripe_requested :post, "/v1/accounts/acct_123/login_links"
end
end

0 comments on commit 2e9116e

Please sign in to comment.