lib/stripe/util.rb in stripe-6.3.0 vs lib/stripe/util.rb in stripe-6.4.0

- old
+ new

@@ -88,11 +88,11 @@ url, params, opts ) - Util.convert_to_stripe_object(resp.data, opts) + Util.convert_to_stripe_object_with_params(resp.data, params, opts) end end # Converts a hash of fields or an array of hashes into a +StripeObject+ or # array of +StripeObject+s. These new objects will be created as a concrete @@ -102,22 +102,48 @@ # to being a +StripeObject+. # # ==== Attributes # # * +data+ - Hash of fields and values to be converted into a StripeObject. + # * +params+ - Params for +StripeObject+ like filters used in search that + # will be reused on subsequent API calls. # * +opts+ - Options for +StripeObject+ like an API key that will be reused # on subsequent API calls. def self.convert_to_stripe_object(data, opts = {}) + convert_to_stripe_object_with_params(data, {}, opts) + end + + # Converts a hash of fields or an array of hashes into a +StripeObject+ or + # array of +StripeObject+s. These new objects will be created as a concrete + # type as dictated by their `object` field (e.g. an `object` value of + # `charge` would create an instance of +Charge+), but if `object` is not + # present or of an unknown type, the newly created instance will fall back + # to being a +StripeObject+. + # + # ==== Attributes + # + # * +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 = {}) opts = normalize_opts(opts) case data when Array data.map { |i| convert_to_stripe_object(i, opts) } when Hash # Try converting to a known object class. If none available, fall back # to generic StripeObject - object_classes.fetch(data[:object], StripeObject) - .construct_from(data, opts) + obj = object_classes.fetch(data[:object], StripeObject) + .construct_from(data, opts) + + # set filters so that we can fetch the same limit, expansions, and + # predicates when accessing the next and previous pages + if obj && (obj.is_a?(SearchResultObject) || obj.is_a?(ListObject)) + obj.filters = params.dup + end + + obj else data end end