mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-28 00:02:45 -05:00
Add support for account bank accounts
This commit is contained in:
parent
8ba1a0e490
commit
5883e421c1
@ -39,6 +39,7 @@ require 'stripe/token'
|
|||||||
require 'stripe/event'
|
require 'stripe/event'
|
||||||
require 'stripe/transfer'
|
require 'stripe/transfer'
|
||||||
require 'stripe/recipient'
|
require 'stripe/recipient'
|
||||||
|
require 'stripe/bank_account'
|
||||||
require 'stripe/card'
|
require 'stripe/card'
|
||||||
require 'stripe/subscription'
|
require 'stripe/subscription'
|
||||||
require 'stripe/application_fee'
|
require 'stripe/application_fee'
|
||||||
|
|||||||
19
lib/stripe/bank_account.rb
Normal file
19
lib/stripe/bank_account.rb
Normal 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
|
||||||
@ -9,6 +9,8 @@ module Stripe
|
|||||||
"#{Recipient.url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
|
"#{Recipient.url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
|
||||||
elsif respond_to?(:customer)
|
elsif respond_to?(:customer)
|
||||||
"#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
"#{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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ module Stripe
|
|||||||
'application_fee' => ApplicationFee,
|
'application_fee' => ApplicationFee,
|
||||||
'balance' => Balance,
|
'balance' => Balance,
|
||||||
'balance_transaction' => BalanceTransaction,
|
'balance_transaction' => BalanceTransaction,
|
||||||
|
'bank_account' => BankAccount,
|
||||||
'card' => Card,
|
'card' => Card,
|
||||||
'charge' => Charge,
|
'charge' => Charge,
|
||||||
'coupon' => Coupon,
|
'coupon' => Coupon,
|
||||||
|
|||||||
@ -78,5 +78,41 @@ module Stripe
|
|||||||
Stripe::Account.retrieve(:api_key => nil)
|
Stripe::Account.retrieve(:api_key => nil)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user