Skip to content

Commit

Permalink
Pass params to transfer reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
prathmesh-stripe committed May 8, 2024
1 parent f538d42 commit 9cc328f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/stripe/api_operations/nested_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions test/stripe/transfer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9cc328f

Please sign in to comment.