stripe 1.30.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.github/ISSUE_TEMPLATE.md +5 -0
  4. data/.travis.yml +3 -14
  5. data/Gemfile +28 -4
  6. data/History.txt +180 -0
  7. data/README.md +147 -0
  8. data/Rakefile +10 -0
  9. data/VERSION +1 -1
  10. data/bin/stripe-console +12 -5
  11. data/lib/data/ca-certificates.crt +3868 -5114
  12. data/lib/stripe/account.rb +43 -23
  13. data/lib/stripe/alipay_account.rb +20 -0
  14. data/lib/stripe/api_operations/create.rb +2 -2
  15. data/lib/stripe/api_operations/delete.rb +2 -2
  16. data/lib/stripe/api_operations/list.rb +2 -3
  17. data/lib/stripe/api_operations/request.rb +9 -3
  18. data/lib/stripe/api_operations/save.rb +85 -0
  19. data/lib/stripe/api_resource.rb +38 -5
  20. data/lib/stripe/apple_pay_domain.rb +12 -0
  21. data/lib/stripe/application_fee.rb +8 -8
  22. data/lib/stripe/application_fee_refund.rb +7 -3
  23. data/lib/stripe/balance_transaction.rb +1 -1
  24. data/lib/stripe/bank_account.rb +13 -4
  25. data/lib/stripe/bitcoin_receiver.rb +6 -6
  26. data/lib/stripe/bitcoin_transaction.rb +1 -1
  27. data/lib/stripe/card.rb +9 -5
  28. data/lib/stripe/charge.rb +38 -20
  29. data/lib/stripe/country_spec.rb +9 -0
  30. data/lib/stripe/coupon.rb +1 -1
  31. data/lib/stripe/customer.rb +12 -10
  32. data/lib/stripe/dispute.rb +4 -5
  33. data/lib/stripe/errors.rb +92 -0
  34. data/lib/stripe/file_upload.rb +1 -1
  35. data/lib/stripe/invoice.rb +7 -7
  36. data/lib/stripe/invoice_item.rb +1 -1
  37. data/lib/stripe/list_object.rb +8 -7
  38. data/lib/stripe/order.rb +12 -4
  39. data/lib/stripe/order_return.rb +9 -0
  40. data/lib/stripe/plan.rb +1 -1
  41. data/lib/stripe/product.rb +2 -10
  42. data/lib/stripe/recipient.rb +1 -1
  43. data/lib/stripe/refund.rb +1 -1
  44. data/lib/stripe/reversal.rb +7 -3
  45. data/lib/stripe/singleton_api_resource.rb +3 -3
  46. data/lib/stripe/sku.rb +2 -2
  47. data/lib/stripe/source.rb +11 -0
  48. data/lib/stripe/stripe_client.rb +396 -0
  49. data/lib/stripe/stripe_object.rb +167 -91
  50. data/lib/stripe/stripe_response.rb +48 -0
  51. data/lib/stripe/subscription.rb +15 -9
  52. data/lib/stripe/subscription_item.rb +12 -0
  53. data/lib/stripe/three_d_secure.rb +9 -0
  54. data/lib/stripe/transfer.rb +4 -5
  55. data/lib/stripe/util.rb +105 -33
  56. data/lib/stripe/version.rb +1 -1
  57. data/lib/stripe.rb +69 -266
  58. data/spec/fixtures.json +1409 -0
  59. data/spec/fixtures.yaml +1153 -0
  60. data/spec/spec.json +19949 -0
  61. data/spec/spec.yaml +15504 -0
  62. data/stripe.gemspec +5 -18
  63. data/test/api_fixtures.rb +29 -0
  64. data/test/api_stub_helpers.rb +125 -0
  65. data/test/stripe/account_test.rb +163 -211
  66. data/test/stripe/alipay_account_test.rb +19 -0
  67. data/test/stripe/api_operations_test.rb +31 -0
  68. data/test/stripe/api_resource_test.rb +174 -340
  69. data/test/stripe/apple_pay_domain_test.rb +33 -0
  70. data/test/stripe/application_fee_refund_test.rb +22 -31
  71. data/test/stripe/application_fee_test.rb +6 -14
  72. data/test/stripe/balance_test.rb +3 -3
  73. data/test/stripe/bank_account_test.rb +41 -0
  74. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  75. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  76. data/test/stripe/charge_test.rb +39 -98
  77. data/test/stripe/country_spec_test.rb +20 -0
  78. data/test/stripe/coupon_test.rb +35 -11
  79. data/test/stripe/customer_card_test.rb +25 -46
  80. data/test/stripe/customer_test.rb +89 -61
  81. data/test/stripe/dispute_test.rb +28 -31
  82. data/test/stripe/errors_test.rb +18 -0
  83. data/test/stripe/file_upload_test.rb +32 -24
  84. data/test/stripe/invoice_item_test.rb +55 -0
  85. data/test/stripe/invoice_test.rb +50 -24
  86. data/test/stripe/list_object_test.rb +57 -45
  87. data/test/stripe/order_return_test.rb +21 -0
  88. data/test/stripe/order_test.rb +41 -34
  89. data/test/stripe/plan_test.rb +52 -0
  90. data/test/stripe/product_test.rb +31 -25
  91. data/test/stripe/recipient_card_test.rb +23 -40
  92. data/test/stripe/recipient_test.rb +50 -0
  93. data/test/stripe/refund_test.rb +20 -36
  94. data/test/stripe/reversal_test.rb +27 -31
  95. data/test/stripe/sku_test.rb +39 -13
  96. data/test/stripe/source_test.rb +43 -0
  97. data/test/stripe/stripe_client_test.rb +428 -0
  98. data/test/stripe/stripe_object_test.rb +186 -13
  99. data/test/stripe/stripe_response_test.rb +46 -0
  100. data/test/stripe/subscription_item_test.rb +54 -0
  101. data/test/stripe/subscription_test.rb +40 -52
  102. data/test/stripe/three_d_secure_test.rb +23 -0
  103. data/test/stripe/transfer_test.rb +38 -13
  104. data/test/stripe/util_test.rb +48 -16
  105. data/test/stripe_test.rb +25 -0
  106. data/test/test_data.rb +5 -621
  107. data/test/test_helper.rb +24 -24
  108. metadata +60 -139
  109. data/README.rdoc +0 -68
  110. data/gemfiles/default-with-activesupport.gemfile +0 -10
  111. data/gemfiles/json.gemfile +0 -12
  112. data/gemfiles/yajl.gemfile +0 -12
  113. data/lib/stripe/api_operations/update.rb +0 -58
  114. data/lib/stripe/errors/api_connection_error.rb +0 -4
  115. data/lib/stripe/errors/api_error.rb +0 -4
  116. data/lib/stripe/errors/authentication_error.rb +0 -4
  117. data/lib/stripe/errors/card_error.rb +0 -12
  118. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  119. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  120. data/lib/stripe/errors/stripe_error.rb +0 -26
  121. data/test/stripe/charge_refund_test.rb +0 -55
  122. data/test/stripe/metadata_test.rb +0 -129
data/stripe.gemspec CHANGED
@@ -5,28 +5,15 @@ require 'stripe/version'
5
5
  spec = Gem::Specification.new do |s|
6
6
  s.name = 'stripe'
7
7
  s.version = Stripe::VERSION
8
+ s.required_ruby_version = '>= 1.9.3'
8
9
  s.summary = 'Ruby bindings for the Stripe API'
9
10
  s.description = 'Stripe is the easiest way to accept payments online. See https://stripe.com for details.'
10
- s.authors = ['Ross Boucher', 'Greg Brockman']
11
- s.email = ['boucher@stripe.com', 'gdb@stripe.com']
12
- s.homepage = 'https://stripe.com/api'
11
+ s.author = 'Stripe'
12
+ s.email = 'support@stripe.com'
13
+ s.homepage = 'https://stripe.com/docs/api/ruby'
13
14
  s.license = 'MIT'
14
15
 
15
- s.add_dependency('rest-client', '~> 1.4')
16
- s.add_dependency('json', '~> 1.8.1')
17
-
18
- s.add_development_dependency('mocha', '~> 0.13.2')
19
- s.add_development_dependency('shoulda', '~> 3.4.0')
20
- s.add_development_dependency('test-unit')
21
- s.add_development_dependency('rake')
22
-
23
- # to avoid problems, bring Byebug in on just versions of Ruby under which
24
- # it's known to work well
25
- if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
26
- s.add_development_dependency("byebug")
27
- s.add_development_dependency("pry")
28
- s.add_development_dependency("pry-byebug")
29
- end
16
+ s.add_dependency('faraday', '~> 0')
30
17
 
31
18
  s.files = `git ls-files`.split("\n")
32
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,251 +2,203 @@ 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
- should "be updatable" do
56
- resp = {
57
- :id => 'acct_foo',
58
- :legal_entity => {
59
- :address => {
60
- :line1 => '1 Two Three'
61
- }
62
- }
63
- }
64
- @mock.expects(:get).
65
- once.
66
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
67
- returns(make_response(resp))
68
-
69
- @mock.expects(:post).
70
- once.
71
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[address][line1]=2+Three+Four&legal_entity[first_name]=Bob').
72
- returns(make_response(resp))
73
-
74
- a = Stripe::Account.retrieve('acct_foo')
75
- a.legal_entity.first_name = 'Bob'
76
- a.legal_entity.address.line1 = '2 Three Four'
77
- a.save
78
- end
26
+ should "be rejectable" do
27
+ account_data = {:id => 'acct_foo'}
28
+ stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
29
+ to_return(body: JSON.generate(account_data))
79
30
 
80
- should 'disallow direct overrides of legal_entity' do
81
- account = Stripe::Account.construct_from(make_account({
82
- :keys => {
83
- :publishable => 'publishable-key',
84
- :secret => 'secret-key',
85
- },
86
- :legal_entity => {
87
- :first_name => 'Bling'
88
- }
89
- }))
31
+ stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject").
32
+ to_return(body: JSON.generate(account_data))
90
33
 
91
- assert_raise NoMethodError do
92
- account.legal_entity = {:first_name => 'Blah'}
93
- end
34
+ account = Stripe::Account.retrieve('acct_foo')
35
+ account.reject(:reason => 'fraud')
36
+ end
94
37
 
95
- account.legal_entity.first_name = 'Blah'
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)
96
42
  end
97
43
 
98
- should "be able to deauthorize an account" do
99
- resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
100
- @mock.expects(:get).once.returns(make_response(resp))
101
- a = Stripe::Account.retrieve
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]}"
49
+ end
102
50
 
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)
55
+ end
103
56
 
104
- @mock.expects(:post).once.with do |url, api_key, params|
105
- url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]}
106
- end.returns(make_response({ 'stripe_user_id' => a.id }))
107
- 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)
108
62
  end
109
63
 
110
- should "reject nil api keys" do
111
- assert_raise TypeError do
112
- Stripe::Account.retrieve(nil)
113
- end
114
- assert_raise TypeError do
115
- 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
116
77
  end
117
78
  end
118
79
 
119
- should "be able to create a bank account" do
120
- resp = {
121
- :id => 'acct_1234',
122
- :external_accounts => {
123
- :object => "list",
124
- :url => "/v1/accounts/acct_1234/external_accounts",
125
- :data => [],
126
- }
127
- }
128
- @mock.expects(:get).once.returns(make_response(resp))
129
- a = Stripe::Account.retrieve
130
-
131
- @mock.expects(:post).
132
- once.
133
- with('https://api.stripe.com/v1/accounts/acct_1234/external_accounts', nil, 'external_account=btok_1234').
134
- returns(make_response(resp))
135
- a.external_accounts.create({:external_account => 'btok_1234'})
136
- end
80
+ context "#deauthorize" do
81
+ should "deauthorize an account" do
82
+ account = Stripe::Account.retrieve(FIXTURE[:id])
137
83
 
138
- should "be able to retrieve a bank account" do
139
- resp = {
140
- :id => 'acct_1234',
141
- :external_accounts => {
142
- :object => "list",
143
- :url => "/v1/accounts/acct_1234/external_accounts",
144
- :data => [{
145
- :id => "ba_1234",
146
- :object => "bank_account",
147
- }],
148
- }
149
- }
150
- @mock.expects(:get).once.returns(make_response(resp))
151
- a = Stripe::Account.retrieve
152
- assert_equal(BankAccount, a.external_accounts.data[0].class)
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
153
91
  end
154
92
 
155
- should "#serialize_params an a new additional_owners" do
156
- obj = Stripe::Util.convert_to_stripe_object({
157
- :object => "account",
158
- :legal_entity => {
159
- },
160
- }, {})
161
- obj.legal_entity.additional_owners = [
162
- { :first_name => "Joe" },
163
- { :first_name => "Jane" },
164
- ]
165
-
166
- expected = {
167
- :legal_entity => {
168
- :additional_owners => {
169
- "0" => { :first_name => "Joe" },
170
- "1" => { :first_name => "Jane" },
171
- }
172
- }
173
- }
174
- assert_equal(expected, obj.class.serialize_params(obj))
93
+ context "#legal_entity=" do
94
+ should 'disallow direct overrides' do
95
+ account = Stripe::Account.retrieve(FIXTURE[:id])
96
+
97
+ assert_raise NoMethodError do
98
+ account.legal_entity = {:first_name => 'Blah'}
99
+ end
100
+
101
+ account.legal_entity.first_name = 'Blah'
102
+ end
175
103
  end
176
104
 
177
- should "#serialize_params on an partially changed additional_owners" do
178
- obj = Stripe::Util.convert_to_stripe_object({
179
- :object => "account",
180
- :legal_entity => {
181
- :additional_owners => [
182
- Stripe::StripeObject.construct_from({
183
- :first_name => "Joe"
184
- }),
185
- Stripe::StripeObject.construct_from({
186
- :first_name => "Jane"
187
- }),
188
- ]
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
+ }
189
124
  }
190
- }, {})
191
- obj.legal_entity.additional_owners[1].first_name = "Stripe"
125
+ assert_equal(expected, obj.serialize_params)
126
+ end
192
127
 
193
- expected = {
194
- :legal_entity => {
195
- :additional_owners => {
196
- "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
+ }
197
149
  }
198
150
  }
199
- }
200
- assert_equal(expected, obj.class.serialize_params(obj))
201
- end
151
+ assert_equal(expected, obj.serialize_params)
152
+ end
202
153
 
203
- should "#serialize_params on an unchanged additional_owners" do
204
- obj = Stripe::Util.convert_to_stripe_object({
205
- :object => "account",
206
- :legal_entity => {
207
- :additional_owners => [
208
- Stripe::StripeObject.construct_from({
209
- :first_name => "Joe"
210
- }),
211
- Stripe::StripeObject.construct_from({
212
- :first_name => "Jane"
213
- }),
214
- ]
215
- }
216
- }, {})
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
+ }, {})
217
168
 
218
- expected = {
219
- :legal_entity => {
220
- :additional_owners => {}
169
+ expected = {
170
+ :legal_entity => {
171
+ :additional_owners => {}
172
+ }
221
173
  }
222
- }
223
- assert_equal(expected, obj.class.serialize_params(obj))
224
- end
174
+ assert_equal(expected, obj.serialize_params)
175
+ end
225
176
 
226
- # Note that the empty string that we send for this one has a special
227
- # meaning for the server, which interprets it as an array unset.
228
- should "#serialize_params on an unset additional_owners" do
229
- obj = Stripe::Util.convert_to_stripe_object({
230
- :object => "account",
231
- :legal_entity => {
232
- :additional_owners => [
233
- Stripe::StripeObject.construct_from({
234
- :first_name => "Joe"
235
- }),
236
- Stripe::StripeObject.construct_from({
237
- :first_name => "Jane"
238
- }),
239
- ]
240
- }
241
- }, {})
242
- 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
243
194
 
244
- expected = {
245
- :legal_entity => {
246
- :additional_owners => ""
195
+ expected = {
196
+ :legal_entity => {
197
+ :additional_owners => ""
198
+ }
247
199
  }
248
- }
249
- assert_equal(expected, obj.class.serialize_params(obj))
200
+ assert_equal(expected, obj.serialize_params)
201
+ end
250
202
  end
251
203
  end
252
204
  end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class AlipayAccountTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:alipay_account)
6
+
7
+ should "raise on #retrieve" do
8
+ assert_raises NotImplementedError do
9
+ Stripe::AlipayAccount.retrieve FIXTURE[:id]
10
+ end
11
+ end
12
+
13
+ should "raise on #update" do
14
+ assert_raises NotImplementedError do
15
+ Stripe::AlipayAccount.update FIXTURE[:id], {}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../../test_helper', __FILE__)
3
+
4
+ module Stripe
5
+ class ApiOperationsTest < Test::Unit::TestCase
6
+ class UpdateableResource < APIResource
7
+ include Stripe::APIOperations::Save
8
+
9
+ def self.protected_fields
10
+ [:protected]
11
+ end
12
+ end
13
+
14
+ context ".update" do
15
+ should "post the correct parameters to the resource URL" do
16
+ stub_request(:post, "#{Stripe.api_base}/v1/updateableresources/id").
17
+ with(body: { foo: "bar" }).
18
+ to_return(body: JSON.generate({ foo: "bar" }))
19
+ resource = UpdateableResource::update("id", { foo: "bar" })
20
+ assert_equal('bar', resource.foo)
21
+ end
22
+
23
+ should "error on protected fields" do
24
+ e = assert_raises do
25
+ UpdateableResource::update("id", { protected: "bar" })
26
+ end
27
+ assert_equal "Cannot update protected field: protected", e.message
28
+ end
29
+ end
30
+ end
31
+ end