mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-12-07 00:00:35 -05:00
Allow stripe_account to be set globally:
- When performing requests on the behalf of a managed account, `stripe_account` option must be passed everytime, this can become redundant - Allowing to set the `stripe_account` globally makes thing easier for wrapping every request in a single method, the same way as it is for defining the `api_key` globally
This commit is contained in:
parent
c98f555aeb
commit
75f366acb9
@ -82,7 +82,7 @@ module Stripe
|
|||||||
@read_timeout = 80
|
@read_timeout = 80
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base,
|
attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base,
|
||||||
:open_timeout, :read_timeout
|
:open_timeout, :read_timeout
|
||||||
|
|
||||||
attr_reader :max_network_retry_delay, :initial_network_retry_delay
|
attr_reader :max_network_retry_delay, :initial_network_retry_delay
|
||||||
@ -278,10 +278,11 @@ module Stripe
|
|||||||
# It is only safe to retry network failures on post and delete
|
# It is only safe to retry network failures on post and delete
|
||||||
# requests if we add an Idempotency-Key header
|
# requests if we add an Idempotency-Key header
|
||||||
if [:post, :delete].include?(method) && self.max_network_retries > 0
|
if [:post, :delete].include?(method) && self.max_network_retries > 0
|
||||||
headers[:idempotency_key] ||= SecureRandom.uuid
|
headers[:idempotency_key] ||= SecureRandom.uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
headers[:stripe_version] = api_version if api_version
|
headers[:stripe_version] = api_version if api_version
|
||||||
|
headers[:stripe_account] = stripe_account if stripe_account
|
||||||
|
|
||||||
begin
|
begin
|
||||||
headers.update(:x_stripe_client_user_agent => JSON.generate(user_agent))
|
headers.update(:x_stripe_client_user_agent => JSON.generate(user_agent))
|
||||||
|
|||||||
@ -33,4 +33,19 @@ class StripeTest < Test::Unit::TestCase
|
|||||||
Stripe.max_network_retries = old
|
Stripe.max_network_retries = old
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "makes requests with the Stripe-Account header" do
|
||||||
|
response = make_account(
|
||||||
|
charges_enabled: false,
|
||||||
|
details_submitted: false,
|
||||||
|
email: "test+bindings@stripe.com"
|
||||||
|
)
|
||||||
|
Stripe.stripe_account = 'acct_1234'
|
||||||
|
|
||||||
|
Stripe.expects(:execute_request).with(
|
||||||
|
has_entry(:headers, has_entry(:stripe_account, 'acct_1234')),
|
||||||
|
).returns(make_response(response))
|
||||||
|
|
||||||
|
Stripe.request(:post, '/v1/account', 'sk_live12334566')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user