stripe 1.57.1 → 1.58.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc1cb05bfb9a08a00e144b883b27f19adecd393a
4
- data.tar.gz: ba84a7e8456dc66a137cb149a8dc8ca36962e2d3
3
+ metadata.gz: 62e0a925e86bf0a18b48c88a9a359241075cd94a
4
+ data.tar.gz: 8de490482c9fd1a2e7e8d5bd28ac8eb34a0276c6
5
5
  SHA512:
6
- metadata.gz: f023b3c00e55b05fc9a7eb84dc2d876c9b518a51ce445f0c78f03e82158a544c2f2a7d825953bd80228f527fd7cd6db14a88f87913d4a6309ff26b423b57ebcb
7
- data.tar.gz: 125b78e32aebaaaee71f8d22afd33a10f90d899f8a4ff1bf9352ed2fd8dd35549186b2ef96c943670cd17dcbaa95c1d0f7ce3c6808fa0a690529ba42b716f037
6
+ metadata.gz: bf4525ce47f09b015d0a450667df948a15794538b13c076aefa0ba147d7d6829e344abd7c61285f38c2fcbad7a859f708942a661fe6521b4f76357383627ca6d
7
+ data.tar.gz: b86195048056fb06aade87235e6bf46c7d642101bf55b7bfd1f3375bf9f741ff522c22f1b74cee3fa4c7d8228a47f1fd53bf548e89b243e8af5826f5ebef3393
@@ -1,3 +1,7 @@
1
+ === 1.58.0 2017-01-19
2
+
3
+ * Remove erroneously added list methods for `Source` model
4
+
1
5
  === 1.57.1 2016-11-28
2
6
 
3
7
  * Disallow sending protected fields along with API resource `.update`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.57.1
1
+ 1.58.0
@@ -19,56 +19,49 @@ require 'stripe/api_operations/delete'
19
19
  require 'stripe/api_operations/list'
20
20
  require 'stripe/api_operations/request'
21
21
 
22
- # Resources
22
+ # API resource support classes
23
+ require 'stripe/errors'
23
24
  require 'stripe/util'
24
25
  require 'stripe/stripe_object'
26
+ require 'stripe/list_object'
25
27
  require 'stripe/api_resource'
26
28
  require 'stripe/singleton_api_resource'
27
- require 'stripe/list_object'
29
+
30
+ # Named API resources
28
31
  require 'stripe/account'
32
+ require 'stripe/alipay_account'
33
+ require 'stripe/apple_pay_domain'
34
+ require 'stripe/application_fee'
35
+ require 'stripe/application_fee_refund'
29
36
  require 'stripe/balance'
30
37
  require 'stripe/balance_transaction'
31
- require 'stripe/customer'
32
- require 'stripe/invoice'
33
- require 'stripe/invoice_item'
38
+ require 'stripe/bank_account'
39
+ require 'stripe/bitcoin_receiver'
40
+ require 'stripe/bitcoin_transaction'
41
+ require 'stripe/card'
34
42
  require 'stripe/charge'
35
43
  require 'stripe/country_spec'
36
- require 'stripe/plan'
37
- require 'stripe/file_upload'
38
44
  require 'stripe/coupon'
39
- require 'stripe/token'
45
+ require 'stripe/customer'
46
+ require 'stripe/dispute'
40
47
  require 'stripe/event'
41
- require 'stripe/transfer'
48
+ require 'stripe/file_upload'
49
+ require 'stripe/invoice'
50
+ require 'stripe/invoice_item'
51
+ require 'stripe/order'
52
+ require 'stripe/order_return'
53
+ require 'stripe/plan'
54
+ require 'stripe/product'
42
55
  require 'stripe/recipient'
43
- require 'stripe/bank_account'
44
- require 'stripe/card'
45
- require 'stripe/subscription'
46
- require 'stripe/subscription_item'
47
- require 'stripe/application_fee'
48
56
  require 'stripe/refund'
49
57
  require 'stripe/reversal'
50
- require 'stripe/application_fee_refund'
51
- require 'stripe/bitcoin_receiver'
52
- require 'stripe/bitcoin_transaction'
53
- require 'stripe/dispute'
54
- require 'stripe/product'
55
58
  require 'stripe/sku'
56
- require 'stripe/order'
57
- require 'stripe/order_return'
58
- require 'stripe/alipay_account'
59
- require 'stripe/three_d_secure'
60
59
  require 'stripe/source'
61
- require 'stripe/apple_pay_domain'
62
-
63
- # Errors
64
- require 'stripe/errors/stripe_error'
65
- require 'stripe/errors/api_error'
66
- require 'stripe/errors/api_connection_error'
67
- require 'stripe/errors/card_error'
68
- require 'stripe/errors/invalid_request_error'
69
- require 'stripe/errors/authentication_error'
70
- require 'stripe/errors/permission_error'
71
- require 'stripe/errors/rate_limit_error'
60
+ require 'stripe/subscription'
61
+ require 'stripe/subscription_item'
62
+ require 'stripe/three_d_secure'
63
+ require 'stripe/token'
64
+ require 'stripe/transfer'
72
65
 
73
66
  module Stripe
74
67
  DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt'
@@ -128,6 +121,37 @@ module Stripe
128
121
  (api_base_url || @api_base) + url
129
122
  end
130
123
 
124
+ # The location of a file containing a bundle of CA certificates. By default
125
+ # the library will use an included bundle that can successfully validate
126
+ # Stripe certificates.
127
+ def self.ca_bundle_path
128
+ @ca_bundle_path
129
+ end
130
+
131
+ def self.ca_bundle_path=(path)
132
+ @ca_bundle_path = path
133
+
134
+ # empty this field so a new store is initialized
135
+ @ca_store = nil
136
+ end
137
+
138
+ # A certificate store initialized from the the bundle in #ca_bundle_path and
139
+ # which is used to validate TLS on every request.
140
+ #
141
+ # This was added to the give the gem "pseudo thread safety" in that it seems
142
+ # when initiating many parallel requests marshaling the certificate store is
143
+ # the most likely point of failure (see issue #382). Any program attempting
144
+ # to leverage this pseudo safety should make a call to this method (i.e.
145
+ # `Stripe.ca_store`) in their initialization code because it marshals lazily
146
+ # and is itself not thread safe.
147
+ def self.ca_store
148
+ @ca_store ||= begin
149
+ store = OpenSSL::X509::Store.new
150
+ store.add_file(ca_bundle_path)
151
+ store
152
+ end
153
+ end
154
+
131
155
  def self.request(method, url, api_key, params={}, headers={}, api_base_url=nil)
132
156
  api_base_url = api_base_url || @api_base
133
157
 
@@ -184,46 +208,33 @@ module Stripe
184
208
  [parse(response), api_key]
185
209
  end
186
210
 
187
- # The location of a file containing a bundle of CA certificates. By default
188
- # the library will use an included bundle that can successfully validate
189
- # Stripe certificates.
190
- def self.ca_bundle_path
191
- @ca_bundle_path
211
+ def self.max_network_retries
212
+ @max_network_retries
192
213
  end
193
214
 
194
- def self.ca_bundle_path=(path)
195
- @ca_bundle_path = path
196
-
197
- # empty this field so a new store is initialized
198
- @ca_store = nil
215
+ def self.max_network_retries=(val)
216
+ @max_network_retries = val.to_i
199
217
  end
200
218
 
201
- # A certificate store initialized from the the bundle in #ca_bundle_path and
202
- # which is used to validate TLS on every request.
203
- #
204
- # This was added to the give the gem "pseudo thread safety" in that it seems
205
- # when initiating many parallel requests marshaling the certificate store is
206
- # the most likely point of failure (see issue #382). Any program attempting
207
- # to leverage this pseudo safety should make a call to this method (i.e.
208
- # `Stripe.ca_store`) in their initialization code because it marshals lazily
209
- # and is itself not thread safe.
210
- def self.ca_store
211
- @ca_store ||= begin
212
- store = OpenSSL::X509::Store.new
213
- store.add_file(ca_bundle_path)
214
- store
215
- end
219
+ private
220
+
221
+ def self.api_error(error, resp, error_obj)
222
+ APIError.new(error[:message], resp.code, resp.body, error_obj, resp.headers)
216
223
  end
217
224
 
218
- def self.max_network_retries
219
- @max_network_retries
225
+ def self.authentication_error(error, resp, error_obj)
226
+ AuthenticationError.new(error[:message], resp.code, resp.body, error_obj,
227
+ resp.headers)
220
228
  end
221
229
 
222
- def self.max_network_retries=(val)
223
- @max_network_retries = val.to_i
230
+ def self.card_error(error, resp, error_obj)
231
+ CardError.new(error[:message], error[:param], error[:code],
232
+ resp.code, resp.body, error_obj, resp.headers)
224
233
  end
225
234
 
226
- private
235
+ def self.execute_request(opts)
236
+ RestClient::Request.execute(opts)
237
+ end
227
238
 
228
239
  def self.execute_request_with_rescues(request_opts, api_base_url, retry_count = 0)
229
240
  begin
@@ -263,21 +274,9 @@ module Stripe
263
274
  response
264
275
  end
265
276
 
266
- def self.user_agent
267
- @uname ||= get_uname
268
- lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
269
-
270
- {
271
- :bindings_version => Stripe::VERSION,
272
- :lang => 'ruby',
273
- :lang_version => lang_version,
274
- :platform => RUBY_PLATFORM,
275
- :engine => defined?(RUBY_ENGINE) ? RUBY_ENGINE : '',
276
- :publisher => 'stripe',
277
- :uname => @uname,
278
- :hostname => Socket.gethostname,
279
- }
280
-
277
+ def self.general_api_error(rcode, rbody)
278
+ APIError.new("Invalid response object from API: #{rbody.inspect} " +
279
+ "(HTTP response code was #{rcode})", rcode, rbody)
281
280
  end
282
281
 
283
282
  def self.get_uname
@@ -286,81 +285,31 @@ module Stripe
286
285
  else
287
286
  case RbConfig::CONFIG['host_os']
288
287
  when /linux|darwin|bsd|sunos|solaris|cygwin/i
289
- _uname_uname
288
+ get_uname_from_system
290
289
  when /mswin|mingw/i
291
- _uname_ver
290
+ get_uname_from_system_ver
292
291
  else
293
292
  "unknown platform"
294
293
  end
295
294
  end
296
295
  end
297
296
 
298
- def self._uname_uname
297
+ def self.get_uname_from_system
299
298
  (`uname -a 2>/dev/null` || '').strip
299
+ rescue Errno::ENOENT
300
+ "uname executable not found"
300
301
  rescue Errno::ENOMEM # couldn't create subprocess
301
302
  "uname lookup failed"
302
303
  end
303
304
 
304
- def self._uname_ver
305
+ def self.get_uname_from_system_ver
305
306
  (`ver` || '').strip
307
+ rescue Errno::ENOENT
308
+ "ver executable not found"
306
309
  rescue Errno::ENOMEM # couldn't create subprocess
307
310
  "uname lookup failed"
308
311
  end
309
312
 
310
- # DEPRECATED. Use `Util#encode_parameters` instead.
311
- def self.uri_encode(params)
312
- Util.encode_parameters(params)
313
- end
314
- class << self
315
- extend Gem::Deprecate
316
- deprecate :uri_encode, "Stripe::Util#encode_parameters", 2016, 01
317
- end
318
-
319
- def self.request_headers(api_key, method)
320
- headers = {
321
- 'User-Agent' => "Stripe/v1 RubyBindings/#{Stripe::VERSION}",
322
- 'Authorization' => "Bearer #{api_key}",
323
- 'Content-Type' => 'application/x-www-form-urlencoded'
324
- }
325
-
326
- # It is only safe to retry network failures on post and delete
327
- # requests if we add an Idempotency-Key header
328
- if [:post, :delete].include?(method) && self.max_network_retries > 0
329
- headers['Idempotency-Key'] ||= SecureRandom.uuid
330
- end
331
-
332
- headers['Stripe-Version'] = api_version if api_version
333
- headers['Stripe-Account'] = stripe_account if stripe_account
334
-
335
- begin
336
- headers.update('X-Stripe-Client-User-Agent' => JSON.generate(user_agent))
337
- rescue => e
338
- headers.update('X-Stripe-Client-Raw-User-Agent' => user_agent.inspect,
339
- :error => "#{e} (#{e.class})")
340
- end
341
- end
342
-
343
- def self.execute_request(opts)
344
- RestClient::Request.execute(opts)
345
- end
346
-
347
- def self.parse(response)
348
- begin
349
- # Would use :symbolize_names => true, but apparently there is
350
- # some library out there that makes symbolize_names not work.
351
- response = JSON.parse(response.body)
352
- rescue JSON::ParserError
353
- raise general_api_error(response.code, response.body)
354
- end
355
-
356
- Util.symbolize_names(response)
357
- end
358
-
359
- def self.general_api_error(rcode, rbody)
360
- APIError.new("Invalid response object from API: #{rbody.inspect} " +
361
- "(HTTP response code was #{rcode})", rcode, rbody)
362
- end
363
-
364
313
  def self.handle_api_error(resp)
365
314
  begin
366
315
  error_obj = JSON.parse(resp.body)
@@ -389,34 +338,6 @@ module Stripe
389
338
 
390
339
  end
391
340
 
392
- def self.invalid_request_error(error, resp, error_obj)
393
- InvalidRequestError.new(error[:message], error[:param], resp.code,
394
- resp.body, error_obj, resp.headers)
395
- end
396
-
397
- def self.authentication_error(error, resp, error_obj)
398
- AuthenticationError.new(error[:message], resp.code, resp.body, error_obj,
399
- resp.headers)
400
- end
401
-
402
- def self.rate_limit_error(error, resp, error_obj)
403
- RateLimitError.new(error[:message], resp.code, resp.body, error_obj,
404
- resp.headers)
405
- end
406
-
407
- def self.card_error(error, resp, error_obj)
408
- CardError.new(error[:message], error[:param], error[:code],
409
- resp.code, resp.body, error_obj, resp.headers)
410
- end
411
-
412
- def self.permission_error(error, resp, error_obj)
413
- PermissionError.new(error[:message], resp.code, resp.body, error_obj, resp.headers)
414
- end
415
-
416
- def self.api_error(error, resp, error_obj)
417
- APIError.new(error[:message], resp.code, resp.body, error_obj, resp.headers)
418
- end
419
-
420
341
  def self.handle_restclient_error(e, request_opts, retry_count, api_base_url=nil)
421
342
 
422
343
  api_base_url = @api_base unless api_base_url
@@ -462,6 +383,56 @@ module Stripe
462
383
  raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
463
384
  end
464
385
 
386
+ def self.invalid_request_error(error, resp, error_obj)
387
+ InvalidRequestError.new(error[:message], error[:param], resp.code,
388
+ resp.body, error_obj, resp.headers)
389
+ end
390
+
391
+ def self.parse(response)
392
+ begin
393
+ # Would use :symbolize_names => true, but apparently there is
394
+ # some library out there that makes symbolize_names not work.
395
+ response = JSON.parse(response.body)
396
+ rescue JSON::ParserError
397
+ raise general_api_error(response.code, response.body)
398
+ end
399
+
400
+ Util.symbolize_names(response)
401
+ end
402
+
403
+ def self.permission_error(error, resp, error_obj)
404
+ PermissionError.new(error[:message], resp.code, resp.body, error_obj, resp.headers)
405
+ end
406
+
407
+ def self.rate_limit_error(error, resp, error_obj)
408
+ RateLimitError.new(error[:message], resp.code, resp.body, error_obj,
409
+ resp.headers)
410
+ end
411
+
412
+ def self.request_headers(api_key, method)
413
+ headers = {
414
+ 'User-Agent' => "Stripe/v1 RubyBindings/#{Stripe::VERSION}",
415
+ 'Authorization' => "Bearer #{api_key}",
416
+ 'Content-Type' => 'application/x-www-form-urlencoded'
417
+ }
418
+
419
+ # It is only safe to retry network failures on post and delete
420
+ # requests if we add an Idempotency-Key header
421
+ if [:post, :delete].include?(method) && self.max_network_retries > 0
422
+ headers['Idempotency-Key'] ||= SecureRandom.uuid
423
+ end
424
+
425
+ headers['Stripe-Version'] = api_version if api_version
426
+ headers['Stripe-Account'] = stripe_account if stripe_account
427
+
428
+ begin
429
+ headers.update('X-Stripe-Client-User-Agent' => JSON.generate(user_agent))
430
+ rescue => e
431
+ headers.update('X-Stripe-Client-Raw-User-Agent' => user_agent.inspect,
432
+ :error => "#{e} (#{e.class})")
433
+ end
434
+ end
435
+
465
436
  def self.should_retry?(e, retry_count)
466
437
  retry_count < self.max_network_retries &&
467
438
  RETRY_EXCEPTIONS.any? { |klass| e.is_a?(klass) }
@@ -482,4 +453,30 @@ module Stripe
482
453
 
483
454
  sleep_seconds
484
455
  end
456
+
457
+ # DEPRECATED. Use `Util#encode_parameters` instead.
458
+ def self.uri_encode(params)
459
+ Util.encode_parameters(params)
460
+ end
461
+ class << self
462
+ extend Gem::Deprecate
463
+ deprecate :uri_encode, "Stripe::Util#encode_parameters", 2016, 01
464
+ end
465
+
466
+ def self.user_agent
467
+ @uname ||= get_uname
468
+ lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
469
+
470
+ {
471
+ :bindings_version => Stripe::VERSION,
472
+ :lang => 'ruby',
473
+ :lang_version => lang_version,
474
+ :platform => RUBY_PLATFORM,
475
+ :engine => defined?(RUBY_ENGINE) ? RUBY_ENGINE : '',
476
+ :publisher => 'stripe',
477
+ :uname => @uname,
478
+ :hostname => Socket.gethostname,
479
+ }
480
+
481
+ end
485
482
  end
@@ -0,0 +1,82 @@
1
+ module Stripe
2
+ # StripeError is the base error from which all other more specific Stripe
3
+ # errors derive.
4
+ class StripeError < StandardError
5
+ attr_reader :message
6
+ attr_reader :http_status
7
+ attr_reader :http_body
8
+ attr_reader :http_headers
9
+ attr_reader :request_id
10
+ attr_reader :json_body
11
+
12
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil,
13
+ http_headers=nil)
14
+ @message = message
15
+ @http_status = http_status
16
+ @http_body = http_body
17
+ @http_headers = http_headers || {}
18
+ @json_body = json_body
19
+ @request_id = @http_headers[:request_id]
20
+ end
21
+
22
+ def to_s
23
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
24
+ id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
25
+ "#{status_string}#{id_string}#{@message}"
26
+ end
27
+ end
28
+
29
+ # AuthenticationError is raised when invalid credentials are used to connect
30
+ # to Stripe's servers.
31
+ class AuthenticationError < StripeError
32
+ end
33
+
34
+ # APIConnectionError is raised in the event that the SDK can't connect to
35
+ # Stripe's servers. That can be for a variety of different reasons from a
36
+ # downed network to a bad TLS certificate.
37
+ class APIConnectionError < StripeError
38
+ end
39
+
40
+ # APIError is a generic error that may be raised in cases where none of the
41
+ # other named errors cover the problem. It could also be raised in the case
42
+ # that a new error has been introduced in the API, but this version of the
43
+ # Ruby SDK doesn't know how to handle it.
44
+ class APIError < StripeError
45
+ end
46
+
47
+ # CardError is raised when a user enters a card that can't be charged for
48
+ # some reason.
49
+ class CardError < StripeError
50
+ attr_reader :param, :code
51
+
52
+ def initialize(message, param, code, http_status=nil, http_body=nil, json_body=nil,
53
+ http_headers=nil)
54
+ super(message, http_status, http_body, json_body, http_headers)
55
+ @param = param
56
+ @code = code
57
+ end
58
+ end
59
+
60
+ # InvalidRequestError is raised when a request is initiated with invalid
61
+ # parameters.
62
+ class InvalidRequestError < StripeError
63
+ attr_accessor :param
64
+
65
+ def initialize(message, param, http_status=nil, http_body=nil, json_body=nil,
66
+ http_headers=nil)
67
+ super(message, http_status, http_body, json_body, http_headers)
68
+ @param = param
69
+ end
70
+ end
71
+
72
+ # PermissionError is raised in cases where access was attempted on a resource
73
+ # that wasn't allowed.
74
+ class PermissionError < StripeError
75
+ end
76
+
77
+ # RateLimitError is raised in cases where an account is putting too much load
78
+ # on Stripe's API servers (usually by performing too many requests). Please
79
+ # back off on request rate.
80
+ class RateLimitError < StripeError
81
+ end
82
+ end
@@ -1,8 +1,7 @@
1
1
  module Stripe
2
2
  class Source < APIResource
3
- include Stripe::APIOperations::Save
4
3
  extend Stripe::APIOperations::Create
5
- extend Stripe::APIOperations::List
4
+ include Stripe::APIOperations::Save
6
5
 
7
6
  def verify(params={}, opts={})
8
7
  response, opts = request(:post, resource_url + '/verify', params, opts)
@@ -52,10 +52,10 @@ module Stripe
52
52
  'sku' => SKU,
53
53
  'subscription' => Subscription,
54
54
  'subscription_item' => SubscriptionItem,
55
+ 'three_d_secure' => ThreeDSecure,
55
56
  'token' => Token,
56
57
  'transfer' => Transfer,
57
58
  'transfer_reversal' => Reversal,
58
- 'three_d_secure' => ThreeDSecure,
59
59
  }
60
60
  end
61
61
 
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.57.1'
2
+ VERSION = '1.58.0'
3
3
  end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class StripeErrorTest < Test::Unit::TestCase
5
+ context "#to_s" do
6
+ should "convert to string" do
7
+ e = StripeError.new("message")
8
+ assert_equal "message", e.to_s
9
+
10
+ e = StripeError.new("message", 200)
11
+ assert_equal "(Status 200) message", e.to_s
12
+
13
+ e = StripeError.new("message", nil, nil, nil, { :request_id => "request-id" })
14
+ assert_equal "(Request request-id) message", e.to_s
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,17 +2,82 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class SourceTest < Test::Unit::TestCase
5
- should 'be verifiable' do
6
- source = Stripe::Source.construct_from({
7
- :id => 'ba_foo',
8
- })
5
+ should 'be creatable' do
6
+ @mock.expects(:post).once.returns(make_response(make_source_card))
7
+ src = Stripe::Source.create(
8
+ type: 'card',
9
+ token: 'tok_test',
10
+ )
11
+ assert_equal 'src_test_card', src.id
12
+ end
13
+
14
+ should 'be retrievable' do
15
+ @mock.expects(:get).once.returns(make_response(make_source_card))
16
+ src = Stripe::Source.retrieve('src_test_card')
17
+ assert_equal 'src_test_card', src.id
18
+ end
9
19
 
10
- @mock.expects(:post).
11
- once.
12
- with('https://api.stripe.com/v1/sources/ba_foo/verify', nil, 'amounts[]=1&amounts[]=2').
13
- returns(make_response(:status => 'verified'))
20
+ should 'be updatable' do
21
+ @mock.expects(:post).once
22
+ .with(
23
+ "#{Stripe.api_base}/v1/sources/src_test_card",
24
+ nil,
25
+ 'metadata[foo]=bar'
26
+ )
27
+ .returns(make_response(make_source_card(metadata: {foo: 'bar'})))
28
+ src = Stripe::Source.update('src_test_card', metadata: {foo: 'bar'})
29
+ assert_equal 'bar', src.metadata['foo']
30
+ end
31
+
32
+ should 'be saveable' do
33
+ @mock.expects(:get).once.returns(make_response(make_source_card))
34
+ src = Stripe::Source.retrieve('src_test_card')
35
+
36
+ @mock.expects(:post).once
37
+ .with(
38
+ "#{Stripe.api_base}/v1/sources/src_test_card",
39
+ nil,
40
+ 'metadata[foo]=bar'
41
+ )
42
+ .returns(make_response(make_source_card(metadata: {foo: 'bar'})))
43
+ src.metadata['foo'] = 'bar'
44
+ src.save
45
+ assert_equal 'bar', src.metadata['foo']
46
+ end
47
+
48
+ should 'not be deletable' do
49
+ @mock.expects(:get).once.returns(make_response(make_source_card))
50
+ src = Stripe::Source.retrieve('src_test_card')
51
+
52
+ assert_raises NoMethodError do
53
+ src.delete
54
+ end
55
+ end
56
+
57
+ should 'not be listable' do
58
+ assert_raises NoMethodError do
59
+ Stripe::Source.list
60
+ end
61
+ end
62
+
63
+ should 'be verifiable' do
64
+ @mock.expects(:get).once.returns(make_response(make_source_ach_debit))
65
+ src = Stripe::Source.retrieve('src_test_ach_debit')
14
66
 
15
- source.verify(:amounts => [1,2])
67
+ @mock.expects(:post).once
68
+ .with(
69
+ 'https://api.stripe.com/v1/sources/src_test_ach_debit/verify',
70
+ nil,
71
+ 'values[]=32&values[]=45'
72
+ )
73
+ .returns(make_response(make_source_ach_debit(
74
+ verification: {
75
+ attempts_remaining: 0,
76
+ status: 'succeeded',
77
+ }
78
+ )))
79
+ src.verify(values: [32, 45])
80
+ assert_equal 'succeeded', src.verification.status
16
81
  end
17
82
  end
18
83
  end
@@ -48,4 +48,27 @@ class StripeTest < Test::Unit::TestCase
48
48
 
49
49
  Stripe.request(:post, '/v1/account', 'sk_live12334566')
50
50
  end
51
+
52
+ context "#get_uname" do
53
+ should "run without failure" do
54
+ # Don't actually check the result because we try a variety of different
55
+ # strategies that will have different results depending on where this
56
+ # test and running. We're mostly making sure that no exception is thrown.
57
+ _ = Stripe.get_uname
58
+ end
59
+ end
60
+
61
+ context "#get_uname_from_system" do
62
+ should "run without failure" do
63
+ # as above, just verify that an exception is not thrown
64
+ _ = Stripe.get_uname_from_system
65
+ end
66
+ end
67
+
68
+ context "#get_uname_from_system_ver" do
69
+ should "run without failure" do
70
+ # as above, just verify that an exception is not thrown
71
+ _ = Stripe.get_uname_from_system_ver
72
+ end
73
+ end
51
74
  end
@@ -895,5 +895,91 @@ module Stripe
895
895
  ]
896
896
  }
897
897
  end
898
+
899
+ def make_source_card(params={})
900
+ id = params[:id] || 'src_test_card'
901
+ {
902
+ :id => id,
903
+ :object => 'source',
904
+ :type => 'card',
905
+ :amount => nil,
906
+ :card => {
907
+ :address_line1_check => nil,
908
+ :address_zip_check => nil,
909
+ :brand => 'Visa',
910
+ :country => 'US',
911
+ :cvc_check => 'unchecked',
912
+ :description => nil,
913
+ :dynamic_last4 => nil,
914
+ :exp_month => 1,
915
+ :exp_year => 2020,
916
+ :fingerprint => 'NrVafqTONZfbLkQK',
917
+ :funding => 'credit',
918
+ :google_reference => nil,
919
+ :iin => nil,
920
+ :issuer => nil,
921
+ :last4 => '4242',
922
+ :three_d_secure => 'optional',
923
+ :tokenization_method => 'nil',
924
+ },
925
+ :client_secret => 'src_client_secret_test',
926
+ :created => 1484841032,
927
+ :currency => nil,
928
+ :flow => 'none',
929
+ :livemode => false,
930
+ :metadata => {},
931
+ :owner => {
932
+ :address => nil,
933
+ :email => nil,
934
+ :name => nil,
935
+ :phone => nil,
936
+ :verified_address => nil,
937
+ :verified_email => nil,
938
+ :verified_name => nil,
939
+ :verified_phone => nil,
940
+ },
941
+ :status => 'chargeable',
942
+ :usage => 'reusable',
943
+ }.merge(params)
944
+ end
945
+
946
+ def make_source_ach_debit(params={})
947
+ id = params[:id] || 'src_test_ach_debit'
948
+ {
949
+ :id => id,
950
+ :object => 'source',
951
+ :type => 'ach_debit',
952
+ :ach_debit => {
953
+ :country => 'US',
954
+ :fingerprint => 'yY5BWKwnW98uydOa',
955
+ :last4 => '6789',
956
+ :routing_number => '110000000',
957
+ :type => 'individual',
958
+ },
959
+ :amount => nil,
960
+ :client_secret => 'src_client_secret_test',
961
+ :created => 1484842122,
962
+ :currency => 'usd',
963
+ :flow => 'verification',
964
+ :livemode => false,
965
+ :metadata => {},
966
+ :owner => {
967
+ :address => nil,
968
+ :email => nil,
969
+ :name => 'Jenny Rosen',
970
+ :phone => nil,
971
+ :verified_address => nil,
972
+ :verified_email => nil,
973
+ :verified_name => nil,
974
+ :verified_phone => nil,
975
+ },
976
+ :status => 'pending',
977
+ :usage => 'reusable',
978
+ :verification => {
979
+ :attempts_remaining => 10,
980
+ :status => 'pending',
981
+ },
982
+ }.merge(params)
983
+ end
898
984
  end
899
985
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.57.1
4
+ version: 1.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-29 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -73,14 +73,7 @@ files:
73
73
  - lib/stripe/coupon.rb
74
74
  - lib/stripe/customer.rb
75
75
  - lib/stripe/dispute.rb
76
- - lib/stripe/errors/api_connection_error.rb
77
- - lib/stripe/errors/api_error.rb
78
- - lib/stripe/errors/authentication_error.rb
79
- - lib/stripe/errors/card_error.rb
80
- - lib/stripe/errors/invalid_request_error.rb
81
- - lib/stripe/errors/permission_error.rb
82
- - lib/stripe/errors/rate_limit_error.rb
83
- - lib/stripe/errors/stripe_error.rb
76
+ - lib/stripe/errors.rb
84
77
  - lib/stripe/event.rb
85
78
  - lib/stripe/file_upload.rb
86
79
  - lib/stripe/invoice.rb
@@ -123,6 +116,7 @@ files:
123
116
  - test/stripe/customer_card_test.rb
124
117
  - test/stripe/customer_test.rb
125
118
  - test/stripe/dispute_test.rb
119
+ - test/stripe/errors_test.rb
126
120
  - test/stripe/file_upload_test.rb
127
121
  - test/stripe/invoice_item_test.rb
128
122
  - test/stripe/invoice_test.rb
@@ -190,6 +184,7 @@ test_files:
190
184
  - test/stripe/customer_card_test.rb
191
185
  - test/stripe/customer_test.rb
192
186
  - test/stripe/dispute_test.rb
187
+ - test/stripe/errors_test.rb
193
188
  - test/stripe/file_upload_test.rb
194
189
  - test/stripe/invoice_item_test.rb
195
190
  - test/stripe/invoice_test.rb
@@ -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 PermissionError < StripeError
3
- end
4
- 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