stripe 1.27.2 → 5.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +942 -0
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/Gemfile +29 -4
  5. data/History.txt +1 -361
  6. data/README.md +349 -0
  7. data/Rakefile +33 -3
  8. data/VERSION +1 -1
  9. data/bin/stripe-console +14 -5
  10. data/lib/data/ca-certificates.crt +4016 -5138
  11. data/lib/stripe.rb +102 -320
  12. data/lib/stripe/api_operations/create.rb +5 -9
  13. data/lib/stripe/api_operations/delete.rb +32 -4
  14. data/lib/stripe/api_operations/list.rb +11 -9
  15. data/lib/stripe/api_operations/nested_resource.rb +73 -0
  16. data/lib/stripe/api_operations/request.rb +66 -11
  17. data/lib/stripe/api_operations/save.rb +97 -0
  18. data/lib/stripe/api_resource.rb +96 -12
  19. data/lib/stripe/connection_manager.rb +164 -0
  20. data/lib/stripe/error_object.rb +94 -0
  21. data/lib/stripe/errors.rb +177 -0
  22. data/lib/stripe/instrumentation.rb +82 -0
  23. data/lib/stripe/list_object.rb +118 -13
  24. data/lib/stripe/multipart_encoder.rb +131 -0
  25. data/lib/stripe/oauth.rb +65 -0
  26. data/lib/stripe/object_types.rb +104 -0
  27. data/lib/stripe/resources.rb +87 -0
  28. data/lib/stripe/resources/account.rb +170 -0
  29. data/lib/stripe/resources/account_link.rb +10 -0
  30. data/lib/stripe/resources/alipay_account.rb +34 -0
  31. data/lib/stripe/resources/apple_pay_domain.rb +17 -0
  32. data/lib/stripe/resources/application_fee.rb +14 -0
  33. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  34. data/lib/stripe/resources/balance.rb +8 -0
  35. data/lib/stripe/resources/balance_transaction.rb +10 -0
  36. data/lib/stripe/resources/bank_account.rb +43 -0
  37. data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
  38. data/lib/stripe/resources/billing_portal/session.rb +12 -0
  39. data/lib/stripe/resources/bitcoin_receiver.rb +24 -0
  40. data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
  41. data/lib/stripe/resources/capability.rb +33 -0
  42. data/lib/stripe/resources/card.rb +38 -0
  43. data/lib/stripe/resources/charge.rb +23 -0
  44. data/lib/stripe/resources/checkout/session.rb +16 -0
  45. data/lib/stripe/resources/country_spec.rb +10 -0
  46. data/lib/stripe/resources/coupon.rb +13 -0
  47. data/lib/stripe/resources/credit_note.rb +33 -0
  48. data/lib/stripe/resources/credit_note_line_item.rb +7 -0
  49. data/lib/stripe/resources/customer.rb +41 -0
  50. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  51. data/lib/stripe/resources/discount.rb +7 -0
  52. data/lib/stripe/resources/dispute.rb +22 -0
  53. data/lib/stripe/resources/ephemeral_key.rb +20 -0
  54. data/lib/stripe/resources/event.rb +10 -0
  55. data/lib/stripe/resources/exchange_rate.rb +10 -0
  56. data/lib/stripe/resources/file.rb +36 -0
  57. data/lib/stripe/resources/file_link.rb +12 -0
  58. data/lib/stripe/resources/identity/verification_report.rb +12 -0
  59. data/lib/stripe/resources/identity/verification_session.rb +35 -0
  60. data/lib/stripe/resources/invoice.rb +74 -0
  61. data/lib/stripe/resources/invoice_item.rb +13 -0
  62. data/lib/stripe/resources/invoice_line_item.rb +7 -0
  63. data/lib/stripe/resources/issuing/authorization.rb +34 -0
  64. data/lib/stripe/resources/issuing/card.rb +25 -0
  65. data/lib/stripe/resources/issuing/card_details.rb +9 -0
  66. data/lib/stripe/resources/issuing/cardholder.rb +14 -0
  67. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  68. data/lib/stripe/resources/issuing/transaction.rb +13 -0
  69. data/lib/stripe/resources/line_item.rb +7 -0
  70. data/lib/stripe/resources/login_link.rb +14 -0
  71. data/lib/stripe/resources/mandate.rb +8 -0
  72. data/lib/stripe/resources/order.rb +33 -0
  73. data/lib/stripe/resources/order_return.rb +10 -0
  74. data/lib/stripe/resources/payment_intent.rb +43 -0
  75. data/lib/stripe/resources/payment_method.rb +33 -0
  76. data/lib/stripe/resources/payout.rb +33 -0
  77. data/lib/stripe/resources/person.rb +31 -0
  78. data/lib/stripe/resources/plan.rb +13 -0
  79. data/lib/stripe/resources/price.rb +12 -0
  80. data/lib/stripe/resources/product.rb +13 -0
  81. data/lib/stripe/resources/promotion_code.rb +12 -0
  82. data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
  83. data/lib/stripe/resources/radar/value_list.rb +15 -0
  84. data/lib/stripe/resources/radar/value_list_item.rb +14 -0
  85. data/lib/stripe/resources/recipient.rb +14 -0
  86. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  87. data/lib/stripe/resources/refund.rb +12 -0
  88. data/lib/stripe/resources/reporting/report_run.rb +13 -0
  89. data/lib/stripe/resources/reporting/report_type.rb +13 -0
  90. data/lib/stripe/resources/reversal.rb +29 -0
  91. data/lib/stripe/resources/review.rb +21 -0
  92. data/lib/stripe/resources/setup_attempt.rb +10 -0
  93. data/lib/stripe/resources/setup_intent.rb +33 -0
  94. data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
  95. data/lib/stripe/resources/sku.rb +13 -0
  96. data/lib/stripe/resources/source.rb +47 -0
  97. data/lib/stripe/resources/source_transaction.rb +7 -0
  98. data/lib/stripe/resources/subscription.rb +26 -0
  99. data/lib/stripe/resources/subscription_item.rb +26 -0
  100. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  101. data/lib/stripe/resources/tax_id.rb +26 -0
  102. data/lib/stripe/resources/tax_rate.rb +12 -0
  103. data/lib/stripe/resources/terminal/connection_token.rb +12 -0
  104. data/lib/stripe/resources/terminal/location.rb +15 -0
  105. data/lib/stripe/resources/terminal/reader.rb +15 -0
  106. data/lib/stripe/resources/three_d_secure.rb +14 -0
  107. data/lib/stripe/resources/token.rb +10 -0
  108. data/lib/stripe/resources/topup.rb +23 -0
  109. data/lib/stripe/resources/transfer.rb +27 -0
  110. data/lib/stripe/resources/usage_record.rb +7 -0
  111. data/lib/stripe/resources/usage_record_summary.rb +7 -0
  112. data/lib/stripe/resources/webhook_endpoint.rb +13 -0
  113. data/lib/stripe/singleton_api_resource.rb +13 -7
  114. data/lib/stripe/stripe_client.rb +989 -0
  115. data/lib/stripe/stripe_configuration.rb +194 -0
  116. data/lib/stripe/stripe_object.rb +481 -148
  117. data/lib/stripe/stripe_response.rb +82 -0
  118. data/lib/stripe/util.rb +265 -70
  119. data/lib/stripe/version.rb +3 -1
  120. data/lib/stripe/webhook.rb +121 -0
  121. data/stripe.gemspec +35 -21
  122. metadata +118 -198
  123. data/.gitignore +0 -4
  124. data/.travis.yml +0 -22
  125. data/README.rdoc +0 -43
  126. data/gemfiles/default-with-activesupport.gemfile +0 -10
  127. data/gemfiles/json.gemfile +0 -12
  128. data/gemfiles/yajl.gemfile +0 -12
  129. data/lib/stripe/account.rb +0 -39
  130. data/lib/stripe/api_operations/update.rb +0 -19
  131. data/lib/stripe/application_fee.rb +0 -20
  132. data/lib/stripe/application_fee_refund.rb +0 -14
  133. data/lib/stripe/balance.rb +0 -4
  134. data/lib/stripe/balance_transaction.rb +0 -9
  135. data/lib/stripe/bank_account.rb +0 -19
  136. data/lib/stripe/bitcoin_receiver.rb +0 -20
  137. data/lib/stripe/bitcoin_transaction.rb +0 -9
  138. data/lib/stripe/card.rb +0 -21
  139. data/lib/stripe/charge.rb +0 -62
  140. data/lib/stripe/coupon.rb +0 -8
  141. data/lib/stripe/customer.rb +0 -75
  142. data/lib/stripe/dispute.rb +0 -16
  143. data/lib/stripe/errors/api_connection_error.rb +0 -4
  144. data/lib/stripe/errors/api_error.rb +0 -4
  145. data/lib/stripe/errors/authentication_error.rb +0 -4
  146. data/lib/stripe/errors/card_error.rb +0 -12
  147. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  148. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  149. data/lib/stripe/errors/stripe_error.rb +0 -26
  150. data/lib/stripe/event.rb +0 -5
  151. data/lib/stripe/file_upload.rb +0 -22
  152. data/lib/stripe/invoice.rb +0 -27
  153. data/lib/stripe/invoice_item.rb +0 -8
  154. data/lib/stripe/order.rb +0 -19
  155. data/lib/stripe/plan.rb +0 -8
  156. data/lib/stripe/product.rb +0 -16
  157. data/lib/stripe/recipient.rb +0 -12
  158. data/lib/stripe/refund.rb +0 -7
  159. data/lib/stripe/reversal.rb +0 -14
  160. data/lib/stripe/sku.rb +0 -8
  161. data/lib/stripe/subscription.rb +0 -25
  162. data/lib/stripe/token.rb +0 -5
  163. data/lib/stripe/transfer.rb +0 -17
  164. data/test/stripe/account_test.rb +0 -118
  165. data/test/stripe/api_resource_test.rb +0 -632
  166. data/test/stripe/application_fee_refund_test.rb +0 -47
  167. data/test/stripe/application_fee_test.rb +0 -22
  168. data/test/stripe/balance_test.rb +0 -11
  169. data/test/stripe/bitcoin_receiver_test.rb +0 -61
  170. data/test/stripe/bitcoin_transaction_test.rb +0 -29
  171. data/test/stripe/charge_refund_test.rb +0 -55
  172. data/test/stripe/charge_test.rb +0 -118
  173. data/test/stripe/coupon_test.rb +0 -20
  174. data/test/stripe/customer_card_test.rb +0 -63
  175. data/test/stripe/customer_test.rb +0 -88
  176. data/test/stripe/dispute_test.rb +0 -45
  177. data/test/stripe/file_upload_test.rb +0 -28
  178. data/test/stripe/invoice_test.rb +0 -40
  179. data/test/stripe/list_object_test.rb +0 -16
  180. data/test/stripe/metadata_test.rb +0 -129
  181. data/test/stripe/order_test.rb +0 -52
  182. data/test/stripe/product_test.rb +0 -41
  183. data/test/stripe/recipient_card_test.rb +0 -57
  184. data/test/stripe/refund_test.rb +0 -55
  185. data/test/stripe/reversal_test.rb +0 -47
  186. data/test/stripe/sku_test.rb +0 -24
  187. data/test/stripe/stripe_object_test.rb +0 -28
  188. data/test/stripe/subscription_test.rb +0 -72
  189. data/test/stripe/transfer_test.rb +0 -25
  190. data/test/stripe/util_test.rb +0 -34
  191. data/test/test_data.rb +0 -666
  192. data/test/test_helper.rb +0 -41
@@ -1,16 +0,0 @@
1
- module Stripe
2
- class Dispute < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- def close(params={}, opts={})
8
- response, opts = request(:post, close_url, params, opts)
9
- refresh_from(response, opts)
10
- end
11
-
12
- def close_url
13
- url + '/close'
14
- end
15
- end
16
- end
@@ -1,4 +0,0 @@
1
- module Stripe
2
- class APIConnectionError < StripeError
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Stripe
2
- class APIError < StripeError
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Stripe
2
- class AuthenticationError < StripeError
3
- end
4
- end
@@ -1,12 +0,0 @@
1
- module Stripe
2
- class CardError < StripeError
3
- attr_reader :param, :code
4
-
5
- def initialize(message, param, code, http_status=nil, http_body=nil, json_body=nil,
6
- http_headers=nil)
7
- super(message, http_status, http_body, json_body, http_headers)
8
- @param = param
9
- @code = code
10
- end
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- module Stripe
2
- class InvalidRequestError < StripeError
3
- attr_accessor :param
4
-
5
- def initialize(message, param, http_status=nil, http_body=nil, json_body=nil,
6
- http_headers=nil)
7
- super(message, http_status, http_body, json_body, http_headers)
8
- @param = param
9
- end
10
- end
11
- end
@@ -1,4 +0,0 @@
1
- module Stripe
2
- class RateLimitError < StripeError
3
- end
4
- end
@@ -1,26 +0,0 @@
1
- module Stripe
2
- class StripeError < StandardError
3
- attr_reader :message
4
- attr_reader :http_status
5
- attr_reader :http_body
6
- attr_reader :http_headers
7
- attr_reader :request_id
8
- attr_reader :json_body
9
-
10
- def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil,
11
- http_headers=nil)
12
- @message = message
13
- @http_status = http_status
14
- @http_body = http_body
15
- @http_headers = http_headers || {}
16
- @json_body = json_body
17
- @request_id = @http_headers[:request_id]
18
- end
19
-
20
- def to_s
21
- status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
22
- id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
23
- "#{status_string}#{id_string}#{@message}"
24
- end
25
- end
26
- end
data/lib/stripe/event.rb DELETED
@@ -1,5 +0,0 @@
1
- module Stripe
2
- class Event < APIResource
3
- include Stripe::APIOperations::List
4
- end
5
- end
@@ -1,22 +0,0 @@
1
- module Stripe
2
- class FileUpload < APIResource
3
- def self.url
4
- "/v1/files"
5
- end
6
-
7
- def self.create(params={}, opts={})
8
- opts = {
9
- :content_type => 'multipart/form-data',
10
- :api_base => Stripe::uploads_base
11
- }.merge(opts)
12
- response, opts = request(:post, url, params, opts)
13
- Util.convert_to_stripe_object(response, opts)
14
- end
15
-
16
- def self.all(filters={}, opts={})
17
- opts = {:api_base => Stripe::uploads_base}.merge(opts)
18
- response, opts = request(:get, url, filters, opts)
19
- Util.convert_to_stripe_object(response, opts)
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- module Stripe
2
- class Invoice < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Update
5
- include Stripe::APIOperations::Create
6
-
7
- def self.upcoming(params, opts={})
8
- response, opts = request(:get, upcoming_url, params, opts)
9
- Util.convert_to_stripe_object(response, opts)
10
- end
11
-
12
- def pay(opts={})
13
- response, opts = request(:post, pay_url, {}, opts)
14
- refresh_from(response, opts)
15
- end
16
-
17
- private
18
-
19
- def self.upcoming_url
20
- url + '/upcoming'
21
- end
22
-
23
- def pay_url
24
- url + '/pay'
25
- end
26
- end
27
- end
@@ -1,8 +0,0 @@
1
- module Stripe
2
- class InvoiceItem < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Delete
6
- include Stripe::APIOperations::Update
7
- end
8
- end
data/lib/stripe/order.rb DELETED
@@ -1,19 +0,0 @@
1
- module Stripe
2
- class Order < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- def pay(params, opts={})
8
- response, opts = request(:post, pay_url, params, opts)
9
- refresh_from(response, opts)
10
- end
11
-
12
- private
13
-
14
- def pay_url
15
- url + "/pay"
16
- end
17
-
18
- end
19
- end
data/lib/stripe/plan.rb DELETED
@@ -1,8 +0,0 @@
1
- module Stripe
2
- class Plan < APIResource
3
- include Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::List
6
- include Stripe::APIOperations::Update
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- module Stripe
2
- class Product < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- # Keep APIResource#url as `api_url` to avoid letting the external URL
8
- # replace the Stripe URL.
9
- alias_method :api_url, :url
10
-
11
- # Override Stripe::APIOperations::Update#save to explicitly pass URL.
12
- def save
13
- super(:req_url => api_url)
14
- end
15
- end
16
- end
@@ -1,12 +0,0 @@
1
- module Stripe
2
- class Recipient < APIResource
3
- include Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::Update
6
- include Stripe::APIOperations::List
7
-
8
- def transfers
9
- Transfer.all({ :recipient => id }, @api_key)
10
- end
11
- end
12
- end
data/lib/stripe/refund.rb DELETED
@@ -1,7 +0,0 @@
1
- module Stripe
2
- class Refund < APIResource
3
- include Stripe::APIOperations::Create
4
- include Stripe::APIOperations::List
5
- include Stripe::APIOperations::Update
6
- end
7
- end
@@ -1,14 +0,0 @@
1
- module Stripe
2
- class Reversal < APIResource
3
- include Stripe::APIOperations::Update
4
- include Stripe::APIOperations::List
5
-
6
- def url
7
- "#{Transfer.url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
8
- end
9
-
10
- def self.retrieve(id, opts={})
11
- raise NotImplementedError.new("Reversals cannot be retrieved without a transfer ID. Retrieve a reversal using transfer.reversals.retrieve('reversal_id')")
12
- end
13
- end
14
- end
data/lib/stripe/sku.rb DELETED
@@ -1,8 +0,0 @@
1
- module Stripe
2
- class SKU < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- end
8
- end
@@ -1,25 +0,0 @@
1
- module Stripe
2
- class Subscription < APIResource
3
- include Stripe::APIOperations::Update
4
- include Stripe::APIOperations::Delete
5
-
6
- def url
7
- "#{Customer.url}/#{CGI.escape(customer)}/subscriptions/#{CGI.escape(id)}"
8
- end
9
-
10
- def self.retrieve(id, opts=nil)
11
- raise NotImplementedError.new("Subscriptions cannot be retrieved without a customer ID. Retrieve a subscription using customer.subscriptions.retrieve('subscription_id')")
12
- end
13
-
14
- def delete_discount
15
- response, opts = request(:delete, discount_url)
16
- refresh_from({ :discount => nil }, opts, true)
17
- end
18
-
19
- private
20
-
21
- def discount_url
22
- url + '/discount'
23
- end
24
- end
25
- end
data/lib/stripe/token.rb DELETED
@@ -1,5 +0,0 @@
1
- module Stripe
2
- class Token < APIResource
3
- include Stripe::APIOperations::Create
4
- end
5
- end
@@ -1,17 +0,0 @@
1
- module Stripe
2
- class Transfer < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- def cancel
8
- response, api_key = Stripe.request(:post, cancel_url, @api_key)
9
- refresh_from(response, api_key)
10
- end
11
-
12
- def cancel_url
13
- url + '/cancel'
14
- end
15
-
16
- end
17
- end
@@ -1,118 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class AccountTest < Test::Unit::TestCase
5
- should "be retrievable" do
6
- resp = {:email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
7
- @mock.expects(:get).
8
- once.
9
- with('https://api.stripe.com/v1/account', nil, nil).
10
- returns(make_response(resp))
11
- a = Stripe::Account.retrieve
12
- assert_equal "test+bindings@stripe.com", a.email
13
- assert !a.charge_enabled
14
- assert !a.details_submitted
15
- end
16
-
17
- should "be retrievable via plural endpoint" do
18
- resp = {:email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
19
- @mock.expects(:get).
20
- once.
21
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
22
- returns(make_response(resp))
23
- a = Stripe::Account.retrieve('acct_foo')
24
- assert_equal "test+bindings@stripe.com", a.email
25
- assert !a.charge_enabled
26
- assert !a.details_submitted
27
- end
28
-
29
- should "be retrievable using an API key as the only argument" do
30
- account = mock
31
- Stripe::Account.expects(:new).once.with(nil, {:api_key => 'sk_foobar'}).returns(account)
32
- account.expects(:refresh).once
33
- Stripe::Account.retrieve('sk_foobar')
34
- end
35
-
36
- should "be updatable" do
37
- resp = {
38
- :id => 'acct_foo',
39
- :legal_entity => {
40
- :address => {
41
- :line1 => '1 Two Three'
42
- }
43
- }
44
- }
45
- @mock.expects(:get).
46
- once.
47
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
48
- returns(make_response(resp))
49
-
50
- @mock.expects(:post).
51
- once.
52
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[first_name]=Bob&legal_entity[address][line1]=2%20Three%20Four').
53
- returns(make_response(resp))
54
-
55
- a = Stripe::Account.retrieve('acct_foo')
56
- a.legal_entity.first_name = 'Bob'
57
- a.legal_entity.address.line1 = '2 Three Four'
58
- a.save
59
- end
60
-
61
- should "be able to deauthorize an account" do
62
- resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
63
- @mock.expects(:get).once.returns(make_response(resp))
64
- a = Stripe::Account.retrieve
65
-
66
-
67
- @mock.expects(:post).once.with do |url, api_key, params|
68
- url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]}
69
- end.returns(make_response({ 'stripe_user_id' => a.id }))
70
- a.deauthorize('ca_1234', 'sk_test_1234')
71
- end
72
-
73
- should "reject nil api keys" do
74
- assert_raise TypeError do
75
- Stripe::Account.retrieve(nil)
76
- end
77
- assert_raise TypeError do
78
- Stripe::Account.retrieve(:api_key => nil)
79
- end
80
- end
81
-
82
- should "be able to create a bank account" do
83
- resp = {
84
- :id => 'acct_1234',
85
- :external_accounts => {
86
- :object => "list",
87
- :url => "/v1/accounts/acct_1234/external_accounts",
88
- :data => [],
89
- }
90
- }
91
- @mock.expects(:get).once.returns(make_response(resp))
92
- a = Stripe::Account.retrieve
93
-
94
- @mock.expects(:post).
95
- once.
96
- with('https://api.stripe.com/v1/accounts/acct_1234/external_accounts', nil, 'external_account=btok_1234').
97
- returns(make_response(resp))
98
- a.external_accounts.create({:external_account => 'btok_1234'})
99
- end
100
-
101
- should "be able to retrieve a bank account" do
102
- resp = {
103
- :id => 'acct_1234',
104
- :external_accounts => {
105
- :object => "list",
106
- :url => "/v1/accounts/acct_1234/external_accounts",
107
- :data => [{
108
- :id => "ba_1234",
109
- :object => "bank_account",
110
- }],
111
- }
112
- }
113
- @mock.expects(:get).once.returns(make_response(resp))
114
- a = Stripe::Account.retrieve
115
- assert_equal(BankAccount, a.external_accounts.data[0].class)
116
- end
117
- end
118
- end
@@ -1,632 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../../test_helper', __FILE__)
3
-
4
- module Stripe
5
- class ApiResourceTest < Test::Unit::TestCase
6
- should "creating a new APIResource should not fetch over the network" do
7
- @mock.expects(:get).never
8
- Stripe::Customer.new("someid")
9
- end
10
-
11
- should "creating a new APIResource from a hash should not fetch over the network" do
12
- @mock.expects(:get).never
13
- Stripe::Customer.construct_from({
14
- :id => "somecustomer",
15
- :card => {:id => "somecard", :object => "card"},
16
- :object => "customer"
17
- })
18
- end
19
-
20
- should "setting an attribute should not cause a network request" do
21
- @mock.expects(:get).never
22
- @mock.expects(:post).never
23
- c = Stripe::Customer.new("test_customer");
24
- c.card = {:id => "somecard", :object => "card"}
25
- end
26
-
27
- should "accessing id should not issue a fetch" do
28
- @mock.expects(:get).never
29
- c = Stripe::Customer.new("test_customer")
30
- c.id
31
- end
32
-
33
- should "not specifying api credentials should raise an exception" do
34
- Stripe.api_key = nil
35
- assert_raises Stripe::AuthenticationError do
36
- Stripe::Customer.new("test_customer").refresh
37
- end
38
- end
39
-
40
- should "using a nil api key should raise an exception" do
41
- assert_raises TypeError do
42
- Stripe::Customer.all({}, nil)
43
- end
44
- assert_raises TypeError do
45
- Stripe::Customer.all({}, { :api_key => nil })
46
- end
47
- end
48
-
49
- should "specifying api credentials containing whitespace should raise an exception" do
50
- Stripe.api_key = "key "
51
- assert_raises Stripe::AuthenticationError do
52
- Stripe::Customer.new("test_customer").refresh
53
- end
54
- end
55
-
56
- should "specifying invalid api credentials should raise an exception" do
57
- Stripe.api_key = "invalid"
58
- response = make_response(make_invalid_api_key_error, 401)
59
- assert_raises Stripe::AuthenticationError do
60
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
61
- Stripe::Customer.retrieve("failing_customer")
62
- end
63
- end
64
-
65
- should "AuthenticationErrors should have an http status, http body, and JSON body" do
66
- Stripe.api_key = "invalid"
67
- response = make_response(make_invalid_api_key_error, 401)
68
- begin
69
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
70
- Stripe::Customer.retrieve("failing_customer")
71
- rescue Stripe::AuthenticationError => e
72
- assert_equal(401, e.http_status)
73
- assert_equal(true, !!e.http_body)
74
- assert_equal(true, !!e.json_body[:error][:message])
75
- assert_equal(make_invalid_api_key_error[:error][:message], e.json_body[:error][:message])
76
- end
77
- end
78
-
79
- should "send expand on fetch properly" do
80
- @mock.expects(:get).once.
81
- with("#{Stripe.api_base}/v1/charges/ch_test_charge?expand[]=customer", nil, nil).
82
- returns(make_response(make_charge))
83
-
84
- Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
85
- end
86
-
87
- should "preserve expand across refreshes" do
88
- @mock.expects(:get).twice.
89
- with("#{Stripe.api_base}/v1/charges/ch_test_charge?expand[]=customer", nil, nil).
90
- returns(make_response(make_charge))
91
-
92
- ch = Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
93
- ch.refresh
94
- end
95
-
96
- should "send expand when fetching through ListObject" do
97
- @mock.expects(:get).once.
98
- with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).
99
- returns(make_response(make_customer))
100
-
101
- @mock.expects(:get).once.
102
- with("#{Stripe.api_base}/v1/customers/c_test_customer/sources/cc_test_card?expand[]=customer", nil, nil).
103
- returns(make_response(make_card))
104
-
105
- customer = Stripe::Customer.retrieve('c_test_customer')
106
- customer.sources.retrieve({:id => 'cc_test_card', :expand => [:customer]})
107
- end
108
-
109
- should "send stripe account as header when set" do
110
- stripe_account = "acct_0000"
111
- Stripe.expects(:execute_request).with do |opts|
112
- opts[:headers][:stripe_account] == stripe_account
113
- end.returns(make_response(make_charge))
114
-
115
- Stripe::Charge.create({:card => {:number => '4242424242424242'}},
116
- {:stripe_account => stripe_account, :api_key => 'sk_test_local'})
117
- end
118
-
119
- should "not send stripe account as header when not set" do
120
- Stripe.expects(:execute_request).with do |opts|
121
- opts[:headers][:stripe_account].nil?
122
- end.returns(make_response(make_charge))
123
-
124
- Stripe::Charge.create({:card => {:number => '4242424242424242'}},
125
- 'sk_test_local')
126
- end
127
-
128
- should "handle error response with empty body" do
129
- response = make_response('', 500)
130
- @mock.expects(:post).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
131
-
132
- e = assert_raises Stripe::APIError do
133
- Stripe::Charge.create
134
- end
135
-
136
- assert_equal 'Invalid response object from API: "" (HTTP response code was 500)', e.message
137
- end
138
-
139
- should "handle error response with non-object error value" do
140
- response = make_response('{"error": "foo"}', 500)
141
- @mock.expects(:post).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
142
-
143
- e = assert_raises Stripe::APIError do
144
- Stripe::Charge.create
145
- end
146
-
147
- assert_equal 'Invalid response object from API: "{\"error\": \"foo\"}" (HTTP response code was 500)', e.message
148
- end
149
-
150
- should "have default open and read timeouts" do
151
- assert_equal Stripe.open_timeout, 30
152
- assert_equal Stripe.read_timeout, 80
153
- end
154
-
155
- should "allow configurable open and read timeouts" do
156
- original_timeouts = Stripe.open_timeout, Stripe.read_timeout
157
-
158
- begin
159
- Stripe.open_timeout = 999
160
- Stripe.read_timeout = 998
161
-
162
- Stripe.expects(:execute_request).with do |opts|
163
- opts[:open_timeout] == 999 && opts[:timeout] == 998
164
- end.returns(make_response(make_charge))
165
-
166
- Stripe::Charge.create({:card => {:number => '4242424242424242'}},
167
- 'sk_test_local')
168
- ensure
169
- Stripe.open_timeout, Stripe.read_timeout = original_timeouts
170
- end
171
- end
172
-
173
- context "when specifying per-object credentials" do
174
- context "with no global API key set" do
175
- should "use the per-object credential when creating" do
176
- Stripe.expects(:execute_request).with do |opts|
177
- opts[:headers][:authorization] == 'Bearer sk_test_local'
178
- end.returns(make_response(make_charge))
179
-
180
- Stripe::Charge.create({:card => {:number => '4242424242424242'}},
181
- 'sk_test_local')
182
- end
183
- end
184
-
185
- context "with a global API key set" do
186
- setup do
187
- Stripe.api_key = "global"
188
- end
189
-
190
- teardown do
191
- Stripe.api_key = nil
192
- end
193
-
194
- should "use the per-object credential when creating" do
195
- Stripe.expects(:execute_request).with do |opts|
196
- opts[:headers][:authorization] == 'Bearer local'
197
- end.returns(make_response(make_charge))
198
-
199
- Stripe::Charge.create({:card => {:number => '4242424242424242'}},
200
- 'local')
201
- end
202
-
203
- should "use the per-object credential when retrieving and making other calls" do
204
- Stripe.expects(:execute_request).with do |opts|
205
- opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge" &&
206
- opts[:headers][:authorization] == 'Bearer local'
207
- end.returns(make_response(make_charge))
208
- Stripe.expects(:execute_request).with do |opts|
209
- opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge/refund" &&
210
- opts[:headers][:authorization] == 'Bearer local'
211
- end.returns(make_response(make_charge))
212
-
213
- ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
214
- ch.refund
215
- end
216
- end
217
- end
218
-
219
- context "with valid credentials" do
220
- should "send along the idempotency-key header" do
221
- Stripe.expects(:execute_request).with do |opts|
222
- opts[:headers][:idempotency_key] == 'bar'
223
- end.returns(make_response(make_charge))
224
-
225
- Stripe::Charge.create({:card => {:number => '4242424242424242'}}, {
226
- :idempotency_key => 'bar',
227
- :api_key => 'local',
228
- })
229
- end
230
-
231
- should "urlencode values in GET params" do
232
- response = make_response(make_charge_array)
233
- @mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
234
- charges = Stripe::Charge.all(:customer => 'test customer').data
235
- assert charges.kind_of? Array
236
- end
237
-
238
- should "construct URL properly with base query parameters" do
239
- response = make_response(make_invoice_customer_array)
240
- @mock.expects(:get).with("#{Stripe.api_base}/v1/invoices?customer=test_customer", nil, nil).returns(response)
241
- invoices = Stripe::Invoice.all(:customer => 'test_customer')
242
-
243
- @mock.expects(:get).with("#{Stripe.api_base}/v1/invoices?customer=test_customer&paid=true", nil, nil).returns(response)
244
- invoices.all(:paid => true)
245
- end
246
-
247
- should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
248
- response = make_response(make_missing_id_error, 400)
249
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
250
- begin
251
- Stripe::Customer.retrieve("foo")
252
- rescue Stripe::InvalidRequestError => e
253
- assert_equal(400, e.http_status)
254
- assert_equal(true, !!e.http_body)
255
- assert_equal(true, e.json_body.kind_of?(Hash))
256
- end
257
- end
258
-
259
- should "a 401 should give an AuthenticationError with http status, body, and JSON body" do
260
- response = make_response(make_missing_id_error, 401)
261
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
262
- begin
263
- Stripe::Customer.retrieve("foo")
264
- rescue Stripe::AuthenticationError => e
265
- assert_equal(401, e.http_status)
266
- assert_equal(true, !!e.http_body)
267
- assert_equal(true, e.json_body.kind_of?(Hash))
268
- end
269
- end
270
-
271
- should "a 402 should give a CardError with http status, body, and JSON body" do
272
- response = make_response(make_missing_id_error, 402)
273
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
274
- begin
275
- Stripe::Customer.retrieve("foo")
276
- rescue Stripe::CardError => e
277
- assert_equal(402, e.http_status)
278
- assert_equal(true, !!e.http_body)
279
- assert_equal(true, e.json_body.kind_of?(Hash))
280
- end
281
- end
282
-
283
- should "a 404 should give an InvalidRequestError with http status, body, and JSON body" do
284
- response = make_response(make_missing_id_error, 404)
285
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
286
- begin
287
- Stripe::Customer.retrieve("foo")
288
- rescue Stripe::InvalidRequestError => e
289
- assert_equal(404, e.http_status)
290
- assert_equal(true, !!e.http_body)
291
- assert_equal(true, e.json_body.kind_of?(Hash))
292
- end
293
- end
294
-
295
- should "a 429 should give a RateLimitError with http status, body, and JSON body" do
296
- response = make_response(make_rate_limit_error, 429)
297
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 429))
298
- begin
299
- Stripe::Customer.retrieve("foo")
300
- rescue Stripe::RateLimitError => e
301
- assert_equal(429, e.http_status)
302
- assert_equal(true, !!e.http_body)
303
- assert_equal(true, e.json_body.kind_of?(Hash))
304
- end
305
- end
306
-
307
- should "setting a nil value for a param should exclude that param from the request" do
308
- @mock.expects(:get).with do |url, api_key, params|
309
- uri = URI(url)
310
- query = CGI.parse(uri.query)
311
- (url =~ %r{^#{Stripe.api_base}/v1/charges?} &&
312
- query.keys.sort == ['offset', 'sad'])
313
- end.returns(make_response({ :count => 1, :data => [make_charge] }))
314
- Stripe::Charge.all(:count => nil, :offset => 5, :sad => false)
315
-
316
- @mock.expects(:post).with do |url, api_key, params|
317
- url == "#{Stripe.api_base}/v1/charges" &&
318
- api_key.nil? &&
319
- CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
320
- end.returns(make_response({ :count => 1, :data => [make_charge] }))
321
- Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
322
- end
323
-
324
- should "requesting with a unicode ID should result in a request" do
325
- response = make_response(make_missing_id_error, 404)
326
- @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
327
- c = Stripe::Customer.new("☃")
328
- assert_raises(Stripe::InvalidRequestError) { c.refresh }
329
- end
330
-
331
- should "requesting with no ID should result in an InvalidRequestError with no request" do
332
- c = Stripe::Customer.new
333
- assert_raises(Stripe::InvalidRequestError) { c.refresh }
334
- end
335
-
336
- should "making a GET request with parameters should have a query string and no body" do
337
- params = { :limit => 1 }
338
- @mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).returns(make_response([make_charge]))
339
- Stripe::Charge.all(params)
340
- end
341
-
342
- should "making a POST request with parameters should have a body and no query string" do
343
- params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
344
- @mock.expects(:post).once.with do |url, get, post|
345
- get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']}
346
- end.returns(make_response(make_charge))
347
- Stripe::Charge.create(params)
348
- end
349
-
350
- should "loading an object should issue a GET request" do
351
- @mock.expects(:get).once.returns(make_response(make_customer))
352
- c = Stripe::Customer.new("test_customer")
353
- c.refresh
354
- end
355
-
356
- should "using array accessors should be the same as the method interface" do
357
- @mock.expects(:get).once.returns(make_response(make_customer))
358
- c = Stripe::Customer.new("test_customer")
359
- c.refresh
360
- assert_equal c.created, c[:created]
361
- assert_equal c.created, c['created']
362
- c['created'] = 12345
363
- assert_equal c.created, 12345
364
- end
365
-
366
- should "accessing a property other than id or parent on an unfetched object should fetch it" do
367
- @mock.expects(:get).once.returns(make_response(make_customer))
368
- c = Stripe::Customer.new("test_customer")
369
- c.charges
370
- end
371
-
372
- should "updating an object should issue a POST request with only the changed properties" do
373
- @mock.expects(:post).with do |url, api_key, params|
374
- url == "#{Stripe.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'description' => ['another_mn']}
375
- end.once.returns(make_response(make_customer))
376
- c = Stripe::Customer.construct_from(make_customer)
377
- c.description = "another_mn"
378
- c.save
379
- end
380
-
381
- should "updating should merge in returned properties" do
382
- @mock.expects(:post).once.returns(make_response(make_customer))
383
- c = Stripe::Customer.new("c_test_customer")
384
- c.description = "another_mn"
385
- c.save
386
- assert_equal false, c.livemode
387
- end
388
-
389
- should "deleting should send no props and result in an object that has no props other deleted" do
390
- @mock.expects(:get).never
391
- @mock.expects(:post).never
392
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(make_response({ "id" => "test_customer", "deleted" => true }))
393
- c = Stripe::Customer.construct_from(make_customer)
394
- c.delete
395
- assert_equal true, c.deleted
396
-
397
- assert_raises NoMethodError do
398
- c.livemode
399
- end
400
- end
401
-
402
- should "loading an object with properties that have specific types should instantiate those classes" do
403
- @mock.expects(:get).once.returns(make_response(make_charge))
404
- c = Stripe::Charge.retrieve("test_charge")
405
- assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
406
- end
407
-
408
- should "loading all of an APIResource should return an array of recursively instantiated objects" do
409
- @mock.expects(:get).once.returns(make_response(make_charge_array))
410
- c = Stripe::Charge.all.data
411
- assert c.kind_of? Array
412
- assert c[0].kind_of? Stripe::Charge
413
- assert c[0].card.kind_of?(Stripe::StripeObject) && c[0].card.object == 'card'
414
- end
415
-
416
- should "passing in a stripe_account header should pass it through on call" do
417
- Stripe.expects(:execute_request).with do |opts|
418
- opts[:method] == :get &&
419
- opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
420
- opts[:headers][:stripe_account] == 'acct_abc'
421
- end.once.returns(make_response(make_customer))
422
- c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
423
- end
424
-
425
- should "passing in a stripe_account header should pass it through on save" do
426
- Stripe.expects(:execute_request).with do |opts|
427
- opts[:method] == :get &&
428
- opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
429
- opts[:headers][:stripe_account] == 'acct_abc'
430
- end.once.returns(make_response(make_customer))
431
- c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
432
-
433
- Stripe.expects(:execute_request).with do |opts|
434
- opts[:method] == :post &&
435
- opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
436
- opts[:headers][:stripe_account] == 'acct_abc' &&
437
- opts[:payload] == 'description=FOO'
438
- end.once.returns(make_response(make_customer))
439
- c.description = 'FOO'
440
- c.save
441
- end
442
-
443
- context "error checking" do
444
-
445
- should "404s should raise an InvalidRequestError" do
446
- response = make_response(make_missing_id_error, 404)
447
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
448
-
449
- rescued = false
450
- begin
451
- Stripe::Customer.new("test_customer").refresh
452
- assert false #shouldn't get here either
453
- rescue Stripe::InvalidRequestError => e # we don't use assert_raises because we want to examine e
454
- rescued = true
455
- assert e.kind_of? Stripe::InvalidRequestError
456
- assert_equal "id", e.param
457
- assert_equal "Missing id", e.message
458
- end
459
-
460
- assert_equal true, rescued
461
- end
462
-
463
- should "5XXs should raise an APIError" do
464
- response = make_response(make_api_error, 500)
465
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
466
-
467
- rescued = false
468
- begin
469
- Stripe::Customer.new("test_customer").refresh
470
- assert false #shouldn't get here either
471
- rescue Stripe::APIError => e # we don't use assert_raises because we want to examine e
472
- rescued = true
473
- assert e.kind_of? Stripe::APIError
474
- end
475
-
476
- assert_equal true, rescued
477
- end
478
-
479
- should "402s should raise a CardError" do
480
- response = make_response(make_invalid_exp_year_error, 402)
481
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 402))
482
-
483
- rescued = false
484
- begin
485
- Stripe::Customer.new("test_customer").refresh
486
- assert false #shouldn't get here either
487
- rescue Stripe::CardError => e # we don't use assert_raises because we want to examine e
488
- rescued = true
489
- assert e.kind_of? Stripe::CardError
490
- assert_equal "invalid_expiry_year", e.code
491
- assert_equal "exp_year", e.param
492
- assert_equal "Your card's expiration year is invalid", e.message
493
- end
494
-
495
- assert_equal true, rescued
496
- end
497
- end
498
-
499
- should 'add key to nested objects' do
500
- acct = Stripe::Account.construct_from({
501
- :id => 'myid',
502
- :legal_entity => {
503
- :size => 'l',
504
- :score => 4,
505
- :height => 10
506
- }
507
- })
508
-
509
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[first_name]=Bob').returns(make_response({"id" => "myid"}))
510
-
511
- acct.legal_entity.first_name = 'Bob'
512
- acct.save
513
- end
514
-
515
- should 'save nothing if nothing changes' do
516
- acct = Stripe::Account.construct_from({
517
- :id => 'myid',
518
- :metadata => {
519
- :key => 'value'
520
- }
521
- })
522
-
523
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
524
-
525
- acct.save
526
- end
527
-
528
- should 'not save nested API resources' do
529
- ch = Stripe::Charge.construct_from({
530
- :id => 'charge_id',
531
- :customer => {
532
- :object => 'customer',
533
- :id => 'customer_id'
534
- }
535
- })
536
-
537
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/charges/charge_id", nil, '').returns(make_response({"id" => "charge_id"}))
538
-
539
- ch.customer.description = 'Bob'
540
- ch.save
541
- end
542
-
543
- should 'correctly handle replaced nested objects' do
544
- acct = Stripe::Account.construct_from({
545
- :id => 'myid',
546
- :legal_entity => {
547
- :last_name => 'Smith',
548
- }
549
- })
550
-
551
- @mock.expects(:post).once.with(
552
- "#{Stripe.api_base}/v1/accounts/myid",
553
- nil,
554
- any_of(
555
- 'legal_entity[first_name]=Bob&legal_entity[last_name]=',
556
- 'legal_entity[last_name]=&legal_entity[first_name]=Bob'
557
- )
558
- ).returns(make_response({"id" => "myid"}))
559
-
560
- acct.legal_entity = {:first_name => 'Bob'}
561
- acct.save
562
- end
563
-
564
- should 'correctly handle array setting' do
565
- acct = Stripe::Account.construct_from({
566
- :id => 'myid',
567
- :legal_entity => {}
568
- })
569
-
570
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(make_response({"id" => "myid"}))
571
-
572
- acct.legal_entity.additional_owners = [{:first_name => 'Bob'}]
573
- acct.save
574
- end
575
-
576
- should 'correctly handle array insertion' do
577
- acct = Stripe::Account.construct_from({
578
- :id => 'myid',
579
- :legal_entity => {
580
- :additional_owners => []
581
- }
582
- })
583
-
584
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(make_response({"id" => "myid"}))
585
-
586
- acct.legal_entity.additional_owners << {:first_name => 'Bob'}
587
- acct.save
588
- end
589
-
590
- should 'correctly handle array updates' do
591
- acct = Stripe::Account.construct_from({
592
- :id => 'myid',
593
- :legal_entity => {
594
- :additional_owners => [{:first_name => 'Bob'}, {:first_name => 'Jane'}]
595
- }
596
- })
597
-
598
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][1][first_name]=Janet').returns(make_response({"id" => "myid"}))
599
-
600
- acct.legal_entity.additional_owners[1].first_name = 'Janet'
601
- acct.save
602
- end
603
-
604
- should 'correctly handle array noops' do
605
- acct = Stripe::Account.construct_from({
606
- :id => 'myid',
607
- :legal_entity => {
608
- :additional_owners => [{:first_name => 'Bob'}]
609
- },
610
- :currencies_supported => ['usd', 'cad']
611
- })
612
-
613
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
614
-
615
- acct.save
616
- end
617
-
618
- should 'correctly handle hash noops' do
619
- acct = Stripe::Account.construct_from({
620
- :id => 'myid',
621
- :legal_entity => {
622
- :address => {:line1 => '1 Two Three'}
623
- }
624
- })
625
-
626
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
627
-
628
- acct.save
629
- end
630
- end
631
- end
632
- end