diff --git a/lib/stripe/converter.ex b/lib/stripe/converter.ex index 0ebb5d15..0a1e81f4 100644 --- a/lib/stripe/converter.ex +++ b/lib/stripe/converter.ex @@ -30,6 +30,12 @@ defmodule Stripe.Converter do file invoice invoiceitem + issuing.authorization + issuing.card + issuing.card_details + issuing.cardholder + issuing.dispute + issuing.transaction line_item list oauth diff --git a/lib/stripe/issuing/authorization.ex b/lib/stripe/issuing/authorization.ex new file mode 100644 index 00000000..046d2336 --- /dev/null +++ b/lib/stripe/issuing/authorization.ex @@ -0,0 +1,170 @@ +defmodule Stripe.Issuing.Authorization do + @moduledoc """ + Work with Stripe Issuing authorization objects. + + You can: + + - Retrieve an authorization + - Update an authorization + - Approve an authorization + - Decline an authorization + - List all authorizations + + Stripe API reference: https://stripe.com/docs/api/issuing/authorizations + """ + + use Stripe.Entity + import Stripe.Request + + @type request_history :: %{ + approved: boolean, + authorized_amount: integer, + authorized_currency: String.t(), + created: Stripe.timestamp(), + held_amount: integer, + held_currency: String.t(), + reason: String.t() + } + + @type verification_data :: %{ + address_line1_check: String.t(), + address_zip_check: String.t(), + cvc_check: String.t() + } + + @type t :: %__MODULE__{ + id: Stripe.id(), + object: String.t(), + approved: boolean, + authorization_method: String.t(), + authorized_amount: integer, + authorized_currency: String.t() | nil, + balance_transactions: Stripe.List.t(Stripe.BalanceTransaction.t()), + card: Stripe.Issuing.Card.t(), + cardholder: Stripe.id() | Stripe.Issuing.Cardholder.t(), + created: Stripe.timestamp(), + held_amount: integer, + held_currency: String.t() | nil, + is_held_amount_controllable: boolean, + livemode: boolean, + merchant_data: Stripe.Issuing.Types.merchant_data(), + metadata: Stripe.Types.metadata(), + pending_authorized_amount: integer, + pending_held_amount: integer, + request_history: Stripe.List.t(request_history()), + status: String.t(), + transactions: Stripe.List.t(Stripe.Issuing.Transaction.t()), + verification_data: verification_data(), + wallet_provider: String.t() | nil + } + + defstruct [ + :id, + :object, + :approved, + :authorization_method, + :authorized_amount, + :authorized_currency, + :balance_transactions, + :card, + :cardholder, + :created, + :held_amount, + :held_currency, + :is_held_amount_controllable, + :livemode, + :merchant_data, + :metadata, + :pending_authorized_amount, + :pending_held_amount, + :request_history, + :status, + :transactions, + :verification_data, + :wallet_provider + ] + + @plural_endpoint "issuing/authorizations" + + @doc """ + Retrieve an authorization. + """ + @spec retrieve(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:get) + |> make_request() + end + + @doc """ + Update an authorization. + """ + @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:metadata) => Stripe.Types.metadata() + } + | %{} + def update(id, params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + Approve an authorization. + """ + @spec approve(Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:held_amount) => non_neg_integer + } + | %{} + def approve(id, params \\ %{}, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}" <> "/approve") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + Decline an authorization. + """ + @spec decline(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def decline(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}" <> "/decline") + |> put_method(:post) + |> make_request() + end + + @doc """ + List all authorizations. + """ + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:card) => Stripe.Issuing.Card.t() | Stripe.id(), + optional(:cardholder) => Stripe.Issuing.Cardholder.t() | Stripe.id(), + optional(:created) => String.t() | Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id(), + optional(:status) => String.t() + } + | %{} + def list(params \\ %{}, opts \\ []) do + new_request(opts) + |> prefix_expansions() + |> put_endpoint(@plural_endpoint) + |> put_method(:get) + |> put_params(params) + |> cast_to_id([:card, :cardholder, :ending_before, :starting_after]) + |> make_request() + end +end diff --git a/lib/stripe/issuing/card.ex b/lib/stripe/issuing/card.ex new file mode 100644 index 00000000..087963a2 --- /dev/null +++ b/lib/stripe/issuing/card.ex @@ -0,0 +1,151 @@ +defmodule Stripe.Issuing.Card do + @moduledoc """ + Work with Stripe Issuing card objects. + + You can: + + - Create a card + - Retrieve a card + - Update a card + - List all cards + + Stripe API reference: https://stripe.com/docs/api/issuing/cards + """ + + use Stripe.Entity + import Stripe.Request + + @type t :: %__MODULE__{ + id: Stripe.id(), + object: String.t(), + authorization_controls: Stripe.Issuing.Types.authorization_controls(), + brand: String.t(), + cardholder: Stripe.Issuing.Cardholder.t(), + created: Stripe.timestamp(), + currency: String.t(), + exp_month: pos_integer, + exp_year: pos_integer, + last4: String.t(), + livemode: boolean, + metadata: Stripe.Types.metadata(), + name: String.t(), + replacement_for: t | Stripe.id() | nil, + replacement_reason: String.t() | nil, + shipping: Stripe.Types.shipping() | nil, + status: String.t(), + type: atom() | String.t() + } + + defstruct [ + :id, + :object, + :authorization_controls, + :brand, + :cardholder, + :created, + :currency, + :exp_month, + :exp_year, + :last4, + :livemode, + :metadata, + :name, + :replacement_for, + :replacement_reason, + :shipping, + :status, + :type + ] + + @plural_endpoint "issuing/cards" + + @doc """ + Create a card. + """ + @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + :currency => String.t(), + :type => :physical | :virtual, + optional(:authorization_controls) => + Stripe.Issuing.Types.authorization_controls(), + optional(:cardholder) => Stripe.Issuing.Cardholder.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:replacement_for) => t | Stripe.id(), + optional(:replacement_reason) => String.t(), + optional(:shipping) => Stripe.Types.shipping(), + optional(:status) => String.t() + } + | %{} + def create(params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint) + |> put_params(params) + |> put_method(:post) + |> make_request() + end + + @doc """ + Retrieve a card. + """ + @spec retrieve(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:get) + |> make_request() + end + + @doc """ + Update a card. + """ + @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:authorization_controls) => + Stripe.Issuing.Types.authorization_controls(), + optional(:cardholder) => Stripe.Issuing.Cardholder.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:replacement_for) => t | Stripe.id(), + optional(:replacement_reason) => String.t(), + optional(:shipping) => Stripe.Types.shipping(), + optional(:status) => String.t() + } + | %{} + def update(id, params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + List all cards. + """ + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:cardholder) => Stripe.Issuing.Cardholder.t() | Stripe.id(), + optional(:created) => String.t() | Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:exp_month) => String.t(), + optional(:exp_year) => String.t(), + optional(:last4) => String.t(), + optional(:limit) => 1..100, + optional(:source) => String.t(), + optional(:starting_after) => t | Stripe.id(), + optional(:status) => String.t(), + optional(:type) => String.t() + } + | %{} + def list(params \\ %{}, opts \\ []) do + new_request(opts) + |> prefix_expansions() + |> put_endpoint(@plural_endpoint) + |> put_method(:get) + |> put_params(params) + |> cast_to_id([:cardholder, :ending_before, :starting_after]) + |> make_request() + end +end diff --git a/lib/stripe/issuing/card_details.ex b/lib/stripe/issuing/card_details.ex new file mode 100644 index 00000000..46568ca6 --- /dev/null +++ b/lib/stripe/issuing/card_details.ex @@ -0,0 +1,46 @@ +defmodule Stripe.Issuing.CardDetails do + @moduledoc """ + Work with Stripe Issuing card details. + + You can: + + - Retrieve card details + + Stripe API reference: https://stripe.com/docs/api/issuing/cards/retrieve_details + """ + + use Stripe.Entity + import Stripe.Request + + @type t :: %__MODULE__{ + card: Stripe.Issuing.Card.t(), + object: String.t(), + cvc: String.t(), + exp_month: String.t(), + exp_year: String.t(), + number: String.t() + } + + defstruct [ + :card, + :object, + :cvc, + :exp_month, + :exp_year, + :number + ] + + @plural_endpoint "issuing/cards" + + @doc """ + Retrieve card details. + """ + @spec retrieve(Stripe.id() | Stripe.Issuing.Card.t(), Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}" <> "/details") + |> put_method(:get) + |> make_request() + end +end diff --git a/lib/stripe/issuing/cardholder.ex b/lib/stripe/issuing/cardholder.ex new file mode 100644 index 00000000..0762ec6a --- /dev/null +++ b/lib/stripe/issuing/cardholder.ex @@ -0,0 +1,137 @@ +defmodule Stripe.Issuing.Cardholder do + @moduledoc """ + Work with Stripe Issuing cardholder objects. + + You can: + + - Create a cardholder + - Retrieve a cardholder + - Update a cardholder + + Stripe API reference: https://stripe.com/docs/api/issuing/cardholders + """ + + use Stripe.Entity + import Stripe.Request + + @type t :: %__MODULE__{ + id: Stripe.id(), + object: String.t(), + authorization_controls: Stripe.Issuing.Types.authorization_controls() | nil, + billing: Stripe.Issuing.Types.billing(), + created: Stripe.timestamp(), + email: String.t() | nil, + is_default: boolean | nil, + livemode: boolean, + metadata: Stripe.Types.metadata(), + name: String.t(), + phone_number: String.t() | nil, + status: String.t() | nil, + type: atom() | String.t() + } + + defstruct [ + :id, + :object, + :authorization_controls, + :billing, + :created, + :email, + :is_default, + :livemode, + :metadata, + :name, + :phone_number, + :status, + :type + ] + + @plural_endpoint "issuing/cardholders" + + @doc """ + Create a cardholder. + """ + @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + :billing => Stripe.Issuing.Types.billing(), + :name => String.t(), + :type => :individual | :business_entity, + optional(:authorization_controls) => + Stripe.Issuing.Types.authorization_controls(), + optional(:email) => String.t(), + optional(:is_default) => boolean, + optional(:metadata) => Stripe.Types.metadata(), + optional(:phone_number) => String.t(), + optional(:status) => String.t() + } + | %{} + def create(params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint) + |> put_params(params) + |> put_method(:post) + |> make_request() + end + + @doc """ + Retrieve a cardholder. + """ + @spec retrieve(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:get) + |> make_request() + end + + @doc """ + Update a cardholder. + """ + @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:authorization_controls) => + Stripe.Issuing.Types.authorization_controls(), + optional(:email) => String.t(), + optional(:is_default) => boolean, + optional(:metadata) => Stripe.Types.metadata(), + optional(:phone_number) => String.t(), + optional(:status) => String.t() + } + | %{} + def update(id, params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + List all cardholders. + """ + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:created) => String.t() | Stripe.date_query(), + optional(:email) => String.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:is_default) => boolean, + optional(:limit) => 1..100, + optional(:phone_number) => String.t(), + optional(:starting_after) => t | Stripe.id(), + optional(:status) => String.t(), + optional(:type) => String.t() + } + | %{} + def list(params \\ %{}, opts \\ []) do + new_request(opts) + |> prefix_expansions() + |> put_endpoint(@plural_endpoint) + |> put_method(:get) + |> put_params(params) + |> cast_to_id([:ending_before, :starting_after]) + |> make_request() + end +end diff --git a/lib/stripe/issuing/dispute.ex b/lib/stripe/issuing/dispute.ex new file mode 100644 index 00000000..4a6d16c1 --- /dev/null +++ b/lib/stripe/issuing/dispute.ex @@ -0,0 +1,130 @@ +defmodule Stripe.Issuing.Dispute do + @moduledoc """ + Work with Stripe Issuing dispute objects. + + You can: + + - Create a dispute + - Retrieve a dispute + - Update a dispute + - List all disputes + + Stripe API reference: https://stripe.com/docs/api/issuing/disputes + """ + + use Stripe.Entity + import Stripe.Request + + @type evidence :: %{ + fraudulent: evidence_detail() | nil, + other: evidence_detail() | nil + } + + @type evidence_detail :: %{ + dispute_explanation: String.t(), + uncategorized_file: String.t() + } + + @type t :: %__MODULE__{ + id: Stripe.id(), + object: String.t(), + amount: integer, + created: Stripe.timestamp(), + currency: String.t() | nil, + disputed_transaction: Stripe.id() | Stripe.Issuing.Transaction.t(), + evidence: evidence(), + livemode: boolean, + metadata: Stripe.Types.metadata(), + reason: atom() | String.t(), + status: String.t() + } + + defstruct [ + :id, + :object, + :amount, + :created, + :currency, + :disputed_transaction, + :evidence, + :livemode, + :metadata, + :reason, + :status + ] + + @plural_endpoint "issuing/disputes" + + @doc """ + Create a dispute. + """ + @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + :disputed_transaction => Stripe.id() | Stripe.Issuing.Transaction.t(), + :reason => :other | :fradulent, + optional(:amount) => non_neg_integer, + optional(:evidence) => evidence(), + optional(:metadata) => Stripe.Types.metadata() + } + | %{} + def create(params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint) + |> put_params(params) + |> put_method(:post) + |> cast_to_id([:disputed_transaction]) + |> make_request() + end + + @doc """ + Retrieve a dispute. + """ + @spec retrieve(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:get) + |> make_request() + end + + @doc """ + Update a dispute. + """ + @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:metadata) => Stripe.Types.metadata() + } + | %{} + def update(id, params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + List all disputes. + """ + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:created) => String.t() | Stripe.date_query(), + optional(:disputed_transaction) => Stripe.Issuing.Transaction.t() | Stripe.id(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } + | %{} + def list(params \\ %{}, opts \\ []) do + new_request(opts) + |> prefix_expansions() + |> put_endpoint(@plural_endpoint) + |> put_method(:get) + |> put_params(params) + |> cast_to_id([:disputed_transaction, :ending_before, :starting_after]) + |> make_request() + end +end diff --git a/lib/stripe/issuing/transaction.ex b/lib/stripe/issuing/transaction.ex new file mode 100644 index 00000000..006b7f51 --- /dev/null +++ b/lib/stripe/issuing/transaction.ex @@ -0,0 +1,106 @@ +defmodule Stripe.Issuing.Transaction do + @moduledoc """ + Work with Stripe Issuing transaction objects. + + You can: + + - Retrieve a transaction + - Update a transaction + - List all transactions + + Stripe API reference: https://stripe.com/docs/api/issuing/transactions + """ + + use Stripe.Entity + import Stripe.Request + + @type t :: %__MODULE__{ + id: Stripe.id(), + object: String.t(), + amount: integer, + authorization: Stripe.id() | Stripe.Issuing.Authorization.t(), + balance_transaction: String.t(), + card: Stripe.id() | Stripe.Issuing.Card.t(), + cardholder: Stripe.id() | Stripe.Issuing.Cardholder.t(), + created: Stripe.timestamp(), + currency: String.t() | nil, + dispute: Stripe.id() | Stripe.Issuing.Dispute.t(), + livemode: boolean, + merchant_data: Stripe.Issuing.Types.merchant_data(), + metadata: Stripe.Types.metadata(), + type: String.t() + } + + defstruct [ + :id, + :object, + :amount, + :authorization, + :balance_transaction, + :card, + :cardholder, + :created, + :currency, + :dispute, + :livemode, + :merchant_data, + :metadata, + :type + ] + + @plural_endpoint "issuing/transactions" + + @doc """ + Retrieve a transaction. + """ + @spec retrieve(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + def retrieve(id, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:get) + |> make_request() + end + + @doc """ + Update a transaction. + """ + @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:metadata) => Stripe.Types.metadata() + } + | %{} + def update(id, params, opts \\ []) do + new_request(opts) + |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") + |> put_method(:post) + |> put_params(params) + |> make_request() + end + + @doc """ + List all transactions. + """ + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:card) => Stripe.Issuing.Card.t() | Stripe.id(), + optional(:cardholder) => Stripe.Issuing.Cardholder.t() | Stripe.id(), + optional(:created) => String.t() | Stripe.date_query(), + optional(:dispute) => Stripe.Issuing.Dispute.t() | Stripe.id(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:settlement) => String.t(), + optional(:starting_after) => t | Stripe.id() + } + | %{} + def list(params \\ %{}, opts \\ []) do + new_request(opts) + |> prefix_expansions() + |> put_endpoint(@plural_endpoint) + |> put_method(:get) + |> put_params(params) + |> cast_to_id([:card, :cardholder, :dispute, :ending_before, :starting_after]) + |> make_request() + end +end diff --git a/lib/stripe/issuing/types.ex b/lib/stripe/issuing/types.ex new file mode 100644 index 00000000..007c9a46 --- /dev/null +++ b/lib/stripe/issuing/types.ex @@ -0,0 +1,35 @@ +defmodule Stripe.Issuing.Types do + @moduledoc """ + A module that contains shared issuing types matching Stripe schemas. + """ + + @type authorization_controls :: %{ + allowed_categories: list() | nil, + blocked_categories: list() | nil, + spending_limits: list(spending_limits()) | nil, + currency: String.t() | nil, + max_amount: non_neg_integer | nil, + max_approvals: non_neg_integer | nil + } + + @type billing :: %{ + address: Stripe.Types.address(), + name: String.t() + } + + @type merchant_data :: %{ + category: String.t(), + city: String.t(), + country: String.t(), + name: String.t(), + network_id: String.t(), + postal_code: String.t(), + state: String.t() + } + + @type spending_limits :: %{ + amount: non_neg_integer, + categories: list(), + interval: String.t() + } +end diff --git a/lib/stripe/types.ex b/lib/stripe/types.ex index 471153f9..6d19c0a5 100644 --- a/lib/stripe/types.ex +++ b/lib/stripe/types.ex @@ -27,9 +27,12 @@ defmodule Stripe.Types do @type shipping :: %{ address: Stripe.Types.address(), carrier: String.t() | nil, + eta: Stripe.timestamp() | nil, name: String.t(), phone: String.t() | nil, - tracking_number: String.t() | nil + status: String.t() | nil, + tracking_number: String.t() | nil, + tracking_url: String.t() | nil } @type tax_info :: %{ diff --git a/lib/stripe/util.ex b/lib/stripe/util.ex index f01300db..83e97813 100644 --- a/lib/stripe/util.ex +++ b/lib/stripe/util.ex @@ -53,6 +53,12 @@ defmodule Stripe.Util do @spec object_name_to_module(String.t()) :: module def object_name_to_module("checkout.session"), do: Stripe.Session def object_name_to_module("file"), do: Stripe.FileUpload + def object_name_to_module("issuing.authorization"), do: Stripe.Issuing.Authorization + def object_name_to_module("issuing.card"), do: Stripe.Issuing.Card + def object_name_to_module("issuing.card_details"), do: Stripe.Issuing.CardDetails + def object_name_to_module("issuing.cardholder"), do: Stripe.Issuing.Cardholder + def object_name_to_module("issuing.dispute"), do: Stripe.Issuing.Dispute + def object_name_to_module("issuing.transaction"), do: Stripe.Issuing.Transaction def object_name_to_module(object_name) do module_name = diff --git a/test/stripe/issuing/authorization_test.exs b/test/stripe/issuing/authorization_test.exs new file mode 100644 index 00000000..2d441afa --- /dev/null +++ b/test/stripe/issuing/authorization_test.exs @@ -0,0 +1,40 @@ +defmodule Stripe.Issuing.AuthorizationTest do + use Stripe.StripeCase, async: true + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.Authorization{}} = + Stripe.Issuing.Authorization.retrieve("iauth_123") + + assert_stripe_requested(:get, "/v1/issuing/authorizations/iauth_123") + end + + test "is updateable" do + params = %{metadata: %{key: "value"}} + + assert {:ok, %Stripe.Issuing.Authorization{}} = + Stripe.Issuing.Authorization.update("iauth_123", params) + + assert_stripe_requested(:post, "/v1/issuing/authorizations/iauth_123") + end + + test "is approvable" do + assert {:ok, %Stripe.Issuing.Authorization{}} = + Stripe.Issuing.Authorization.approve("iauth_123") + + assert_stripe_requested(:post, "/v1/issuing/authorizations/iauth_123/approve") + end + + test "is declinable" do + assert {:ok, %Stripe.Issuing.Authorization{}} = + Stripe.Issuing.Authorization.decline("iauth_123") + + assert_stripe_requested(:post, "/v1/issuing/authorizations/iauth_123/decline") + end + + test "is listable" do + assert {:ok, %Stripe.List{data: authorizations}} = Stripe.Issuing.Authorization.list() + assert_stripe_requested(:get, "/v1/issuing/authorizations") + assert is_list(authorizations) + assert %Stripe.Issuing.Authorization{} = hd(authorizations) + end +end diff --git a/test/stripe/issuing/card_details_test.exs b/test/stripe/issuing/card_details_test.exs new file mode 100644 index 00000000..db8b07e2 --- /dev/null +++ b/test/stripe/issuing/card_details_test.exs @@ -0,0 +1,8 @@ +defmodule Stripe.Issuing.CardDetailsTest do + use Stripe.StripeCase, async: true + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.CardDetails{}} = Stripe.Issuing.CardDetails.retrieve("ic_123") + assert_stripe_requested(:get, "/v1/issuing/cards/ic_123/details") + end +end diff --git a/test/stripe/issuing/card_test.exs b/test/stripe/issuing/card_test.exs new file mode 100644 index 00000000..2b5b82c2 --- /dev/null +++ b/test/stripe/issuing/card_test.exs @@ -0,0 +1,32 @@ +defmodule Stripe.Issuing.CardTest do + use Stripe.StripeCase, async: true + + test "is creatable" do + params = %{ + currency: "usd", + type: :virtual + } + + assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.create(params) + + assert_stripe_requested(:post, "/v1/issuing/cards") + end + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.retrieve("ic_123") + assert_stripe_requested(:get, "/v1/issuing/cards/ic_123") + end + + test "is updateable" do + params = %{metadata: %{key: "value"}} + assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.update("ic_123", params) + assert_stripe_requested(:post, "/v1/issuing/cards/ic_123") + end + + test "is listable" do + assert {:ok, %Stripe.List{data: cards}} = Stripe.Issuing.Card.list() + assert_stripe_requested(:get, "/v1/issuing/cards") + assert is_list(cards) + assert %Stripe.Issuing.Card{} = hd(cards) + end +end diff --git a/test/stripe/issuing/cardholder_test.exs b/test/stripe/issuing/cardholder_test.exs new file mode 100644 index 00000000..7413978b --- /dev/null +++ b/test/stripe/issuing/cardholder_test.exs @@ -0,0 +1,45 @@ +defmodule Stripe.Issuing.CardholderTest do + use Stripe.StripeCase, async: true + + test "is creatable" do + params = %{ + name: "Jenny Rosen", + type: :individual, + billing: %{ + address: %{ + line1: "123 Fake St", + line2: "Apt 3", + city: "Beverly Hills", + state: "CA", + postal_code: "90210", + country: "US" + } + } + } + + assert {:ok, %Stripe.Issuing.Cardholder{}} = Stripe.Issuing.Cardholder.create(params) + + assert_stripe_requested(:post, "/v1/issuing/cardholders") + end + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.Cardholder{}} = Stripe.Issuing.Cardholder.retrieve("ich_123") + assert_stripe_requested(:get, "/v1/issuing/cardholders/ich_123") + end + + test "is updateable" do + params = %{metadata: %{key: "value"}} + + assert {:ok, %Stripe.Issuing.Cardholder{}} = + Stripe.Issuing.Cardholder.update("ich_123", params) + + assert_stripe_requested(:post, "/v1/issuing/cardholders/ich_123") + end + + test "is listable" do + assert {:ok, %Stripe.List{data: cardholders}} = Stripe.Issuing.Cardholder.list() + assert_stripe_requested(:get, "/v1/issuing/cardholders") + assert is_list(cardholders) + assert %Stripe.Issuing.Cardholder{} = hd(cardholders) + end +end diff --git a/test/stripe/issuing/dispute_test.exs b/test/stripe/issuing/dispute_test.exs new file mode 100644 index 00000000..09bd089d --- /dev/null +++ b/test/stripe/issuing/dispute_test.exs @@ -0,0 +1,32 @@ +defmodule Stripe.Issuing.DisputeTest do + use Stripe.StripeCase, async: true + + test "is creatable" do + params = %{ + disputed_transaction: "ipi_123", + reason: :fraudulent + } + + assert {:ok, %Stripe.Issuing.Dispute{}} = Stripe.Issuing.Dispute.create(params) + + assert_stripe_requested(:post, "/v1/issuing/disputes") + end + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.Dispute{}} = Stripe.Issuing.Dispute.retrieve("idp_123") + assert_stripe_requested(:get, "/v1/issuing/disputes/idp_123") + end + + test "is updateable" do + params = %{metadata: %{key: "value"}} + assert {:ok, %Stripe.Issuing.Dispute{}} = Stripe.Issuing.Dispute.update("idp_123", params) + assert_stripe_requested(:post, "/v1/issuing/disputes/idp_123") + end + + test "is listable" do + assert {:ok, %Stripe.List{data: disputes}} = Stripe.Issuing.Dispute.list() + assert_stripe_requested(:get, "/v1/issuing/disputes") + assert is_list(disputes) + assert %Stripe.Issuing.Dispute{} = hd(disputes) + end +end diff --git a/test/stripe/issuing/transaction_test.exs b/test/stripe/issuing/transaction_test.exs new file mode 100644 index 00000000..4550aabf --- /dev/null +++ b/test/stripe/issuing/transaction_test.exs @@ -0,0 +1,24 @@ +defmodule Stripe.Issuing.TransactionTest do + use Stripe.StripeCase, async: true + + test "is retrievable" do + assert {:ok, %Stripe.Issuing.Transaction{}} = Stripe.Issuing.Transaction.retrieve("ipi_123") + assert_stripe_requested(:get, "/v1/issuing/transactions/ipi_123") + end + + test "is updateable" do + params = %{metadata: %{key: "value"}} + + assert {:ok, %Stripe.Issuing.Transaction{}} = + Stripe.Issuing.Transaction.update("ipi_123", params) + + assert_stripe_requested(:post, "/v1/issuing/transactions/ipi_123") + end + + test "is listable" do + assert {:ok, %Stripe.List{data: transactions}} = Stripe.Issuing.Transaction.list() + assert_stripe_requested(:get, "/v1/issuing/transactions") + assert is_list(transactions) + assert %Stripe.Issuing.Transaction{} = hd(transactions) + end +end