stripe 3.5.2 → 3.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/CHANGELOG.md +10 -4
- data/VERSION +1 -1
- data/lib/stripe.rb +3 -3
- data/lib/stripe/api_operations/request.rb +1 -1
- data/lib/stripe/invoice.rb +1 -0
- data/lib/stripe/order.rb +6 -0
- data/lib/stripe/stripe_object.rb +11 -2
- data/lib/stripe/subscription.rb +10 -0
- data/lib/stripe/util.rb +6 -2
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_object_test.rb +21 -0
- data/test/stripe/subscription_test.rb +46 -0
- data/test/stripe/util_test.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31bc202ae773c518a1f9d9382b08c76df41d4252
|
4
|
+
data.tar.gz: 0a8007b7d10c5c4a7cc4f8721553f58042e7ee9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82412fadaa6d945c754cd1712eebad95cb6fc5ab35564ae7878e1c3d7095e4794821fc44119a45c0bd15c52818301c110b33964665c6fb741c2affd5d08237f1
|
7
|
+
data.tar.gz: cd2a601d172ae2a1eabf23616832d40716eebdea2c00e101a51419e9f06021463aa4abdb6776e6089df47d163ac87bd9659028e198d8da1e2bd2fb0495e5ba2a
|
data/.rubocop_todo.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.5.3 - 2017-10-16
|
4
|
+
* [#594](https://github.com/stripe/stripe-ruby#594) Make sure that `StripeObject`'s `#deep_copy` maintains original class
|
5
|
+
* [#595](https://github.com/stripe/stripe-ruby#595) Allow `Object#method` to be called on `StripeObject` even if it conflicts with an accessor
|
6
|
+
* [#596](https://github.com/stripe/stripe-ruby#596) Encode arrays as integer-indexed hashes where appropriate
|
7
|
+
* [#598](https://github.com/stripe/stripe-ruby#598) Don't persist `idempotency_key` opt between requests
|
8
|
+
|
3
9
|
## 3.5.2 - 2017-10-13
|
4
10
|
* [#592](https://github.com/stripe/stripe-ruby#592) Bring back `Marshal.dump/load` support with custom marshal encoder/decoder
|
5
11
|
|
6
12
|
## 3.5.1 - 2017-10-12
|
7
|
-
* [#591](https://github.com/stripe/stripe-
|
13
|
+
* [#591](https://github.com/stripe/stripe-ruby#591) Use thread-local `StripeClient` instances for thread safety
|
8
14
|
|
9
15
|
## 3.5.0 - 2017-10-11
|
10
|
-
* [#589](https://github.com/stripe/stripe-
|
16
|
+
* [#589](https://github.com/stripe/stripe-ruby#589) Rename source `delete` to `detach` (and deprecate the former)
|
11
17
|
|
12
18
|
## 3.4.1 - 2017-10-05
|
13
|
-
* [#586](https://github.com/stripe/stripe-
|
14
|
-
* [#588](https://github.com/stripe/stripe-
|
19
|
+
* [#586](https://github.com/stripe/stripe-ruby#586) Log query strings as well as form bodies with STRIPE_LOG
|
20
|
+
* [#588](https://github.com/stripe/stripe-ruby#588) Require minimum Faraday 0.10 for bug fix in parameter encoding
|
15
21
|
|
16
22
|
## 3.4.0 - 2017-09-20
|
17
23
|
* Mark legacy Bitcoin API as deprecated, and remove corresponding tests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.5.
|
1
|
+
3.5.3
|
data/lib/stripe.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Stripe Ruby bindings
|
2
2
|
# API spec at https://stripe.com/docs/api
|
3
3
|
require "cgi"
|
4
|
+
require "faraday"
|
5
|
+
require "json"
|
4
6
|
require "logger"
|
5
7
|
require "openssl"
|
6
8
|
require "rbconfig"
|
7
9
|
require "securerandom"
|
8
10
|
require "set"
|
9
11
|
require "socket"
|
10
|
-
|
11
|
-
require "faraday"
|
12
|
-
require "json"
|
12
|
+
require "uri"
|
13
13
|
|
14
14
|
# Version
|
15
15
|
require "stripe/version"
|
@@ -23,7 +23,7 @@ module Stripe
|
|
23
23
|
# Hash#select returns an array before 1.9
|
24
24
|
opts_to_persist = {}
|
25
25
|
opts.each do |k, v|
|
26
|
-
opts_to_persist[k] = v if Util::
|
26
|
+
opts_to_persist[k] = v if Util::OPTS_PERSISTABLE.include?(k)
|
27
27
|
end
|
28
28
|
|
29
29
|
[resp, opts_to_persist]
|
data/lib/stripe/invoice.rb
CHANGED
@@ -7,6 +7,7 @@ module Stripe
|
|
7
7
|
OBJECT_NAME = "invoice".freeze
|
8
8
|
|
9
9
|
def self.upcoming(params, opts = {})
|
10
|
+
params[:subscription_items] = Util.array_to_hash(params[:subscription_items]) if params[:subscription_items]
|
10
11
|
resp, opts = request(:get, upcoming_url, params, opts)
|
11
12
|
Util.convert_to_stripe_object(resp.data, opts)
|
12
13
|
end
|
data/lib/stripe/order.rb
CHANGED
@@ -12,10 +12,16 @@ module Stripe
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def return_order(params, opts = {})
|
15
|
+
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
15
16
|
resp, opts = request(:post, returns_url, params, opts)
|
16
17
|
Util.convert_to_stripe_object(resp.data, opts)
|
17
18
|
end
|
18
19
|
|
20
|
+
def self.create(params = {}, opts = {})
|
21
|
+
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
22
|
+
super(params, opts)
|
23
|
+
end
|
24
|
+
|
19
25
|
private
|
20
26
|
|
21
27
|
def pay_url
|
data/lib/stripe/stripe_object.rb
CHANGED
@@ -241,7 +241,16 @@ module Stripe
|
|
241
241
|
next if protected_fields.include?(k)
|
242
242
|
next if @@permanent_attributes.include?(k)
|
243
243
|
|
244
|
-
|
244
|
+
if k == :method
|
245
|
+
# Object#method is a built-in Ruby method that accepts a symbol
|
246
|
+
# and returns the corresponding Method object. Because the API may
|
247
|
+
# also use `method` as a field name, we check the arity of *args
|
248
|
+
# to decide whether to act as a getter or call the parent method.
|
249
|
+
define_method(k) { |*args| args.empty? ? @values[k] : super(*args) }
|
250
|
+
else
|
251
|
+
define_method(k) { @values[k] }
|
252
|
+
end
|
253
|
+
|
245
254
|
define_method(:"#{k}=") do |v|
|
246
255
|
if v == ""
|
247
256
|
raise ArgumentError, "You cannot set #{k} to an empty string. " \
|
@@ -427,7 +436,7 @@ module Stripe
|
|
427
436
|
copy
|
428
437
|
end
|
429
438
|
when StripeObject
|
430
|
-
|
439
|
+
obj.class.construct_from(
|
431
440
|
deep_copy(obj.instance_variable_get(:@values)),
|
432
441
|
obj.instance_variable_get(:@opts).select do |k, _v|
|
433
442
|
Util::OPTS_COPYABLE.include?(k)
|
data/lib/stripe/subscription.rb
CHANGED
@@ -24,6 +24,16 @@ module Stripe
|
|
24
24
|
super(params, opts)
|
25
25
|
end
|
26
26
|
|
27
|
+
def serialize_params(options = {})
|
28
|
+
update_hash = super
|
29
|
+
if @unsaved_values.include?(:items)
|
30
|
+
value = Util.array_to_hash(@values[:items])
|
31
|
+
update_hash[:items] =
|
32
|
+
serialize_params_value(value, nil, true, options[:force], key: :items)
|
33
|
+
end
|
34
|
+
update_hash
|
35
|
+
end
|
36
|
+
|
27
37
|
private
|
28
38
|
|
29
39
|
def discount_url
|
data/lib/stripe/util.rb
CHANGED
@@ -12,11 +12,15 @@ module Stripe
|
|
12
12
|
|
13
13
|
# Options that should be copyable from one StripeObject to another
|
14
14
|
# including options that may be internal.
|
15
|
-
OPTS_COPYABLE = (
|
15
|
+
OPTS_COPYABLE = (
|
16
|
+
OPTS_USER_SPECIFIED + Set[:api_base]
|
17
|
+
).freeze
|
16
18
|
|
17
19
|
# Options that should be persisted between API requests. This includes
|
18
20
|
# client, which is an object containing an HTTP client to reuse.
|
19
|
-
|
21
|
+
OPTS_PERSISTABLE = (
|
22
|
+
OPTS_USER_SPECIFIED + Set[:client] - Set[:idempotency_key]
|
23
|
+
).freeze
|
20
24
|
|
21
25
|
def self.objects_to_ids(h)
|
22
26
|
case h
|
data/lib/stripe/version.rb
CHANGED
@@ -104,6 +104,15 @@ module Stripe
|
|
104
104
|
assert_equal opts.reject { |k, _v| k == :client },
|
105
105
|
copy_obj.instance_variable_get(:@opts)
|
106
106
|
end
|
107
|
+
|
108
|
+
should "return an instance of the same class" do
|
109
|
+
class TestObject < Stripe::StripeObject; end
|
110
|
+
|
111
|
+
obj = TestObject.construct_from(id: 1)
|
112
|
+
copy_obj = obj.class.send(:deep_copy, obj)
|
113
|
+
|
114
|
+
assert_equal obj.class, copy_obj.class
|
115
|
+
end
|
107
116
|
end
|
108
117
|
|
109
118
|
should "recursively call to_hash on its values" do
|
@@ -423,5 +432,17 @@ module Stripe
|
|
423
432
|
expected_hash = { api_key: "apikey" }
|
424
433
|
assert_equal expected_hash, m.instance_variable_get("@opts")
|
425
434
|
end
|
435
|
+
|
436
|
+
context "#method" do
|
437
|
+
should "act as a getter if no arguments are provided" do
|
438
|
+
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
439
|
+
assert_equal "foo", obj.method
|
440
|
+
end
|
441
|
+
|
442
|
+
should "call Object#method if an argument is provided" do
|
443
|
+
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
444
|
+
assert obj.method(:id).is_a?(Method)
|
445
|
+
end
|
446
|
+
end
|
426
447
|
end
|
427
448
|
end
|
@@ -54,5 +54,51 @@ module Stripe
|
|
54
54
|
assert subscription.is_a?(Stripe::Subscription)
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
context "#serialize_params" do
|
59
|
+
should "serialize when items is set to an Array" do
|
60
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
61
|
+
object: "subscription",
|
62
|
+
items: Stripe::Util.convert_to_stripe_object(
|
63
|
+
object: "list",
|
64
|
+
data: []
|
65
|
+
),
|
66
|
+
}, {})
|
67
|
+
obj.items = [
|
68
|
+
{ id: "si_foo", deleted: true },
|
69
|
+
{ plan: "plan_bar" },
|
70
|
+
]
|
71
|
+
|
72
|
+
expected = {
|
73
|
+
items: {
|
74
|
+
:"0" => { id: "si_foo", deleted: true },
|
75
|
+
:"1" => { plan: "plan_bar" },
|
76
|
+
},
|
77
|
+
}
|
78
|
+
assert_equal(expected, obj.serialize_params)
|
79
|
+
end
|
80
|
+
|
81
|
+
should "serialize when items is set to a Hash" do
|
82
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
83
|
+
object: "subscription",
|
84
|
+
items: Stripe::Util.convert_to_stripe_object(
|
85
|
+
object: "list",
|
86
|
+
data: []
|
87
|
+
),
|
88
|
+
}, {})
|
89
|
+
obj.items = {
|
90
|
+
"0" => { id: "si_foo", deleted: true },
|
91
|
+
"1" => { plan: "plan_bar" },
|
92
|
+
}
|
93
|
+
|
94
|
+
expected = {
|
95
|
+
items: {
|
96
|
+
:"0" => { id: "si_foo", deleted: true },
|
97
|
+
:"1" => { plan: "plan_bar" },
|
98
|
+
},
|
99
|
+
}
|
100
|
+
assert_equal(expected, obj.serialize_params)
|
101
|
+
end
|
102
|
+
end
|
57
103
|
end
|
58
104
|
end
|
data/test/stripe/util_test.rb
CHANGED
@@ -2,6 +2,22 @@ require File.expand_path("../../test_helper", __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class UtilTest < Test::Unit::TestCase
|
5
|
+
context "OPTS_COPYABLE" do
|
6
|
+
should "include :apibase" do
|
7
|
+
assert_include Stripe::Util::OPTS_COPYABLE, :api_base
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "OPTS_PERSISTABLE" do
|
12
|
+
should "include :client" do
|
13
|
+
assert_include Stripe::Util::OPTS_PERSISTABLE, :client
|
14
|
+
end
|
15
|
+
|
16
|
+
should "not include :idempotency_key" do
|
17
|
+
refute_includes Stripe::Util::OPTS_PERSISTABLE, :idempotency_key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
5
21
|
should "#encode_parameters should prepare parameters for an HTTP request" do
|
6
22
|
params = {
|
7
23
|
a: 3,
|
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.5.
|
4
|
+
version: 3.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.6.
|
175
|
+
rubygems_version: 2.6.14
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Ruby bindings for the Stripe API
|