Compare commits

..

5 Commits

Author SHA1 Message Date
Pavel Krymets
b063187c61 lints 2023-05-17 13:49:26 -07:00
Pavel Krymets
af07fda46d revert 2023-05-17 13:44:19 -07:00
Pavel Krymets
7f0315e4d6 test fixes 2023-05-17 13:42:45 -07:00
anniel-stripe
5ae2124628
Merge branch 'beta' into pakrym/Add_raw-request 2023-05-17 12:03:13 -07:00
stripe-openapi[bot]
adc0ccf8e7
Update generated code for v309 (#1216)
Co-authored-by: Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>
2023-04-27 09:40:10 -07:00
7 changed files with 137 additions and 104 deletions

View File

@ -1 +1 @@
v305
v309

View File

@ -122,7 +122,7 @@ module Stripe
class Preview
def self._get_default_opts(opts)
{ stripe_version: ApiVersion::PREVIEW, api_mode: :preview }.merge(opts)
{ api_mode: :preview }.merge(opts)
end
def self.get(url, opts = {})

View File

@ -462,8 +462,6 @@ module Stripe
headers = request_headers(api_key, method, api_mode)
.update(Util.normalize_headers(headers))
headers.delete("Content-Type") if api_mode == :preview && body_params.nil?
url = api_url(path, api_base)
# Merge given query parameters with any already encoded in the path.
@ -890,10 +888,13 @@ module Stripe
headers = {
"User-Agent" => user_agent,
"Authorization" => "Bearer #{api_key}",
# TODO: (major) don't set Content-Type if method is not post
"Content-Type" => "application/x-www-form-urlencoded",
}
if api_mode != :preview
# TODO: (major) don't set Content-Type if method is not post
headers["Content-Type"] = "application/x-www-form-urlencoded"
end
if config.enable_telemetry? && !@last_request_metrics.nil?
headers["X-Stripe-Client-Telemetry"] = JSON.generate(
last_request_metrics: @last_request_metrics.payload

View File

@ -1365,6 +1365,17 @@ module Stripe
)
assert_requested :post, "#{Stripe.api_base}/v1/plans"
end
should "support requests with args: amount, currency, interval, product2" do
Stripe::Plan.create(
{
amount: 2000,
currency: "usd",
interval: "month",
product: { name: "My product" },
}
)
assert_requested :post, "#{Stripe.api_base}/v1/plans"
end
end
context "Plan.delete" do
should "support requests with args: id" do

View File

@ -14,7 +14,7 @@ class PreviewTest < Test::Unit::TestCase
resp = Stripe::Preview.get("/v2/accounts/acc_123")
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal nil, req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
assert_equal expected_body, resp.http_body
end
@ -45,7 +45,7 @@ class PreviewTest < Test::Unit::TestCase
resp = Stripe::Preview.delete("/v2/accounts/acc_123")
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal nil, req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
assert_equal expected_body, resp.http_body
end
@ -61,7 +61,7 @@ class PreviewTest < Test::Unit::TestCase
resp = Stripe::Preview.post("/v2/accounts", {}, { stripe_version: stripe_version_override })
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal "application/json", req.headers["Content-Type"]
assert_equal stripe_version_override, req.headers["Stripe-Version"]
assert_equal expected_body, resp.http_body
end
@ -77,7 +77,7 @@ class PreviewTest < Test::Unit::TestCase
Stripe::Preview.post("/v2/accounts", {}, { stripe_context: stripe_context })
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal "application/json", req.headers["Content-Type"]
assert_equal stripe_context, req.headers["Stripe-Context"]
end
end

View File

@ -0,0 +1,112 @@
# frozen_string_literal: true
require ::File.expand_path("../test_helper", __dir__)
class RawRequestTest < Test::Unit::TestCase
context "raw_request" do
should "send get request and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
assert_equal expected_body, resp.http_body
assert_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::CURRENT, req.headers["Stripe-Version"]
end
should "send post request with body and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "p1=1&p2=string")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" })
assert_equal expected_body, resp.http_body
assert_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::CURRENT, req.headers["Stripe-Version"]
end
should "send post request with json body and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "{\"p1\":1,\"p2\":\"string\"}")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview })
assert_equal expected_body, resp.http_body
assert_equal "application/json", req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
end
should "send post request with json body and headers and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "{\"p1\":1,\"p2\":\"string\"}")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview, "Stripe-Context": "bar" })
assert_equal expected_body, resp.http_body
assert_equal "application/json", req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
assert_equal "bar", req.headers["Stripe-Context"]
end
should "send get request with json body and headers and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, "Stripe-Account": "bar" })
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal expected_body, resp.http_body
end
should "set default preview version when api_mode is preview and stripe_version not specified" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview })
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
end
should "allow overriding stripe version when api_mode is preview" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
stripe_version_override = "2023-05-15.preview"
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, stripe_version: stripe_version_override })
assert_equal stripe_version_override, req.headers["Stripe-Version"]
end
end
end

View File

@ -94,14 +94,9 @@ class StripeTest < Test::Unit::TestCase
end
should "allow logger to be configured" do
old_logger = Stripe.logger
begin
logger = Object.new
Stripe.logger = logger
assert_equal logger, Stripe.logger
ensure
Stripe.logger = old_logger
end
logger = Object.new
Stripe.logger = logger
assert_equal logger, Stripe.logger
end
should "allow proxy to be configured" do
@ -140,92 +135,6 @@ class StripeTest < Test::Unit::TestCase
end
end
context "raw_request" do
should "send get request and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.to_return(body: expected_body)
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
assert_equal expected_body, resp.http_body
end
should "send post request with body and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "p1=1&p2=string")
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" })
assert_equal expected_body, resp.http_body
end
should "send post request with json body and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "{\"p1\":1,\"p2\":\"string\"}")
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview })
assert_equal expected_body, resp.http_body
end
should "send post request with json body and headers and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
.with(body: "{\"p1\":1,\"p2\":\"string\"}", headers: { "Stripe-Account" => "bar", "Content-Type" => "application/json" })
.to_return(body: expected_body)
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview, "Stripe-Account": "bar" })
assert_equal expected_body, resp.http_body
end
should "send get request with json body and headers and return a response" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, "Stripe-Account": "bar" })
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal expected_body, resp.http_body
end
should "set default preview version when api_mode is preview and stripe_version not specified" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview })
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
end
should "allow overriding stripe version when api_mode is preview" do
expected_body = "{\"id\": \"acc_123\"}"
req = nil
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
.with { |request| req = request }
.to_return(body: expected_body)
stripe_version_override = "2023-05-15.preview"
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, stripe_version: stripe_version_override })
assert_equal stripe_version_override, req.headers["Stripe-Version"]
end
end
context "deserialize" do
should "deserializes string into known object" do
expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}"