mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-04 00:00:47 -04:00
⚠️ Drop support for Ruby < 2.6 & clarify version policy (#1684)
* update version requirements * linting * Fix linting * add ci comment * remove unused block
This commit is contained in:
parent
3919242336
commit
fd4368dbb8
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -46,7 +46,8 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, jruby-9.4.0.0, truffleruby-head]
|
# following https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
|
||||||
|
ruby-version: [2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, jruby-9.4.0.0, truffleruby-head]
|
||||||
steps:
|
steps:
|
||||||
- uses: extractions/setup-just@v2
|
- uses: extractions/setup-just@v2
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
17
.rubocop.yml
17
.rubocop.yml
@ -2,7 +2,8 @@ inherit_from: .rubocop_todo.yml
|
|||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
DisplayCopNames: true
|
DisplayCopNames: true
|
||||||
TargetRubyVersion: 2.3
|
TargetRubyVersion: 2.6
|
||||||
|
SuggestExtensions: false
|
||||||
|
|
||||||
Layout/CaseIndentation:
|
Layout/CaseIndentation:
|
||||||
EnforcedStyle: end
|
EnforcedStyle: end
|
||||||
@ -72,14 +73,6 @@ Metrics/MethodLength:
|
|||||||
- initialize
|
- initialize
|
||||||
- inner_class_types
|
- inner_class_types
|
||||||
|
|
||||||
# TODO(xavdid): remove this once the first `basil` release is out
|
|
||||||
Naming/MethodName:
|
|
||||||
# these endpoints are removed soon so we pulled their overrides, meaning their names are wrong
|
|
||||||
# that won't make it out to users, but it's breaking linting/formatting in the meantime
|
|
||||||
Exclude:
|
|
||||||
- "lib/stripe/services/invoice_service.rb"
|
|
||||||
- "lib/stripe/resources/invoice.rb"
|
|
||||||
|
|
||||||
Metrics/ModuleLength:
|
Metrics/ModuleLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
@ -122,6 +115,9 @@ Style/HashTransformKeys:
|
|||||||
|
|
||||||
Style/HashTransformValues:
|
Style/HashTransformValues:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
Exclude:
|
||||||
|
# RUN_DEVSDK-1956
|
||||||
|
- "lib/stripe/api_requestor.rb"
|
||||||
|
|
||||||
Style/NumericPredicate:
|
Style/NumericPredicate:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
@ -266,6 +262,9 @@ Style/MapCompactWithConditionalBlock: # new in 1.30
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
Style/MapToHash: # new in 1.24
|
Style/MapToHash: # new in 1.24
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
Exclude:
|
||||||
|
# RUN_DEVSDK-1956
|
||||||
|
- "lib/stripe/api_requestor.rb"
|
||||||
Style/MapToSet: # new in 1.42
|
Style/MapToSet: # new in 1.42
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Style/MinMaxComparison: # new in 1.42
|
Style/MinMaxComparison: # new in 1.42
|
||||||
|
@ -37,7 +37,9 @@ gem build stripe.gemspec
|
|||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
- Ruby 2.3+.
|
Per our [Language Version Support Policy](https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy), we currently support **Ruby 2.6+**.
|
||||||
|
|
||||||
|
Support for Ruby 2.6 and 2.7 is deprecated and will be removed in upcoming major versions. Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
|
||||||
|
|
||||||
### Bundler
|
### Bundler
|
||||||
|
|
||||||
@ -55,8 +57,7 @@ gem 'stripe'
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The library needs to be configured with your account's secret key which is
|
The library needs to be configured with your account's secret key which is
|
||||||
available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
|
available in your [Stripe Dashboard][api-keys]. Initialize a new client with your API key:
|
||||||
value:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require 'stripe'
|
require 'stripe'
|
||||||
|
@ -572,8 +572,10 @@ module Stripe
|
|||||||
headers["Content-Type"] = content_type
|
headers["Content-Type"] = content_type
|
||||||
|
|
||||||
# `#to_s` any complex objects like files and the like to build output
|
# `#to_s` any complex objects like files and the like to build output
|
||||||
# that's more condusive to logging.
|
# that's more conducive to logging.
|
||||||
flattened_params =
|
flattened_params =
|
||||||
|
# https://go/j/RUN_DEVSDK-1956 - this is probably a bug
|
||||||
|
# once fixed, you can remove the exclusions referencing this ticket in .rubocop.yml
|
||||||
flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
|
flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
|
||||||
|
|
||||||
elsif api_mode == :v2
|
elsif api_mode == :v2
|
||||||
|
@ -132,9 +132,7 @@ module Stripe
|
|||||||
|
|
||||||
# Get options that are copyable from StripeObject to StripeObject
|
# Get options that are copyable from StripeObject to StripeObject
|
||||||
def self.copyable(req_opts)
|
def self.copyable(req_opts)
|
||||||
req_opts.select do |k, _v|
|
req_opts.slice(*RequestOptions::OPTS_COPYABLE)
|
||||||
RequestOptions::OPTS_COPYABLE.include?(k)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,7 +43,7 @@ module Stripe
|
|||||||
connect_base: connect_base,
|
connect_base: connect_base,
|
||||||
meter_events_base: meter_events_base,
|
meter_events_base: meter_events_base,
|
||||||
client_id: client_id,
|
client_id: client_id,
|
||||||
}.reject { |_k, v| v.nil? }
|
}.compact
|
||||||
|
|
||||||
config = StripeConfiguration.client_init(config_opts)
|
config = StripeConfiguration.client_init(config_opts)
|
||||||
@requestor = APIRequestor.new(config)
|
@requestor = APIRequestor.new(config)
|
||||||
|
@ -45,12 +45,7 @@ module Stripe
|
|||||||
imported_options = USER_CONFIGURABLE_GLOBAL_OPTIONS - StripeClient::CLIENT_OPTIONS
|
imported_options = USER_CONFIGURABLE_GLOBAL_OPTIONS - StripeClient::CLIENT_OPTIONS
|
||||||
client_config = StripeConfiguration.setup do |instance|
|
client_config = StripeConfiguration.setup do |instance|
|
||||||
imported_options.each do |key|
|
imported_options.each do |key|
|
||||||
begin
|
|
||||||
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
|
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
|
||||||
rescue NotImplementedError => e
|
|
||||||
# In Ruby <= 2.5, we can't set write_timeout on Net::HTTP, log an error and continue
|
|
||||||
Util.log_error("Failed to set #{key} on client configuration: #{e}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
client_config.reverse_duplicate_merge(config_opts)
|
client_config.reverse_duplicate_merge(config_opts)
|
||||||
|
@ -202,8 +202,8 @@ module Stripe
|
|||||||
value.respond_to?(:to_hash) ? value.to_hash : value
|
value.respond_to?(:to_hash) ? value.to_hash : value
|
||||||
end
|
end
|
||||||
|
|
||||||
@values.each_with_object({}) do |(key, value), acc|
|
@values.transform_values do |value|
|
||||||
acc[key] = case value
|
case value
|
||||||
when Array
|
when Array
|
||||||
value.map(&maybe_to_hash)
|
value.map(&maybe_to_hash)
|
||||||
else
|
else
|
||||||
@ -273,7 +273,7 @@ module Stripe
|
|||||||
|
|
||||||
# a `nil` that makes it out of `#serialize_params_value` signals an empty
|
# a `nil` that makes it out of `#serialize_params_value` signals an empty
|
||||||
# value that we shouldn't appear in the serialized form of the object
|
# value that we shouldn't appear in the serialized form of the object
|
||||||
update_hash.reject! { |_, v| v.nil? }
|
update_hash.compact!
|
||||||
|
|
||||||
update_hash
|
update_hash
|
||||||
end
|
end
|
||||||
|
@ -328,7 +328,7 @@ module Stripe
|
|||||||
def self.valid_variable_name?(key)
|
def self.valid_variable_name?(key)
|
||||||
return false if key.empty? || key[0] !~ LEGAL_FIRST_CHARACTER
|
return false if key.empty? || key[0] !~ LEGAL_FIRST_CHARACTER
|
||||||
|
|
||||||
key[1..-1].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
|
key[1..].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_string_argument!(key)
|
def self.check_string_argument!(key)
|
||||||
@ -428,7 +428,7 @@ module Stripe
|
|||||||
private_class_method :level_name
|
private_class_method :level_name
|
||||||
|
|
||||||
def self.log_internal(message, data = {}, color:, level:, logger:, out:)
|
def self.log_internal(message, data = {}, color:, level:, logger:, out:)
|
||||||
data_str = data.reject { |_k, v| v.nil? }
|
data_str = data.compact
|
||||||
.map do |(k, v)|
|
.map do |(k, v)|
|
||||||
format("%<key>s=%<value>s",
|
format("%<key>s=%<value>s",
|
||||||
key: colorize(k, color, logger.nil? && !out.nil? && out.isatty),
|
key: colorize(k, color, logger.nil? && !out.nil? && out.isatty),
|
||||||
|
@ -7,7 +7,7 @@ require "stripe/version"
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "stripe"
|
s.name = "stripe"
|
||||||
s.version = Stripe::VERSION
|
s.version = Stripe::VERSION
|
||||||
s.required_ruby_version = ">= 2.3.0"
|
s.required_ruby_version = ">= 2.6.0"
|
||||||
s.summary = "Ruby bindings for the Stripe API"
|
s.summary = "Ruby bindings for the Stripe API"
|
||||||
s.description = "Stripe is the easiest way to accept payments online. " \
|
s.description = "Stripe is the easiest way to accept payments online. " \
|
||||||
"See https://stripe.com for details."
|
"See https://stripe.com for details."
|
||||||
|
@ -728,7 +728,6 @@ module Stripe
|
|||||||
|
|
||||||
context "Stripe-Account header" do
|
context "Stripe-Account header" do
|
||||||
should "use a globally set header" do
|
should "use a globally set header" do
|
||||||
begin
|
|
||||||
old = Stripe.stripe_account
|
old = Stripe.stripe_account
|
||||||
Stripe.stripe_account = "acct_1234"
|
Stripe.stripe_account = "acct_1234"
|
||||||
|
|
||||||
@ -740,7 +739,6 @@ module Stripe
|
|||||||
ensure
|
ensure
|
||||||
Stripe.stripe_account = old
|
Stripe.stripe_account = old
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "use a local request set header" do
|
should "use a local request set header" do
|
||||||
stripe_account = "acct_0000"
|
stripe_account = "acct_0000"
|
||||||
@ -798,7 +796,6 @@ module Stripe
|
|||||||
|
|
||||||
context "app_info" do
|
context "app_info" do
|
||||||
should "send app_info if set" do
|
should "send app_info if set" do
|
||||||
begin
|
|
||||||
old = Stripe.app_info
|
old = Stripe.app_info
|
||||||
Stripe.set_app_info(
|
Stripe.set_app_info(
|
||||||
"MyAwesomePlugin",
|
"MyAwesomePlugin",
|
||||||
@ -834,7 +831,6 @@ module Stripe
|
|||||||
Stripe.app_info = old
|
Stripe.app_info = old
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "error handling" do
|
context "error handling" do
|
||||||
should "handle error response with empty body" do
|
should "handle error response with empty body" do
|
||||||
@ -1361,7 +1357,6 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "reset local thread state after a call" do
|
should "reset local thread state after a call" do
|
||||||
begin
|
|
||||||
APIRequestor.current_thread_context.active_requestor = :api_requestor
|
APIRequestor.current_thread_context.active_requestor = :api_requestor
|
||||||
|
|
||||||
client = APIRequestor.new("sk_test_123")
|
client = APIRequestor.new("sk_test_123")
|
||||||
@ -1372,7 +1367,6 @@ module Stripe
|
|||||||
ensure
|
ensure
|
||||||
APIRequestor.current_thread_context.active_requestor = nil
|
APIRequestor.current_thread_context.active_requestor = nil
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "correctly return last responses despite multiple clients" do
|
should "correctly return last responses despite multiple clients" do
|
||||||
charge_resp = { object: "charge" }
|
charge_resp = { object: "charge" }
|
||||||
@ -1468,7 +1462,6 @@ module Stripe
|
|||||||
|
|
||||||
context "#proxy" do
|
context "#proxy" do
|
||||||
should "run the request through the proxy" do
|
should "run the request through the proxy" do
|
||||||
begin
|
|
||||||
APIRequestor.clear_all_connection_managers
|
APIRequestor.clear_all_connection_managers
|
||||||
|
|
||||||
Stripe.proxy = "http://user:pass@localhost:8080"
|
Stripe.proxy = "http://user:pass@localhost:8080"
|
||||||
@ -1488,7 +1481,6 @@ module Stripe
|
|||||||
APIRequestor.clear_all_connection_managers
|
APIRequestor.clear_all_connection_managers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "#telemetry" do
|
context "#telemetry" do
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -126,7 +126,7 @@ module Stripe
|
|||||||
@client_opts[:api_key] = "client_test_123"
|
@client_opts[:api_key] = "client_test_123"
|
||||||
@client_opts[:stripe_account] = "client_acct_123"
|
@client_opts[:stripe_account] = "client_acct_123"
|
||||||
@client_opts[:uploads_base] = "client_uploads_base.stripe.com"
|
@client_opts[:uploads_base] = "client_uploads_base.stripe.com"
|
||||||
@client_opts.reject! { |_k, v| v.nil? }
|
@client_opts.compact!
|
||||||
|
|
||||||
client_config = Stripe::StripeConfiguration.client_init(@client_opts)
|
client_config = Stripe::StripeConfiguration.client_init(@client_opts)
|
||||||
|
|
||||||
|
@ -159,7 +159,6 @@ module Stripe
|
|||||||
|
|
||||||
context "#to_hash" do
|
context "#to_hash" do
|
||||||
should "skip calling to_hash on nil" do
|
should "skip calling to_hash on nil" do
|
||||||
begin
|
|
||||||
module NilWithToHash
|
module NilWithToHash
|
||||||
def to_hash
|
def to_hash
|
||||||
raise "Can't call to_hash on nil"
|
raise "Can't call to_hash on nil"
|
||||||
@ -174,7 +173,6 @@ module Stripe
|
|||||||
ensure
|
ensure
|
||||||
::NilClass.send(:undef_method, :to_hash)
|
::NilClass.send(:undef_method, :to_hash)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "recursively call to_hash on its values" do
|
should "recursively call to_hash on its values" do
|
||||||
# deep nested hash (when contained in an array) or StripeObject
|
# deep nested hash (when contained in an array) or StripeObject
|
||||||
|
@ -4,7 +4,6 @@ require File.expand_path("test_helper", __dir__)
|
|||||||
|
|
||||||
class StripeTest < Test::Unit::TestCase
|
class StripeTest < Test::Unit::TestCase
|
||||||
should "allow app_info to be configured" do
|
should "allow app_info to be configured" do
|
||||||
begin
|
|
||||||
old = Stripe.app_info
|
old = Stripe.app_info
|
||||||
Stripe.set_app_info(
|
Stripe.set_app_info(
|
||||||
"MyAwesomePlugin",
|
"MyAwesomePlugin",
|
||||||
@ -21,7 +20,6 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
ensure
|
ensure
|
||||||
Stripe.app_info = old
|
Stripe.app_info = old
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "forwardable configurations" do
|
context "forwardable configurations" do
|
||||||
context "internal configurations" do
|
context "internal configurations" do
|
||||||
@ -78,7 +76,6 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "allow enable_telemetry to be configured" do
|
should "allow enable_telemetry to be configured" do
|
||||||
begin
|
|
||||||
old = Stripe.enable_telemetry?
|
old = Stripe.enable_telemetry?
|
||||||
|
|
||||||
Stripe.enable_telemetry = false
|
Stripe.enable_telemetry = false
|
||||||
@ -86,7 +83,6 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
ensure
|
ensure
|
||||||
Stripe.enable_telemetry = old
|
Stripe.enable_telemetry = old
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "allow log_level to be configured" do
|
should "allow log_level to be configured" do
|
||||||
Stripe.log_level = "debug"
|
Stripe.log_level = "debug"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user