Skip to content

Commit

Permalink
Add functions to update managed accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
nkezhaya committed Feb 24, 2017
1 parent e35cd0f commit da3c82a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/stripe/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ defmodule Stripe.Accounts do
|> Stripe.Util.handle_stripe_response
end

@doc """
Updates an Account with the given parameters - all of which are optional.
## Example
```
new_fields = [
email: "new_email@test.com"
]
{:ok, res} = Stripe.Accounts.update(account_id, new_fields)
```
"""
def update(account_id, params) do
update(account_id, params, Stripe.config_or_env_key)
end

@doc """
Updates an Account with the given parameters - all of which are optional.
Using a given stripe key to apply against the account associated.
## Example
```
{:ok, res} = Stripe.Accounts.update(account_id, new_fields, key)
```
"""
def update(account_id, params, key) do
Stripe.make_request_with_key(:post, "#{@endpoint}/#{account_id}", key, params)
|> Stripe.Util.handle_stripe_response
end

@max_fetch_size 100
@doc """
List all accounts.
Expand Down
22 changes: 22 additions & 0 deletions test/stripe/account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ defmodule Stripe.AccountTest do
end
end

@tag disabled: false
test "Update w/key works", %{account: account} do
use_cassette "account_test/update_with_key", match_requests_on: [:query, :request_body] do
new_params = [email: "newemail@example.com"]
case Stripe.Accounts.update(account.id, new_params, Stripe.config_or_env_key) do
{:ok, res} -> assert res.email == "newemail@example.com"
{:error, err} -> flunk err
end
end
end

@tag disabled: false
test "Update works", %{account: account} do
use_cassette "account_test/update", match_requests_on: [:query, :request_body] do
new_params = [email: "newemail@example.com"]
case Stripe.Accounts.update(account.id, new_params) do
{:ok, res} -> assert res.email == "newemail@example.com"
{:error, err} -> flunk err
end
end
end

test "Delete single works", %{account: account} do
use_cassette "account_test/delete", match_requests_on: [:query, :request_body] do
case Stripe.Accounts.delete account.id do
Expand Down

0 comments on commit da3c82a

Please sign in to comment.