stripe 10.2.0.pre.beta.1 → 10.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -239
  3. data/Gemfile +5 -2
  4. data/OPENAPI_VERSION +1 -1
  5. data/README.md +0 -11
  6. data/Rakefile +7 -5
  7. data/VERSION +1 -1
  8. data/bin/stripe-console +1 -1
  9. data/lib/stripe/api_operations/request.rb +3 -7
  10. data/lib/stripe/api_operations/save.rb +5 -7
  11. data/lib/stripe/api_resource_test_helpers.rb +2 -2
  12. data/lib/stripe/api_version.rb +0 -1
  13. data/lib/stripe/connection_manager.rb +4 -6
  14. data/lib/stripe/errors.rb +3 -11
  15. data/lib/stripe/instrumentation.rb +5 -21
  16. data/lib/stripe/multipart_encoder.rb +7 -7
  17. data/lib/stripe/oauth.rb +6 -6
  18. data/lib/stripe/object_types.rb +3 -21
  19. data/lib/stripe/resources/account.rb +6 -10
  20. data/lib/stripe/resources/alipay_account.rb +1 -1
  21. data/lib/stripe/resources/application_fee_refund.rb +1 -1
  22. data/lib/stripe/resources/bank_account.rb +2 -2
  23. data/lib/stripe/resources/capability.rb +1 -1
  24. data/lib/stripe/resources/climate/order.rb +34 -0
  25. data/lib/stripe/resources/climate/product.rb +14 -0
  26. data/lib/stripe/resources/climate/supplier.rb +13 -0
  27. data/lib/stripe/resources/event.rb +2 -2
  28. data/lib/stripe/resources/file.rb +2 -4
  29. data/lib/stripe/resources/financial_connections/account.rb +0 -39
  30. data/lib/stripe/resources/invoice.rb +0 -21
  31. data/lib/stripe/resources/quote.rb +0 -94
  32. data/lib/stripe/resources/reversal.rb +1 -1
  33. data/lib/stripe/resources/subscription_schedule.rb +0 -18
  34. data/lib/stripe/resources/tax_id.rb +1 -1
  35. data/lib/stripe/resources/terminal/reader.rb +0 -54
  36. data/lib/stripe/resources.rb +3 -20
  37. data/lib/stripe/stripe_client.rb +51 -102
  38. data/lib/stripe/stripe_configuration.rb +13 -31
  39. data/lib/stripe/stripe_object.rb +15 -18
  40. data/lib/stripe/stripe_response.rb +1 -3
  41. data/lib/stripe/util.rb +11 -20
  42. data/lib/stripe/version.rb +1 -1
  43. data/lib/stripe.rb +0 -46
  44. data/stripe.gemspec +3 -2
  45. metadata +8 -25
  46. data/lib/stripe/request_signing_authenticator.rb +0 -83
  47. data/lib/stripe/resources/account_notice.rb +0 -14
  48. data/lib/stripe/resources/capital/financing_offer.rb +0 -32
  49. data/lib/stripe/resources/capital/financing_summary.rb +0 -12
  50. data/lib/stripe/resources/capital/financing_transaction.rb +0 -13
  51. data/lib/stripe/resources/confirmation_token.rb +0 -11
  52. data/lib/stripe/resources/customer_session.rb +0 -12
  53. data/lib/stripe/resources/financial_connections/account_inferred_balance.rb +0 -13
  54. data/lib/stripe/resources/financial_connections/transaction.rb +0 -13
  55. data/lib/stripe/resources/gift_cards/card.rb +0 -25
  56. data/lib/stripe/resources/gift_cards/transaction.rb +0 -56
  57. data/lib/stripe/resources/invoice_payment.rb +0 -11
  58. data/lib/stripe/resources/issuing/credit_underwriting_record.rb +0 -69
  59. data/lib/stripe/resources/issuing/personalization_design.rb +0 -77
  60. data/lib/stripe/resources/issuing/physical_bundle.rb +0 -13
  61. data/lib/stripe/resources/margin.rb +0 -14
  62. data/lib/stripe/resources/order.rb +0 -89
  63. data/lib/stripe/resources/quote_phase.rb +0 -29
  64. data/lib/stripe/resources/quote_preview_invoice.rb +0 -42
  65. data/lib/stripe/resources/quote_preview_subscription_schedule.rb +0 -10
  66. data/lib/stripe/resources/tax/form.rb +0 -39
@@ -23,33 +23,6 @@ module Stripe
23
23
  )
24
24
  end
25
25
 
26
- def collect_inputs(params = {}, opts = {})
27
- request_stripe_object(
28
- method: :post,
29
- path: format("/v1/terminal/readers/%<reader>s/collect_inputs", { reader: CGI.escape(self["id"]) }),
30
- params: params,
31
- opts: opts
32
- )
33
- end
34
-
35
- def collect_payment_method(params = {}, opts = {})
36
- request_stripe_object(
37
- method: :post,
38
- path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(self["id"]) }),
39
- params: params,
40
- opts: opts
41
- )
42
- end
43
-
44
- def confirm_payment_intent(params = {}, opts = {})
45
- request_stripe_object(
46
- method: :post,
47
- path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(self["id"]) }),
48
- params: params,
49
- opts: opts
50
- )
51
- end
52
-
53
26
  def process_payment_intent(params = {}, opts = {})
54
27
  request_stripe_object(
55
28
  method: :post,
@@ -95,33 +68,6 @@ module Stripe
95
68
  )
96
69
  end
97
70
 
98
- def self.collect_inputs(reader, params = {}, opts = {})
99
- request_stripe_object(
100
- method: :post,
101
- path: format("/v1/terminal/readers/%<reader>s/collect_inputs", { reader: CGI.escape(reader) }),
102
- params: params,
103
- opts: opts
104
- )
105
- end
106
-
107
- def self.collect_payment_method(reader, params = {}, opts = {})
108
- request_stripe_object(
109
- method: :post,
110
- path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(reader) }),
111
- params: params,
112
- opts: opts
113
- )
114
- end
115
-
116
- def self.confirm_payment_intent(reader, params = {}, opts = {})
117
- request_stripe_object(
118
- method: :post,
119
- path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(reader) }),
120
- params: params,
121
- opts: opts
122
- )
123
- end
124
-
125
71
  def self.process_payment_intent(reader, params = {}, opts = {})
126
72
  request_stripe_object(
127
73
  method: :post,
@@ -3,7 +3,6 @@
3
3
 
4
4
  require "stripe/resources/account"
5
5
  require "stripe/resources/account_link"
6
- require "stripe/resources/account_notice"
7
6
  require "stripe/resources/account_session"
8
7
  require "stripe/resources/apple_pay_domain"
9
8
  require "stripe/resources/application_fee"
@@ -15,14 +14,13 @@ require "stripe/resources/bank_account"
15
14
  require "stripe/resources/billing_portal/configuration"
16
15
  require "stripe/resources/billing_portal/session"
17
16
  require "stripe/resources/capability"
18
- require "stripe/resources/capital/financing_offer"
19
- require "stripe/resources/capital/financing_summary"
20
- require "stripe/resources/capital/financing_transaction"
21
17
  require "stripe/resources/card"
22
18
  require "stripe/resources/cash_balance"
23
19
  require "stripe/resources/charge"
24
20
  require "stripe/resources/checkout/session"
25
- require "stripe/resources/confirmation_token"
21
+ require "stripe/resources/climate/order"
22
+ require "stripe/resources/climate/product"
23
+ require "stripe/resources/climate/supplier"
26
24
  require "stripe/resources/country_spec"
27
25
  require "stripe/resources/coupon"
28
26
  require "stripe/resources/credit_note"
@@ -30,7 +28,6 @@ require "stripe/resources/credit_note_line_item"
30
28
  require "stripe/resources/customer"
31
29
  require "stripe/resources/customer_balance_transaction"
32
30
  require "stripe/resources/customer_cash_balance_transaction"
33
- require "stripe/resources/customer_session"
34
31
  require "stripe/resources/discount"
35
32
  require "stripe/resources/dispute"
36
33
  require "stripe/resources/ephemeral_key"
@@ -39,34 +36,24 @@ require "stripe/resources/exchange_rate"
39
36
  require "stripe/resources/file"
40
37
  require "stripe/resources/file_link"
41
38
  require "stripe/resources/financial_connections/account"
42
- require "stripe/resources/financial_connections/account_inferred_balance"
43
39
  require "stripe/resources/financial_connections/account_owner"
44
40
  require "stripe/resources/financial_connections/account_ownership"
45
41
  require "stripe/resources/financial_connections/session"
46
- require "stripe/resources/financial_connections/transaction"
47
42
  require "stripe/resources/funding_instructions"
48
- require "stripe/resources/gift_cards/card"
49
- require "stripe/resources/gift_cards/transaction"
50
43
  require "stripe/resources/identity/verification_report"
51
44
  require "stripe/resources/identity/verification_session"
52
45
  require "stripe/resources/invoice"
53
46
  require "stripe/resources/invoice_item"
54
47
  require "stripe/resources/invoice_line_item"
55
- require "stripe/resources/invoice_payment"
56
48
  require "stripe/resources/issuing/authorization"
57
49
  require "stripe/resources/issuing/card"
58
50
  require "stripe/resources/issuing/cardholder"
59
- require "stripe/resources/issuing/credit_underwriting_record"
60
51
  require "stripe/resources/issuing/dispute"
61
- require "stripe/resources/issuing/personalization_design"
62
- require "stripe/resources/issuing/physical_bundle"
63
52
  require "stripe/resources/issuing/token"
64
53
  require "stripe/resources/issuing/transaction"
65
54
  require "stripe/resources/line_item"
66
55
  require "stripe/resources/login_link"
67
56
  require "stripe/resources/mandate"
68
- require "stripe/resources/margin"
69
- require "stripe/resources/order"
70
57
  require "stripe/resources/payment_intent"
71
58
  require "stripe/resources/payment_link"
72
59
  require "stripe/resources/payment_method"
@@ -79,9 +66,6 @@ require "stripe/resources/price"
79
66
  require "stripe/resources/product"
80
67
  require "stripe/resources/promotion_code"
81
68
  require "stripe/resources/quote"
82
- require "stripe/resources/quote_phase"
83
- require "stripe/resources/quote_preview_invoice"
84
- require "stripe/resources/quote_preview_subscription_schedule"
85
69
  require "stripe/resources/radar/early_fraud_warning"
86
70
  require "stripe/resources/radar/value_list"
87
71
  require "stripe/resources/radar/value_list_item"
@@ -101,7 +85,6 @@ require "stripe/resources/subscription_item"
101
85
  require "stripe/resources/subscription_schedule"
102
86
  require "stripe/resources/tax/calculation"
103
87
  require "stripe/resources/tax/calculation_line_item"
104
- require "stripe/resources/tax/form"
105
88
  require "stripe/resources/tax/registration"
106
89
  require "stripe/resources/tax/settings"
107
90
  require "stripe/resources/tax/transaction"
@@ -36,8 +36,7 @@ module Stripe
36
36
  end
37
37
  end
38
38
 
39
- attr_reader :config
40
- attr_reader :options
39
+ attr_reader :config, :options
41
40
 
42
41
  # Gets a currently active `StripeClient`. Set for the current thread when
43
42
  # `StripeClient#request` is being run so that API operations being executed
@@ -80,9 +79,7 @@ module Stripe
80
79
  end
81
80
  end
82
81
 
83
- if thread_context.default_connection_managers.empty?
84
- pruned_contexts << thread_context
85
- end
82
+ pruned_contexts << thread_context if thread_context.default_connection_managers.empty?
86
83
  end
87
84
 
88
85
  @thread_contexts_with_connection_managers.subtract(pruned_contexts)
@@ -120,7 +117,7 @@ module Stripe
120
117
  when Net::OpenTimeout, Net::ReadTimeout
121
118
  # Retry on timeout-related problems (either on open or read).
122
119
  true
123
- when EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET,
120
+ when EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, # rubocop:todo Lint/DuplicateBranch
124
121
  Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
125
122
  # Destination refused the connection, the connection was reset, or a
126
123
  # variety of other connection failures. This could occur from a single
@@ -212,10 +209,9 @@ module Stripe
212
209
  end
213
210
 
214
211
  def execute_request(method, path,
215
- api_base: nil, api_key: nil,
216
- headers: {}, params: {}, api_mode: nil)
212
+ api_base: nil, api_key: nil, headers: {}, params: {})
217
213
  http_resp, api_key = execute_request_internal(
218
- method, path, api_base, api_key, headers, params, api_mode
214
+ method, path, api_base, api_key, headers, params
219
215
  )
220
216
 
221
217
  begin
@@ -246,7 +242,6 @@ module Stripe
246
242
  def execute_request_stream(method, path,
247
243
  api_base: nil, api_key: nil,
248
244
  headers: {}, params: {},
249
- api_mode: nil,
250
245
  &read_body_chunk_block)
251
246
  unless block_given?
252
247
  raise ArgumentError,
@@ -254,8 +249,7 @@ module Stripe
254
249
  end
255
250
 
256
251
  http_resp, api_key = execute_request_internal(
257
- method, path, api_base, api_key,
258
- headers, params, api_mode, &read_body_chunk_block
252
+ method, path, api_base, api_key, headers, params, &read_body_chunk_block
259
253
  )
260
254
 
261
255
  # When the read_body_chunk_block is given, we no longer have access to the
@@ -290,21 +284,21 @@ module Stripe
290
284
 
291
285
  ERROR_MESSAGE_CONNECTION =
292
286
  "Unexpected error communicating when trying to connect to " \
293
- "Stripe (%s). You may be seeing this message because your DNS is not " \
294
- "working or you don't have an internet connection. To check, try " \
295
- "running `host stripe.com` from the command line."
287
+ "Stripe (%s). You may be seeing this message because your DNS is not " \
288
+ "working or you don't have an internet connection. To check, try " \
289
+ "running `host stripe.com` from the command line."
296
290
  ERROR_MESSAGE_SSL =
297
291
  "Could not establish a secure connection to Stripe (%s), you " \
298
- "may need to upgrade your OpenSSL version. To check, try running " \
299
- "`openssl s_client -connect api.stripe.com:443` from the command " \
300
- "line."
292
+ "may need to upgrade your OpenSSL version. To check, try running " \
293
+ "`openssl s_client -connect api.stripe.com:443` from the command " \
294
+ "line."
301
295
 
302
296
  # Common error suffix sared by both connect and read timeout messages.
303
297
  ERROR_MESSAGE_TIMEOUT_SUFFIX =
304
298
  "Please check your internet connection and try again. " \
305
- "If this problem persists, you should check Stripe's service " \
306
- "status at https://status.stripe.com, or let us know at " \
307
- "support@stripe.com."
299
+ "If this problem persists, you should check Stripe's service " \
300
+ "status at https://status.stripe.com, or let us know at " \
301
+ "support@stripe.com."
308
302
 
309
303
  ERROR_MESSAGE_TIMEOUT_CONNECT = (
310
304
  "Timed out connecting to Stripe (%s). " +
@@ -435,7 +429,7 @@ module Stripe
435
429
 
436
430
  private def execute_request_internal(method, path,
437
431
  api_base, api_key, headers, params,
438
- api_mode, &read_body_chunk_block)
432
+ &read_body_chunk_block)
439
433
  raise ArgumentError, "method should be a symbol" \
440
434
  unless method.is_a?(Symbol)
441
435
  raise ArgumentError, "path should be a string" \
@@ -443,10 +437,9 @@ module Stripe
443
437
 
444
438
  api_base ||= config.api_base
445
439
  api_key ||= config.api_key
446
- authenticator ||= config.authenticator
447
440
  params = Util.objects_to_ids(params)
448
441
 
449
- check_keys!(api_key, authenticator)
442
+ check_api_key!(api_key)
450
443
 
451
444
  body_params = nil
452
445
  query_params = nil
@@ -459,9 +452,8 @@ module Stripe
459
452
 
460
453
  query_params, path = merge_query_params(query_params, path)
461
454
 
462
- headers = request_headers(api_key, method, api_mode)
455
+ headers = request_headers(api_key, method)
463
456
  .update(Util.normalize_headers(headers))
464
-
465
457
  url = api_url(path, api_base)
466
458
 
467
459
  # Merge given query parameters with any already encoded in the path.
@@ -472,16 +464,13 @@ module Stripe
472
464
  # a log-friendly variant of the encoded form. File objects are displayed
473
465
  # as such instead of as their file contents.
474
466
  body, body_log =
475
- body_params ? encode_body(body_params, headers, api_mode) : [nil, nil]
476
-
477
- authenticator.authenticate(method, headers, body) unless api_key
467
+ body_params ? encode_body(body_params, headers) : [nil, nil]
478
468
 
479
469
  # stores information on the request we're about to make so that we don't
480
470
  # have to pass as many parameters around for logging.
481
471
  context = RequestLogContext.new
482
472
  context.account = headers["Stripe-Account"]
483
473
  context.api_key = api_key
484
- context.authenticator = authenticator
485
474
  context.api_version = headers["Stripe-Version"]
486
475
  context.body = body_log
487
476
  context.idempotency_key = headers["Idempotency-Key"]
@@ -496,9 +485,7 @@ module Stripe
496
485
  response_block =
497
486
  if block_given?
498
487
  lambda do |response|
499
- unless should_handle_as_error(response.code.to_i)
500
- response.read_body(&read_body_chunk_block)
501
- end
488
+ response.read_body(&read_body_chunk_block) unless should_handle_as_error(response.code.to_i)
502
489
  end
503
490
  end
504
491
 
@@ -520,35 +507,27 @@ module Stripe
520
507
  (api_base || config.api_base) + url
521
508
  end
522
509
 
523
- private def check_keys!(api_key, authenticator)
524
- if api_key && authenticator
525
- raise AuthenticationError, "Can't specify both API key " \
526
- "and authenticator. Either set your API key" \
527
- 'using "Stripe.api_key = <API-KEY>", or set your authenticator ' \
528
- 'using "Stripe.authenticator = <AUTHENTICATOR>"' \
529
- end
530
-
531
- unless api_key || authenticator
532
- # Default to missing API key error message for general users.
510
+ private def check_api_key!(api_key)
511
+ unless api_key
533
512
  raise AuthenticationError, "No API key provided. " \
534
- 'Set your API key using "Stripe.api_key = <API-KEY>". ' \
535
- "You can generate API keys from the Stripe web interface. " \
536
- "See https://stripe.com/api for details, or email " \
537
- "support@stripe.com if you have any questions."
513
+ 'Set your API key using "Stripe.api_key = <API-KEY>". ' \
514
+ "You can generate API keys from the Stripe web interface. " \
515
+ "See https://stripe.com/api for details, or email " \
516
+ "support@stripe.com if you have any questions."
538
517
  end
539
518
 
540
519
  return unless api_key =~ /\s/
541
520
 
542
521
  raise AuthenticationError, "Your API key is invalid, as it contains " \
543
- "whitespace. (HINT: You can double-check your API key from the " \
544
- "Stripe web interface. See https://stripe.com/api for details, or " \
545
- "email support@stripe.com if you have any questions.)"
522
+ "whitespace. (HINT: You can double-check your API key from the " \
523
+ "Stripe web interface. See https://stripe.com/api for details, or " \
524
+ "email support@stripe.com if you have any questions.)"
546
525
  end
547
526
 
548
527
  # Encodes a set of body parameters using multipart if `Content-Type` is set
549
528
  # for that, or standard form-encoding otherwise. Returns the encoded body
550
529
  # and a version of the encoded body that's safe to be logged.
551
- private def encode_body(body_params, headers, api_mode)
530
+ private def encode_body(body_params, headers)
552
531
  body = nil
553
532
  flattened_params = Util.flatten_params(body_params)
554
533
 
@@ -564,22 +543,15 @@ module Stripe
564
543
  flattened_params =
565
544
  flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
566
545
 
567
- elsif api_mode == :preview
568
- body = JSON.generate(body_params)
569
- headers["Content-Type"] = "application/json"
570
546
  else
571
547
  body = Util.encode_parameters(body_params)
572
548
  end
573
549
 
574
- if api_mode == :preview
575
- body_log = body
576
- else
577
- # We don't use `Util.encode_parameters` partly as an optimization (to
578
- # not redo work we've already done), and partly because the encoded
579
- # forms of certain characters introduce a lot of visual noise and it's
580
- # nice to have a clearer format for logs.
581
- body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
582
- end
550
+ # We don't use `Util.encode_parameters` partly as an optimization (to not
551
+ # redo work we've already done), and partly because the encoded forms of
552
+ # certain characters introduce a lot of visual noise and it's nice to
553
+ # have a clearer format for logs.
554
+ body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
583
555
 
584
556
  [body, body_log]
585
557
  end
@@ -605,9 +577,7 @@ module Stripe
605
577
  http_status = resp.code.to_i
606
578
  context = context.dup_from_response_headers(resp)
607
579
 
608
- if should_handle_as_error(http_status)
609
- handle_error_response(resp, context)
610
- end
580
+ handle_error_response(resp, context) if should_handle_as_error(http_status)
611
581
 
612
582
  log_response(context, request_start, http_status, resp.body, resp)
613
583
  notify_request_end(context, request_duration, http_status,
@@ -657,7 +627,7 @@ module Stripe
657
627
 
658
628
  # Only handle errors when we know we can do so, and re-raise otherwise.
659
629
  # This should be pretty infrequent.
660
- else
630
+ else # rubocop:todo Lint/DuplicateBranch
661
631
  raise
662
632
  end
663
633
  end
@@ -768,11 +738,10 @@ module Stripe
768
738
  end
769
739
 
770
740
  private def specific_api_error(resp, error_data, context)
771
- message = error_data[:message]
772
741
  Util.log_error("Stripe API error",
773
742
  status: resp.http_status,
774
743
  error_code: error_data[:code],
775
- error_message: message,
744
+ error_message: error_data[:message],
776
745
  error_param: error_data[:param],
777
746
  error_type: error_data[:type],
778
747
  idempotency_key: context.idempotency_key,
@@ -793,26 +762,26 @@ module Stripe
793
762
  when 400, 404
794
763
  case error_data[:type]
795
764
  when "idempotency_error"
796
- IdempotencyError.new(message, **opts)
765
+ IdempotencyError.new(error_data[:message], **opts)
797
766
  else
798
767
  InvalidRequestError.new(
799
- message, error_data[:param],
768
+ error_data[:message], error_data[:param],
800
769
  **opts
801
770
  )
802
771
  end
803
772
  when 401
804
- AuthenticationError.new(message, **opts)
773
+ AuthenticationError.new(error_data[:message], **opts)
805
774
  when 402
806
775
  CardError.new(
807
- message, error_data[:param],
776
+ error_data[:message], error_data[:param],
808
777
  **opts
809
778
  )
810
779
  when 403
811
- PermissionError.new(message, **opts)
780
+ PermissionError.new(error_data[:message], **opts)
812
781
  when 429
813
- RateLimitError.new(message, **opts)
782
+ RateLimitError.new(error_data[:message], **opts)
814
783
  else
815
- APIError.new(message, **opts)
784
+ APIError.new(error_data[:message], **opts)
816
785
  end
817
786
  end
818
787
 
@@ -868,7 +837,7 @@ module Stripe
868
837
 
869
838
  if errors.nil?
870
839
  message = "Unexpected error #{error.class.name} communicating " \
871
- "with Stripe. Please let us know at support@stripe.com."
840
+ "with Stripe. Please let us know at support@stripe.com."
872
841
  end
873
842
 
874
843
  api_base ||= config.api_base
@@ -880,22 +849,16 @@ module Stripe
880
849
  message + "\n\n(Network error: #{error.message})"
881
850
  end
882
851
 
883
- private def request_headers(api_key, method, api_mode)
852
+ private def request_headers(api_key, method)
884
853
  user_agent = "Stripe/v1 RubyBindings/#{Stripe::VERSION}"
885
- unless Stripe.app_info.nil?
886
- user_agent += " " + format_app_info(Stripe.app_info)
887
- end
854
+ user_agent += " " + format_app_info(Stripe.app_info) unless Stripe.app_info.nil?
888
855
 
889
856
  headers = {
890
857
  "User-Agent" => user_agent,
891
858
  "Authorization" => "Bearer #{api_key}",
859
+ "Content-Type" => "application/x-www-form-urlencoded",
892
860
  }
893
861
 
894
- if api_mode != :preview
895
- # TODO: (major) don't set Content-Type if method is not post
896
- headers["Content-Type"] = "application/x-www-form-urlencoded"
897
- end
898
-
899
862
  if config.enable_telemetry? && !@last_request_metrics.nil?
900
863
  headers["X-Stripe-Client-Telemetry"] = JSON.generate(
901
864
  last_request_metrics: @last_request_metrics.payload
@@ -908,12 +871,7 @@ module Stripe
908
871
  headers["Idempotency-Key"] ||= SecureRandom.uuid
909
872
  end
910
873
 
911
- if api_mode == :preview
912
- headers["Stripe-Version"] = ApiVersion::PREVIEW
913
- elsif config.api_version
914
- headers["Stripe-Version"] = config.api_version
915
- end
916
-
874
+ headers["Stripe-Version"] = config.api_version if config.api_version
917
875
  headers["Stripe-Account"] = config.stripe_account if config.stripe_account
918
876
 
919
877
  user_agent = @system_profiler.user_agent
@@ -996,16 +954,7 @@ module Stripe
996
954
  # that we can log certain information. It's useful because it means that we
997
955
  # don't have to pass around as many parameters.
998
956
  class RequestLogContext
999
- attr_accessor :body
1000
- attr_accessor :account
1001
- attr_accessor :api_key
1002
- attr_accessor :authenticator
1003
- attr_accessor :api_version
1004
- attr_accessor :idempotency_key
1005
- attr_accessor :method
1006
- attr_accessor :path
1007
- attr_accessor :query
1008
- attr_accessor :request_id
957
+ attr_accessor :body, :account, :api_key, :api_version, :idempotency_key, :method, :path, :query, :request_id
1009
958
 
1010
959
  # The idea with this method is that we might want to update some of
1011
960
  # context information because a response that we've received from the API
@@ -25,27 +25,12 @@ module Stripe
25
25
  # If `.logger` is set, the value of `.log_level` is ignored. The decision on
26
26
  # what levels to print is entirely deferred to the logger.
27
27
  class StripeConfiguration
28
- attr_accessor :api_key
29
- attr_accessor :api_version
30
- attr_accessor :authenticator
31
- attr_accessor :client_id
32
- attr_accessor :enable_telemetry
33
- attr_accessor :logger
34
- attr_accessor :stripe_account
35
-
36
- attr_reader :api_base
37
- attr_reader :uploads_base
38
- attr_reader :connect_base
39
- attr_reader :ca_bundle_path
40
- attr_reader :log_level
41
- attr_reader :initial_network_retry_delay
42
- attr_reader :max_network_retries
43
- attr_reader :max_network_retry_delay
44
- attr_reader :open_timeout
45
- attr_reader :read_timeout
46
- attr_reader :write_timeout
47
- attr_reader :proxy
48
- attr_reader :verify_ssl_certs
28
+ attr_accessor :api_key, :api_version, :client_id, :enable_telemetry, :logger, :stripe_account
29
+
30
+ attr_reader :api_base, :uploads_base, :connect_base, :ca_bundle_path, :log_level, :initial_network_retry_delay,
31
+ # rubocop:todo Layout/LineLength
32
+ :max_network_retries, :max_network_retry_delay, :open_timeout, :read_timeout, :write_timeout, :proxy, :verify_ssl_certs
33
+ # rubocop:enable Layout/LineLength
49
34
 
50
35
  def self.setup
51
36
  new.tap do |instance|
@@ -65,7 +50,6 @@ module Stripe
65
50
 
66
51
  def initialize
67
52
  @api_version = ApiVersion::CURRENT
68
-
69
53
  @ca_bundle_path = Stripe::DEFAULT_CA_BUNDLE_PATH
70
54
  @enable_telemetry = true
71
55
  @verify_ssl_certs = true
@@ -97,8 +81,8 @@ module Stripe
97
81
 
98
82
  if !val.nil? && !levels.include?(val)
99
83
  raise ArgumentError,
100
- "log_level should only be set to `nil`, `debug`, `info`," \
101
- " or `error`"
84
+ "log_level should only be set to `nil`, `debug`, `info`, " \
85
+ "or `error`"
102
86
  end
103
87
  @log_level = val
104
88
  end
@@ -126,9 +110,7 @@ module Stripe
126
110
  end
127
111
 
128
112
  def write_timeout=(write_timeout)
129
- unless Net::HTTP.instance_methods.include?(:write_timeout=)
130
- raise NotImplementedError
131
- end
113
+ raise NotImplementedError unless Net::HTTP.instance_methods.include?(:write_timeout=)
132
114
 
133
115
  @write_timeout = write_timeout
134
116
  StripeClient.clear_all_connection_managers(config: self)
@@ -179,10 +161,10 @@ module Stripe
179
161
  # and is itself not thread safe.
180
162
  def ca_store
181
163
  @ca_store ||= begin
182
- store = OpenSSL::X509::Store.new
183
- store.add_file(ca_bundle_path)
184
- store
185
- end
164
+ store = OpenSSL::X509::Store.new
165
+ store.add_file(ca_bundle_path)
166
+ store
167
+ end
186
168
  end
187
169
 
188
170
  def enable_telemetry?
@@ -320,8 +320,8 @@ module Stripe
320
320
  # Here we swallow that error and issue a warning so at least
321
321
  # the program doesn't crash.
322
322
  warn("WARNING: Unable to remove method `#{method_name}`; " \
323
- "if custom, please consider renaming to a name that doesn't " \
324
- "collide with an API property name.")
323
+ "if custom, please consider renaming to a name that doesn't " \
324
+ "collide with an API property name.")
325
325
  end
326
326
  end
327
327
  end
@@ -351,17 +351,15 @@ module Stripe
351
351
  define_method(:"#{k}=") do |v|
352
352
  if v == ""
353
353
  raise ArgumentError, "You cannot set #{k} to an empty string. " \
354
- "We interpret empty strings as nil in requests. " \
355
- "You may set (object).#{k} = nil to delete the property."
354
+ "We interpret empty strings as nil in requests. " \
355
+ "You may set (object).#{k} = nil to delete the property."
356
356
  end
357
357
  @values[k] = Util.convert_to_stripe_object(v, @opts)
358
358
  dirty_value!(@values[k])
359
359
  @unsaved_values.add(k)
360
360
  end
361
361
 
362
- if [FalseClass, TrueClass].include?(values[k].class)
363
- define_method(:"#{k}?") { @values[k] }
364
- end
362
+ define_method(:"#{k}?") { @values[k] } if [FalseClass, TrueClass].include?(values[k].class)
365
363
  end
366
364
  end
367
365
  end
@@ -369,7 +367,6 @@ module Stripe
369
367
  # Disabling the cop because it's confused by the fact that the methods are
370
368
  # protected, but we do define `#respond_to_missing?` just below. Hopefully
371
369
  # this is fixed in more recent Rubocop versions.
372
- # rubocop:disable Style/MissingRespondToMissing
373
370
  protected def method_missing(name, *args)
374
371
  # TODO: only allow setting in updateable classes.
375
372
  if name.to_s.end_with?("=")
@@ -405,16 +402,14 @@ module Stripe
405
402
 
406
403
  raise NoMethodError,
407
404
  e.message + ". HINT: The '#{name}' attribute was set in the " \
408
- "past, however. It was then wiped when refreshing the object " \
409
- "with the result returned by Stripe's API, probably as a " \
410
- "result of a save(). The attributes currently available on " \
411
- "this object are: #{@values.keys.join(', ')}"
405
+ "past, however. It was then wiped when refreshing the object " \
406
+ "with the result returned by Stripe's API, probably as a " \
407
+ "result of a save(). The attributes currently available on " \
408
+ "this object are: #{@values.keys.join(', ')}"
412
409
  end
413
410
  end
414
- # rubocop:enable Style/MissingRespondToMissing
415
-
416
411
  protected def respond_to_missing?(symbol, include_private = false)
417
- @values && @values.key?(symbol) || super
412
+ (@values && @values.key?(symbol)) || super
418
413
  end
419
414
 
420
415
  # Re-initializes the object based on a hash of values (usually one that's
@@ -460,7 +455,8 @@ module Stripe
460
455
  self
461
456
  end
462
457
 
463
- protected def serialize_params_value(value, original, unsaved, force,
458
+ # rubocop:todo Metrics/PerceivedComplexity
459
+ protected def serialize_params_value(value, original, unsaved, force, # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
464
460
  key: nil)
465
461
  if value.nil?
466
462
  ""
@@ -494,8 +490,8 @@ module Stripe
494
490
  value
495
491
  else
496
492
  raise ArgumentError, "Cannot save property `#{key}` containing " \
497
- "an API resource. It doesn't appear to be persisted and is " \
498
- "not marked as `save_with_parent`."
493
+ "an API resource. It doesn't appear to be persisted and is " \
494
+ "not marked as `save_with_parent`."
499
495
  end
500
496
 
501
497
  elsif value.is_a?(Array)
@@ -535,6 +531,7 @@ module Stripe
535
531
  value
536
532
  end
537
533
  end
534
+ # rubocop:enable Metrics/PerceivedComplexity
538
535
 
539
536
  # Produces a deep copy of the given object including support for arrays,
540
537
  # hashes, and StripeObjects.