diff --git a/lib/stripe/invoice.rb b/lib/stripe/invoice.rb index 2c451beb..311fbc64 100644 --- a/lib/stripe/invoice.rb +++ b/lib/stripe/invoice.rb @@ -5,13 +5,12 @@ module Stripe include Stripe::APIOperations::Create def self.upcoming(params, opts={}) - opts = Util.normalize_opts(opts) - response, api_key = Stripe.request(:get, upcoming_url, opts, params) + response, opts = request(:get, upcoming_url, params, opts) Util.convert_to_stripe_object(response, opts) end - def pay - response, opts = Stripe.request(:post, pay_url, @opts, {}) + def pay(opts={}) + response, opts = request(:post, pay_url, {}, opts) refresh_from(response, opts) end diff --git a/test/stripe/invoice_test.rb b/test/stripe/invoice_test.rb index 4e8270d3..a56264f4 100644 --- a/test/stripe/invoice_test.rb +++ b/test/stripe/invoice_test.rb @@ -22,5 +22,19 @@ module Stripe i.pay assert_equal nil, i.next_payment_attempt end + + should "pay with extra opts should pay an invoice" do + @mock.expects(:get).once.returns(test_response(test_invoice)) + i = Stripe::Invoice.retrieve('in_test_invoice', {api_key: 'foobar'}) + + Stripe.expects(:execute_request).with do |opts| + opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" && + opts[:method] == :post && + opts[:headers][:authorization] == 'Bearer foobar' + end.returns(test_response(test_paid_invoice)) + + i.pay + assert_equal nil, i.next_payment_attempt + end end end