Skip to content

Commit

Permalink
Add balance transactions and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Apr 27, 2018
1 parent 880dbec commit 57d8b2e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
41 changes: 41 additions & 0 deletions lib/stripe/core_resources/balance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,45 @@ defmodule Stripe.Balance do
|> put_method(:get)
|> make_request()
end

@doc """
Retrieves a balance transaction
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()}
def retrieve_transaction(id, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint <> "/history/" <> id)
|> put_method(:get)
|> make_request()
end

@doc """
List balance history
See the [Stripe docs](https://stripe.com/docs/api#balance_history).
"""
@spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:available_on) => Stripe.date_query(),
optional(:created) => Stripe.date_query(),
optional(:currency) => String.t(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:payout) => String.t(),
optional(:source) => %{
optional(:object) => String.t()
},
optional(:starting_after) => t | Stripe.id(),
optional(:type) => String.t()
}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint <> "/history")
|> put_method(:get)
|> put_params(params)
|> cast_to_id([:available_on, :created, :ending_before, :starting_after])
|> make_request()
end
end
3 changes: 2 additions & 1 deletion lib/stripe/core_resources/balance_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ defmodule Stripe.BalanceTransaction do
created: Stripe.timestamp(),
currency: String.t(),
description: String.t() | nil,
exchange_rate: integer | nil,
fee: integer,
fee_details: list(Stripe.Types.fee()) | [],
net: integer,
# TODO: clarify these
source: Stripe.id() | Stripe.Source.t() | nil,
status: String.t(),
type: String.t()
Expand All @@ -35,6 +35,7 @@ defmodule Stripe.BalanceTransaction do
:created,
:currency,
:description,
:exchange_rate,
:fee,
:fee_details,
:net,
Expand Down
12 changes: 12 additions & 0 deletions test/stripe/core_resources/balance_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
defmodule Stripe.BalanceTest do
use Stripe.StripeCase, async: true

test "is listable" do
assert {:ok, %Stripe.List{data: balances}} = Stripe.Balance.list()
assert_stripe_requested(:get, "/v1/balance/history")
assert is_list(balances)
assert %Stripe.BalanceTransaction{} = hd(balances)
end

test "transaction is retrievable" do
assert {:ok, %Stripe.BalanceTransaction{}} = Stripe.Balance.retrieve_transaction("b_123")
assert_stripe_requested(:get, "/v1/balance/history/#{"b_123"}")
end

test "is retrievable" do
assert {:ok, %Stripe.Balance{}} = Stripe.Balance.retrieve()
assert_stripe_requested(:get, "/v1/balance")
Expand Down

0 comments on commit 57d8b2e

Please sign in to comment.