mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-13 00:02:50 -04:00
Compare commits
2 Commits
a0b5b50bc1
...
420218c7a1
Author | SHA1 | Date | |
---|---|---|---|
|
420218c7a1 | ||
|
6cb8102c4f |
@ -120,16 +120,35 @@ module Stripe
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Preview
|
||||||
|
PREVIEW_API_VERSION = "20230509T165653"
|
||||||
|
|
||||||
|
def self._get_default_opts(opts)
|
||||||
|
{ stripe_version: PREVIEW_API_VERSION, encoding: :json }.merge(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get(url, opts = {})
|
||||||
|
Stripe.raw_request(:get, url, {}, _get_default_opts(opts))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.post(url, params = {}, opts = {})
|
||||||
|
Stripe.raw_request(:post, url, params, _get_default_opts(opts))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.delete(url, opts = {})
|
||||||
|
Stripe.raw_request(:delete, url, {}, _get_default_opts(opts))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class RawRequest
|
class RawRequest
|
||||||
include Stripe::APIOperations::Request
|
include Stripe::APIOperations::Request
|
||||||
|
|
||||||
def initialize()
|
def initialize
|
||||||
@opts = {}
|
@opts = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(method, url, params = {}, opts = {})
|
def execute(method, url, params = {}, opts = {})
|
||||||
resp, _ = execute_resource_request(method, url, params, opts)
|
resp, = execute_resource_request(method, url, params, opts)
|
||||||
|
|
||||||
resp
|
resp
|
||||||
end
|
end
|
||||||
|
@ -459,6 +459,9 @@ module Stripe
|
|||||||
|
|
||||||
headers = request_headers(api_key, method)
|
headers = request_headers(api_key, method)
|
||||||
.update(Util.normalize_headers(headers))
|
.update(Util.normalize_headers(headers))
|
||||||
|
|
||||||
|
headers.delete("Content-Type") if encoding == :json && body_params.nil?
|
||||||
|
|
||||||
url = api_url(path, api_base)
|
url = api_url(path, api_base)
|
||||||
|
|
||||||
# Merge given query parameters with any already encoded in the path.
|
# Merge given query parameters with any already encoded in the path.
|
||||||
@ -885,7 +888,7 @@ module Stripe
|
|||||||
headers = {
|
headers = {
|
||||||
"User-Agent" => user_agent,
|
"User-Agent" => user_agent,
|
||||||
"Authorization" => "Bearer #{api_key}",
|
"Authorization" => "Bearer #{api_key}",
|
||||||
"Content-Type" => "application/x-www-form-urlencoded",
|
"Content-Type" => "application/x-www-form-urlencoded", # TODO: (major) don't set if method is not post
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.enable_telemetry? && !@last_request_metrics.nil?
|
if config.enable_telemetry? && !@last_request_metrics.nil?
|
||||||
|
@ -146,7 +146,6 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||||
.to_return(body: expected_body)
|
.to_return(body: expected_body)
|
||||||
|
|
||||||
|
|
||||||
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
|
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
|
||||||
|
|
||||||
assert_equal resp.http_body, expected_body
|
assert_equal resp.http_body, expected_body
|
||||||
@ -163,7 +162,6 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
assert_equal resp.http_body, expected_body
|
assert_equal resp.http_body, expected_body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
should "send post request with json body and return a response" do
|
should "send post request with json body and return a response" do
|
||||||
expected_body = "{\"id\": \"acc_123\"}"
|
expected_body = "{\"id\": \"acc_123\"}"
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||||
@ -178,16 +176,29 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
should "send post request with json body and headers and return a response" do
|
should "send post request with json body and headers and return a response" do
|
||||||
expected_body = "{\"id\": \"acc_123\"}"
|
expected_body = "{\"id\": \"acc_123\"}"
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||||
.with(body: "{\"p1\":1,\"p2\":\"string\"}", headers: { "Stripe-Account" => "bar" })
|
.with(body: "{\"p1\":1,\"p2\":\"string\"}", headers: { "Stripe-Account" => "bar" , "Content-Type" => "application/json"})
|
||||||
.to_return(body: expected_body)
|
.to_return(body: expected_body)
|
||||||
|
|
||||||
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { encoding: :json, "Stripe-Account": "bar" })
|
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { encoding: :json, "Stripe-Account": "bar" })
|
||||||
|
|
||||||
|
assert_equal expected_body, resp.http_body
|
||||||
|
end
|
||||||
|
|
||||||
|
should "send get request with json body" do
|
||||||
|
expected_body = "{\"id\": \"acc_123\"}"
|
||||||
|
req = nil
|
||||||
|
|
||||||
|
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||||
|
.with { |request| req = request; true }
|
||||||
|
.to_return(body: expected_body)
|
||||||
|
|
||||||
|
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { encoding: :json, "Stripe-Account": "bar" })
|
||||||
|
|
||||||
|
assert_not_equal req.headers["Content-Type"], "application/x-www-form-urlencoded"
|
||||||
assert_equal resp.http_body, expected_body
|
assert_equal resp.http_body, expected_body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context "deserialize" do
|
context "deserialize" do
|
||||||
should "deserializes string into known object" do
|
should "deserializes string into known object" do
|
||||||
expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}"
|
expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user