Add support for account bank accounts

This commit is contained in:
Brian Krausz 2015-06-06 12:48:23 -07:00
parent 8ba1a0e490
commit 5883e421c1
5 changed files with 59 additions and 0 deletions

View File

@ -39,6 +39,7 @@ require 'stripe/token'
require 'stripe/event'
require 'stripe/transfer'
require 'stripe/recipient'
require 'stripe/bank_account'
require 'stripe/card'
require 'stripe/subscription'
require 'stripe/application_fee'

View File

@ -0,0 +1,19 @@
module Stripe
class BankAccount < APIResource
include Stripe::APIOperations::Update
include Stripe::APIOperations::Delete
include Stripe::APIOperations::List
def url
if respond_to?(:customer)
"#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
elsif respond_to?(:account)
"#{Account.url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
end
end
def self.retrieve(id, opts=nil)
raise NotImplementedError.new("Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')")
end
end
end

View File

@ -9,6 +9,8 @@ module Stripe
"#{Recipient.url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
elsif respond_to?(:customer)
"#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
elsif respond_to?(:account)
"#{Account.url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
end
end

View File

@ -25,6 +25,7 @@ module Stripe
'application_fee' => ApplicationFee,
'balance' => Balance,
'balance_transaction' => BalanceTransaction,
'bank_account' => BankAccount,
'card' => Card,
'charge' => Charge,
'coupon' => Coupon,

View File

@ -78,5 +78,41 @@ module Stripe
Stripe::Account.retrieve(:api_key => nil)
end
end
should "be able to create a bank account" do
resp = {
:id => 'acct_1234',
:external_accounts => {
:object => "list",
:url => "/v1/accounts/acct_1234/external_accounts",
:data => [],
}
}
@mock.expects(:get).once.returns(test_response(resp))
a = Stripe::Account.retrieve
@mock.expects(:post).
once.
with('https://api.stripe.com/v1/accounts/acct_1234/external_accounts', nil, 'external_account=batok_1234').
returns(test_response(resp))
a.external_accounts.create({:external_account => 'batok_1234'})
end
should "be able to retrieve a bank account" do
resp = {
:id => 'acct_1234',
:external_accounts => {
:object => "list",
:url => "/v1/accounts/acct_1234/external_accounts",
:data => [{
:id => "ba_1234",
:object => "bank_account",
}],
}
}
@mock.expects(:get).once.returns(test_response(resp))
a = Stripe::Account.retrieve
assert_equal(BankAccount, a.external_accounts.data[0].class)
end
end
end