Skip to content

Commit

Permalink
Merge pull request #412 from Edouard-chin/global-stripe-account-head
Browse files Browse the repository at this point in the history
Allow `stripe_account` to be set globally:
  • Loading branch information
brandur committed Apr 13, 2016
2 parents c98f555 + 75f366a commit 679b2b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module Stripe
@read_timeout = 80

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

attr_reader :max_network_retry_delay, :initial_network_retry_delay
Expand Down Expand Up @@ -278,10 +278,11 @@ def self.request_headers(api_key, method)
# It is only safe to retry network failures on post and delete
# requests if we add an Idempotency-Key header
if [:post, :delete].include?(method) && self.max_network_retries > 0
headers[:idempotency_key] ||= SecureRandom.uuid
headers[:idempotency_key] ||= SecureRandom.uuid
end

headers[:stripe_version] = api_version if api_version
headers[:stripe_account] = stripe_account if stripe_account

begin
headers.update(:x_stripe_client_user_agent => JSON.generate(user_agent))
Expand Down
15 changes: 15 additions & 0 deletions test/stripe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ class StripeTest < Test::Unit::TestCase
Stripe.max_network_retries = old
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

0 comments on commit 679b2b9

Please sign in to comment.