stripe 3.21.0 → 3.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/stripe/invoice.rb +0 -1
- data/lib/stripe/order.rb +0 -6
- data/lib/stripe/subscription.rb +0 -15
- data/lib/stripe/util.rb +3 -56
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/subscription_test.rb +0 -46
- data/test/stripe/util_test.rb +7 -39
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20dbcf02b1a4654d1ec60751b52efe4583e42ac0
|
4
|
+
data.tar.gz: 648b11cf6f57fb6c71609593553b978954fef2d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db7998300c64ccaebc98f5fe66ec5a93416652b6bd2c5d98efc7df5f353a92af2314fe8621fd6c6661800b456b208f15e9b1da4de2893b0ca95c6de5abc2574
|
7
|
+
data.tar.gz: e49a1de7f488e0b94c0ce0d58b7e427f78c3fd99112bf75df55f3a676411723df2c48e4b44b2d3348a57af8992ba69b97343da02459f51b4c94aa0ea09291eea
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.22.0
|
data/lib/stripe/invoice.rb
CHANGED
@@ -9,7 +9,6 @@ module Stripe
|
|
9
9
|
OBJECT_NAME = "invoice".freeze
|
10
10
|
|
11
11
|
def self.upcoming(params, opts = {})
|
12
|
-
params[:subscription_items] = Util.array_to_hash(params[:subscription_items]) if params[:subscription_items]
|
13
12
|
resp, opts = request(:get, upcoming_url, params, opts)
|
14
13
|
Util.convert_to_stripe_object(resp.data, opts)
|
15
14
|
end
|
data/lib/stripe/order.rb
CHANGED
@@ -14,16 +14,10 @@ module Stripe
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def return_order(params, opts = {})
|
17
|
-
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
18
17
|
resp, opts = request(:post, returns_url, params, opts)
|
19
18
|
Util.convert_to_stripe_object(resp.data, opts)
|
20
19
|
end
|
21
20
|
|
22
|
-
def self.create(params = {}, opts = {})
|
23
|
-
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
24
|
-
super(params, opts)
|
25
|
-
end
|
26
|
-
|
27
21
|
private
|
28
22
|
|
29
23
|
def pay_url
|
data/lib/stripe/subscription.rb
CHANGED
@@ -16,21 +16,6 @@ module Stripe
|
|
16
16
|
initialize_from({ discount: nil }, opts, true)
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.update(id, params = {}, opts = {})
|
20
|
-
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
21
|
-
super(id, params, opts)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.create(params = {}, opts = {})
|
25
|
-
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
26
|
-
super(params, opts)
|
27
|
-
end
|
28
|
-
|
29
|
-
def serialize_params(options = {})
|
30
|
-
@values[:items] = Util.array_to_hash(@values[:items]) if @values[:items]
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
19
|
private
|
35
20
|
|
36
21
|
def discount_url
|
data/lib/stripe/util.rb
CHANGED
@@ -190,20 +190,6 @@ module Stripe
|
|
190
190
|
.map { |k, v| "#{url_encode(k)}=#{url_encode(v)}" }.join("&")
|
191
191
|
end
|
192
192
|
|
193
|
-
# Transforms an array into a hash with integer keys. Used for a small
|
194
|
-
# number of API endpoints. If the argument is not an Array, return it
|
195
|
-
# unchanged. Example: [{foo: 'bar'}] => {"0" => {foo: "bar"}}
|
196
|
-
def self.array_to_hash(array)
|
197
|
-
case array
|
198
|
-
when Array
|
199
|
-
hash = {}
|
200
|
-
array.each_with_index { |v, i| hash[i.to_s] = v }
|
201
|
-
hash
|
202
|
-
else
|
203
|
-
array
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
193
|
# Encodes a string in a way that makes it suitable for use in a set of
|
208
194
|
# query parameters in a URI or in a set of form parameters in a request
|
209
195
|
# body.
|
@@ -225,7 +211,6 @@ module Stripe
|
|
225
211
|
if value.is_a?(Hash)
|
226
212
|
result += flatten_params(value, calculated_key)
|
227
213
|
elsif value.is_a?(Array)
|
228
|
-
check_array_of_maps_start_keys!(value)
|
229
214
|
result += flatten_params_array(value, calculated_key)
|
230
215
|
else
|
231
216
|
result << [calculated_key, value]
|
@@ -237,13 +222,13 @@ module Stripe
|
|
237
222
|
|
238
223
|
def self.flatten_params_array(value, calculated_key)
|
239
224
|
result = []
|
240
|
-
value.
|
225
|
+
value.each_with_index do |elem, i|
|
241
226
|
if elem.is_a?(Hash)
|
242
|
-
result += flatten_params(elem, "#{calculated_key}[]")
|
227
|
+
result += flatten_params(elem, "#{calculated_key}[#{i}]")
|
243
228
|
elsif elem.is_a?(Array)
|
244
229
|
result += flatten_params_array(elem, calculated_key)
|
245
230
|
else
|
246
|
-
result << ["#{calculated_key}[]", elem]
|
231
|
+
result << ["#{calculated_key}[#{i}]", elem]
|
247
232
|
end
|
248
233
|
end
|
249
234
|
result
|
@@ -337,44 +322,6 @@ module Stripe
|
|
337
322
|
}.freeze
|
338
323
|
private_constant :COLOR_CODES
|
339
324
|
|
340
|
-
# We use a pretty janky version of form encoding (Rack's) that supports
|
341
|
-
# more complex data structures like maps and arrays through the use of
|
342
|
-
# specialized syntax. To encode an array of maps like:
|
343
|
-
#
|
344
|
-
# [{a: 1, b: 2}, {a: 3, b: 4}]
|
345
|
-
#
|
346
|
-
# We have to produce something that looks like this:
|
347
|
-
#
|
348
|
-
# arr[][a]=1&arr[][b]=2&arr[][a]=3&arr[][b]=4
|
349
|
-
#
|
350
|
-
# The only way for the server to recognize that this is a two item array is
|
351
|
-
# that it notices the repetition of element "a", so it's key that these
|
352
|
-
# repeated elements are encoded first.
|
353
|
-
#
|
354
|
-
# This method is invoked for any arrays being encoded and checks that if
|
355
|
-
# the array contains all non-empty maps, that each of those maps must start
|
356
|
-
# with the same key so that their boundaries can be properly encoded.
|
357
|
-
def self.check_array_of_maps_start_keys!(arr)
|
358
|
-
expected_key = nil
|
359
|
-
arr.each do |item|
|
360
|
-
break unless item.is_a?(Hash)
|
361
|
-
break if item.count.zero?
|
362
|
-
|
363
|
-
first_key = item.first[0]
|
364
|
-
|
365
|
-
if expected_key
|
366
|
-
if expected_key != first_key
|
367
|
-
raise ArgumentError,
|
368
|
-
"All maps nested in an array should start with the same key " \
|
369
|
-
"(expected starting key '#{expected_key}', got '#{first_key}')"
|
370
|
-
end
|
371
|
-
else
|
372
|
-
expected_key = first_key
|
373
|
-
end
|
374
|
-
end
|
375
|
-
end
|
376
|
-
private_class_method :check_array_of_maps_start_keys!
|
377
|
-
|
378
325
|
# Uses an ANSI escape code to colorize text if it's going to be sent to a
|
379
326
|
# TTY.
|
380
327
|
def self.colorize(val, color, isatty)
|
data/lib/stripe/version.rb
CHANGED
@@ -56,51 +56,5 @@ module Stripe
|
|
56
56
|
assert subscription.is_a?(Stripe::Subscription)
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
60
|
-
context "#serialize_params" do
|
61
|
-
should "serialize when items is set to an Array" do
|
62
|
-
obj = Stripe::Util.convert_to_stripe_object({
|
63
|
-
object: "subscription",
|
64
|
-
items: Stripe::Util.convert_to_stripe_object(
|
65
|
-
object: "list",
|
66
|
-
data: []
|
67
|
-
),
|
68
|
-
}, {})
|
69
|
-
obj.items = [
|
70
|
-
{ id: "si_foo", deleted: true },
|
71
|
-
{ plan: "plan_bar" },
|
72
|
-
]
|
73
|
-
|
74
|
-
expected = {
|
75
|
-
items: {
|
76
|
-
:"0" => { id: "si_foo", deleted: true },
|
77
|
-
:"1" => { plan: "plan_bar" },
|
78
|
-
},
|
79
|
-
}
|
80
|
-
assert_equal(expected, obj.serialize_params)
|
81
|
-
end
|
82
|
-
|
83
|
-
should "serialize when items is set to a Hash" do
|
84
|
-
obj = Stripe::Util.convert_to_stripe_object({
|
85
|
-
object: "subscription",
|
86
|
-
items: Stripe::Util.convert_to_stripe_object(
|
87
|
-
object: "list",
|
88
|
-
data: []
|
89
|
-
),
|
90
|
-
}, {})
|
91
|
-
obj.items = {
|
92
|
-
"0" => { id: "si_foo", deleted: true },
|
93
|
-
"1" => { plan: "plan_bar" },
|
94
|
-
}
|
95
|
-
|
96
|
-
expected = {
|
97
|
-
items: {
|
98
|
-
:"0" => { id: "si_foo", deleted: true },
|
99
|
-
:"1" => { plan: "plan_bar" },
|
100
|
-
},
|
101
|
-
}
|
102
|
-
assert_equal(expected, obj.serialize_params)
|
103
|
-
end
|
104
|
-
end
|
105
59
|
end
|
106
60
|
end
|
data/test/stripe/util_test.rb
CHANGED
@@ -33,39 +33,11 @@ module Stripe
|
|
33
33
|
g: [],
|
34
34
|
}
|
35
35
|
assert_equal(
|
36
|
-
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1&f=",
|
36
|
+
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[0]=0&e[1]=1&f=",
|
37
37
|
Stripe::Util.encode_parameters(params)
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
-
should "#encode_params should throw an error on an array of maps that cannot be encoded" do
|
42
|
-
params = {
|
43
|
-
a: [
|
44
|
-
{ a: 1, b: 2 },
|
45
|
-
{ c: 3, a: 4 },
|
46
|
-
],
|
47
|
-
}
|
48
|
-
e = assert_raises(ArgumentError) do
|
49
|
-
Stripe::Util.encode_parameters(params)
|
50
|
-
end
|
51
|
-
expected = "All maps nested in an array should start with the same key " \
|
52
|
-
"(expected starting key 'a', got 'c')"
|
53
|
-
assert_equal expected, e.message
|
54
|
-
|
55
|
-
# Make sure the check is recursive by taking our original params and
|
56
|
-
# nesting it into yet another map and array. Should throw exactly the
|
57
|
-
# same error because it's still the in inner array of maps that's wrong.
|
58
|
-
params = {
|
59
|
-
x: [
|
60
|
-
params,
|
61
|
-
],
|
62
|
-
}
|
63
|
-
e = assert_raises(ArgumentError) do
|
64
|
-
Stripe::Util.encode_parameters(params)
|
65
|
-
end
|
66
|
-
assert_equal expected, e.message
|
67
|
-
end
|
68
|
-
|
69
41
|
should "#url_encode should prepare strings for HTTP" do
|
70
42
|
assert_equal "foo", Stripe::Util.url_encode("foo")
|
71
43
|
assert_equal "foo", Stripe::Util.url_encode(:foo)
|
@@ -92,16 +64,16 @@ module Stripe
|
|
92
64
|
["c", "bar&baz"],
|
93
65
|
["d[a]", "a"],
|
94
66
|
["d[b]", "b"],
|
95
|
-
["e[]", 0],
|
96
|
-
["e[]", 1],
|
67
|
+
["e[0]", 0],
|
68
|
+
["e[1]", 1],
|
97
69
|
|
98
70
|
# *The key here is the order*. In order to be properly interpreted as
|
99
71
|
# an array of hashes on the server, everything from a single hash must
|
100
72
|
# come in at once. A duplicate key in an array triggers a new element.
|
101
|
-
["f[][foo]", "1"],
|
102
|
-
["f[][ghi]", "2"],
|
103
|
-
["f[][foo]", "3"],
|
104
|
-
["f[][bar]", "4"],
|
73
|
+
["f[0][foo]", "1"],
|
74
|
+
["f[0][ghi]", "2"],
|
75
|
+
["f[1][foo]", "3"],
|
76
|
+
["f[1][bar]", "4"],
|
105
77
|
], Stripe::Util.flatten_params(params))
|
106
78
|
end
|
107
79
|
|
@@ -160,10 +132,6 @@ module Stripe
|
|
160
132
|
assert_equal [1, 2, 3], obj
|
161
133
|
end
|
162
134
|
|
163
|
-
should "#array_to_hash should convert an array into a hash with integer keys" do
|
164
|
-
assert_equal({ "0" => 1, "1" => 2, "2" => 3 }, Util.array_to_hash([1, 2, 3]))
|
165
|
-
end
|
166
|
-
|
167
135
|
context ".request_id_dashboard_url" do
|
168
136
|
should "generate a livemode URL" do
|
169
137
|
assert_equal "https://dashboard.stripe.com/live/logs/request-id",
|
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: 3.
|
4
|
+
version: 3.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.6.14
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Ruby bindings for the Stripe API
|