stripe 1.58.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.travis.yml +1 -2
  4. data/Gemfile +11 -12
  5. data/History.txt +8 -0
  6. data/README.md +44 -31
  7. data/Rakefile +1 -1
  8. data/VERSION +1 -1
  9. data/lib/stripe.rb +4 -344
  10. data/lib/stripe/account.rb +4 -4
  11. data/lib/stripe/api_operations/create.rb +2 -2
  12. data/lib/stripe/api_operations/delete.rb +2 -2
  13. data/lib/stripe/api_operations/list.rb +2 -2
  14. data/lib/stripe/api_operations/request.rb +9 -3
  15. data/lib/stripe/api_operations/save.rb +4 -6
  16. data/lib/stripe/api_resource.rb +2 -2
  17. data/lib/stripe/bank_account.rb +2 -2
  18. data/lib/stripe/bitcoin_receiver.rb +1 -1
  19. data/lib/stripe/charge.rb +12 -12
  20. data/lib/stripe/customer.rb +6 -6
  21. data/lib/stripe/dispute.rb +2 -3
  22. data/lib/stripe/errors.rb +20 -10
  23. data/lib/stripe/invoice.rb +4 -4
  24. data/lib/stripe/list_object.rb +2 -2
  25. data/lib/stripe/order.rb +4 -4
  26. data/lib/stripe/reversal.rb +1 -1
  27. data/lib/stripe/source.rb +2 -2
  28. data/lib/stripe/stripe_client.rb +396 -0
  29. data/lib/stripe/stripe_response.rb +48 -0
  30. data/lib/stripe/transfer.rb +2 -2
  31. data/lib/stripe/util.rb +6 -6
  32. data/lib/stripe/version.rb +1 -1
  33. data/spec/fixtures.json +0 -0
  34. data/spec/fixtures.yaml +0 -0
  35. data/spec/spec.json +0 -0
  36. data/spec/spec.yaml +0 -0
  37. data/stripe.gemspec +1 -1
  38. data/test/api_fixtures.rb +29 -0
  39. data/test/api_stub_helpers.rb +125 -0
  40. data/test/stripe/account_test.rb +153 -247
  41. data/test/stripe/alipay_account_test.rb +10 -2
  42. data/test/stripe/api_operations_test.rb +3 -3
  43. data/test/stripe/api_resource_test.rb +139 -499
  44. data/test/stripe/apple_pay_domain_test.rb +22 -23
  45. data/test/stripe/application_fee_refund_test.rb +22 -31
  46. data/test/stripe/application_fee_test.rb +6 -17
  47. data/test/stripe/balance_test.rb +3 -3
  48. data/test/stripe/bank_account_test.rb +31 -11
  49. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  50. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  51. data/test/stripe/charge_test.rb +39 -126
  52. data/test/stripe/country_spec_test.rb +7 -30
  53. data/test/stripe/coupon_test.rb +33 -17
  54. data/test/stripe/customer_card_test.rb +25 -46
  55. data/test/stripe/customer_test.rb +86 -81
  56. data/test/stripe/dispute_test.rb +27 -38
  57. data/test/stripe/errors_test.rb +2 -2
  58. data/test/stripe/file_upload_test.rb +32 -24
  59. data/test/stripe/invoice_item_test.rb +46 -10
  60. data/test/stripe/invoice_test.rb +48 -48
  61. data/test/stripe/list_object_test.rb +22 -31
  62. data/test/stripe/order_return_test.rb +11 -15
  63. data/test/stripe/order_test.rb +38 -51
  64. data/test/stripe/plan_test.rb +39 -18
  65. data/test/stripe/product_test.rb +29 -33
  66. data/test/stripe/recipient_card_test.rb +23 -40
  67. data/test/stripe/recipient_test.rb +39 -10
  68. data/test/stripe/refund_test.rb +20 -45
  69. data/test/stripe/reversal_test.rb +27 -31
  70. data/test/stripe/sku_test.rb +36 -19
  71. data/test/stripe/source_test.rb +26 -66
  72. data/test/stripe/stripe_client_test.rb +428 -0
  73. data/test/stripe/stripe_object_test.rb +6 -2
  74. data/test/stripe/stripe_response_test.rb +46 -0
  75. data/test/stripe/subscription_item_test.rb +37 -59
  76. data/test/stripe/subscription_test.rb +40 -176
  77. data/test/stripe/three_d_secure_test.rb +13 -12
  78. data/test/stripe/transfer_test.rb +36 -19
  79. data/test/stripe_test.rb +3 -36
  80. data/test/test_data.rb +5 -931
  81. data/test/test_helper.rb +21 -25
  82. metadata +22 -17
  83. data/test/stripe/charge_refund_test.rb +0 -67
  84. data/test/stripe/metadata_test.rb +0 -129
@@ -0,0 +1,48 @@
1
+ module Stripe
2
+ # StripeResponse encapsulates some vitals of a response that came back from
3
+ # the Stripe API.
4
+ class StripeResponse
5
+ # The data contained by the HTTP body of the response deserialized from
6
+ # JSON.
7
+ attr_accessor :data
8
+
9
+ # The raw HTTP body of the response.
10
+ attr_accessor :http_body
11
+
12
+ # A Hash of the HTTP headers of the response.
13
+ attr_accessor :http_headers
14
+
15
+ # The integer HTTP status code of the response.
16
+ attr_accessor :http_status
17
+
18
+ # The Stripe request ID of the response.
19
+ attr_accessor :request_id
20
+
21
+ # Initializes a StripeResponse object from a Hash like the kind returned as
22
+ # part of a Faraday exception.
23
+ #
24
+ # This may throw JSON::ParserError if the response body is not valid JSON.
25
+ def self.from_faraday_hash(http_resp)
26
+ resp = StripeResponse.new
27
+ resp.data = JSON.parse(http_resp[:body], symbolize_names: true)
28
+ resp.http_body = http_resp[:body]
29
+ resp.http_headers = http_resp[:headers]
30
+ resp.http_status = http_resp[:status]
31
+ resp.request_id = http_resp[:headers]["Request-Id"]
32
+ resp
33
+ end
34
+
35
+ # Initializes a StripeResponse object from a Faraday HTTP response object.
36
+ #
37
+ # This may throw JSON::ParserError if the response body is not valid JSON.
38
+ def self.from_faraday_response(http_resp)
39
+ resp = StripeResponse.new
40
+ resp.data = JSON.parse(http_resp.body, symbolize_names: true)
41
+ resp.http_body = http_resp.body
42
+ resp.http_headers = http_resp.headers
43
+ resp.http_status = http_resp.status
44
+ resp.request_id = http_resp.headers["Request-Id"]
45
+ resp
46
+ end
47
+ end
48
+ end
@@ -5,8 +5,8 @@ module Stripe
5
5
  include Stripe::APIOperations::Save
6
6
 
7
7
  def cancel
8
- response, api_key = self.request(:post, cancel_url)
9
- initialize_from(response, api_key)
8
+ resp, api_key = self.request(:post, cancel_url)
9
+ initialize_from(resp.data, api_key)
10
10
  end
11
11
 
12
12
  def cancel_url
@@ -68,18 +68,18 @@ module Stripe
68
68
  #
69
69
  # ==== Attributes
70
70
  #
71
- # * +resp+ - Hash of fields and values to be converted into a StripeObject.
71
+ # * +data+ - Hash of fields and values to be converted into a StripeObject.
72
72
  # * +opts+ - Options for +StripeObject+ like an API key that will be reused
73
73
  # on subsequent API calls.
74
- def self.convert_to_stripe_object(resp, opts)
75
- case resp
74
+ def self.convert_to_stripe_object(data, opts)
75
+ case data
76
76
  when Array
77
- resp.map { |i| convert_to_stripe_object(i, opts) }
77
+ data.map { |i| convert_to_stripe_object(i, opts) }
78
78
  when Hash
79
79
  # Try converting to a known object class. If none available, fall back to generic StripeObject
80
- object_classes.fetch(resp[:object], StripeObject).construct_from(resp, opts)
80
+ object_classes.fetch(data[:object], StripeObject).construct_from(data, opts)
81
81
  else
82
- resp
82
+ data
83
83
  end
84
84
  end
85
85
 
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.58.0'
2
+ VERSION = '2.0.0'
3
3
  end
Binary file
Binary file
Binary file
Binary file
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.homepage = 'https://stripe.com/docs/api/ruby'
14
14
  s.license = 'MIT'
15
15
 
16
- s.add_dependency('rest-client', '>= 1.4', '< 4.0')
16
+ s.add_dependency('faraday', '~> 0')
17
17
 
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -0,0 +1,29 @@
1
+ # APIFixtures loads fixture data generated by the core Stripe API so that we
2
+ # can have slightly more accurate and up-to-date resource information in our
3
+ # tests.
4
+ class APIFixtures
5
+ def initialize
6
+ @fixtures = ::JSON.parse(File.read("#{PROJECT_ROOT}/spec/fixtures.json"),
7
+ symbolize_names: true)
8
+ freeze_recursively(@fixtures)
9
+ end
10
+
11
+ def [](name)
12
+ @fixtures[name]
13
+ end
14
+
15
+ def fetch(*args)
16
+ @fixtures.fetch(*args)
17
+ end
18
+
19
+ private
20
+
21
+ def freeze_recursively(data)
22
+ data.each do |k, v|
23
+ if v.is_a?(Hash)
24
+ freeze_recursively(v)
25
+ end
26
+ end
27
+ data.freeze
28
+ end
29
+ end
@@ -0,0 +1,125 @@
1
+ require "json"
2
+
3
+ # Provides a set of helpers for a test suite that help to mock out the Stripe
4
+ # API.
5
+ module APIStubHelpers
6
+ protected
7
+
8
+ # Uses Webmock to stub out the Stripe API for testing purposes. The stub will
9
+ # by default respond on any routes that are defined in the bundled OpenAPI
10
+ # spec with generated response data.
11
+ #
12
+ # An `override_app` can be specified to get finer grain control over how a
13
+ # stubbed endpoint responds. It can be used to modify generated responses,
14
+ # mock expectations, or even to override the default stub completely.
15
+ def stub_api
16
+ stub_request(:any, /^#{Stripe.api_base}/).to_rack(new_api_stub)
17
+ end
18
+
19
+ def stub_connect
20
+ stub_request(:any, /^#{Stripe.connect_base}/).to_return(:body => "{}")
21
+ end
22
+
23
+ private
24
+
25
+ # APIStubMiddleware intercepts a response generated by Committee's stubbing
26
+ # middleware, and tries to replace it with a better version from a set of
27
+ # sample fixtures data generated from Stripe's core API service.
28
+ class APIStubMiddleware
29
+ API_FIXTURES = APIFixtures.new
30
+
31
+ def initialize(app)
32
+ @app = app
33
+ end
34
+
35
+ def call(env)
36
+ # We use a vendor specific prefix (`x-resourceId`) embedded in the schema
37
+ # of any resource in our spec to identify it (e.g. "charge"). This allows
38
+ # us to cross-reference that response with some data that we might find
39
+ # in our fixtures file so that we can respond with a higher fidelity
40
+ # response.
41
+ schema = env["committee.response_schema"]
42
+ resource_id = schema.data["x-resourceId"] || ""
43
+
44
+ if data = API_FIXTURES[resource_id.to_sym]
45
+ # standard top-level API resource
46
+ data = fixturize_lists_recursively(schema, data)
47
+ env["committee.response"] = data
48
+ elsif schema.properties["object"].enum == ["list"]
49
+ # top level list (like from a list endpoint)
50
+ data = fixturize_list(schema, env["committee.response"])
51
+ env["committee.response"] = data
52
+ else
53
+ raise "no fixture for: #{resource_id}"
54
+ end
55
+ @app.call(env)
56
+ end
57
+
58
+ private
59
+
60
+ # If schema looks like a Stripe list object, then we look up the resource
61
+ # that the list is supposed to include and inject it into `data` as a
62
+ # fixture. Also calls into that other schema recursively so that sublists
63
+ # within it will also be assigned a fixture.
64
+ def fixturize_list(schema, data)
65
+ object_schema = schema.properties["object"]
66
+ if object_schema && object_schema.enum == ["list"]
67
+ subschema = schema.properties["data"].items
68
+ resource_id = subschema.data["x-resourceId"] || ""
69
+ if subdata = API_FIXTURES[resource_id.to_sym]
70
+ subdata = fixturize_lists_recursively(subschema, subdata)
71
+
72
+ data = data ? data.dup : {}
73
+ data[:data] = [subdata]
74
+ end
75
+ end
76
+ data
77
+ end
78
+
79
+ # Examines each of the given schema's properties and calls #fixturize_list
80
+ # on them so that any sublists will be populated with sample fixture data.
81
+ def fixturize_lists_recursively(schema, data)
82
+ data = data.dup
83
+ schema.properties.each do |key, subschema|
84
+ data[key.to_sym] = fixturize_list(subschema, data[key.to_sym])
85
+ end
86
+ data
87
+ end
88
+ end
89
+
90
+ # A descendant of the standard `Sinatra::Base` that we can use to enrich
91
+ # certain types of responses.
92
+ class APIStubApp < Sinatra::Base
93
+ not_found do
94
+ "endpoint not found in API stub: #{request.request_method} #{request.path_info}"
95
+ end
96
+ end
97
+
98
+ # Finds the latest OpenAPI specification in ROOT/spec/ and parses it for
99
+ # use with Committee.
100
+ def self.initialize_spec
101
+ schema_data = ::JSON.parse(File.read("#{PROJECT_ROOT}/spec/spec.json"))
102
+
103
+ driver = Committee::Drivers::OpenAPI2.new
104
+ driver.parse(schema_data)
105
+ end
106
+
107
+ # Creates a new Rack app with Committee middleware it.
108
+ def new_api_stub
109
+ Rack::Builder.new {
110
+ use Committee::Middleware::RequestValidation, schema: @@spec,
111
+ params_response: true, strict: true
112
+ use Committee::Middleware::Stub, schema: @@spec,
113
+ call: true
114
+ use APIStubMiddleware
115
+ run APIStubApp.new
116
+ }
117
+ end
118
+
119
+ # Parse and initialize the OpenAPI spec only once for the entire test suite.
120
+ @@spec = initialize_spec
121
+
122
+ # The default override app. Doesn't respond on any route so generated
123
+ # responses will always take precedence.
124
+ @@default_override_app = Sinatra.new
125
+ end
@@ -2,296 +2,202 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class AccountTest < Test::Unit::TestCase
5
- should "be retrievable" do
6
- resp = make_account({
7
- :charges_enabled => false,
8
- :details_submitted => false,
9
- :email => "test+bindings@stripe.com",
10
- })
11
- @mock.expects(:get).
12
- once.
13
- with('https://api.stripe.com/v1/account', nil, nil).
14
- returns(make_response(resp))
15
- a = Stripe::Account.retrieve
16
- assert_equal "test+bindings@stripe.com", a.email
17
- assert !a.charges_enabled
18
- assert !a.details_submitted
19
- end
5
+ FIXTURE = API_FIXTURES.fetch(:account)
20
6
 
21
- should "be retrievable via plural endpoint" do
22
- resp = make_account({
23
- :charges_enabled => false,
24
- :details_submitted => false,
25
- :email => "test+bindings@stripe.com",
26
- })
27
- @mock.expects(:get).
28
- once.
29
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
30
- returns(make_response(resp))
31
- a = Stripe::Account.retrieve('acct_foo')
32
- assert_equal "test+bindings@stripe.com", a.email
33
- assert !a.charges_enabled
34
- assert !a.details_submitted
7
+ should "be listable" do
8
+ accounts = Stripe::Account.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts"
10
+ assert accounts.data.kind_of?(Array)
11
+ assert accounts.data[0].kind_of?(Stripe::Account)
35
12
  end
36
13
 
37
- should "be retrievable using an API key as the only argument" do
38
- account = mock
39
- Stripe::Account.expects(:new).once.with(nil, {:api_key => 'sk_foobar'}).returns(account)
40
- account.expects(:refresh).once
41
- Stripe::Account.retrieve('sk_foobar')
14
+ should "be retrievable using singular endpoint" do
15
+ account = Stripe::Account.retrieve
16
+ assert_requested :get, "#{Stripe.api_base}/v1/account"
17
+ assert account.kind_of?(Stripe::Account)
42
18
  end
43
19
 
44
- should "allow access to keys by method" do
45
- account = Stripe::Account.construct_from(make_account({
46
- :keys => {
47
- :publishable => 'publishable-key',
48
- :secret => 'secret-key',
49
- }
50
- }))
51
- assert_equal 'publishable-key', account.keys.publishable
52
- assert_equal 'secret-key', account.keys.secret
20
+ should "be retrievable using plural endpoint" do
21
+ account = Stripe::Account.retrieve(FIXTURE[:id])
22
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
23
+ assert account.kind_of?(Stripe::Account)
53
24
  end
54
25
 
55
26
  should "be rejectable" do
56
27
  account_data = {:id => 'acct_foo'}
57
- @mock.expects(:get).
58
- once.
59
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
60
- returns(make_response(account_data))
28
+ stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
29
+ to_return(body: JSON.generate(account_data))
61
30
 
62
- @mock.expects(:post).
63
- once.
64
- with("https://api.stripe.com/v1/accounts/acct_foo/reject", nil, 'reason=fraud').
65
- returns(make_response(account_data))
31
+ stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject").
32
+ to_return(body: JSON.generate(account_data))
66
33
 
67
34
  account = Stripe::Account.retrieve('acct_foo')
68
35
  account.reject(:reason => 'fraud')
69
36
  end
70
37
 
71
- should "be saveable" do
72
- resp = {
73
- :id => 'acct_foo',
74
- :legal_entity => {
75
- :address => {
76
- :line1 => '1 Two Three'
77
- }
78
- }
79
- }
80
- @mock.expects(:get).
81
- once.
82
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
83
- returns(make_response(resp))
84
-
85
- @mock.expects(:post).
86
- once.
87
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[address][line1]=2+Three+Four&legal_entity[first_name]=Bob').
88
- returns(make_response(resp))
89
-
90
- a = Stripe::Account.retrieve('acct_foo')
91
- a.legal_entity.first_name = 'Bob'
92
- a.legal_entity.address.line1 = '2 Three Four'
93
- a.save
38
+ should "be creatable" do
39
+ account = Stripe::Account.create(:metadata => {})
40
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts"
41
+ assert account.kind_of?(Stripe::Account)
94
42
  end
95
43
 
96
- should "be updatable" do
97
- resp = {
98
- :id => 'acct_foo',
99
- :business_name => 'ACME Corp',
100
- }
101
- @mock.expects(:post).
102
- once.
103
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'business_name=ACME+Corp').
104
- returns(make_response(resp))
105
-
106
- a = Stripe::Account.update('acct_foo', :business_name => "ACME Corp")
107
- assert_equal('ACME Corp', a.business_name)
44
+ should "be saveable" do
45
+ account = Stripe::Account.retrieve(FIXTURE[:id])
46
+ account.metadata['key'] = 'value'
47
+ account.save
48
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
108
49
  end
109
50
 
110
- should 'disallow direct overrides of legal_entity' do
111
- account = Stripe::Account.construct_from(make_account({
112
- :keys => {
113
- :publishable => 'publishable-key',
114
- :secret => 'secret-key',
115
- },
116
- :legal_entity => {
117
- :first_name => 'Bling'
118
- }
119
- }))
120
-
121
- assert_raise NoMethodError do
122
- account.legal_entity = {:first_name => 'Blah'}
123
- end
124
-
125
- account.legal_entity.first_name = 'Blah'
51
+ should "be updateable" do
52
+ account = Stripe::Account.update(FIXTURE[:id], metadata: {foo: 'bar'})
53
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
54
+ assert account.kind_of?(Stripe::Account)
126
55
  end
127
56
 
128
- should "be able to deauthorize an account" do
129
- resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
130
- @mock.expects(:get).once.returns(make_response(resp))
131
- a = Stripe::Account.retrieve
132
-
133
-
134
- @mock.expects(:post).once.with do |url, api_key, params|
135
- url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]}
136
- end.returns(make_response({ 'stripe_user_id' => a.id }))
137
- a.deauthorize('ca_1234', 'sk_test_1234')
57
+ should "be deletable" do
58
+ account = Stripe::Account.retrieve(FIXTURE[:id])
59
+ account = account.delete
60
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
61
+ assert account.kind_of?(Stripe::Account)
138
62
  end
139
63
 
140
- should "reject nil api keys" do
141
- assert_raise TypeError do
142
- Stripe::Account.retrieve(nil)
143
- end
144
- assert_raise TypeError do
145
- Stripe::Account.retrieve(:api_key => nil)
64
+ context "#bank_account=" do
65
+ should "warn that #bank_account= is deprecated" do
66
+ old_stderr = $stderr
67
+ $stderr = StringIO.new
68
+ begin
69
+ account = Stripe::Account.retrieve(FIXTURE[:id])
70
+ account.bank_account = "tok_123"
71
+ message = "NOTE: Stripe::Account#bank_account= is " +
72
+ "deprecated; use #external_account= instead"
73
+ assert_match Regexp.new(message), $stderr.string
74
+ ensure
75
+ $stderr = old_stderr
76
+ end
146
77
  end
147
78
  end
148
79
 
149
- should "be able to create a bank account" do
150
- resp = {
151
- :id => 'acct_1234',
152
- :external_accounts => {
153
- :object => "list",
154
- :resource_url => "/v1/accounts/acct_1234/external_accounts",
155
- :data => [],
156
- }
157
- }
158
- @mock.expects(:get).once.returns(make_response(resp))
159
- a = Stripe::Account.retrieve
80
+ context "#deauthorize" do
81
+ should "deauthorize an account" do
82
+ account = Stripe::Account.retrieve(FIXTURE[:id])
160
83
 
161
- @mock.expects(:post).
162
- once.
163
- with('https://api.stripe.com/v1/accounts/acct_1234/external_accounts', nil, 'external_account=btok_1234').
164
- returns(make_response(resp))
165
- a.external_accounts.create({:external_account => 'btok_1234'})
84
+ # Unfortunately, the OpenAPI spec doesn't yet cover anything under the
85
+ # Connect endpoints, so for just stub this out with Webmock.
86
+ stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
87
+ with(body: { 'client_id' => 'ca_1234', 'stripe_user_id' => account.id}).
88
+ to_return(body: JSON.generate({ 'stripe_user_id' => account.id }))
89
+ account.deauthorize('ca_1234', 'sk_test_1234')
90
+ end
166
91
  end
167
92
 
168
- should "be able to retrieve a bank account" do
169
- resp = {
170
- :id => 'acct_1234',
171
- :external_accounts => {
172
- :object => "list",
173
- :resource_url => "/v1/accounts/acct_1234/external_accounts",
174
- :data => [{
175
- :id => "ba_1234",
176
- :object => "bank_account",
177
- }],
178
- }
179
- }
180
- @mock.expects(:get).once.returns(make_response(resp))
181
- a = Stripe::Account.retrieve
182
- assert_equal(BankAccount, a.external_accounts.data[0].class)
183
- end
93
+ context "#legal_entity=" do
94
+ should 'disallow direct overrides' do
95
+ account = Stripe::Account.retrieve(FIXTURE[:id])
184
96
 
185
- should "#serialize_params an a new additional_owners" do
186
- obj = Stripe::Util.convert_to_stripe_object({
187
- :object => "account",
188
- :legal_entity => Stripe::StripeObject.construct_from({
189
- }),
190
- }, {})
191
- obj.legal_entity.additional_owners = [
192
- { :first_name => "Joe" },
193
- { :first_name => "Jane" },
194
- ]
97
+ assert_raise NoMethodError do
98
+ account.legal_entity = {:first_name => 'Blah'}
99
+ end
195
100
 
196
- expected = {
197
- :legal_entity => {
198
- :additional_owners => {
199
- "0" => { :first_name => "Joe" },
200
- "1" => { :first_name => "Jane" },
201
- }
202
- }
203
- }
204
- assert_equal(expected, obj.serialize_params)
101
+ account.legal_entity.first_name = 'Blah'
102
+ end
205
103
  end
206
104
 
207
- should "#serialize_params on an partially changed additional_owners" do
208
- obj = Stripe::Util.convert_to_stripe_object({
209
- :object => "account",
210
- :legal_entity => {
211
- :additional_owners => [
212
- Stripe::StripeObject.construct_from({
213
- :first_name => "Joe"
214
- }),
215
- Stripe::StripeObject.construct_from({
216
- :first_name => "Jane"
217
- }),
218
- ]
105
+ context "#serialize_params" do
106
+ should "serialize an a new additional_owners" do
107
+ obj = Stripe::Util.convert_to_stripe_object({
108
+ :object => "account",
109
+ :legal_entity => Stripe::StripeObject.construct_from({
110
+ }),
111
+ }, {})
112
+ obj.legal_entity.additional_owners = [
113
+ { :first_name => "Joe" },
114
+ { :first_name => "Jane" },
115
+ ]
116
+
117
+ expected = {
118
+ :legal_entity => {
119
+ :additional_owners => {
120
+ "0" => { :first_name => "Joe" },
121
+ "1" => { :first_name => "Jane" },
122
+ }
123
+ }
219
124
  }
220
- }, {})
221
- obj.legal_entity.additional_owners[1].first_name = "Stripe"
125
+ assert_equal(expected, obj.serialize_params)
126
+ end
222
127
 
223
- expected = {
224
- :legal_entity => {
225
- :additional_owners => {
226
- "1" => { :first_name => "Stripe" }
128
+ should "serialize on an partially changed additional_owners" do
129
+ obj = Stripe::Util.convert_to_stripe_object({
130
+ :object => "account",
131
+ :legal_entity => {
132
+ :additional_owners => [
133
+ Stripe::StripeObject.construct_from({
134
+ :first_name => "Joe"
135
+ }),
136
+ Stripe::StripeObject.construct_from({
137
+ :first_name => "Jane"
138
+ }),
139
+ ]
140
+ }
141
+ }, {})
142
+ obj.legal_entity.additional_owners[1].first_name = "Stripe"
143
+
144
+ expected = {
145
+ :legal_entity => {
146
+ :additional_owners => {
147
+ "1" => { :first_name => "Stripe" }
148
+ }
227
149
  }
228
150
  }
229
- }
230
- assert_equal(expected, obj.serialize_params)
231
- end
151
+ assert_equal(expected, obj.serialize_params)
152
+ end
232
153
 
233
- should "#serialize_params on an unchanged additional_owners" do
234
- obj = Stripe::Util.convert_to_stripe_object({
235
- :object => "account",
236
- :legal_entity => {
237
- :additional_owners => [
238
- Stripe::StripeObject.construct_from({
239
- :first_name => "Joe"
240
- }),
241
- Stripe::StripeObject.construct_from({
242
- :first_name => "Jane"
243
- }),
244
- ]
245
- }
246
- }, {})
154
+ should "serialize on an unchanged additional_owners" do
155
+ obj = Stripe::Util.convert_to_stripe_object({
156
+ :object => "account",
157
+ :legal_entity => {
158
+ :additional_owners => [
159
+ Stripe::StripeObject.construct_from({
160
+ :first_name => "Joe"
161
+ }),
162
+ Stripe::StripeObject.construct_from({
163
+ :first_name => "Jane"
164
+ }),
165
+ ]
166
+ }
167
+ }, {})
247
168
 
248
- expected = {
249
- :legal_entity => {
250
- :additional_owners => {}
169
+ expected = {
170
+ :legal_entity => {
171
+ :additional_owners => {}
172
+ }
251
173
  }
252
- }
253
- assert_equal(expected, obj.serialize_params)
254
- end
174
+ assert_equal(expected, obj.serialize_params)
175
+ end
255
176
 
256
- # Note that the empty string that we send for this one has a special
257
- # meaning for the server, which interprets it as an array unset.
258
- should "#serialize_params on an unset additional_owners" do
259
- obj = Stripe::Util.convert_to_stripe_object({
260
- :object => "account",
261
- :legal_entity => {
262
- :additional_owners => [
263
- Stripe::StripeObject.construct_from({
264
- :first_name => "Joe"
265
- }),
266
- Stripe::StripeObject.construct_from({
267
- :first_name => "Jane"
268
- }),
269
- ]
270
- }
271
- }, {})
272
- obj.legal_entity.additional_owners = nil
177
+ # Note that the empty string that we send for this one has a special
178
+ # meaning for the server, which interprets it as an array unset.
179
+ should "serialize on an unset additional_owners" do
180
+ obj = Stripe::Util.convert_to_stripe_object({
181
+ :object => "account",
182
+ :legal_entity => {
183
+ :additional_owners => [
184
+ Stripe::StripeObject.construct_from({
185
+ :first_name => "Joe"
186
+ }),
187
+ Stripe::StripeObject.construct_from({
188
+ :first_name => "Jane"
189
+ }),
190
+ ]
191
+ }
192
+ }, {})
193
+ obj.legal_entity.additional_owners = nil
273
194
 
274
- expected = {
275
- :legal_entity => {
276
- :additional_owners => ""
195
+ expected = {
196
+ :legal_entity => {
197
+ :additional_owners => ""
198
+ }
277
199
  }
278
- }
279
- assert_equal(expected, obj.serialize_params)
280
- end
281
-
282
- context "#bank_account=" do
283
- should "warn that #bank_account= is deprecated" do
284
- old_stderr = $stderr
285
- $stderr = StringIO.new
286
- begin
287
- a = Stripe::Account.new("test_account")
288
- a.bank_account = "tok_123"
289
- message = "NOTE: Stripe::Account#bank_account= is " +
290
- "deprecated; use #external_account= instead"
291
- assert_match Regexp.new(message), $stderr.string
292
- ensure
293
- $stderr = old_stderr
294
- end
200
+ assert_equal(expected, obj.serialize_params)
295
201
  end
296
202
  end
297
203
  end