-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from code-corps/108-add-stripe-account
Add Stripe.Account
- Loading branch information
Showing
7 changed files
with
120 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
/deps | ||
erl_crash.dump | ||
*.ez | ||
config | ||
config/config.secret.exs | ||
/doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use Mix.Config | ||
|
||
if File.exists?("config/config.secret.exs") do | ||
import_config "config.secret.exs" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
defmodule Stripe.Account do | ||
@moduledoc """ | ||
Work with Stripe account objects. | ||
You can: | ||
- Retrieve your own account | ||
- Retrieve an account with a specified `id` | ||
This module does not yet support managed accounts. | ||
Stripe API reference: https://stripe.com/docs/api#account | ||
""" | ||
|
||
alias Stripe.Util | ||
|
||
@type t :: %__MODULE__{} | ||
|
||
defstruct [ | ||
:id, :business_name, :business_primary_color, :business_url, | ||
:charges_enabled, :country, :default_currency, :details_submitted, | ||
:display_name, :email, :managed, :metadata, :statement_descriptor, | ||
:support_email, :support_phone, :support_url, :timezone, | ||
:transfers_enabled | ||
] | ||
|
||
@singular_endpoint "account" | ||
@plural_endpoint "accounts" | ||
|
||
@doc """ | ||
Retrieve your own account without options. | ||
""" | ||
@spec retrieve :: {:ok, t} | {:error, Exception.t} | ||
def retrieve, do: retrieve([]) | ||
|
||
@doc """ | ||
Retrieve your own account with options. | ||
""" | ||
@spec retrieve(Keyword.t) :: {:ok, t} | {:error, Exception.t} | ||
def retrieve(opts), do: do_retrieve(@singular_endpoint, opts) | ||
|
||
@doc """ | ||
Retrieve an account with a specified `id`. | ||
""" | ||
@spec retrieve(binary, Keyword.t) :: {:ok, t} | {:error, Exception.t} | ||
def retrieve(id, opts \\ []), do: do_retrieve(@plural_endpoint <> "/" <> id, opts) | ||
|
||
@spec do_retrieve(String.t, Keyword.t) :: {:ok, t} | {:error, Exception.t} | ||
defp do_retrieve(endpoint, opts) do | ||
case Stripe.request(:get, endpoint, %{}, %{}, opts) do | ||
{:ok, result} -> {:ok, to_struct(result)} | ||
{:error, error} -> {:error, error} | ||
end | ||
end | ||
|
||
defp to_struct(response) do | ||
%__MODULE__{ | ||
id: Map.get(response, "id"), | ||
business_name: Map.get(response, "business_name"), | ||
business_primary_color: Map.get(response, "business_primary_color"), | ||
business_url: Map.get(response, "business_url"), | ||
charges_enabled: Map.get(response, "charges_enabled"), | ||
country: Map.get(response, "country"), | ||
default_currency: Map.get(response, "default_currency"), | ||
details_submitted: Map.get(response, "details_submitted"), | ||
display_name: Map.get(response, "display_name"), | ||
email: Map.get(response, "email"), | ||
managed: Map.get(response, "managed"), | ||
metadata: Map.get(response, "metadata"), | ||
statement_descriptor: Map.get(response, "statement_descriptor"), | ||
support_email: Map.get(response, "support_email"), | ||
support_phone: Map.get(response, "support_phone"), | ||
support_url: Map.get(response, "support_url"), | ||
timezone: Map.get(response, "timezone"), | ||
transfers_enabled: Map.get(response, "transfers_enabled") | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters