diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 00000000..10afd783 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,27 @@ +export_locals_without_parens = [ + plug: 1, + plug: 2, + forward: 2, + forward: 3, + forward: 4, + match: 2, + match: 3, + get: 2, + get: 3, + post: 2, + post: 3, + put: 2, + put: 3, + patch: 2, + patch: 3, + delete: 2, + delete: 3, + options: 2, + options: 3 +] + +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], + locals_without_parens: export_locals_without_parens, + export: [locals_without_parens: export_locals_without_parens] +] diff --git a/lib/stripe.ex b/lib/stripe.ex index 3ed693af..7dad7e46 100644 --- a/lib/stripe.ex +++ b/lib/stripe.ex @@ -62,11 +62,11 @@ defmodule Stripe do @type id :: String.t() @type date_query :: %{ - optional(:gt) => timestamp, - optional(:gte) => timestamp, - optional(:lt) => timestamp, - optional(:lte) => timestamp - } + optional(:gt) => timestamp, + optional(:gte) => timestamp, + optional(:lt) => timestamp, + optional(:lte) => timestamp + } @type options :: Keyword.t() @type timestamp :: pos_integer diff --git a/lib/stripe/config.ex b/lib/stripe/config.ex index 7d88e65a..2f90a167 100644 --- a/lib/stripe/config.ex +++ b/lib/stripe/config.ex @@ -10,10 +10,12 @@ defmodule Stripe.Config do """ @spec resolve(atom, any) :: any def resolve(key, default \\ nil) + def resolve(key, default) when is_atom(key) do Application.get_env(:stripity_stripe, key, default) |> expand_value() end + def resolve(key, _) do raise( ArgumentError, @@ -22,12 +24,13 @@ defmodule Stripe.Config do end defp expand_value({module, function, args}) - when is_atom(function) and is_list(args) - do + when is_atom(function) and is_list(args) do apply(module, function, args) end + defp expand_value(value) when is_function(value) do value.() end + defp expand_value(value), do: value end diff --git a/lib/stripe/connect/application_fee.ex b/lib/stripe/connect/application_fee.ex index a851ef30..deb74f80 100644 --- a/lib/stripe/connect/application_fee.ex +++ b/lib/stripe/connect/application_fee.ex @@ -59,13 +59,15 @@ defmodule Stripe.ApplicationFee do List all application fees """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:charge) => Stripe.id(), - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } | %{} + when params: + %{ + optional(:charge) => Stripe.id(), + optional(:created) => Stripe.date_query(), + 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() diff --git a/lib/stripe/connect/country_spec.ex b/lib/stripe/connect/country_spec.ex index 4b2082f3..319b8a3c 100644 --- a/lib/stripe/connect/country_spec.ex +++ b/lib/stripe/connect/country_spec.ex @@ -56,11 +56,13 @@ defmodule Stripe.CountrySpec do List all country specs. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } | %{} + when params: + %{ + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/connect/external_account.ex b/lib/stripe/connect/external_account.ex index 89b370c3..74cb4ce5 100644 --- a/lib/stripe/connect/external_account.ex +++ b/lib/stripe/connect/external_account.ex @@ -93,7 +93,8 @@ defmodule Stripe.ExternalAccount do Takes either `:bank_account` or `:card` to determine which object to list. """ - @spec list(atom, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec list(atom, params, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ :account => Stripe.id(), optional(:ending_before) => t | Stripe.id(), @@ -101,18 +102,21 @@ defmodule Stripe.ExternalAccount do optional(:starting_after) => t | Stripe.id() } def list(atom, params, opts \\ []) + def list(:bank_account, %{account: _} = params, opts) do endpoint = params |> accounts_plural_endpoint() params = params |> Map.put(:object, "bank_account") do_list(endpoint, params, opts) end + def list(:card, %{account: _} = params, opts) do endpoint = params |> accounts_plural_endpoint() params = params |> Map.put(:object, "card") do_list(endpoint, params, opts) end - @spec do_list(String.t, map, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec do_list(String.t(), map, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} defp do_list(endpoint, params, opts) do new_request(opts) |> put_endpoint(endpoint) diff --git a/lib/stripe/connect/fee_refund.ex b/lib/stripe/connect/fee_refund.ex index 05b233ce..74dd378b 100644 --- a/lib/stripe/connect/fee_refund.ex +++ b/lib/stripe/connect/fee_refund.ex @@ -51,7 +51,8 @@ defmodule Stripe.FeeRefund do @doc """ Retrieve a application fee refund. """ - @spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} def retrieve(id, fee_id, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{id}/refunds/#{fee_id}") @@ -64,9 +65,10 @@ defmodule Stripe.FeeRefund do Takes the `id` and a map of changes. """ - @spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:metadata) => Stripe.Types.metadata(), + optional(:metadata) => Stripe.Types.metadata() } def update(id, fee_id, params, opts \\ []) do new_request(opts) @@ -79,7 +81,8 @@ defmodule Stripe.FeeRefund do @doc """ List all transfers. """ - @spec list(Stripe.id() | t, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec list(Stripe.id() | t, params, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ optional(:ending_before) => t | Stripe.id(), optional(:limit) => 1..100, diff --git a/lib/stripe/connect/recipient.ex b/lib/stripe/connect/recipient.ex index 5e2c7193..7f588752 100644 --- a/lib/stripe/connect/recipient.ex +++ b/lib/stripe/connect/recipient.ex @@ -67,15 +67,15 @@ defmodule Stripe.Recipient do """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :name => String.t(), - :type => String.t(), - optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(), - optional(:recipient) => Stripe.id() | Stripe.Card.t(), - optional(:description) => String.t(), - optional(:email) => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:tax_id) => String.t() - } + :name => String.t(), + :type => String.t(), + optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(), + optional(:recipient) => Stripe.id() | Stripe.Card.t(), + optional(:description) => String.t(), + optional(:email) => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:tax_id) => String.t() + } def create(%{name: _, type: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -102,15 +102,15 @@ defmodule Stripe.Recipient do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(), - optional(:card) => Stripe.id() | Stripe.Card.t(), - optional(:default_card) => Stripe.id() | Stripe.Card.t(), - optional(:description) => String.t(), - optional(:email) => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:name) => String.t(), - optional(:tax_id) => String.t() - } + optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(), + optional(:card) => Stripe.id() | Stripe.Card.t(), + optional(:default_card) => Stripe.id() | Stripe.Card.t(), + optional(:description) => String.t(), + optional(:email) => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:name) => String.t(), + optional(:tax_id) => String.t() + } def update(id, params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -135,13 +135,13 @@ defmodule Stripe.Recipient do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - optional(:created) => Stripe.timestamp(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - optional(:type) => String.t(), - optional(:verified) => boolean - } + optional(:created) => Stripe.timestamp(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id(), + optional(:type) => String.t(), + optional(:verified) => boolean + } def list(params \\ %{}, opts \\ []) do new_request(opts) |> prefix_expansions() diff --git a/lib/stripe/connect/transfer_reversal.ex b/lib/stripe/connect/transfer_reversal.ex index a3ff8d27..ec6c75ac 100644 --- a/lib/stripe/connect/transfer_reversal.ex +++ b/lib/stripe/connect/transfer_reversal.ex @@ -55,7 +55,8 @@ defmodule Stripe.TransferReversal do @doc """ Retrieve a transfer reversal. """ - @spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} def retrieve(id, reversal_id, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{id}/reversals/#{reversal_id}") @@ -68,7 +69,8 @@ defmodule Stripe.TransferReversal do Takes the `id` and a map of changes. """ - @spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} when params: %{ optional(:metadata) => Stripe.Types.metadata() } @@ -83,7 +85,8 @@ defmodule Stripe.TransferReversal do @doc """ List all transfers. """ - @spec list(Stripe.id() | t, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec list(Stripe.id() | t, params, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ optional(:ending_before) => t | Stripe.id(), optional(:limit) => 1..100, diff --git a/lib/stripe/core_resources/balance.ex b/lib/stripe/core_resources/balance.ex index e145e276..95336793 100644 --- a/lib/stripe/core_resources/balance.ex +++ b/lib/stripe/core_resources/balance.ex @@ -55,7 +55,8 @@ defmodule Stripe.Balance do See the [Stripe docs](https://stripe.com/docs/api#balance_transaction_retrieve). """ - @spec retrieve_transaction(String.t(), Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec retrieve_transaction(String.t(), Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} def retrieve_transaction(id, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/history/" <> id) diff --git a/lib/stripe/core_resources/charge.ex b/lib/stripe/core_resources/charge.ex index d3228e37..db6632bf 100644 --- a/lib/stripe/core_resources/charge.ex +++ b/lib/stripe/core_resources/charge.ex @@ -142,25 +142,27 @@ defmodule Stripe.Charge do See the [Stripe docs](https://stripe.com/docs/api#create_charge). """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - :amount => pos_integer, - :currency => String.t(), - optional(:application_fee) => non_neg_integer, - optional(:capture) => boolean, - optional(:description) => String.t(), - optional(:destination) => %{ - :account => Stripe.id() | Stripe.Account.t(), - optional(:amount) => non_neg_integer - }, - optional(:transfer_group) => String.t(), - optional(:on_behalf_of) => Stripe.id() | Stripe.Account.t(), - optional(:metadata) => map, - optional(:receipt_email) => String.t(), - optional(:shipping) => Stripe.Types.shipping(), - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:source) => Stripe.id() | Stripe.Card.t() | card_info, - optional(:statement_descriptor) => String.t() - } | %{} + when params: + %{ + :amount => pos_integer, + :currency => String.t(), + optional(:application_fee) => non_neg_integer, + optional(:capture) => boolean, + optional(:description) => String.t(), + optional(:destination) => %{ + :account => Stripe.id() | Stripe.Account.t(), + optional(:amount) => non_neg_integer + }, + optional(:transfer_group) => String.t(), + optional(:on_behalf_of) => Stripe.id() | Stripe.Account.t(), + optional(:metadata) => map, + optional(:receipt_email) => String.t(), + optional(:shipping) => Stripe.Types.shipping(), + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:source) => Stripe.id() | Stripe.Card.t() | card_info, + optional(:statement_descriptor) => String.t() + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -203,15 +205,17 @@ defmodule Stripe.Charge do See the [Stripe docs](https://stripe.com/docs/api#update_charge). """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:description) => String.t(), - optional(:fraud_details) => user_fraud_report, - optional(:metadata) => Stripe.Types.metadata(), - optional(:receipt_email) => String.t(), - optional(:shipping) => Stripe.Types.shipping(), - optional(:transfer_group) => String.t() - } | %{} + when params: + %{ + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:description) => String.t(), + optional(:fraud_details) => user_fraud_report, + optional(:metadata) => Stripe.Types.metadata(), + optional(:receipt_email) => String.t(), + optional(:shipping) => Stripe.Types.shipping(), + optional(:transfer_group) => String.t() + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") diff --git a/lib/stripe/core_resources/dispute.ex b/lib/stripe/core_resources/dispute.ex index 78176cc7..7ee1782a 100644 --- a/lib/stripe/core_resources/dispute.ex +++ b/lib/stripe/core_resources/dispute.ex @@ -109,11 +109,13 @@ defmodule Stripe.Dispute do Update a dispute. """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:evidence) => dispute_evidence, - optional(:metadata) => Stripe.Types.metadata(), - optional(:submit) => boolean - } | %{} + when params: + %{ + optional(:evidence) => dispute_evidence, + optional(:metadata) => Stripe.Types.metadata(), + optional(:submit) => boolean + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -137,12 +139,14 @@ defmodule Stripe.Dispute do 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(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } | %{} + when params: + %{ + optional(:created) => String.t() | Stripe.date_query(), + 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() diff --git a/lib/stripe/core_resources/event.ex b/lib/stripe/core_resources/event.ex index 82d1a025..8b4b5f85 100644 --- a/lib/stripe/core_resources/event.ex +++ b/lib/stripe/core_resources/event.ex @@ -87,14 +87,16 @@ defmodule Stripe.Event do List all events, going back up to 30 days. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - optional(:type) => String.t(), - optional(:types) => list - } | %{} + when params: + %{ + optional(:created) => Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id(), + optional(:type) => String.t(), + optional(:types) => list + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/core_resources/file_upload.ex b/lib/stripe/core_resources/file_upload.ex index e0eaf58c..51e9716c 100644 --- a/lib/stripe/core_resources/file_upload.ex +++ b/lib/stripe/core_resources/file_upload.ex @@ -15,15 +15,15 @@ defmodule Stripe.FileUpload do import Stripe.Request @type t :: %__MODULE__{ - id: Stripe.id, - object: String.t, - created: Stripe.timestamp, - filename: String.t | nil, - purpose: String.t, - size: integer, - type: String.t | nil, - url: String.t | nil - } + id: Stripe.id(), + object: String.t(), + created: Stripe.timestamp(), + filename: String.t() | nil, + purpose: String.t(), + size: integer, + type: String.t() | nil, + url: String.t() | nil + } defstruct [ :id, @@ -43,7 +43,7 @@ defmodule Stripe.FileUpload do Takes the filepath and the purpose. """ - @spec create(map, Keyword.t) :: {:ok, t} | {:error, Stripe.Error.t} + @spec create(map, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} def create(%{file: _, purpose: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -55,7 +55,7 @@ defmodule Stripe.FileUpload do @doc """ Retrieve a file_upload. """ - @spec retrieve(Stripe.id | t, Stripe.options) :: {:ok, t} | {:error, Stripe.Error.t} + @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)}") @@ -66,13 +66,15 @@ defmodule Stripe.FileUpload do @doc """ List all file uploads, going back up to 30 days. """ - @spec list(params, Stripe.options) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t} - when params: %{ - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:purpose) => String.t(), - optional(:starting_after) => t | Stripe.id() - } | %{} + @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:purpose) => String.t(), + optional(:starting_after) => t | Stripe.id() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/core_resources/payout.ex b/lib/stripe/core_resources/payout.ex index bbebe34e..c94490a1 100644 --- a/lib/stripe/core_resources/payout.ex +++ b/lib/stripe/core_resources/payout.ex @@ -68,16 +68,19 @@ defmodule Stripe.Payout do See the [Stripe docs](https://stripe.com/docs/api#create_payout). """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - :amount => pos_integer, - :currency => String.t(), - optional(:description) => String.t(), - optional(:destination) => Stripe.id() | Stripe.Card.t() | Stripe.BankAccount.t() | String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:method) => String.t(), - optional(:source_type) => String.t(), - optional(:statement_descriptor) => String.t() - } | %{} + when params: + %{ + :amount => pos_integer, + :currency => String.t(), + optional(:description) => String.t(), + optional(:destination) => + Stripe.id() | Stripe.Card.t() | Stripe.BankAccount.t() | String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:method) => String.t(), + optional(:source_type) => String.t(), + optional(:statement_descriptor) => String.t() + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -112,9 +115,11 @@ defmodule Stripe.Payout do See the [Stripe docs](https://stripe.com/docs/api#update_payout). """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:metadata) => Stripe.Types.metadata() - } | %{} + when params: + %{ + optional(:metadata) => Stripe.Types.metadata() + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -132,15 +137,17 @@ defmodule Stripe.Payout do See the [Stripe docs](https://stripe.com/docs/api#list_payouts). """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:arrival_date) => Stripe.date_query(), - optional(:created) => Stripe.date_query(), - optional(:destination) => String.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - optional(:status) => String.t() - } | %{} + when params: + %{ + optional(:arrival_date) => Stripe.date_query(), + optional(:created) => Stripe.date_query(), + optional(:destination) => String.t(), + 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() diff --git a/lib/stripe/core_resources/refund.ex b/lib/stripe/core_resources/refund.ex index dfaefdd0..8d31aec9 100644 --- a/lib/stripe/core_resources/refund.ex +++ b/lib/stripe/core_resources/refund.ex @@ -67,14 +67,16 @@ defmodule Stripe.Refund do See the [Stripe docs](https://stripe.com/docs/api#create_refund). """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - :charge => Stripe.Charge.t() | Stripe.id(), - optional(:amount) => pos_integer, - optional(:metadata) => Stripe.Types.metadata(), - optional(:reason) => String.t(), - optional(:refund_application_fee) => boolean, - optional(:reverse_transfer) => boolean - } | %{} + when params: + %{ + :charge => Stripe.Charge.t() | Stripe.id(), + optional(:amount) => pos_integer, + optional(:metadata) => Stripe.Types.metadata(), + optional(:reason) => String.t(), + optional(:refund_application_fee) => boolean, + optional(:reverse_transfer) => boolean + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -110,9 +112,11 @@ defmodule Stripe.Refund do See the [Stripe docs](https://stripe.com/docs/api#update_refund). """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:metadata) => Stripe.Types.metadata() - } | %{} + when params: + %{ + optional(:metadata) => Stripe.Types.metadata() + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -132,12 +136,14 @@ defmodule Stripe.Refund do See the [Stripe docs](https://stripe.com/docs/api#list_refunds). """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:charget) => Stripe.id() | Stripe.Charge.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } | %{} + when params: + %{ + optional(:charget) => Stripe.id() | Stripe.Charge.t(), + 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() diff --git a/lib/stripe/ephemeral_key.ex b/lib/stripe/ephemeral_key.ex index 25618f35..c5b82d01 100644 --- a/lib/stripe/ephemeral_key.ex +++ b/lib/stripe/ephemeral_key.ex @@ -38,8 +38,8 @@ defmodule Stripe.EphemeralKey do """ @spec create(params, String.t(), Keyword.t()) :: {:ok, t} | {:error, %Stripe.Error{}} when params: %{ - :customer => Stripe.id(), - } + :customer => Stripe.id() + } def create(params, api_version, opts \\ []) do new_request(opts, %{"Stripe-Version": api_version}) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/list.ex b/lib/stripe/list.ex index 2ba33c2b..9e8c5c34 100644 --- a/lib/stripe/list.ex +++ b/lib/stripe/list.ex @@ -17,12 +17,12 @@ defmodule Stripe.List do @type value :: term @type t(value) :: %__MODULE__{ - object: String.t(), - data: [value], - has_more: boolean, - total_count: integer | nil, - url: String.t() - } + object: String.t(), + data: [value], + has_more: boolean, + total_count: integer | nil, + url: String.t() + } defstruct [:object, :data, :has_more, :total_count, :url] end diff --git a/lib/stripe/payment_methods/bank_account.ex b/lib/stripe/payment_methods/bank_account.ex index eb6f76f4..2b44d90c 100644 --- a/lib/stripe/payment_methods/bank_account.ex +++ b/lib/stripe/payment_methods/bank_account.ex @@ -55,10 +55,10 @@ defmodule Stripe.BankAccount do """ @spec create(params, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - :source => Stripe.id() | Stripe.Source.t(), - optional(:metadata) => Stripe.Types.metadata() - } + :customer => Stripe.id() | Stripe.Customer.t(), + :source => Stripe.id() | Stripe.Source.t(), + optional(:metadata) => Stripe.Types.metadata() + } def create(%{customer: _, source: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(params |> plural_endpoint()) @@ -85,11 +85,11 @@ defmodule Stripe.BankAccount do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:account_holder_name) => String.t(), - optional(:account_holder_type) => String.t() - } + :customer => Stripe.id() | Stripe.Customer.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:account_holder_name) => String.t(), + optional(:account_holder_type) => String.t() + } def update(id, %{customer: _} = params, opts \\ []) do endpoint = params |> plural_endpoint() @@ -118,10 +118,10 @@ defmodule Stripe.BankAccount do """ @spec verify(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - optional(:amounts) => list(integer), - optional(:verification_method) => String.t() - } + :customer => Stripe.id() | Stripe.Customer.t(), + optional(:amounts) => list(integer), + optional(:verification_method) => String.t() + } def verify(id, %{customer: _} = params, opts \\ []) do endpoint = params |> plural_endpoint() @@ -137,11 +137,11 @@ defmodule Stripe.BankAccount do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - } + :customer => Stripe.id() | Stripe.Customer.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } def list(%{customer: _} = params, opts \\ []) do endpoint = params |> plural_endpoint() params = params |> Map.put(:object, "card") diff --git a/lib/stripe/payment_methods/card.ex b/lib/stripe/payment_methods/card.ex index 9d82c194..5355496d 100644 --- a/lib/stripe/payment_methods/card.ex +++ b/lib/stripe/payment_methods/card.ex @@ -102,10 +102,10 @@ defmodule Stripe.Card do """ @spec create(params, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - :source => Stripe.id() | Stripe.Source.t(), - optional(:metadata) => Stripe.Types.metadata(), - } + :customer => Stripe.id() | Stripe.Customer.t(), + :source => Stripe.id() | Stripe.Source.t(), + optional(:metadata) => Stripe.Types.metadata() + } def create(%{customer: _, source: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(params |> plural_endpoint()) @@ -134,19 +134,19 @@ defmodule Stripe.Card do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :id => String.t(), - :customer => String.t(), - optional(:address_city) => String.t(), - optional(:address_country) => String.t(), - optional(:address_line1) => String.t(), - optional(:address_line2) => String.t(), - optional(:address_state) => String.t(), - optional(:address_zip) => String.t(), - optional(:exp_month) => String.t(), - optional(:exp_year) => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:name) => String.t(), - } + :id => String.t(), + :customer => String.t(), + optional(:address_city) => String.t(), + optional(:address_country) => String.t(), + optional(:address_line1) => String.t(), + optional(:address_line2) => String.t(), + optional(:address_state) => String.t(), + optional(:address_zip) => String.t(), + optional(:exp_month) => String.t(), + optional(:exp_year) => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:name) => String.t() + } def update(id, %{customer: _} = params, opts \\ []) do endpoint = params |> plural_endpoint() @@ -175,11 +175,11 @@ defmodule Stripe.Card do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - :customer => Stripe.id() | Stripe.Customer.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - } + :customer => Stripe.id() | Stripe.Customer.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } def list(%{customer: _} = params, opts \\ []) do endpoint = params |> plural_endpoint() params = params |> Map.put(:object, "card") diff --git a/lib/stripe/payment_methods/source.ex b/lib/stripe/payment_methods/source.ex index 1e413587..5d3195cf 100644 --- a/lib/stripe/payment_methods/source.ex +++ b/lib/stripe/payment_methods/source.ex @@ -238,20 +238,20 @@ defmodule Stripe.Source do Create a source. """ @spec create(params, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - :type => String.t(), - optional(:amount) => String.t(), - optional(:currency) => String.t(), - optional(:flow) => String.t(), - optional(:mandate) => map, - optional(:metadata) => Stripe.Types.metadata(), - optional(:owner) => owner, - optional(:receiver) => receiver_flow, - optional(:redirect) => redirect_flow, - optional(:statement_descriptor) => String.t(), - optional(:token) => String.t(), - optional(:usage) => String.t() - } + when params: %{ + :type => String.t(), + optional(:amount) => String.t(), + optional(:currency) => String.t(), + optional(:flow) => String.t(), + optional(:mandate) => map, + optional(:metadata) => Stripe.Types.metadata(), + optional(:owner) => owner, + optional(:receiver) => receiver_flow, + optional(:redirect) => redirect_flow, + optional(:statement_descriptor) => String.t(), + optional(:token) => String.t(), + optional(:usage) => String.t() + } def create(%{} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -263,10 +263,11 @@ defmodule Stripe.Source do @doc """ Retrieve a source. """ - @spec retrieve(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec retrieve(Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:client_secret) => String.t(), - } + optional(:client_secret) => String.t() + } def retrieve(id, %{} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -282,10 +283,10 @@ defmodule Stripe.Source do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:mandate) => map, - optional(:metadata) => Stripe.Types.metadata(), - optional(:owner) => owner - } + optional(:mandate) => map, + optional(:metadata) => Stripe.Types.metadata(), + optional(:owner) => owner + } def update(id, %{} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") diff --git a/lib/stripe/relay/order.ex b/lib/stripe/relay/order.ex index 80ea03d5..b996b7fa 100644 --- a/lib/stripe/relay/order.ex +++ b/lib/stripe/relay/order.ex @@ -111,14 +111,14 @@ defmodule Stripe.Order do """ @spec create(params, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :currency => String.t(), - optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:email) => String.t(), - optional(:items) => Stripe.List.t(Stripe.OrderItem.t()), - optional(:metadata) => Stripe.Types.metadata(), - optional(:shipping) => map - } + :currency => String.t(), + optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:email) => String.t(), + optional(:items) => Stripe.List.t(Stripe.OrderItem.t()), + optional(:metadata) => Stripe.Types.metadata(), + optional(:shipping) => map + } def create(%{currency: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) @@ -145,12 +145,12 @@ defmodule Stripe.Order do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:selected_shipping_method) => String.t(), - optional(:shipping) => map, - optional(:status) => String.t() - } + optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:selected_shipping_method) => String.t(), + optional(:shipping) => map, + optional(:status) => String.t() + } def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{get_id!(id)}") @@ -164,12 +164,13 @@ defmodule Stripe.Order do """ @spec pay(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:application_fee) => non_neg_integer, - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:source) => Stripe.id() | Stripe.Card.t() | Stripe.Customer.t() | card_info, - optional(:email) => String.t(), - optional(:metadata) => Stripe.Types.metadata() - } + optional(:application_fee) => non_neg_integer, + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:source) => + Stripe.id() | Stripe.Card.t() | Stripe.Customer.t() | card_info, + optional(:email) => String.t(), + optional(:metadata) => Stripe.Types.metadata() + } def pay(id, params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{get_id!(id)}/" <> "pay") @@ -183,8 +184,8 @@ defmodule Stripe.Order do """ @spec return(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:items) => Stripe.List.t(Stripe.OrderItem.t()) - } + optional(:items) => Stripe.List.t(Stripe.OrderItem.t()) + } def return(id, params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{get_id!(id)}/" <> "returns") @@ -198,15 +199,15 @@ defmodule Stripe.Order do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:ids) => Stripe.List.t(Stripe.id()), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - optional(:status) => String.t(), - optional(:status_transitions) => map, - optional(:upstream_ids) => Stripe.List.t(Stripe.id()) - } + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:ids) => Stripe.List.t(Stripe.id()), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id(), + optional(:status) => String.t(), + optional(:status_transitions) => map, + optional(:upstream_ids) => Stripe.List.t(Stripe.id()) + } def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) diff --git a/lib/stripe/relay/order_return.ex b/lib/stripe/relay/order_return.ex index 97922422..eb859817 100644 --- a/lib/stripe/relay/order_return.ex +++ b/lib/stripe/relay/order_return.ex @@ -50,13 +50,13 @@ defmodule Stripe.OrderReturn do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:ids) => Stripe.List.t(Stripe.id()), - optional(:limit) => 1..100, - optional(:order) => Stripe.Order.t(), - optional(:starting_after) => t | Stripe.id() - } + optional(:created) => Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:ids) => Stripe.List.t(Stripe.id()), + optional(:limit) => 1..100, + optional(:order) => Stripe.Order.t(), + optional(:starting_after) => t | Stripe.id() + } def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/relay/product.ex b/lib/stripe/relay/product.ex index 2be6b834..2f87aa88 100644 --- a/lib/stripe/relay/product.ex +++ b/lib/stripe/relay/product.ex @@ -67,21 +67,23 @@ defmodule Stripe.Relay.Product do Create a product. """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:caption) => String.t(), - optional(:deactive_on) => [Stripe.id()], - optional(:description) => String.t(), - optional(:id) => String.t(), - optional(:images) => [Stripe.id()], - optional(:description) => String.t(), - optional(:attributes) => list, - :name => String.t(), - :type => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:package_dimensions) => map, - optional(:shippable) => boolean, - optional(:url) => String.t() - } | %{} + when params: + %{ + optional(:caption) => String.t(), + optional(:deactive_on) => [Stripe.id()], + optional(:description) => String.t(), + optional(:id) => String.t(), + optional(:images) => [Stripe.id()], + optional(:description) => String.t(), + optional(:attributes) => list, + :name => String.t(), + :type => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:package_dimensions) => map, + optional(:shippable) => boolean, + optional(:url) => String.t() + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) @@ -107,19 +109,21 @@ defmodule Stripe.Relay.Product do Takes the `id` and a map of changes. """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:active) => boolean, - optional(:attributes) => list, - optional(:caption) => String.t(), - optional(:deactive_on) => [Stripe.id()], - optional(:description) => String.t(), - optional(:images) => [Stripe.id()], - optional(:metadata) => Stripe.Types.metadata(), - optional(:name) => String.t(), - optional(:package_dimensions) => map, - optional(:shippable) => boolean, - optional(:url) => String.t() - } | %{} + when params: + %{ + optional(:active) => boolean, + optional(:attributes) => list, + optional(:caption) => String.t(), + optional(:deactive_on) => [Stripe.id()], + optional(:description) => String.t(), + optional(:images) => [Stripe.id()], + optional(:metadata) => Stripe.Types.metadata(), + optional(:name) => String.t(), + optional(:package_dimensions) => map, + optional(:shippable) => boolean, + optional(:url) => String.t() + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{get_id!(id)}") @@ -143,17 +147,19 @@ defmodule Stripe.Relay.Product do List all product. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:active) => boolean, - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:ids) => Stripe.List.t(Stripe.id()), - optional(:limit) => 1..100, - optional(:shippable) => boolean, - optional(:starting_after) => t | Stripe.id(), - optional(:type) => String.t(), - optional(:url) => String.t() - } | %{} + when params: + %{ + optional(:active) => boolean, + optional(:created) => Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:ids) => Stripe.List.t(Stripe.id()), + optional(:limit) => 1..100, + optional(:shippable) => boolean, + optional(:starting_after) => t | Stripe.id(), + optional(:type) => String.t(), + optional(:url) => String.t() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) diff --git a/lib/stripe/relay/sku.ex b/lib/stripe/relay/sku.ex index 4271090a..e2ee958a 100644 --- a/lib/stripe/relay/sku.ex +++ b/lib/stripe/relay/sku.ex @@ -62,16 +62,16 @@ defmodule Stripe.Sku do """ @spec create(params, Keyword.t()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :currency => String.t(), - :inventory => map, - :price => non_neg_integer, - :product => Stripe.id() | Stripe.Relay.Product.t(), - optional(:active) => boolean, - optional(:attributes) => map, - optional(:image) => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:package_dimensions) => map - } + :currency => String.t(), + :inventory => map, + :price => non_neg_integer, + :product => Stripe.id() | Stripe.Relay.Product.t(), + optional(:active) => boolean, + optional(:attributes) => map, + optional(:image) => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:package_dimensions) => map + } def create(%{currency: _, inventory: _, price: _, product: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) @@ -98,16 +98,16 @@ defmodule Stripe.Sku do """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - optional(:active) => boolean, - optional(:attributes) => map, - optional(:currency) => String.t(), - optional(:image) => String.t(), - optional(:inventory) => map, - optional(:metadata) => Stripe.Types.metadata(), - optional(:package_dimensions) => map, - optional(:price) => non_neg_integer, - optional(:product) => Stripe.id() | Stripe.Relay.Product.t() - } + optional(:active) => boolean, + optional(:attributes) => map, + optional(:currency) => String.t(), + optional(:image) => String.t(), + optional(:inventory) => map, + optional(:metadata) => Stripe.Types.metadata(), + optional(:package_dimensions) => map, + optional(:price) => non_neg_integer, + optional(:product) => Stripe.id() | Stripe.Relay.Product.t() + } def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint <> "/#{get_id!(id)}") @@ -132,15 +132,15 @@ defmodule Stripe.Sku do """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - optional(:active) => boolean, - optional(:attributes) => map, - optional(:ending_before) => t | Stripe.id(), - optional(:ids) => Stripe.List.t(Stripe.id()), - optional(:in_stock) => boolean, - optional(:limit) => 1..100, - optional(:product) => Stripe.id() | Stripe.Relay.Product.t(), - optional(:starting_after) => t | Stripe.id() - } + optional(:active) => boolean, + optional(:attributes) => map, + optional(:ending_before) => t | Stripe.id(), + optional(:ids) => Stripe.List.t(Stripe.id()), + optional(:in_stock) => boolean, + optional(:limit) => 1..100, + optional(:product) => Stripe.id() | Stripe.Relay.Product.t(), + optional(:starting_after) => t | Stripe.id() + } def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@endpoint) diff --git a/lib/stripe/subscriptions/invoice.ex b/lib/stripe/subscriptions/invoice.ex index 4ff39573..8fc02fcc 100644 --- a/lib/stripe/subscriptions/invoice.ex +++ b/lib/stripe/subscriptions/invoice.ex @@ -65,12 +65,13 @@ defmodule Stripe.Invoice do webhooks_delivered_at: Stripe.timestamp() | nil } - @type custom_fields :: list(%{ - name: String.t(), - value: String.t() - }) + @type custom_fields :: + list(%{ + name: String.t(), + value: String.t() + }) - @type invoice_settings :: %{ + @type invoice_settings :: %{ custom_fields: custom_fields | nil, footer: String.t() | nil } diff --git a/lib/stripe/subscriptions/invoiceitem.ex b/lib/stripe/subscriptions/invoiceitem.ex index 3ffd1d3c..e28e0417 100644 --- a/lib/stripe/subscriptions/invoiceitem.ex +++ b/lib/stripe/subscriptions/invoiceitem.ex @@ -62,18 +62,20 @@ defmodule Stripe.Invoiceitem do Create an invoiceitem. """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:amount) => integer, - :currency => String.t(), - :customer => Stripe.id() | Stripe.Customer.t(), - optional(:description) => String.t(), - optional(:discountable) => boolean, - optional(:invoice) => Stripe.id() | Stripe.Invoice.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:quantity) => integer, - optional(:subscription) => Stripe.id() | Stripe.Subscription.t(), - optional(:unit_amount) => integer - } | %{} + when params: + %{ + optional(:amount) => integer, + :currency => String.t(), + :customer => Stripe.id() | Stripe.Customer.t(), + optional(:description) => String.t(), + optional(:discountable) => boolean, + optional(:invoice) => Stripe.id() | Stripe.Invoice.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:quantity) => integer, + optional(:subscription) => Stripe.id() | Stripe.Subscription.t(), + optional(:unit_amount) => integer + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -100,14 +102,16 @@ defmodule Stripe.Invoiceitem do Takes the `id` and a map of changes. """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:amount) => integer, - optional(:description) => String.t(), - optional(:discountable) => boolean, - optional(:metadata) => Stripe.Types.metadata(), - optional(:quantity) => integer, - optional(:unit_amount) => integer - } | %{} + when params: + %{ + optional(:amount) => integer, + optional(:description) => String.t(), + optional(:discountable) => boolean, + optional(:metadata) => Stripe.Types.metadata(), + optional(:quantity) => integer, + optional(:unit_amount) => integer + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -133,14 +137,16 @@ defmodule Stripe.Invoiceitem do List all invoiceitems. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:created) => Stripe.timestamp(), - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:invoice) => Stripe.id() | Stripe.Invoice.t(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } | %{} + when params: + %{ + optional(:created) => Stripe.timestamp(), + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:invoice) => Stripe.id() | Stripe.Invoice.t(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> prefix_expansions() diff --git a/lib/stripe/subscriptions/line_item.ex b/lib/stripe/subscriptions/line_item.ex index 1491f5a6..7af6071a 100644 --- a/lib/stripe/subscriptions/line_item.ex +++ b/lib/stripe/subscriptions/line_item.ex @@ -52,21 +52,24 @@ defmodule Stripe.LineItem do @doc """ Retrieve an invoice line item. """ - @spec retrieve(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), - optional(:customer) => Stripe.id() | Stripe.Customer.t(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id(), - optional(:subscription) => Stripe.id() | Stripe.Subscription.t(), - optional(:subscription_billing_cycle_anchor) => integer, - optional(:subscription_items) => Stripe.List.t(Stripe.SubscriptionItem.t()), - optional(:subscription_prorate) => boolean, - optional(:subscription_proration_date) => Stripe.timestamp(), - optional(:subscription_tax_percent) => integer, - optional(:subscription_trial_from_plan) => boolean - } | %{} + @spec retrieve(Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} + when params: + %{ + optional(:coupon) => Stripe.id() | Stripe.Coupon.t(), + optional(:customer) => Stripe.id() | Stripe.Customer.t(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id(), + optional(:subscription) => Stripe.id() | Stripe.Subscription.t(), + optional(:subscription_billing_cycle_anchor) => integer, + optional(:subscription_items) => Stripe.List.t(Stripe.SubscriptionItem.t()), + optional(:subscription_prorate) => boolean, + optional(:subscription_proration_date) => Stripe.timestamp(), + optional(:subscription_tax_percent) => integer, + optional(:subscription_trial_from_plan) => boolean + } + | %{} def retrieve(id, params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint("invoices" <> "/#{get_id!(id)}/" <> "lines") diff --git a/lib/stripe/subscriptions/plan.ex b/lib/stripe/subscriptions/plan.ex index 86c6872d..79463947 100644 --- a/lib/stripe/subscriptions/plan.ex +++ b/lib/stripe/subscriptions/plan.ex @@ -65,7 +65,7 @@ defmodule Stripe.Plan do tiers_mode: boolean | nil, transform_usage: map | nil, trial_period_days: non_neg_integer | nil, - usage_type: String.t() | nil, + usage_type: String.t() | nil } defstruct [ @@ -89,7 +89,7 @@ defmodule Stripe.Plan do :tiers_mode, :transform_usage, :trial_period_days, - :usage_type, + :usage_type ] @plural_endpoint "plans" @@ -98,23 +98,25 @@ defmodule Stripe.Plan do Create a plan. """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - :currency => String.t(), - :interval => String.t(), - :product => Stripe.id() | Stripe.Product.t(), - optional(:id) => String.t(), - optional(:amount) => non_neg_integer, - optional(:active) => boolean, - optional(:billing_scheme) => String.t(), - optional(:interval_count) => pos_integer, - optional(:metadata) => Stripe.Types.metadata(), - optional(:nickname) => String.t(), - optional(:tiers) => Stripe.List.t(map), - optional(:tiers_mode) => String.t(), - optional(:transform_usage) => map, - optional(:trial_period_days) => non_neg_integer, - optional(:usage_type) => String.t(), - } | %{} + when params: + %{ + :currency => String.t(), + :interval => String.t(), + :product => Stripe.id() | Stripe.Product.t(), + optional(:id) => String.t(), + optional(:amount) => non_neg_integer, + optional(:active) => boolean, + optional(:billing_scheme) => String.t(), + optional(:interval_count) => pos_integer, + optional(:metadata) => Stripe.Types.metadata(), + optional(:nickname) => String.t(), + optional(:tiers) => Stripe.List.t(map), + optional(:tiers_mode) => String.t(), + optional(:transform_usage) => map, + optional(:trial_period_days) => non_neg_integer, + optional(:usage_type) => String.t() + } + | %{} def create(%{currency: _, interval: _, product: _} = params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -140,13 +142,15 @@ defmodule Stripe.Plan do Takes the `id` and a map of changes. """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:active) => boolean, - optional(:metadata) => Stripe.Types.metadata(), - optional(:nickname) => String.t(), - optional(:product) => Stripe.id() | Stripe.Product.t(), - optional(:trial_period_days) => non_neg_integer, - } | %{} + when params: + %{ + optional(:active) => boolean, + optional(:metadata) => Stripe.Types.metadata(), + optional(:nickname) => String.t(), + optional(:product) => Stripe.id() | Stripe.Product.t(), + optional(:trial_period_days) => non_neg_integer + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -170,14 +174,16 @@ defmodule Stripe.Plan do List all plans. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:active) => boolean, - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:product) => Stripe.Product.t() | Stripe.id(), - optional(:starting_after) => t | Stripe.id(), - } | %{} + when params: + %{ + optional(:active) => boolean, + optional(:created) => Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:product) => Stripe.Product.t() | Stripe.id(), + optional(:starting_after) => t | Stripe.id() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/subscriptions/product.ex b/lib/stripe/subscriptions/product.ex index 0537fba0..24c24a4d 100644 --- a/lib/stripe/subscriptions/product.ex +++ b/lib/stripe/subscriptions/product.ex @@ -37,7 +37,7 @@ defmodule Stripe.Product do unit_label: String.t() | nil, updated: Stripe.timestamp(), url: String.t() | nil - } + } defstruct [ :id, @@ -68,15 +68,17 @@ defmodule Stripe.Product do Create a product. """ @spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:id) => String.t(), - optional(:attributes) => list, - :name => String.t(), - :type => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:statement_descriptor) => String.t(), - optional(:unit_label) => String.t() - } | %{} + when params: + %{ + optional(:id) => String.t(), + optional(:attributes) => list, + :name => String.t(), + :type => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:statement_descriptor) => String.t(), + optional(:unit_label) => String.t() + } + | %{} def create(params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) @@ -102,12 +104,14 @@ defmodule Stripe.Product do Takes the `id` and a map of changes. """ @spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} - when params: %{ - optional(:attributes) => list, - optional(:name) => String.t(), - optional(:metadata) => Stripe.Types.metadata(), - optional(:statement_descriptor) => String.t() - } | %{} + when params: + %{ + optional(:attributes) => list, + optional(:name) => String.t(), + optional(:metadata) => Stripe.Types.metadata(), + optional(:statement_descriptor) => String.t() + } + | %{} def update(id, params, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}") @@ -131,16 +135,18 @@ defmodule Stripe.Product do List all products. """ @spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} - when params: %{ - optional(:active) => boolean, - optional(:created) => Stripe.date_query(), - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:shippable) => boolean, - optional(:starting_after) => t | Stripe.id(), - optional(:type) => String.t(), - optional(:url) => String.t() - } | %{} + when params: + %{ + optional(:active) => boolean, + optional(:created) => Stripe.date_query(), + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:shippable) => boolean, + optional(:starting_after) => t | Stripe.id(), + optional(:type) => String.t(), + optional(:url) => String.t() + } + | %{} def list(params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint(@plural_endpoint) diff --git a/lib/stripe/subscriptions/subscription_item.ex b/lib/stripe/subscriptions/subscription_item.ex index 3651e064..41de73d2 100644 --- a/lib/stripe/subscriptions/subscription_item.ex +++ b/lib/stripe/subscriptions/subscription_item.ex @@ -108,7 +108,8 @@ defmodule Stripe.SubscriptionItem do @doc """ List all subscriptions. """ - @spec list(Stripe.id(), params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec list(Stripe.id(), params, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ optional(:ending_before) => t | Stripe.id(), optional(:limit) => 1..100, diff --git a/lib/stripe/subscriptions/usage.ex b/lib/stripe/subscriptions/usage.ex index 5885da06..57da2c4f 100644 --- a/lib/stripe/subscriptions/usage.ex +++ b/lib/stripe/subscriptions/usage.ex @@ -40,10 +40,10 @@ defmodule Stripe.SubscriptionItem.Usage do """ @spec create(Stripe.id(), params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} when params: %{ - :quantity => float | pos_integer | 0, - :timestamp => Stripe.timestamp() | non_neg_integer, - optional(:action) => String.t() - } + :quantity => float | pos_integer | 0, + :timestamp => Stripe.timestamp() | non_neg_integer, + optional(:action) => String.t() + } def create(id, params, opts) do new_request(opts) |> put_endpoint("#{@plural_endpoint}/#{id}/usage_records") @@ -55,12 +55,13 @@ defmodule Stripe.SubscriptionItem.Usage do @doc """ List all subscription item period summaries """ - @spec list(Stripe.id(), params, Stripe.options) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} + @spec list(Stripe.id(), params, Stripe.options()) :: + {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()} when params: %{ - optional(:ending_before) => t | Stripe.id(), - optional(:limit) => 1..100, - optional(:starting_after) => t | Stripe.id() - } + optional(:ending_before) => t | Stripe.id(), + optional(:limit) => 1..100, + optional(:starting_after) => t | Stripe.id() + } def list(id, params \\ %{}, opts \\ []) do new_request(opts) |> put_endpoint("#{@plural_endpoint}/#{id}/usage_record_summaries") diff --git a/lib/stripe/types.ex b/lib/stripe/types.ex index 4768ff13..471153f9 100644 --- a/lib/stripe/types.ex +++ b/lib/stripe/types.ex @@ -34,13 +34,13 @@ defmodule Stripe.Types do @type tax_info :: %{ type: String.t(), - tax_id: String.t() | nil, - } + tax_id: String.t() | nil + } @type tax_info_verification :: %{ status: String.t() | nil, - verified_name: String.t() | nil, - } + verified_name: String.t() | nil + } @type transfer_schedule :: %{ delay_days: non_neg_integer, diff --git a/lib/stripe/util.ex b/lib/stripe/util.ex index 1a5502af..d5204aa7 100644 --- a/lib/stripe/util.ex +++ b/lib/stripe/util.ex @@ -52,6 +52,7 @@ defmodule Stripe.Util do @spec object_name_to_module(String.t()) :: module def object_name_to_module("file"), do: object_name_to_module("file_upload") + def object_name_to_module(object_name) do module_name = object_name diff --git a/test/stripe/api_test.exs b/test/stripe/api_test.exs index 21601484..92e5d891 100644 --- a/test/stripe/api_test.exs +++ b/test/stripe/api_test.exs @@ -12,7 +12,7 @@ defmodule Stripe.APITest do verify_on_exit!() Stripe.APIMock - |> expect(:oauth_request, fn(method, _endpoint, _body) -> method end) + |> expect(:oauth_request, fn method, _endpoint, _body -> method end) assert Stripe.APIMock.oauth_request(:post, "www", %{body: "body"}) == :post end diff --git a/test/stripe/config_test.exs b/test/stripe/config_test.exs index 20751e9e..d7b9ffb6 100644 --- a/test/stripe/config_test.exs +++ b/test/stripe/config_test.exs @@ -23,6 +23,7 @@ defmodule Stripe.ConfigTest do :__test, {ValueExpansionTestModule, :value, []} ) + assert(Stripe.Config.resolve(:__test) == "test-test") end @@ -32,6 +33,7 @@ defmodule Stripe.ConfigTest do :__test, {ValueExpansionTestModule, :value, []} ) + assert(Stripe.Config.resolve(:__fake_test, "test-test") == "test-test") end diff --git a/test/stripe/connect/external_account_test.exs b/test/stripe/connect/external_account_test.exs index 22f31375..e4af4ab1 100644 --- a/test/stripe/connect/external_account_test.exs +++ b/test/stripe/connect/external_account_test.exs @@ -3,7 +3,9 @@ defmodule Stripe.ExternalAccountTest do describe "create/2" do test "creates a bank account for an account" do - {:ok, _} = Stripe.ExternalAccount.create(%{account: "acct_123", token: "tok_stripetestbank"}) + {:ok, _} = + Stripe.ExternalAccount.create(%{account: "acct_123", token: "tok_stripetestbank"}) + assert_stripe_requested(:post, "/v1/accounts/acct_123/external_accounts") end @@ -52,14 +54,18 @@ defmodule Stripe.ExternalAccountTest do describe "list/3" do @tag :skip test "lists all bank accounts for an account" do - {:ok, %Stripe.List{data: bank_accounts}} = Stripe.ExternalAccount.list(:bank_account, %{account: "acct_123"}) + {:ok, %Stripe.List{data: bank_accounts}} = + Stripe.ExternalAccount.list(:bank_account, %{account: "acct_123"}) + assert_stripe_requested(:get, "/v1/accounts/acct_123/external_accounts?object=bank_account") assert is_list(bank_accounts) end @tag :skip test "lists all cards for an account" do - {:ok, %Stripe.List{data: cards}} = Stripe.ExternalAccount.list(:card, %{account: "acct_123"}) + {:ok, %Stripe.List{data: cards}} = + Stripe.ExternalAccount.list(:card, %{account: "acct_123"}) + assert_stripe_requested(:get, "/v1/accounts/acct_123/external_accounts?object=card") assert is_list(cards) end diff --git a/test/stripe/connect/oauth_test.exs b/test/stripe/connect/oauth_test.exs index 0f497c8d..f104a6c4 100644 --- a/test/stripe/connect/oauth_test.exs +++ b/test/stripe/connect/oauth_test.exs @@ -7,16 +7,15 @@ defmodule Stripe.Connect.OAuthTest do verify_on_exit!() Stripe.APIMock - |> expect(:oauth_request, fn(method, _endpoint, _body) -> method end) + |> expect(:oauth_request, fn method, _endpoint, _body -> method end) Stripe.Connect.OAuthMock - |> expect(:token, fn(url) -> Stripe.APIMock.oauth_request(:post, url, %{body: "body"}) end) - |> expect(:deauthorize_url, fn(url) -> url end) - |> expect(:authorize_url, fn(%{url: url}) -> url end) + |> expect(:token, fn url -> Stripe.APIMock.oauth_request(:post, url, %{body: "body"}) end) + |> expect(:deauthorize_url, fn url -> url end) + |> expect(:authorize_url, fn %{url: url} -> url end) assert Stripe.Connect.OAuthMock.token("1234") == :post assert Stripe.Connect.OAuthMock.authorize_url(%{url: "www"}) == "www" assert Stripe.Connect.OAuthMock.deauthorize_url("www.google.com") == "www.google.com" end end - diff --git a/test/stripe/connect/recipient_test.exs b/test/stripe/connect/recipient_test.exs index a232e437..be1a3387 100644 --- a/test/stripe/connect/recipient_test.exs +++ b/test/stripe/connect/recipient_test.exs @@ -7,7 +7,9 @@ defmodule Stripe.RecipientTest do end test "is creatable" do - assert {:ok, %Stripe.Recipient{}} = Stripe.Recipient.create(%{name: "scooter", type: "standard"}) + assert {:ok, %Stripe.Recipient{}} = + Stripe.Recipient.create(%{name: "scooter", type: "standard"}) + assert_stripe_requested(:post, "/v1/recipients") end diff --git a/test/stripe/connect/transfer_reversal_test.exs b/test/stripe/connect/transfer_reversal_test.exs index e6378633..e07d1a43 100644 --- a/test/stripe/connect/transfer_reversal_test.exs +++ b/test/stripe/connect/transfer_reversal_test.exs @@ -3,7 +3,9 @@ defmodule Stripe.TransferReversalTest do describe "retrieve/2" do test "retrieves a transfer" do - assert {:ok, %Stripe.TransferReversal{}} = Stripe.TransferReversal.retrieve("transf_123", "rev_123") + assert {:ok, %Stripe.TransferReversal{}} = + Stripe.TransferReversal.retrieve("transf_123", "rev_123") + assert_stripe_requested(:get, "/v1/transfers/trasnf_123/reversals/rev_123") end end @@ -13,7 +15,10 @@ defmodule Stripe.TransferReversalTest do params = %{ amount: 123 } - assert {:ok, %Stripe.TransferReversal{}} = Stripe.TransferReversal.create("transf_123", params) + + assert {:ok, %Stripe.TransferReversal{}} = + Stripe.TransferReversal.create("transf_123", params) + assert_stripe_requested(:post, "/v1/transfers/transf_123/reversals") end end diff --git a/test/stripe/connect/transfer_test.exs b/test/stripe/connect/transfer_test.exs index 5a1a7930..0529cb45 100644 --- a/test/stripe/connect/transfer_test.exs +++ b/test/stripe/connect/transfer_test.exs @@ -15,6 +15,7 @@ defmodule Stripe.TransferTest do currency: "curr_123", destination: "dest_123" } + assert {:ok, %Stripe.Transfer{}} = Stripe.Transfer.create(params) assert_stripe_requested(:post, "/v1/transfers") end diff --git a/test/stripe/core_resources/file_upload_test.exs b/test/stripe/core_resources/file_upload_test.exs index 9d90dfa6..4699b54c 100644 --- a/test/stripe/core_resources/file_upload_test.exs +++ b/test/stripe/core_resources/file_upload_test.exs @@ -4,25 +4,27 @@ defmodule Stripe.FileUploadTest do describe "create/2" do @tag :skip test "creates a file" do - assert {:ok, %Stripe.FileUpload{}} = Stripe.FileUpload.create(%{ - file: "@/path/to/a/file.jpg", - purpose: "dispute_evidence" - }) - assert_stripe_requested :post, "/v1/files" + assert {:ok, %Stripe.FileUpload{}} = + Stripe.FileUpload.create(%{ + file: "@/path/to/a/file.jpg", + purpose: "dispute_evidence" + }) + + assert_stripe_requested(:post, "/v1/files") end end describe "retrieve/2" do test "retrieves an file" do assert {:ok, _} = Stripe.FileUpload.retrieve("file_123") - assert_stripe_requested :get, "/v1/files/file_123" + assert_stripe_requested(:get, "/v1/files/file_123") end end describe "list/2" do test "lists all files" do assert {:ok, _} = Stripe.FileUpload.list() - assert_stripe_requested :get, "/v1/files" + assert_stripe_requested(:get, "/v1/files") end end end diff --git a/test/stripe/payment_methods/source_test.exs b/test/stripe/payment_methods/source_test.exs index b7445c46..600f0d5a 100644 --- a/test/stripe/payment_methods/source_test.exs +++ b/test/stripe/payment_methods/source_test.exs @@ -24,8 +24,7 @@ defmodule Stripe.SourceTest do describe "attach/2" do test "attaches a source to a customer" do - assert {:ok, _} = - Stripe.Source.attach(%{customer: "cus_123", source: "src_123"}) + assert {:ok, _} = Stripe.Source.attach(%{customer: "cus_123", source: "src_123"}) assert_stripe_requested(:post, "/v1/customers/cus_123/sources") end diff --git a/test/stripe/relay/sku_test.exs b/test/stripe/relay/sku_test.exs index eb4639de..6872e2b3 100644 --- a/test/stripe/relay/sku_test.exs +++ b/test/stripe/relay/sku_test.exs @@ -3,7 +3,15 @@ defmodule Stripe.SkuTest do test "is creatable" do inventory = %{type: "finite", quantity: 500} - assert {:ok, %Stripe.Sku{}} = Stripe.Sku.create(%{currency: "USD", product: "prod_123", price: 100, inventory: inventory}) + + assert {:ok, %Stripe.Sku{}} = + Stripe.Sku.create(%{ + currency: "USD", + product: "prod_123", + price: 100, + inventory: inventory + }) + assert_stripe_requested(:post, "/v1/skus") end @@ -42,4 +50,3 @@ defmodule Stripe.SkuTest do assert_stripe_requested(:get, "/v1/skus") end end - diff --git a/test/stripe/subscriptions/invoiceitem_test.exs b/test/stripe/subscriptions/invoiceitem_test.exs index 08dde0ce..6fd6b937 100644 --- a/test/stripe/subscriptions/invoiceitem_test.exs +++ b/test/stripe/subscriptions/invoiceitem_test.exs @@ -3,7 +3,9 @@ defmodule Stripe.InvoiceitemTest do describe "create/2" do test "creates an invoice" do - assert {:ok, %Stripe.Invoiceitem{}} = Stripe.Invoiceitem.create(%{customer: "cus_123", currency: "usd"}) + assert {:ok, %Stripe.Invoiceitem{}} = + Stripe.Invoiceitem.create(%{customer: "cus_123", currency: "usd"}) + assert_stripe_requested(:post, "/v1/invoiceitems") end end diff --git a/test/stripe/subscriptions/subscription_item_test.exs b/test/stripe/subscriptions/subscription_item_test.exs index 675e1752..8893daed 100644 --- a/test/stripe/subscriptions/subscription_item_test.exs +++ b/test/stripe/subscriptions/subscription_item_test.exs @@ -14,6 +14,7 @@ defmodule Stripe.SubscriptionItemTest do subscription: "sub_123", plan: "plan_123" } + assert {:ok, %Stripe.SubscriptionItem{}} = Stripe.SubscriptionItem.create(params) assert_stripe_requested(:post, "/v1/subscription_items") end diff --git a/test/stripe/subscriptions/usage_test.exs b/test/stripe/subscriptions/usage_test.exs index ed4e297b..b3b6a441 100644 --- a/test/stripe/subscriptions/usage_test.exs +++ b/test/stripe/subscriptions/usage_test.exs @@ -1,29 +1,28 @@ defmodule Stripe.SubscriptionItem.UsageTest do use Stripe.StripeCase, async: true - + describe "create/2" do test "create usage record" do item_id = "si_123" params = %{ quantity: 10, - timestamp: 1543335582 + timestamp: 1_543_335_582 } assert {:ok, record} = Stripe.SubscriptionItem.Usage.create(item_id, params) assert %{subscription_item: _sub_id} = record assert_stripe_requested(:post, "/v1/subscription_items/#{item_id}/usage_records") end - + test "create usage record with subsctiption item" do - item = - %Stripe.SubscriptionItem{ - id: "si_123" - } + item = %Stripe.SubscriptionItem{ + id: "si_123" + } params = %{ quantity: 10, - timestamp: 1543335582 + timestamp: 1_543_335_582 } assert {:ok, record} = Stripe.SubscriptionItem.Usage.create(Map.get(item, :id), params) @@ -51,7 +50,9 @@ defmodule Stripe.SubscriptionItem.UsageTest do limit: 10 } - assert {:ok, %Stripe.List{data: usages}} = Stripe.SubscriptionItem.Usage.list(item_id, params) + assert {:ok, %Stripe.List{data: usages}} = + Stripe.SubscriptionItem.Usage.list(item_id, params) + assert_stripe_requested(:get, "/v1/subscription_items/#{item_id}/usage_record_summaries") assert is_list(usages) assert %{subscription_item: _sub_item_id} = hd(usages) diff --git a/test/test_helper.exs b/test/test_helper.exs index 8baedabb..f78c739c 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -8,7 +8,6 @@ Logger.configure(level: :info) {:ok, pid} = Stripe.StripeMock.start_link(port: 12123, global: true) - Application.put_env(:stripity_stripe, :api_base_url, "http://localhost:12123/v1/") Application.put_env(:stripity_stripe, :api_upload_url, "http://localhost:12123/v1/") Application.put_env(:stripity_stripe, :api_key, "sk_test_123") @@ -30,6 +29,7 @@ defmodule Helper do # It might be connection refused. Process.sleep(250) wait_until_stripe_mock_launch() + _ -> true end