stripe 3.8.2 → 3.9.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: d454a76d37a56cc1ac7249b7b1d6130db55fa1fe
4
- data.tar.gz: fa2a235117656908deb0ea747295ef63ae8b92b9
3
+ metadata.gz: eaa933a4f88560dfadd280faf2e4d1ec83aebd10
4
+ data.tar.gz: dfcd075aebb73a0cfa1ac9ec67285ecfa7455c7c
5
5
  SHA512:
6
- metadata.gz: 3e34f48148db809fc089c73bdbdec2481135d3c60a9494959563657e5ddfeeed496a771982c0f56b5c97024aa821ff321afabeac33a9da15d4af99d11342c95b
7
- data.tar.gz: 94c23e01ebcb044b4042fd305345a1d962ccd1d5eb9fa67849941c6e8f4079921b1a3ec770175fd89e50be0b0fa0b4940a12c83b79bf507687f791f5fb3673eb
6
+ metadata.gz: 17ca14c655082ca4e391f0e0b0c9df06bc0055ba4ac28a97d071bff03ffed4b24b72240dcb5851f8bfbca30d3ed5a1211fad99f0af75a64f93b300976573abc3
7
+ data.tar.gz: f598845295dfeff3ac84cff079d98a62410815b72169182bddbceb81b092725dddf47451c6fe9e77fa448aead3d41dd9bbf348e2f6c0080f20dd829f6f086982
data/.rubocop_todo.yml CHANGED
@@ -13,12 +13,12 @@ Metrics/AbcSize:
13
13
  # Offense count: 27
14
14
  # Configuration parameters: CountComments, ExcludedMethods.
15
15
  Metrics/BlockLength:
16
- Max: 455
16
+ Max: 467
17
17
 
18
18
  # Offense count: 8
19
19
  # Configuration parameters: CountComments.
20
20
  Metrics/ClassLength:
21
- Max: 583
21
+ Max: 595
22
22
 
23
23
  # Offense count: 10
24
24
  Metrics/CyclomaticComplexity:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.9.0 - 2017-12-08
4
+ * [#613](https://github.com/stripe/stripe-ruby/pull/613) Introduce new `IdempotencyError` type for idempotency-specific failures
5
+
3
6
  ## 3.8.2 - 2017-12-07
4
7
  * [#612](https://github.com/stripe/stripe-ruby/pull/612) Fix integer-indexed array encoding when sent as query parameter (subscription items can now be used when fetching an upcoming invoice)
5
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.8.2
1
+ 3.9.0
data/lib/stripe/errors.rb CHANGED
@@ -66,6 +66,11 @@ module Stripe
66
66
  end
67
67
  end
68
68
 
69
+ # IdempotencyError is raised in cases where an idempotency key was used
70
+ # improperly.
71
+ class IdempotencyError < StripeError
72
+ end
73
+
69
74
  # InvalidRequestError is raised when a request is initiated with invalid
70
75
  # parameters.
71
76
  class InvalidRequestError < StripeError
@@ -280,53 +280,47 @@ module Stripe
280
280
  def specific_api_error(resp, error_data, context)
281
281
  Util.log_error("Stripe API error",
282
282
  status: resp.http_status,
283
- error_code: error_data["code"],
284
- error_message: error_data["message"],
285
- error_param: error_data["param"],
286
- error_type: error_data["type"],
283
+ error_code: error_data[:code],
284
+ error_message: error_data[:message],
285
+ error_param: error_data[:param],
286
+ error_type: error_data[:type],
287
287
  idempotency_key: context.idempotency_key,
288
288
  request_id: context.request_id)
289
289
 
290
+ # The standard set of arguments that can be used to initialize most of
291
+ # the exceptions.
292
+ opts = {
293
+ http_body: resp.http_body,
294
+ http_headers: resp.http_headers,
295
+ http_status: resp.http_status,
296
+ json_body: resp.data,
297
+ }
298
+
290
299
  case resp.http_status
291
300
  when 400, 404
292
- error = InvalidRequestError.new(
293
- error_data[:message], error_data[:param],
294
- http_status: resp.http_status, http_body: resp.http_body,
295
- json_body: resp.data, http_headers: resp.http_headers
296
- )
301
+ case error_data[:type]
302
+ when "idempotency_error"
303
+ IdempotencyError.new(error_data[:message], opts)
304
+ else
305
+ InvalidRequestError.new(
306
+ error_data[:message], error_data[:param],
307
+ opts
308
+ )
309
+ end
297
310
  when 401
298
- error = AuthenticationError.new(
299
- error_data[:message],
300
- http_status: resp.http_status, http_body: resp.http_body,
301
- json_body: resp.data, http_headers: resp.http_headers
302
- )
311
+ AuthenticationError.new(error_data[:message], opts)
303
312
  when 402
304
- error = CardError.new(
313
+ CardError.new(
305
314
  error_data[:message], error_data[:param], error_data[:code],
306
- http_status: resp.http_status, http_body: resp.http_body,
307
- json_body: resp.data, http_headers: resp.http_headers
315
+ opts
308
316
  )
309
317
  when 403
310
- error = PermissionError.new(
311
- error_data[:message],
312
- http_status: resp.http_status, http_body: resp.http_body,
313
- json_body: resp.data, http_headers: resp.http_headers
314
- )
318
+ PermissionError.new(error_data[:message], opts)
315
319
  when 429
316
- error = RateLimitError.new(
317
- error_data[:message],
318
- http_status: resp.http_status, http_body: resp.http_body,
319
- json_body: resp.data, http_headers: resp.http_headers
320
- )
320
+ RateLimitError.new(error_data[:message], opts)
321
321
  else
322
- error = APIError.new(
323
- error_data[:message],
324
- http_status: resp.http_status, http_body: resp.http_body,
325
- json_body: resp.data, http_headers: resp.http_headers
326
- )
322
+ APIError.new(error_data[:message], opts)
327
323
  end
328
-
329
- error
330
324
  end
331
325
 
332
326
  # Attempts to look at a response's error code and return an OAuth error if
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = "3.8.2".freeze
2
+ VERSION = "3.9.0".freeze
3
3
  end
@@ -242,10 +242,10 @@ module Stripe
242
242
  }
243
243
  Util.expects(:log_error).with("Stripe API error",
244
244
  status: 500,
245
- error_code: error["code"],
246
- error_message: error["message"],
247
- error_param: error["param"],
248
- error_type: error["type"],
245
+ error_code: error[:code],
246
+ error_message: error[:message],
247
+ error_param: error[:param],
248
+ error_type: error[:type],
249
249
  idempotency_key: nil,
250
250
  request_id: nil)
251
251
 
@@ -411,7 +411,22 @@ module Stripe
411
411
  assert_equal 'Invalid response object from API: "{\"bar\":\"foo\"}" (HTTP response code was 500)', e.message
412
412
  end
413
413
 
414
- should "raise InvalidRequestError on 400" do
414
+ should "raise IdempotencyError on 400 of type idempotency_error" do
415
+ data = make_missing_id_error
416
+ data[:error][:type] = "idempotency_error"
417
+
418
+ stub_request(:post, "#{Stripe.api_base}/v1/charges")
419
+ .to_return(body: JSON.generate(data), status: 400)
420
+ client = StripeClient.new
421
+
422
+ e = assert_raises Stripe::IdempotencyError do
423
+ client.execute_request(:post, "/v1/charges")
424
+ end
425
+ assert_equal(400, e.http_status)
426
+ assert_equal(true, e.json_body.is_a?(Hash))
427
+ end
428
+
429
+ should "raise InvalidRequestError on other 400s" do
415
430
  stub_request(:post, "#{Stripe.api_base}/v1/charges")
416
431
  .to_return(body: JSON.generate(make_missing_id_error), status: 400)
417
432
  client = StripeClient.new
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: 3.8.2
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-07 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday