stripe 1.22.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bf9ef8e5a7343b1993b9b828ff317326bf78591
4
+ data.tar.gz: fdae2b4926156adfa71f047dd830f1ff1032c3a8
5
+ SHA512:
6
+ metadata.gz: 5628f1bdbf7b87c0ed664944d60373923741d286bf26e037224a99039930a542beddd15f86304b081cdfd80619926719bee81302ba8a5b2e4823df763b9024fb
7
+ data.tar.gz: 20de174deab2c119dd0521cf700354a7d90cdbd948ef2980ef65d50678edccb54b5f9ff7eb62359d857b770671c3f28059aab40eed62ee2e8d1671ff8457e5d0
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.23.0 2015-07-06
2
+
3
+ * Added request IDs and HTTP headers to errors.
4
+
1
5
  === 1.22.0 2015-06-10
2
6
 
3
7
  * Added support for bank accounts and debit cards in managed accounts (via the `external_accounts` param)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.22.0
1
+ 1.23.0
data/lib/stripe.rb CHANGED
@@ -139,8 +139,8 @@ module Stripe
139
139
  raise
140
140
  end
141
141
  rescue RestClient::ExceptionWithResponse => e
142
- if rcode = e.http_code and rbody = e.http_body
143
- handle_api_error(rcode, rbody)
142
+ if e.response
143
+ handle_api_error(e.response)
144
144
  else
145
145
  handle_restclient_error(e, api_base_url)
146
146
  end
@@ -241,45 +241,46 @@ module Stripe
241
241
  "(HTTP response code was #{rcode})", rcode, rbody)
242
242
  end
243
243
 
244
- def self.handle_api_error(rcode, rbody)
244
+ def self.handle_api_error(resp)
245
245
  begin
246
- error_obj = JSON.parse(rbody)
246
+ error_obj = JSON.parse(resp.body)
247
247
  error_obj = Util.symbolize_names(error_obj)
248
248
  error = error_obj[:error] or raise StripeError.new # escape from parsing
249
249
 
250
250
  rescue JSON::ParserError, StripeError
251
- raise general_api_error(rcode, rbody)
251
+ raise general_api_error(resp.code, resp.body)
252
252
  end
253
253
 
254
- case rcode
254
+ case resp.code
255
255
  when 400, 404
256
- raise invalid_request_error error, rcode, rbody, error_obj
256
+ raise invalid_request_error(error, resp, error_obj)
257
257
  when 401
258
- raise authentication_error error, rcode, rbody, error_obj
258
+ raise authentication_error(error, resp, error_obj)
259
259
  when 402
260
- raise card_error error, rcode, rbody, error_obj
260
+ raise card_error(error, resp, error_obj)
261
261
  else
262
- raise api_error error, rcode, rbody, error_obj
262
+ raise api_error(error, resp, error_obj)
263
263
  end
264
264
 
265
265
  end
266
266
 
267
- def self.invalid_request_error(error, rcode, rbody, error_obj)
268
- InvalidRequestError.new(error[:message], error[:param], rcode,
269
- rbody, error_obj)
267
+ def self.invalid_request_error(error, resp, error_obj)
268
+ InvalidRequestError.new(error[:message], error[:param], resp.code,
269
+ resp.body, error_obj, resp.headers)
270
270
  end
271
271
 
272
- def self.authentication_error(error, rcode, rbody, error_obj)
273
- AuthenticationError.new(error[:message], rcode, rbody, error_obj)
272
+ def self.authentication_error(error, resp, error_obj)
273
+ AuthenticationError.new(error[:message], resp.code, resp.body, error_obj,
274
+ resp.headers)
274
275
  end
275
276
 
276
- def self.card_error(error, rcode, rbody, error_obj)
277
+ def self.card_error(error, resp, error_obj)
277
278
  CardError.new(error[:message], error[:param], error[:code],
278
- rcode, rbody, error_obj)
279
+ resp.code, resp.body, error_obj, resp.headers)
279
280
  end
280
281
 
281
- def self.api_error(error, rcode, rbody, error_obj)
282
- APIError.new(error[:message], rcode, rbody, error_obj)
282
+ def self.api_error(error, resp, error_obj)
283
+ APIError.new(error[:message], resp.code, resp.body, error_obj, resp.headers)
283
284
  end
284
285
 
285
286
  def self.handle_restclient_error(e, api_base_url=nil)
@@ -2,8 +2,9 @@ module Stripe
2
2
  class CardError < StripeError
3
3
  attr_reader :param, :code
4
4
 
5
- def initialize(message, param, code, http_status=nil, http_body=nil, json_body=nil)
6
- super(message, http_status, http_body, json_body)
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)
7
8
  @param = param
8
9
  @code = code
9
10
  end
@@ -2,8 +2,9 @@ module Stripe
2
2
  class InvalidRequestError < StripeError
3
3
  attr_accessor :param
4
4
 
5
- def initialize(message, param, http_status=nil, http_body=nil, json_body=nil)
6
- super(message, http_status, http_body, json_body)
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)
7
8
  @param = param
8
9
  end
9
10
  end
@@ -3,18 +3,24 @@ module Stripe
3
3
  attr_reader :message
4
4
  attr_reader :http_status
5
5
  attr_reader :http_body
6
+ attr_reader :http_headers
7
+ attr_reader :request_id
6
8
  attr_reader :json_body
7
9
 
8
- def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
10
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil,
11
+ http_headers=nil)
9
12
  @message = message
10
13
  @http_status = http_status
11
14
  @http_body = http_body
15
+ @http_headers = http_headers || {}
12
16
  @json_body = json_body
17
+ @request_id = @http_headers[:request_id]
13
18
  end
14
19
 
15
20
  def to_s
16
21
  status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
17
- "#{status_string}#{@message}"
22
+ id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
23
+ "#{status_string}#{id_string}#{@message}"
18
24
  end
19
25
  end
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.22.0'
2
+ VERSION = '1.23.0'
3
3
  end
@@ -7,7 +7,7 @@ module Stripe
7
7
  @mock.expects(:get).
8
8
  once.
9
9
  with('https://api.stripe.com/v1/account', nil, nil).
10
- returns(test_response(resp))
10
+ returns(make_response(resp))
11
11
  a = Stripe::Account.retrieve
12
12
  assert_equal "test+bindings@stripe.com", a.email
13
13
  assert !a.charge_enabled
@@ -19,7 +19,7 @@ module Stripe
19
19
  @mock.expects(:get).
20
20
  once.
21
21
  with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
22
- returns(test_response(resp))
22
+ returns(make_response(resp))
23
23
  a = Stripe::Account.retrieve('acct_foo')
24
24
  assert_equal "test+bindings@stripe.com", a.email
25
25
  assert !a.charge_enabled
@@ -45,12 +45,12 @@ module Stripe
45
45
  @mock.expects(:get).
46
46
  once.
47
47
  with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
48
- returns(test_response(resp))
48
+ returns(make_response(resp))
49
49
 
50
50
  @mock.expects(:post).
51
51
  once.
52
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(test_response(resp))
53
+ returns(make_response(resp))
54
54
 
55
55
  a = Stripe::Account.retrieve('acct_foo')
56
56
  a.legal_entity.first_name = 'Bob'
@@ -60,13 +60,13 @@ module Stripe
60
60
 
61
61
  should "be able to deauthorize an account" do
62
62
  resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
63
- @mock.expects(:get).once.returns(test_response(resp))
63
+ @mock.expects(:get).once.returns(make_response(resp))
64
64
  a = Stripe::Account.retrieve
65
65
 
66
66
 
67
67
  @mock.expects(:post).once.with do |url, api_key, params|
68
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(test_response({ 'stripe_user_id' => a.id }))
69
+ end.returns(make_response({ 'stripe_user_id' => a.id }))
70
70
  a.deauthorize('ca_1234', 'sk_test_1234')
71
71
  end
72
72
 
@@ -88,13 +88,13 @@ module Stripe
88
88
  :data => [],
89
89
  }
90
90
  }
91
- @mock.expects(:get).once.returns(test_response(resp))
91
+ @mock.expects(:get).once.returns(make_response(resp))
92
92
  a = Stripe::Account.retrieve
93
93
 
94
94
  @mock.expects(:post).
95
95
  once.
96
96
  with('https://api.stripe.com/v1/accounts/acct_1234/external_accounts', nil, 'external_account=btok_1234').
97
- returns(test_response(resp))
97
+ returns(make_response(resp))
98
98
  a.external_accounts.create({:external_account => 'btok_1234'})
99
99
  end
100
100
 
@@ -110,7 +110,7 @@ module Stripe
110
110
  }],
111
111
  }
112
112
  }
113
- @mock.expects(:get).once.returns(test_response(resp))
113
+ @mock.expects(:get).once.returns(make_response(resp))
114
114
  a = Stripe::Account.retrieve
115
115
  assert_equal(BankAccount, a.external_accounts.data[0].class)
116
116
  end
@@ -55,7 +55,7 @@ module Stripe
55
55
 
56
56
  should "specifying invalid api credentials should raise an exception" do
57
57
  Stripe.api_key = "invalid"
58
- response = test_response(test_invalid_api_key_error, 401)
58
+ response = make_response(make_invalid_api_key_error, 401)
59
59
  assert_raises Stripe::AuthenticationError do
60
60
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
61
61
  Stripe::Customer.retrieve("failing_customer")
@@ -64,7 +64,7 @@ module Stripe
64
64
 
65
65
  should "AuthenticationErrors should have an http status, http body, and JSON body" do
66
66
  Stripe.api_key = "invalid"
67
- response = test_response(test_invalid_api_key_error, 401)
67
+ response = make_response(make_invalid_api_key_error, 401)
68
68
  begin
69
69
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
70
70
  Stripe::Customer.retrieve("failing_customer")
@@ -72,14 +72,14 @@ module Stripe
72
72
  assert_equal(401, e.http_status)
73
73
  assert_equal(true, !!e.http_body)
74
74
  assert_equal(true, !!e.json_body[:error][:message])
75
- assert_equal(test_invalid_api_key_error[:error][:message], e.json_body[:error][:message])
75
+ assert_equal(make_invalid_api_key_error[:error][:message], e.json_body[:error][:message])
76
76
  end
77
77
  end
78
78
 
79
79
  should "send expand on fetch properly" do
80
80
  @mock.expects(:get).once.
81
81
  with("#{Stripe.api_base}/v1/charges/ch_test_charge?expand[]=customer", nil, nil).
82
- returns(test_response(test_charge))
82
+ returns(make_response(make_charge))
83
83
 
84
84
  Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
85
85
  end
@@ -87,7 +87,7 @@ module Stripe
87
87
  should "preserve expand across refreshes" do
88
88
  @mock.expects(:get).twice.
89
89
  with("#{Stripe.api_base}/v1/charges/ch_test_charge?expand[]=customer", nil, nil).
90
- returns(test_response(test_charge))
90
+ returns(make_response(make_charge))
91
91
 
92
92
  ch = Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
93
93
  ch.refresh
@@ -97,7 +97,7 @@ module Stripe
97
97
  stripe_account = "acct_0000"
98
98
  Stripe.expects(:execute_request).with do |opts|
99
99
  opts[:headers][:stripe_account] == stripe_account
100
- end.returns(test_response(test_charge))
100
+ end.returns(make_response(make_charge))
101
101
 
102
102
  Stripe::Charge.create({:card => {:number => '4242424242424242'}},
103
103
  {:stripe_account => stripe_account, :api_key => 'sk_test_local'})
@@ -106,7 +106,7 @@ module Stripe
106
106
  should "not send stripe account as header when not set" do
107
107
  Stripe.expects(:execute_request).with do |opts|
108
108
  opts[:headers][:stripe_account].nil?
109
- end.returns(test_response(test_charge))
109
+ end.returns(make_response(make_charge))
110
110
 
111
111
  Stripe::Charge.create({:card => {:number => '4242424242424242'}},
112
112
  'sk_test_local')
@@ -117,7 +117,7 @@ module Stripe
117
117
  should "use the per-object credential when creating" do
118
118
  Stripe.expects(:execute_request).with do |opts|
119
119
  opts[:headers][:authorization] == 'Bearer sk_test_local'
120
- end.returns(test_response(test_charge))
120
+ end.returns(make_response(make_charge))
121
121
 
122
122
  Stripe::Charge.create({:card => {:number => '4242424242424242'}},
123
123
  'sk_test_local')
@@ -136,7 +136,7 @@ module Stripe
136
136
  should "use the per-object credential when creating" do
137
137
  Stripe.expects(:execute_request).with do |opts|
138
138
  opts[:headers][:authorization] == 'Bearer local'
139
- end.returns(test_response(test_charge))
139
+ end.returns(make_response(make_charge))
140
140
 
141
141
  Stripe::Charge.create({:card => {:number => '4242424242424242'}},
142
142
  'local')
@@ -146,11 +146,11 @@ module Stripe
146
146
  Stripe.expects(:execute_request).with do |opts|
147
147
  opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge" &&
148
148
  opts[:headers][:authorization] == 'Bearer local'
149
- end.returns(test_response(test_charge))
149
+ end.returns(make_response(make_charge))
150
150
  Stripe.expects(:execute_request).with do |opts|
151
151
  opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge/refund" &&
152
152
  opts[:headers][:authorization] == 'Bearer local'
153
- end.returns(test_response(test_charge))
153
+ end.returns(make_response(make_charge))
154
154
 
155
155
  ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
156
156
  ch.refund
@@ -162,7 +162,7 @@ module Stripe
162
162
  should "send along the idempotency-key header" do
163
163
  Stripe.expects(:execute_request).with do |opts|
164
164
  opts[:headers][:idempotency_key] == 'bar'
165
- end.returns(test_response(test_charge))
165
+ end.returns(make_response(make_charge))
166
166
 
167
167
  Stripe::Charge.create({:card => {:number => '4242424242424242'}}, {
168
168
  :idempotency_key => 'bar',
@@ -171,14 +171,14 @@ module Stripe
171
171
  end
172
172
 
173
173
  should "urlencode values in GET params" do
174
- response = test_response(test_charge_array)
174
+ response = make_response(make_charge_array)
175
175
  @mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
176
176
  charges = Stripe::Charge.all(:customer => 'test customer').data
177
177
  assert charges.kind_of? Array
178
178
  end
179
179
 
180
180
  should "construct URL properly with base query parameters" do
181
- response = test_response(test_invoice_customer_array)
181
+ response = make_response(make_invoice_customer_array)
182
182
  @mock.expects(:get).with("#{Stripe.api_base}/v1/invoices?customer=test_customer", nil, nil).returns(response)
183
183
  invoices = Stripe::Invoice.all(:customer => 'test_customer')
184
184
 
@@ -187,7 +187,7 @@ module Stripe
187
187
  end
188
188
 
189
189
  should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
190
- response = test_response(test_missing_id_error, 400)
190
+ response = make_response(make_missing_id_error, 400)
191
191
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
192
192
  begin
193
193
  Stripe::Customer.retrieve("foo")
@@ -199,7 +199,7 @@ module Stripe
199
199
  end
200
200
 
201
201
  should "a 401 should give an AuthenticationError with http status, body, and JSON body" do
202
- response = test_response(test_missing_id_error, 401)
202
+ response = make_response(make_missing_id_error, 401)
203
203
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
204
204
  begin
205
205
  Stripe::Customer.retrieve("foo")
@@ -211,7 +211,7 @@ module Stripe
211
211
  end
212
212
 
213
213
  should "a 402 should give a CardError with http status, body, and JSON body" do
214
- response = test_response(test_missing_id_error, 402)
214
+ response = make_response(make_missing_id_error, 402)
215
215
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
216
216
  begin
217
217
  Stripe::Customer.retrieve("foo")
@@ -223,7 +223,7 @@ module Stripe
223
223
  end
224
224
 
225
225
  should "a 404 should give an InvalidRequestError with http status, body, and JSON body" do
226
- response = test_response(test_missing_id_error, 404)
226
+ response = make_response(make_missing_id_error, 404)
227
227
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
228
228
  begin
229
229
  Stripe::Customer.retrieve("foo")
@@ -240,19 +240,19 @@ module Stripe
240
240
  query = CGI.parse(uri.query)
241
241
  (url =~ %r{^#{Stripe.api_base}/v1/charges?} &&
242
242
  query.keys.sort == ['offset', 'sad'])
243
- end.returns(test_response({ :count => 1, :data => [test_charge] }))
243
+ end.returns(make_response({ :count => 1, :data => [make_charge] }))
244
244
  Stripe::Charge.all(:count => nil, :offset => 5, :sad => false)
245
245
 
246
246
  @mock.expects(:post).with do |url, api_key, params|
247
247
  url == "#{Stripe.api_base}/v1/charges" &&
248
248
  api_key.nil? &&
249
249
  CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
250
- end.returns(test_response({ :count => 1, :data => [test_charge] }))
250
+ end.returns(make_response({ :count => 1, :data => [make_charge] }))
251
251
  Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
252
252
  end
253
253
 
254
254
  should "requesting with a unicode ID should result in a request" do
255
- response = test_response(test_missing_id_error, 404)
255
+ response = make_response(make_missing_id_error, 404)
256
256
  @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
257
257
  c = Stripe::Customer.new("☃")
258
258
  assert_raises(Stripe::InvalidRequestError) { c.refresh }
@@ -265,7 +265,7 @@ module Stripe
265
265
 
266
266
  should "making a GET request with parameters should have a query string and no body" do
267
267
  params = { :limit => 1 }
268
- @mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).returns(test_response([test_charge]))
268
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).returns(make_response([make_charge]))
269
269
  Stripe::Charge.all(params)
270
270
  end
271
271
 
@@ -273,18 +273,18 @@ module Stripe
273
273
  params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
274
274
  @mock.expects(:post).once.with do |url, get, post|
275
275
  get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']}
276
- end.returns(test_response(test_charge))
276
+ end.returns(make_response(make_charge))
277
277
  Stripe::Charge.create(params)
278
278
  end
279
279
 
280
280
  should "loading an object should issue a GET request" do
281
- @mock.expects(:get).once.returns(test_response(test_customer))
281
+ @mock.expects(:get).once.returns(make_response(make_customer))
282
282
  c = Stripe::Customer.new("test_customer")
283
283
  c.refresh
284
284
  end
285
285
 
286
286
  should "using array accessors should be the same as the method interface" do
287
- @mock.expects(:get).once.returns(test_response(test_customer))
287
+ @mock.expects(:get).once.returns(make_response(make_customer))
288
288
  c = Stripe::Customer.new("test_customer")
289
289
  c.refresh
290
290
  assert_equal c.created, c[:created]
@@ -294,7 +294,7 @@ module Stripe
294
294
  end
295
295
 
296
296
  should "accessing a property other than id or parent on an unfetched object should fetch it" do
297
- @mock.expects(:get).once.returns(test_response(test_customer))
297
+ @mock.expects(:get).once.returns(make_response(make_customer))
298
298
  c = Stripe::Customer.new("test_customer")
299
299
  c.charges
300
300
  end
@@ -302,14 +302,14 @@ module Stripe
302
302
  should "updating an object should issue a POST request with only the changed properties" do
303
303
  @mock.expects(:post).with do |url, api_key, params|
304
304
  url == "#{Stripe.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'description' => ['another_mn']}
305
- end.once.returns(test_response(test_customer))
306
- c = Stripe::Customer.construct_from(test_customer)
305
+ end.once.returns(make_response(make_customer))
306
+ c = Stripe::Customer.construct_from(make_customer)
307
307
  c.description = "another_mn"
308
308
  c.save
309
309
  end
310
310
 
311
311
  should "updating should merge in returned properties" do
312
- @mock.expects(:post).once.returns(test_response(test_customer))
312
+ @mock.expects(:post).once.returns(make_response(make_customer))
313
313
  c = Stripe::Customer.new("c_test_customer")
314
314
  c.description = "another_mn"
315
315
  c.save
@@ -319,8 +319,8 @@ module Stripe
319
319
  should "deleting should send no props and result in an object that has no props other deleted" do
320
320
  @mock.expects(:get).never
321
321
  @mock.expects(:post).never
322
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
323
- c = Stripe::Customer.construct_from(test_customer)
322
+ @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(make_response({ "id" => "test_customer", "deleted" => true }))
323
+ c = Stripe::Customer.construct_from(make_customer)
324
324
  c.delete
325
325
  assert_equal true, c.deleted
326
326
 
@@ -330,13 +330,13 @@ module Stripe
330
330
  end
331
331
 
332
332
  should "loading an object with properties that have specific types should instantiate those classes" do
333
- @mock.expects(:get).once.returns(test_response(test_charge))
333
+ @mock.expects(:get).once.returns(make_response(make_charge))
334
334
  c = Stripe::Charge.retrieve("test_charge")
335
335
  assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
336
336
  end
337
337
 
338
338
  should "loading all of an APIResource should return an array of recursively instantiated objects" do
339
- @mock.expects(:get).once.returns(test_response(test_charge_array))
339
+ @mock.expects(:get).once.returns(make_response(make_charge_array))
340
340
  c = Stripe::Charge.all.data
341
341
  assert c.kind_of? Array
342
342
  assert c[0].kind_of? Stripe::Charge
@@ -348,7 +348,7 @@ module Stripe
348
348
  opts[:method] == :get &&
349
349
  opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
350
350
  opts[:headers][:stripe_account] == 'acct_abc'
351
- end.once.returns(test_response(test_customer))
351
+ end.once.returns(make_response(make_customer))
352
352
  c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
353
353
  end
354
354
 
@@ -357,7 +357,7 @@ module Stripe
357
357
  opts[:method] == :get &&
358
358
  opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
359
359
  opts[:headers][:stripe_account] == 'acct_abc'
360
- end.once.returns(test_response(test_customer))
360
+ end.once.returns(make_response(make_customer))
361
361
  c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
362
362
 
363
363
  Stripe.expects(:execute_request).with do |opts|
@@ -365,7 +365,7 @@ module Stripe
365
365
  opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
366
366
  opts[:headers][:stripe_account] == 'acct_abc' &&
367
367
  opts[:payload] == 'description=FOO'
368
- end.once.returns(test_response(test_customer))
368
+ end.once.returns(make_response(make_customer))
369
369
  c.description = 'FOO'
370
370
  c.save
371
371
  end
@@ -373,7 +373,7 @@ module Stripe
373
373
  context "error checking" do
374
374
 
375
375
  should "404s should raise an InvalidRequestError" do
376
- response = test_response(test_missing_id_error, 404)
376
+ response = make_response(make_missing_id_error, 404)
377
377
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
378
378
 
379
379
  rescued = false
@@ -391,7 +391,7 @@ module Stripe
391
391
  end
392
392
 
393
393
  should "5XXs should raise an APIError" do
394
- response = test_response(test_api_error, 500)
394
+ response = make_response(make_api_error, 500)
395
395
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
396
396
 
397
397
  rescued = false
@@ -407,7 +407,7 @@ module Stripe
407
407
  end
408
408
 
409
409
  should "402s should raise a CardError" do
410
- response = test_response(test_invalid_exp_year_error, 402)
410
+ response = make_response(make_invalid_exp_year_error, 402)
411
411
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 402))
412
412
 
413
413
  rescued = false
@@ -436,7 +436,7 @@ module Stripe
436
436
  }
437
437
  })
438
438
 
439
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[first_name]=Bob').returns(test_response({"id" => "myid"}))
439
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[first_name]=Bob').returns(make_response({"id" => "myid"}))
440
440
 
441
441
  acct.legal_entity.first_name = 'Bob'
442
442
  acct.save
@@ -450,7 +450,7 @@ module Stripe
450
450
  }
451
451
  })
452
452
 
453
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
453
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
454
454
 
455
455
  acct.save
456
456
  end
@@ -464,7 +464,7 @@ module Stripe
464
464
  }
465
465
  })
466
466
 
467
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/charges/charge_id", nil, '').returns(test_response({"id" => "charge_id"}))
467
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/charges/charge_id", nil, '').returns(make_response({"id" => "charge_id"}))
468
468
 
469
469
  ch.customer.description = 'Bob'
470
470
  ch.save
@@ -485,7 +485,7 @@ module Stripe
485
485
  'legal_entity[first_name]=Bob&legal_entity[last_name]=',
486
486
  'legal_entity[last_name]=&legal_entity[first_name]=Bob'
487
487
  )
488
- ).returns(test_response({"id" => "myid"}))
488
+ ).returns(make_response({"id" => "myid"}))
489
489
 
490
490
  acct.legal_entity = {:first_name => 'Bob'}
491
491
  acct.save
@@ -497,7 +497,7 @@ module Stripe
497
497
  :legal_entity => {}
498
498
  })
499
499
 
500
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(test_response({"id" => "myid"}))
500
+ @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"}))
501
501
 
502
502
  acct.legal_entity.additional_owners = [{:first_name => 'Bob'}]
503
503
  acct.save
@@ -511,7 +511,7 @@ module Stripe
511
511
  }
512
512
  })
513
513
 
514
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(test_response({"id" => "myid"}))
514
+ @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"}))
515
515
 
516
516
  acct.legal_entity.additional_owners << {:first_name => 'Bob'}
517
517
  acct.save
@@ -525,7 +525,7 @@ module Stripe
525
525
  }
526
526
  })
527
527
 
528
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][1][first_name]=Janet').returns(test_response({"id" => "myid"}))
528
+ @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"}))
529
529
 
530
530
  acct.legal_entity.additional_owners[1].first_name = 'Janet'
531
531
  acct.save
@@ -540,7 +540,7 @@ module Stripe
540
540
  :currencies_supported => ['usd', 'cad']
541
541
  })
542
542
 
543
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
543
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
544
544
 
545
545
  acct.save
546
546
  end
@@ -553,7 +553,7 @@ module Stripe
553
553
  }
554
554
  })
555
555
 
556
- @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
556
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(make_response({"id" => "myid"}))
557
557
 
558
558
  acct.save
559
559
  end