mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-09 00:03:05 -04:00
Merge pull request #183 from stripe/per-request-headers
Add per-request headers
This commit is contained in:
commit
100c522a32
@ -2,8 +2,8 @@ module Stripe
|
|||||||
module APIOperations
|
module APIOperations
|
||||||
module Create
|
module Create
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def create(params={}, api_key=nil)
|
def create(params={}, api_key=nil, headers={})
|
||||||
response, api_key = Stripe.request(:post, self.url, api_key, params)
|
response, api_key = Stripe.request(:post, self.url, api_key, params, headers)
|
||||||
Util.convert_to_stripe_object(response, api_key)
|
Util.convert_to_stripe_object(response, api_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Stripe
|
module Stripe
|
||||||
module APIOperations
|
module APIOperations
|
||||||
module Delete
|
module Delete
|
||||||
def delete(params = {})
|
def delete(params = {}, api_key=nil, headers={})
|
||||||
response, api_key = Stripe.request(:delete, url, @api_key, params)
|
response, api_key = Stripe.request(:delete, url, api_key, params, headers)
|
||||||
refresh_from(response, api_key)
|
refresh_from(response, api_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,8 @@ module Stripe
|
|||||||
module APIOperations
|
module APIOperations
|
||||||
module List
|
module List
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def all(filters={}, api_key=nil)
|
def all(filters={}, api_key=nil, headers={})
|
||||||
response, api_key = Stripe.request(:get, url, api_key, filters)
|
response, api_key = Stripe.request(:get, url, api_key, filters, headers)
|
||||||
Util.convert_to_stripe_object(response, api_key)
|
Util.convert_to_stripe_object(response, api_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,18 +4,18 @@ module Stripe
|
|||||||
include Stripe::APIOperations::Create
|
include Stripe::APIOperations::Create
|
||||||
include Stripe::APIOperations::Update
|
include Stripe::APIOperations::Update
|
||||||
|
|
||||||
def refund(params={})
|
def refund(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:post, refund_url, @api_key, params)
|
response, api_key = Stripe.request(:post, refund_url, @api_key, params, headers)
|
||||||
refresh_from(response, api_key)
|
refresh_from(response, api_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def capture(params={})
|
def capture(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:post, capture_url, @api_key, params)
|
response, api_key = Stripe.request(:post, capture_url, @api_key, params, headers)
|
||||||
refresh_from(response, api_key)
|
refresh_from(response, api_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_dispute(params)
|
def update_dispute(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:post, dispute_url, @api_key, params)
|
response, api_key = Stripe.request(:post, dispute_url, @api_key, params, headers)
|
||||||
refresh_from({ :dispute => response }, api_key, true)
|
refresh_from({ :dispute => response }, api_key, true)
|
||||||
dispute
|
dispute
|
||||||
end
|
end
|
||||||
|
@ -29,20 +29,20 @@ module Stripe
|
|||||||
Invoice.create(params.merge(:customer => id), @api_key)
|
Invoice.create(params.merge(:customer => id), @api_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel_subscription(params={})
|
def cancel_subscription(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:delete, subscription_url, @api_key, params)
|
response, api_key = Stripe.request(:delete, subscription_url, @api_key, params, headers)
|
||||||
refresh_from({ :subscription => response }, api_key, true)
|
refresh_from({ :subscription => response }, api_key, true)
|
||||||
subscription
|
subscription
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_subscription(params)
|
def update_subscription(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:post, subscription_url, @api_key, params)
|
response, api_key = Stripe.request(:post, subscription_url, @api_key, params, headers)
|
||||||
refresh_from({ :subscription => response }, api_key, true)
|
refresh_from({ :subscription => response }, api_key, true)
|
||||||
subscription
|
subscription
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_subscription(params)
|
def create_subscription(params={}, headers={})
|
||||||
response, api_key = Stripe.request(:post, subscriptions_url, @api_key, params)
|
response, api_key = Stripe.request(:post, subscriptions_url, @api_key, params, headers)
|
||||||
refresh_from({ :subscription => response }, api_key, true)
|
refresh_from({ :subscription => response }, api_key, true)
|
||||||
subscription
|
subscription
|
||||||
end
|
end
|
||||||
|
@ -114,6 +114,15 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "with valid credentials" do
|
context "with valid credentials" do
|
||||||
|
should "send along additional headers" do
|
||||||
|
Stripe.expects(:execute_request).with do |opts|
|
||||||
|
opts[:headers][:foo] == 'bar'
|
||||||
|
end.returns(test_response(test_charge))
|
||||||
|
|
||||||
|
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
||||||
|
'local', {:foo => 'bar'})
|
||||||
|
end
|
||||||
|
|
||||||
should "urlencode values in GET params" do
|
should "urlencode values in GET params" do
|
||||||
response = test_response(test_charge_array)
|
response = test_response(test_charge_array)
|
||||||
@mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user