Skip to content

Commit

Permalink
Merge changes from stripe/stripe-ruby master
Browse files Browse the repository at this point in the history
  • Loading branch information
helenye-stripe committed Apr 11, 2024
2 parents 7eea258 + 5eccf34 commit 8558e0e
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 82 deletions.
53 changes: 35 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# Changelog

## 11.0.0 - 2024-04-10
* [#1374](https://github.com/stripe/stripe-ruby/pull/1374)

* This release changes the pinned API version to `2024-04-10`. Please read the [API Upgrade Guide](https://stripe.com/docs/upgrades#2024-04-10) and carefully review the API changes before upgrading.

### ⚠️ Breaking changes

* When no `x-stripe-should-retry` header is set in the response, the library now retries all requests with `status >= 500`, not just non-POST methods.

## 10.15.0 - 2024-04-09
* [#1377](https://github.com/stripe/stripe-ruby/pull/1377) Add last_response to StripeObject
* Users can now retrieve raw response from the returned resource, using the `last_response` property. See [README](https://github.com/stripe/stripe-ruby/blob/master/README.md) for an example.
* [#1372](https://github.com/stripe/stripe-ruby/pull/1372) Update generated code
* Add support for new resources `Entitlements.ActiveEntitlement` and `Entitlements.Feature`
* Add support for `list` and `retrieve` methods on resource `ActiveEntitlement`
* Add support for `create`, `list`, `retrieve`, and `update` methods on resource `Feature`
* [#1366](https://github.com/stripe/stripe-ruby/pull/1366) Move executables to `exe` folder

## 10.15.0-beta.1 - 2024-04-04
* [#1373](https://github.com/stripe/stripe-ruby/pull/1373) Update generated code for beta
* Add support for `update` method on resource `Entitlements.Feature`
* [#1370](https://github.com/stripe/stripe-ruby/pull/1370) Update generated code for beta


## 10.14.0 - 2024-03-28
* [#1369](https://github.com/stripe/stripe-ruby/pull/1369) Update generated code
* Add support for new resources `Billing.MeterEventAdjustment`, `Billing.MeterEvent`, and `Billing.Meter`
Expand Down Expand Up @@ -258,32 +275,32 @@
**⚠️ ACTION REQUIRED: the breaking change in this release likely affects you ⚠️**

* [#1253](https://github.com/stripe/stripe-ruby/pull/1253) [#1260](https://github.com/stripe/stripe-ruby/pull/1260) Pin latest API version as the default

In this release, Stripe API Version `2023-08-16` (the latest at time of release) will be sent by default on all requests. This is a significant change with wide ramifications. The API version affects the properties you see on responses, the parameters you are allowed to send on requests, and so on. The previous default was to use your [Stripe account's default API version](https://stripe.com/docs/development/dashboard/request-logs#view-your-default-api-version).

To successfully upgrade to stripe-ruby v9, you must either

1. **(Recommended) Upgrade your integration to be compatible with API Version `2023-08-16`.**

Please read the API Changelog carefully for each API Version from `2023-08-16` back to your [Stripe account's default API version](https://stripe.com/docs/development/dashboard/request-logs#view-your-default-api-version). Determine if you are using any of the APIs that have changed in a breaking way, and adjust your integration accordingly. Carefully test your changes with Stripe [Test Mode](https://stripe.com/docs/keys#test-live-modes) before deploying them to production.

You can read the [v9 migration guide](https://github.com/stripe/stripe-ruby/wiki/Migration-guide-for-v9) for more detailed instructions.
2. **(Alternative option) Specify a version other than `2023-08-16` when initializing `stripe-ruby`.**

If you were previously initializing stripe-ruby without an explicit API Version, you can postpone modifying your integration by specifying a version equal to your [Stripe account's default API version](https://stripe.com/docs/development/dashboard/request-logs#view-your-default-api-version). For example:

```diff
require 'stripe'
Stripe.api_key = "sk_test_..."
+ Stripe.api_version = '2020-08-27'
```

If you were already initializing stripe-ruby with an explicit API Version, upgrading to v9 will not affect your integration.

Read the [v9 migration guide](https://github.com/stripe/stripe-ruby/wiki/Migration-guide-for-v9) for more details.

Going forward, each major release of this library will be *pinned* by default to the latest Stripe API Version at the time of release.

That is, instead of upgrading stripe-ruby and separately upgrading your Stripe API Version through the Stripe Dashboard. whenever you upgrade major versions of stripe-ruby, you should also upgrade your integration to be compatible with the latest Stripe API version.

## 9.0.0-beta.1 - 2023-08-24
Expand Down Expand Up @@ -339,7 +356,7 @@

* [#1225](https://github.com/stripe/stripe-ruby/pull/1225) Downgrade jaro_winkler
* [#1219](https://github.com/stripe/stripe-ruby/pull/1219) Update generated code

Documentation updates.
* [#1215](https://github.com/stripe/stripe-ruby/pull/1215) Update generated code

Expand Down Expand Up @@ -567,7 +584,7 @@ Breaking changes that arose during code generation of the library that we postpo
* [#1072](https://github.com/stripe/stripe-ruby/pull/1072) Trigger workflows on beta branches
* [#1071](https://github.com/stripe/stripe-ruby/pull/1071) Use request_stripe_object for all requests
* [#1070](https://github.com/stripe/stripe-ruby/pull/1070) API Updates

Switch from using meta-programing to generating explicit methods for custom methods.
* [#1069](https://github.com/stripe/stripe-ruby/pull/1069) chore: Stop special implementation of Account.persons method.

Expand All @@ -587,9 +604,9 @@ Breaking changes that arose during code generation of the library that we postpo
## 6.0.0 - 2022-05-09
* [#1056](https://github.com/stripe/stripe-ruby/pull/1056) API Updates
Major version release. The [migration guide](https://github.com/stripe/stripe-ruby/wiki/Migration-Guide-for-v6) contains more information.

(⚠️ = breaking changes):
* ⚠️ Replace the legacy `Order` API with the new `Order` API.
* ⚠️ Replace the legacy `Order` API with the new `Order` API.
* New methods: `cancel`, `list_line_items`, `reopen`, and `submit`
* Removed methods: `pay` and `return_order`
* Removed resources: `OrderItem` and `OrderReturn`
Expand All @@ -608,7 +625,7 @@ Breaking changes that arose during code generation of the library that we postpo
* Add support for `expire` test helper method on resource `Refund`

## 5.52.0 - 2022-04-18
* [#1046](https://github.com/stripe/stripe-ruby/pull/1046) [#1047](https://github.com/stripe/stripe-ruby/pull/1047) API Updates
* [#1046](https://github.com/stripe/stripe-ruby/pull/1046) [#1047](https://github.com/stripe/stripe-ruby/pull/1047) API Updates
* Add support for new resources `FundingInstructions` and `Terminal.Configuration`

## 5.51.0 - 2022-04-15
Expand All @@ -630,7 +647,7 @@ Breaking changes that arose during code generation of the library that we postpo
* [#1040](https://github.com/stripe/stripe-ruby/pull/1040) API Updates
* Add support for Search API
* Add support for `search` method on resources `Charge`, `Customer`, `Invoice`, `PaymentIntent`, `Price`, `Product`, and `Subscription`

* [#1034](https://github.com/stripe/stripe-ruby/pull/1034) Add supporting classes for test helper generation

## 5.46.0 - 2022-03-23
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ update-version:

codegen-format:
bundle install --quiet
bundle exec rubocop -o /dev/null --autocorrect
bundle exec rubocop --autocorrect

ci-test:
bundle install && bundle exec rake test
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v923
v923
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@ puts customer.unknown # raises NoMethodError

### Accessing a response object

Get access to response objects by initializing a client and using its `request`
method:
Get access to response objects by using the `last_response` property of the returned resource:

```ruby
client = Stripe::StripeClient.new
customer, resp = client.request do
Stripe::Customer.retrieve('cus_123456789',)
end
puts resp.request_id
customer = Stripe::Customer.retrieve('cus_123456789')

print(customer.last_response.http_status) # to retrieve status code
print(customer.last_response.http_headers) # to retrieve headers
```

### Configuring a proxy
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/stripe/api_operations/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute_resource_request_stream(method, url,

private def request_stripe_object(method:, path:, params:, opts: {}, usage: [])
resp, opts = execute_resource_request(method, path, params, opts, usage)
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
end

private def execute_resource_request_internal(client_request_method_sym,
Expand Down Expand Up @@ -130,7 +130,7 @@ def self.included(base)

private def request_stripe_object(method:, path:, params:, opts: {}, usage: [])
resp, opts = execute_resource_request(method, path, params, opts, usage)
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
end

# See notes on `alias` above.
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/api_operations/save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def save(params = {}, opts = {})
values.delete(:id)

resp, opts = execute_resource_request(:post, save_url, values, opts, ["save"])
initialize_from(resp.data, opts)
initialize_from(resp.data, opts, resp)
end
extend Gem::Deprecate
deprecate :save, "the `update` class method (for examples " \
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/api_operations/singleton_save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def save(params = {}, opts = {})
values = serialize_params(self).merge(params)

resp, opts = execute_resource_request(:post, resource_url, values, opts, ["save"])
initialize_from(resp.data, opts)
initialize_from(resp.data, opts, resp)
end
extend Gem::Deprecate
deprecate :save, "the `update` class method (for examples " \
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def resource_url
def refresh
resp, opts = execute_resource_request(:get, resource_url,
@retrieve_params)
initialize_from(resp.data, opts)
initialize_from(resp.data, opts, resp)
end

def self.retrieve(id, opts = {})
Expand All @@ -104,9 +104,9 @@ def request_stripe_object(method:, path:, params:, opts: {})

# If we're getting back this thing, update; otherwise, instantiate.
if Util.object_name_matches_class?(resp.data[:object], self.class)
initialize_from(resp.data, opts)
initialize_from(resp.data, opts, resp)
else
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/stripe/object_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.object_names_to_classes
SearchResultObject.object_name => SearchResultObject,
File.object_name_alt => File,

# The beginning of the section generated from our OpenAPI spec
# object classes: The beginning of the section generated from our OpenAPI spec
Account.object_name => Account,
AccountLink.object_name => AccountLink,
AccountNotice.object_name => AccountNotice,
Expand Down Expand Up @@ -155,7 +155,7 @@ def self.object_names_to_classes
UsageRecord.object_name => UsageRecord,
UsageRecordSummary.object_name => UsageRecordSummary,
WebhookEndpoint.object_name => WebhookEndpoint,
# The end of the section generated from our OpenAPI spec
# object classes: The end of the section generated from our OpenAPI spec
}
end
end
Expand Down
20 changes: 8 additions & 12 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def self.default_connection_manager(config = Stripe.config)
# both socket errors that may represent an intermittent problem and some
# special HTTP statuses.
def self.should_retry?(error,
method:, num_retries:, config: Stripe.config)
num_retries:, config: Stripe.config)
return false if num_retries >= config.max_network_retries

case error
Expand Down Expand Up @@ -143,15 +143,12 @@ def self.should_retry?(error,
# These 429s are safe to retry.
return true if error.http_status == 429 && error.code == "lock_timeout"

# 500 Internal Server Error
# Retry on 500, 503, and other internal errors.
#
# We only bother retrying these for non-POST requests. POSTs end up
# being cached by the idempotency layer so there's no purpose in
# retrying them.
return true if error.http_status == 500 && method != :post

# 503 Service Unavailable
error.http_status == 503
# Note that we expect the stripe-should-retry header to be false
# in most cases when a 500 is returned, since our idempotency framework
# would typically replay it anyway.
true if error.http_status >= 500
else
false
end
Expand Down Expand Up @@ -498,7 +495,7 @@ def self.maybe_gc_connection_managers
end

http_resp =
execute_request_with_rescues(method, api_base, headers, usage, context) do
execute_request_with_rescues(api_base, headers, usage, context) do
self.class
.default_connection_manager(config)
.execute_request(method, url,
Expand Down Expand Up @@ -583,7 +580,7 @@ def self.maybe_gc_connection_managers
http_status >= 400
end

private def execute_request_with_rescues(method, api_base, headers, usage, context)
private def execute_request_with_rescues(api_base, headers, usage, context)
num_retries = 0

begin
Expand Down Expand Up @@ -634,7 +631,6 @@ def self.maybe_gc_connection_managers
user_data, resp, headers)

if self.class.should_retry?(e,
method: method,
num_retries: num_retries,
config: config)
num_retries += 1
Expand Down
11 changes: 8 additions & 3 deletions lib/stripe/stripe_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Stripe
class StripeObject
include Enumerable

attr_reader :last_response

@@permanent_attributes = Set.new([:id]) # rubocop:disable Style/ClassVars

# The default :id method is deprecated and isn't useful to us
Expand Down Expand Up @@ -80,13 +82,14 @@ def initialize(id = nil, opts = {})
@unsaved_values = Set.new
@transient_values = Set.new
@values[:id] = id if id
@last_response = nil
end

def self.construct_from(values, opts = {})
def self.construct_from(values, opts = {}, last_response = nil)
values = Stripe::Util.symbolize_names(values)

# work around protected #initialize_from for now
new(values[:id]).send(:initialize_from, values, opts)
new(values[:id]).send(:initialize_from, values, opts, last_response)
end

# Determines the equality of two Stripe objects. Stripe objects are
Expand Down Expand Up @@ -424,7 +427,9 @@ class << self; self; end
# * +:opts:+ Options for StripeObject like an API key.
# * +:partial:+ Indicates that the re-initialization should not attempt to
# remove accessors.
protected def initialize_from(values, opts)
protected def initialize_from(values, opts, last_response = nil)
@last_response = last_response

@opts = Util.normalize_opts(opts)

# the `#send` is here so that we can keep this method private
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def self.custom_method(resource, target, name, http_verb, http_path)
opts
)

Util.convert_to_stripe_object_with_params(resp.data, params, opts)
Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
end
end

Expand Down Expand Up @@ -125,7 +125,7 @@ def self.convert_to_stripe_object(data, opts = {})
# * +data+ - Hash of fields and values to be converted into a StripeObject.
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
# on subsequent API calls.
def self.convert_to_stripe_object_with_params(data, params, opts = {})
def self.convert_to_stripe_object_with_params(data, params, opts = {}, last_response = nil)
opts = normalize_opts(opts)

case data
Expand All @@ -136,7 +136,7 @@ def self.convert_to_stripe_object_with_params(data, params, opts = {})
# to generic StripeObject
object_name = data[:object] || data["object"]
obj = object_classes.fetch(object_name, StripeObject)
.construct_from(data, opts)
.construct_from(data, opts, last_response)

# set filters so that we can fetch the same limit, expansions, and
# predicates when accessing the next and previous pages
Expand Down
9 changes: 4 additions & 5 deletions stripe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ Gem::Specification.new do |s|
/\A\.rubocop/,
/\A\.travis.yml/,
/\A\.vscode/,
%r{\A(bin/tapioca)},
/\Abin/,
/\Asorbet/,
/\Atest/
)
s.files = `git ls-files`.split("\n").reject { |f| ignored.match(f) }
s.executables = `git ls-files -- bin/*`.split("\n")
.map { |f| File.basename(f) }
.reject { |f| f == "tapioca" }
s.files = `git ls-files`.split("\n").grep_v(ignored)
s.bindir = "exe"
s.executables = `git ls-files -- exe/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ["lib"]
end

0 comments on commit 8558e0e

Please sign in to comment.