Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding of arrays that are sent in query strings #612

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ def execute_request(method, path,
url = api_url(path, api_base)

body = nil
query_string = nil
query_params = nil

case method.to_s.downcase.to_sym
when :get, :head, :delete
query_string = Util.encode_parameters(params) if params && params.any?
url += "#{URI.parse(url).query ? '&' : '?'}#{query_string}" unless query_string.nil?
query_params = params
else
body = if headers[:content_type] && headers[:content_type] == "multipart/form-data"
params
Expand All @@ -148,12 +147,13 @@ def execute_request(method, path,
context.idempotency_key = headers["Idempotency-Key"]
context.method = method
context.path = path
context.query_string = query_string
context.query_params = query_params ? Util.encode_parameters(query_params) : nil

http_resp = execute_request_with_rescues(api_base, context) do
conn.run_request(method, url, body, headers) do |req|
req.options.open_timeout = Stripe.open_timeout
req.options.timeout = Stripe.read_timeout
req.params = query_params unless query_params.nil?
end
end

Expand Down Expand Up @@ -443,7 +443,7 @@ def log_request(context, num_retries)
Util.log_debug("Request details",
body: context.body,
idempotency_key: context.idempotency_key,
query_string: context.query_string)
query_params: context.query_params)
end
private :log_request

Expand Down Expand Up @@ -492,7 +492,7 @@ class RequestLogContext
attr_accessor :idempotency_key
attr_accessor :method
attr_accessor :path
attr_accessor :query_string
attr_accessor :query_params
attr_accessor :request_id

# The idea with this method is that we might want to update some of
Expand Down
5 changes: 3 additions & 2 deletions test/stripe/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class InvoiceTest < Test::Unit::TestCase
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
query: {
customer: "cus_123",
:'subscription_items[][plan]' => "gold",
:'subscription_items[][quantity]' => 2,
subscription_items: [
{ plan: "gold", quantity: "2" },
],
}
assert invoice.is_a?(Stripe::Invoice)
end
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class StripeClientTest < Test::Unit::TestCase
Util.expects(:log_debug).with("Request details",
body: "",
idempotency_key: "abc",
query_string: nil)
query_params: nil)

Util.expects(:log_info).with("Response from Stripe API",
account: "acct_123",
Expand Down