diff --git a/lib/stripe.rb b/lib/stripe.rb index 7e37b6de..6f55b500 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -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' diff --git a/lib/stripe/bank_account.rb b/lib/stripe/bank_account.rb new file mode 100644 index 00000000..040541cc --- /dev/null +++ b/lib/stripe/bank_account.rb @@ -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 diff --git a/lib/stripe/card.rb b/lib/stripe/card.rb index e53e4e16..755f4744 100644 --- a/lib/stripe/card.rb +++ b/lib/stripe/card.rb @@ -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 diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index 3b0f7a6d..144d729a 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -25,6 +25,7 @@ module Stripe 'application_fee' => ApplicationFee, 'balance' => Balance, 'balance_transaction' => BalanceTransaction, + 'bank_account' => BankAccount, 'card' => Card, 'charge' => Charge, 'coupon' => Coupon, diff --git a/test/stripe/account_test.rb b/test/stripe/account_test.rb index 63b7323e..674bbaaa 100644 --- a/test/stripe/account_test.rb +++ b/test/stripe/account_test.rb @@ -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