stripe 1.50.1 → 1.51.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/VERSION +1 -1
- data/lib/stripe.rb +8 -8
- data/lib/stripe/util.rb +40 -0
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/api_resource_test.rb +13 -7
- data/test/stripe/charge_test.rb +1 -1
- data/test/stripe/invoice_test.rb +1 -1
- data/test/stripe/util_test.rb +28 -0
- data/test/stripe_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53821741b8b4c5d1ab26760b8dc79065a2b2ebf9
|
4
|
+
data.tar.gz: d61f8ae7d2501b2d4d3198fd31aebea2a07cf105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4d5995dd5bbdd5ea063a79023a9467932470fb1299c69e73d1e9758600a4e890d66caa410680a7e2c13579a7b76bec62565d0cb665fbee5feb3c6124a049ce
|
7
|
+
data.tar.gz: 8db2e0a89f0327bb3b9c3fcbd61630dbab4d19d2b2150381ca551db9c4fda1b4778b8f972bf62f358db45173395e25969031466a9fb3352cc6de092d45cb9766
|
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 1.51.0 2016-08-26
|
2
|
+
|
3
|
+
* Error when an array of maps is detected that cannot be accurately encoded
|
4
|
+
* Start using strings for header names instead of symbols for better clarity
|
5
|
+
|
1
6
|
=== 1.50.1 2016-08-25
|
2
7
|
|
3
8
|
* Fix encoding of arrays of maps where maps unequal sets of keys
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.51.0
|
data/lib/stripe.rb
CHANGED
@@ -303,24 +303,24 @@ module Stripe
|
|
303
303
|
|
304
304
|
def self.request_headers(api_key, method)
|
305
305
|
headers = {
|
306
|
-
|
307
|
-
|
308
|
-
|
306
|
+
'User-Agent' => "Stripe/v1 RubyBindings/#{Stripe::VERSION}",
|
307
|
+
'Authorization' => "Bearer #{api_key}",
|
308
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
309
309
|
}
|
310
310
|
|
311
311
|
# It is only safe to retry network failures on post and delete
|
312
312
|
# requests if we add an Idempotency-Key header
|
313
313
|
if [:post, :delete].include?(method) && self.max_network_retries > 0
|
314
|
-
headers[
|
314
|
+
headers['Idempotency-Key'] ||= SecureRandom.uuid
|
315
315
|
end
|
316
316
|
|
317
|
-
headers[
|
318
|
-
headers[
|
317
|
+
headers['Stripe-Version'] = api_version if api_version
|
318
|
+
headers['Stripe-Account'] = stripe_account if stripe_account
|
319
319
|
|
320
320
|
begin
|
321
|
-
headers.update(
|
321
|
+
headers.update('X-Stripe-Client-User-Agent' => JSON.generate(user_agent))
|
322
322
|
rescue => e
|
323
|
-
headers.update(
|
323
|
+
headers.update('X-Stripe-Client-Raw-User-Agent' => user_agent.inspect,
|
324
324
|
:error => "#{e} (#{e.class})")
|
325
325
|
end
|
326
326
|
end
|
data/lib/stripe/util.rb
CHANGED
@@ -140,6 +140,7 @@ module Stripe
|
|
140
140
|
if value.is_a?(Hash)
|
141
141
|
result += flatten_params(value, calculated_key)
|
142
142
|
elsif value.is_a?(Array)
|
143
|
+
check_array_of_maps_start_keys!(value)
|
143
144
|
result += flatten_params_array(value, calculated_key)
|
144
145
|
else
|
145
146
|
result << [calculated_key, value]
|
@@ -196,5 +197,44 @@ module Stripe
|
|
196
197
|
raise TypeError.new("api_key must be a string") unless key.is_a?(String)
|
197
198
|
key
|
198
199
|
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
# We use a pretty janky version of form encoding (Rack's) that supports
|
204
|
+
# more complex data structures like maps and arrays through the use of
|
205
|
+
# specialized syntax. To encode an array of maps like:
|
206
|
+
#
|
207
|
+
# [{a: 1, b: 2}, {a: 3, b: 4}]
|
208
|
+
#
|
209
|
+
# We have to produce something that looks like this:
|
210
|
+
#
|
211
|
+
# arr[][a]=1&arr[][b]=2&arr[][a]=3&arr[][b]=4
|
212
|
+
#
|
213
|
+
# The only way for the server to recognize that this is a two item array is
|
214
|
+
# that it notices the repetition of element "a", so it's key that these
|
215
|
+
# repeated elements are encoded first.
|
216
|
+
#
|
217
|
+
# This method is invoked for any arrays being encoded and checks that if
|
218
|
+
# the array contains all non-empty maps, that each of those maps must start
|
219
|
+
# with the same key so that their boundaries can be properly encoded.
|
220
|
+
def self.check_array_of_maps_start_keys!(arr)
|
221
|
+
expected_key = nil
|
222
|
+
arr.each do |item|
|
223
|
+
return if !item.is_a?(Hash)
|
224
|
+
return if item.count == 0
|
225
|
+
|
226
|
+
first_key = item.first[0]
|
227
|
+
|
228
|
+
if expected_key
|
229
|
+
if expected_key != first_key
|
230
|
+
raise ArgumentError,
|
231
|
+
"All maps nested in an array should start with the same key " +
|
232
|
+
"(expected starting key '#{expected_key}', got '#{first_key}')"
|
233
|
+
end
|
234
|
+
else
|
235
|
+
expected_key = first_key
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
199
239
|
end
|
200
240
|
end
|
data/lib/stripe/version.rb
CHANGED
@@ -174,7 +174,7 @@ module Stripe
|
|
174
174
|
context "with no global API key set" do
|
175
175
|
should "use the per-object credential when creating" do
|
176
176
|
Stripe.expects(:execute_request).with do |opts|
|
177
|
-
opts[:headers][
|
177
|
+
opts[:headers]['Authorization'] == 'Bearer sk_test_local'
|
178
178
|
end.returns(make_response(make_charge))
|
179
179
|
|
180
180
|
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
@@ -193,7 +193,7 @@ module Stripe
|
|
193
193
|
|
194
194
|
should "use the per-object credential when creating" do
|
195
195
|
Stripe.expects(:execute_request).with do |opts|
|
196
|
-
opts[:headers][
|
196
|
+
opts[:headers]['Authorization'] == 'Bearer local'
|
197
197
|
end.returns(make_response(make_charge))
|
198
198
|
|
199
199
|
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
@@ -203,11 +203,11 @@ module Stripe
|
|
203
203
|
should "use the per-object credential when retrieving and making other calls" do
|
204
204
|
Stripe.expects(:execute_request).with do |opts|
|
205
205
|
opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge" &&
|
206
|
-
opts[:headers][
|
206
|
+
opts[:headers]['Authorization'] == 'Bearer local'
|
207
207
|
end.returns(make_response(make_charge))
|
208
208
|
Stripe.expects(:execute_request).with do |opts|
|
209
209
|
opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge/refunds" &&
|
210
|
-
opts[:headers][
|
210
|
+
opts[:headers]['Authorization'] == 'Bearer local'
|
211
211
|
end.returns(make_response(make_refund))
|
212
212
|
|
213
213
|
ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
|
@@ -405,7 +405,7 @@ module Stripe
|
|
405
405
|
|
406
406
|
should "updating should use the supplied api_key" do
|
407
407
|
Stripe.expects(:execute_request).with do |opts|
|
408
|
-
opts[:headers][
|
408
|
+
opts[:headers]['Authorization'] == 'Bearer sk_test_local'
|
409
409
|
end.returns(make_response(make_customer))
|
410
410
|
c = Stripe::Customer.new
|
411
411
|
c.save({}, { :api_key => 'sk_test_local' })
|
@@ -725,7 +725,7 @@ module Stripe
|
|
725
725
|
should 'ensure there is always an idempotency_key on POST requests' do
|
726
726
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
727
727
|
Stripe.expects(:execute_request).with do |opts|
|
728
|
-
opts[:headers][
|
728
|
+
opts[:headers]['Idempotency-Key'] == "random_key"
|
729
729
|
end.returns(make_response({"id" => "myid"}))
|
730
730
|
|
731
731
|
Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
@@ -734,7 +734,7 @@ module Stripe
|
|
734
734
|
should 'ensure there is always an idempotency_key on DELETE requests' do
|
735
735
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
736
736
|
Stripe.expects(:execute_request).with do |opts|
|
737
|
-
opts[:headers][
|
737
|
+
opts[:headers]['Idempotency-Key'] == "random_key"
|
738
738
|
end.returns(make_response({"id" => "myid"}))
|
739
739
|
|
740
740
|
c = Stripe::Customer.construct_from(make_customer)
|
@@ -742,6 +742,12 @@ module Stripe
|
|
742
742
|
end
|
743
743
|
|
744
744
|
should 'not override a provided idempotency_key' do
|
745
|
+
# Note that this expectation looks like `:idempotency_key` instead of
|
746
|
+
# the header `Idempotency-Key` because it's user provided as seen
|
747
|
+
# below. The ones injected by the library itself look like headers
|
748
|
+
# (`Idempotency-Key`), but rest-client does allow this symbol
|
749
|
+
# formatting and will properly override the system generated one as
|
750
|
+
# expected.
|
745
751
|
Stripe.expects(:execute_request).with do |opts|
|
746
752
|
opts[:headers][:idempotency_key] == "provided_key"
|
747
753
|
end.returns(make_response({"id" => "myid"}))
|
data/test/stripe/charge_test.rb
CHANGED
@@ -138,7 +138,7 @@ module Stripe
|
|
138
138
|
:amount => 100,
|
139
139
|
:source => 'btcrcv_test_receiver',
|
140
140
|
:currency => "usd",
|
141
|
-
:level3 => [{:red => 'firstred'}, {:
|
141
|
+
:level3 => [{:red => 'firstred'}, {:red => 'another', :one => 'fish'}]
|
142
142
|
})
|
143
143
|
assert c.paid
|
144
144
|
end
|
data/test/stripe/invoice_test.rb
CHANGED
@@ -38,7 +38,7 @@ module Stripe
|
|
38
38
|
Stripe.expects(:execute_request).with do |opts|
|
39
39
|
opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" &&
|
40
40
|
opts[:method] == :post &&
|
41
|
-
opts[:headers][
|
41
|
+
opts[:headers]['Authorization'] == 'Bearer foobar'
|
42
42
|
end.returns(make_response(make_paid_invoice))
|
43
43
|
|
44
44
|
i.pay
|
data/test/stripe/util_test.rb
CHANGED
@@ -20,6 +20,34 @@ module Stripe
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
+
should "#encode_params should throw an error on an array of maps that cannot be encoded" do
|
24
|
+
params = {
|
25
|
+
:a => [
|
26
|
+
{ :a => 1, :b => 2 },
|
27
|
+
{ :c => 3, :a => 4 },
|
28
|
+
]
|
29
|
+
}
|
30
|
+
e = assert_raises(ArgumentError) do
|
31
|
+
Stripe::Util.encode_parameters(params)
|
32
|
+
end
|
33
|
+
expected = "All maps nested in an array should start with the same key " +
|
34
|
+
"(expected starting key 'a', got 'c')"
|
35
|
+
assert_equal expected, e.message
|
36
|
+
|
37
|
+
# Make sure the check is recursive by taking our original params and
|
38
|
+
# nesting it into yet another map and array. Should throw exactly the
|
39
|
+
# same error because it's still the in inner array of maps that's wrong.
|
40
|
+
params = {
|
41
|
+
:x => [
|
42
|
+
params
|
43
|
+
]
|
44
|
+
}
|
45
|
+
e = assert_raises(ArgumentError) do
|
46
|
+
Stripe::Util.encode_parameters(params)
|
47
|
+
end
|
48
|
+
assert_equal expected, e.message
|
49
|
+
end
|
50
|
+
|
23
51
|
should "#url_encode should prepare strings for HTTP" do
|
24
52
|
assert_equal "foo", Stripe::Util.url_encode("foo")
|
25
53
|
assert_equal "foo", Stripe::Util.url_encode(:foo)
|
data/test/stripe_test.rb
CHANGED
@@ -43,7 +43,7 @@ class StripeTest < Test::Unit::TestCase
|
|
43
43
|
Stripe.stripe_account = 'acct_1234'
|
44
44
|
|
45
45
|
Stripe.expects(:execute_request).with(
|
46
|
-
has_entry(:headers, has_entry(
|
46
|
+
has_entry(:headers, has_entry('Stripe-Account', 'acct_1234')),
|
47
47
|
).returns(make_response(response))
|
48
48
|
|
49
49
|
Stripe.request(:post, '/v1/account', 'sk_live12334566')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.51.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|