Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Allow passing in the Stripe API version as an initialiation option
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Odorcic committed Jan 7, 2014
1 parent 1b7ca22 commit 9195de8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/active_merchant/billing/gateways/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def initialize(options = {})
requires!(options, :login)
@api_key = options[:login]
@fee_refund_api_key = options[:fee_refund_login]
@version = options[:version]

super
end

Expand Down Expand Up @@ -258,15 +260,16 @@ def headers(options = {})
:publisher => 'active_merchant'
})

key = options[:key] || @api_key
key = options[:key] || @api_key
version = options[:version] || @version

headers = {
"Authorization" => "Basic " + Base64.encode64(key.to_s + ":").strip,
"User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
"X-Stripe-Client-User-Agent" => @@ua,
"X-Stripe-Client-User-Metadata" => {:ip => options[:ip]}.to_json
}
headers.merge!("Stripe-Version" => options[:version]) if options[:version]
headers.merge!("Stripe-Version" => version) if version
headers
end

Expand Down
9 changes: 9 additions & 0 deletions test/unit/gateways/stripe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ def test_optional_version_header
@gateway.purchase(@amount, @credit_card, @options.merge(:version => '2013-10-29'))
end

def test_initialize_gateway_with_version
@gateway = StripeGateway.new(:login => 'login', :version => '2013-12-03')
@gateway.expects(:ssl_request).once.with {|method, url, post, headers|
headers && headers['Stripe-Version'] == '2013-12-03'
}.returns(successful_purchase_response)

@gateway.purchase(@amount, @credit_card, @options)
end

def test_track_data_and_traditional_should_be_mutually_exclusive
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options)
Expand Down

0 comments on commit 9195de8

Please sign in to comment.