Skip to content

Commit

Permalink
add account links (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsbty authored and snewcomer committed Dec 6, 2019
1 parent 636da22 commit 5b9a82c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
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

0 comments on commit 5b9a82c

Please sign in to comment.