From 9cc328f244858536f2edd2006a1b82c3cea53680 Mon Sep 17 00:00:00 2001 From: Prathmesh Ranaut Date: Wed, 8 May 2024 15:14:37 -0400 Subject: [PATCH] Pass params to transfer reversal --- lib/stripe/api_operations/nested_resource.rb | 24 ++++++++++++++++++-- test/stripe/transfer_test.rb | 11 +++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/stripe/api_operations/nested_resource.rb b/lib/stripe/api_operations/nested_resource.rb index 09b570944..c02fa180e 100644 --- a/lib/stripe/api_operations/nested_resource.rb +++ b/lib/stripe/api_operations/nested_resource.rb @@ -35,6 +35,7 @@ def nested_resource_class_methods(resource, path: nil, operations: nil, end end + # rubocop:disable Metrics/MethodLength private def define_operation( resource, operation, @@ -53,12 +54,30 @@ def nested_resource_class_methods(resource, path: nil, operations: nil, ) end when :retrieve + # TODO: (Major) Split params_or_opts to params and opts and get rid of the complicated way to add params define_singleton_method(:"retrieve_#{resource}") \ - do |id, nested_id, opts = {}| + do |id, nested_id, params_or_opts = {}, definitely_opts = nil| + opts = nil + params = nil + if definitely_opts.nil? + unrecognized_key = params_or_opts.keys.find { |k| !Util::OPTS_USER_SPECIFIED.include?(k) } + if unrecognized_key + raise ArgumentError, + "Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as " \ + "retrieve params? " \ + "If so, you must explicitly pass an opts hash as a third argument. " \ + "For example: .retrieve({#{unrecognized_key}: 'foo'}, {})" + end + + opts = params_or_opts + else + opts = definitely_opts + params = params_or_opts + end request_stripe_object( method: :get, path: send(resource_url_method, id, nested_id), - params: {}, + params: params, opts: opts ) end @@ -96,6 +115,7 @@ def nested_resource_class_methods(resource, path: nil, operations: nil, raise ArgumentError, "Unknown operation: #{operation.inspect}" end end + # rubocop:enable Metrics/MethodLength end end end diff --git a/test/stripe/transfer_test.rb b/test/stripe/transfer_test.rb index e3fb068fc..864b69dc0 100644 --- a/test/stripe/transfer_test.rb +++ b/test/stripe/transfer_test.rb @@ -84,5 +84,16 @@ class TransferTest < Test::Unit::TestCase assert reversals.data.is_a?(Array) end end + + should "retrieve a reversal with expand" do + reversal = Stripe::Transfer.retrieve_reversal( + "tr_123", + "trr_123", + { expand: %w[transfer] }, + {} + ) + assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_123/reversals/trr_123?expand%5B%5D=transfer" + assert reversal.is_a?(Stripe::Reversal) + end end end