Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add account links #562

Merged
merged 2 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/stripe/connect/account_link.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Stripe.AccountLink do
@moduledoc """
Work with Stripe Connect account link objects.

You can:

- Create an account link

Stripe API reference: https://stripe.com/docs/api/account_links
"""

use Stripe.Entity
import Stripe.Request

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

defstruct [
:object,
:created,
:expires_at,
:url
]

@plural_endpoint "account_links"

@doc """
Create an account link.
"""
@spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
:account => Stripe.Account.t() | Stripe.id(),
:failure_url => String.t(),
:success_url => String.t(),
:type => String.t(),
optional(:collect) => String.t()
}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
|> put_params(params)
|> put_method(:post)
|> cast_to_id([:account])
|> make_request()
end
end
1 change: 1 addition & 0 deletions lib/stripe/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Stripe.Converter do

@supported_objects ~w(
account
account_link
application_fee
fee_refund
balance
Expand Down
15 changes: 15 additions & 0 deletions test/stripe/connect/account_link_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Stripe.AccountLinkTest do
use Stripe.StripeCase, async: true

test "is creatable" do
params = %{
account: "acct_123",
failure_url: "https://stripe.com",
success_url: "https://stripe.com",
type: "custom_account_verification"
}

assert {:ok, %Stripe.AccountLink{}} = Stripe.AccountLink.create(params)
assert_stripe_requested(:post, "/v1/account_links")
end
end