stripe 1.20.1 → 1.20.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/VERSION +1 -1
- data/lib/stripe/api_operations/update.rb +1 -41
- data/lib/stripe/singleton_api_resource.rb +2 -2
- data/lib/stripe/stripe_object.rb +70 -1
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/account_test.rb +25 -0
- data/test/stripe/api_resource_test.rb +110 -0
- data/test/stripe/balance_test.rb +11 -0
- metadata +5 -2
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.20.
|
1
|
+
1.20.2
|
@@ -2,11 +2,7 @@ module Stripe
|
|
2
2
|
module APIOperations
|
3
3
|
module Update
|
4
4
|
def save(params={})
|
5
|
-
values = serialize_params(self).merge(params)
|
6
|
-
|
7
|
-
if @values[:metadata]
|
8
|
-
values[:metadata] = serialize_metadata
|
9
|
-
end
|
5
|
+
values = self.class.serialize_params(self).merge(params)
|
10
6
|
|
11
7
|
if values.length > 0
|
12
8
|
values.delete(:id)
|
@@ -16,42 +12,6 @@ module Stripe
|
|
16
12
|
end
|
17
13
|
self
|
18
14
|
end
|
19
|
-
|
20
|
-
def serialize_metadata
|
21
|
-
if @unsaved_values.include?(:metadata)
|
22
|
-
# the metadata object has been reassigned
|
23
|
-
# i.e. as object.metadata = {key => val}
|
24
|
-
metadata_update = @values[:metadata] # new hash
|
25
|
-
new_keys = metadata_update.keys.map(&:to_sym)
|
26
|
-
# remove keys at the server, but not known locally
|
27
|
-
keys_to_unset = @previous_metadata.keys - new_keys
|
28
|
-
keys_to_unset.each {|key| metadata_update[key] = ''}
|
29
|
-
|
30
|
-
metadata_update
|
31
|
-
else
|
32
|
-
# metadata is a StripeObject, and can be serialized normally
|
33
|
-
serialize_params(@values[:metadata])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def serialize_params(obj)
|
38
|
-
case obj
|
39
|
-
when nil
|
40
|
-
''
|
41
|
-
when StripeObject
|
42
|
-
unsaved_keys = obj.instance_variable_get(:@unsaved_values)
|
43
|
-
obj_values = obj.instance_variable_get(:@values)
|
44
|
-
update_hash = {}
|
45
|
-
|
46
|
-
unsaved_keys.each do |k|
|
47
|
-
update_hash[k] = serialize_params(obj_values[k])
|
48
|
-
end
|
49
|
-
|
50
|
-
update_hash
|
51
|
-
else
|
52
|
-
obj
|
53
|
-
end
|
54
|
-
end
|
55
15
|
end
|
56
16
|
end
|
57
17
|
end
|
data/lib/stripe/stripe_object.rb
CHANGED
@@ -43,7 +43,7 @@ module Stripe
|
|
43
43
|
|
44
44
|
def refresh_from(values, opts, partial=false)
|
45
45
|
@opts = opts
|
46
|
-
@
|
46
|
+
@original_values = Marshal.load(Marshal.dump(values)) # deep copy
|
47
47
|
removed = partial ? Set.new : Set.new(@values.keys - values.keys)
|
48
48
|
added = Set.new(values.keys - @values.keys)
|
49
49
|
# Wipe old state before setting new. This is useful for e.g. updating a
|
@@ -118,6 +118,75 @@ module Stripe
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
|
122
|
+
def serialize_nested_object(key)
|
123
|
+
new_value = @values[key]
|
124
|
+
if @unsaved_values.include?(key)
|
125
|
+
# the object has been reassigned
|
126
|
+
# e.g. as object.key = {foo => bar}
|
127
|
+
update = new_value
|
128
|
+
new_keys = update.keys.map(&:to_sym)
|
129
|
+
# remove keys at the server, but not known locally
|
130
|
+
keys_to_unset = @original_values[key].keys - new_keys
|
131
|
+
keys_to_unset.each {|key| update[key] = ''}
|
132
|
+
|
133
|
+
update
|
134
|
+
else
|
135
|
+
# can be serialized normally
|
136
|
+
self.class.serialize_params(new_value)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.serialize_params(obj, original_value=nil)
|
141
|
+
case obj
|
142
|
+
when nil
|
143
|
+
''
|
144
|
+
when StripeObject
|
145
|
+
unsaved_keys = obj.instance_variable_get(:@unsaved_values)
|
146
|
+
obj_values = obj.instance_variable_get(:@values)
|
147
|
+
update_hash = {}
|
148
|
+
|
149
|
+
unsaved_keys.each do |k|
|
150
|
+
update_hash[k] = serialize_params(obj_values[k])
|
151
|
+
end
|
152
|
+
|
153
|
+
obj_values.each do |k, v|
|
154
|
+
if v.is_a?(StripeObject) || v.is_a?(Hash)
|
155
|
+
update_hash[k] = obj.serialize_nested_object(k)
|
156
|
+
elsif v.is_a?(Array)
|
157
|
+
original_value = obj.instance_variable_get(:@original_values)[k]
|
158
|
+
if original_value && original_value.length > v.length
|
159
|
+
# url params provide no mechanism for deleting an item in an array,
|
160
|
+
# just overwriting the whole array or adding new items. So let's not
|
161
|
+
# allow deleting without a full overwrite until we have a solution.
|
162
|
+
raise ArgumentError.new(
|
163
|
+
"You cannot delete an item from an array, you must instead set a new array"
|
164
|
+
)
|
165
|
+
end
|
166
|
+
update_hash[k] = serialize_params(v, original_value)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
update_hash
|
171
|
+
when Array
|
172
|
+
update_hash = {}
|
173
|
+
obj.each_with_index do |value, index|
|
174
|
+
update = serialize_params(value)
|
175
|
+
if update != {} && (!original_value || update != original_value[index])
|
176
|
+
update_hash[index] = update
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
if update_hash == {}
|
181
|
+
nil
|
182
|
+
else
|
183
|
+
update_hash
|
184
|
+
end
|
185
|
+
else
|
186
|
+
obj
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
121
190
|
protected
|
122
191
|
|
123
192
|
def metaclass
|
data/lib/stripe/version.rb
CHANGED
data/test/stripe/account_test.rb
CHANGED
@@ -26,6 +26,31 @@ module Stripe
|
|
26
26
|
assert !a.details_submitted
|
27
27
|
end
|
28
28
|
|
29
|
+
should "be updatable" do
|
30
|
+
resp = {
|
31
|
+
:id => 'acct_foo',
|
32
|
+
:legal_entity => {
|
33
|
+
:address => {
|
34
|
+
:line1 => '1 Two Three'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
@mock.expects(:get).
|
39
|
+
once.
|
40
|
+
with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
|
41
|
+
returns(test_response(resp))
|
42
|
+
|
43
|
+
@mock.expects(:post).
|
44
|
+
once.
|
45
|
+
with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[first_name]=Bob&legal_entity[address][line1]=2%20Three%20Four').
|
46
|
+
returns(test_response(resp))
|
47
|
+
|
48
|
+
a = Stripe::Account.retrieve('acct_foo')
|
49
|
+
a.legal_entity.first_name = 'Bob'
|
50
|
+
a.legal_entity.address.line1 = '2 Three Four'
|
51
|
+
a.save
|
52
|
+
end
|
53
|
+
|
29
54
|
should "be able to deauthorize an account" do
|
30
55
|
resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
|
31
56
|
@mock.expects(:get).once.returns(test_response(resp))
|
@@ -416,6 +416,116 @@ module Stripe
|
|
416
416
|
assert_equal true, rescued
|
417
417
|
end
|
418
418
|
end
|
419
|
+
|
420
|
+
should 'add key to nested objects' do
|
421
|
+
acct = Stripe::Account.construct_from({
|
422
|
+
:id => 'myid',
|
423
|
+
:legal_entity => {
|
424
|
+
:size => 'l',
|
425
|
+
:score => 4,
|
426
|
+
:height => 10
|
427
|
+
}
|
428
|
+
})
|
429
|
+
|
430
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[first_name]=Bob').returns(test_response({"id" => "myid"}))
|
431
|
+
|
432
|
+
acct.legal_entity.first_name = 'Bob'
|
433
|
+
acct.save
|
434
|
+
end
|
435
|
+
|
436
|
+
should 'save nothing if nothing changes' do
|
437
|
+
acct = Stripe::Account.construct_from({
|
438
|
+
:id => 'myid',
|
439
|
+
:metadata => {
|
440
|
+
:key => 'value'
|
441
|
+
}
|
442
|
+
})
|
443
|
+
|
444
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
|
445
|
+
|
446
|
+
acct.save
|
447
|
+
end
|
448
|
+
|
449
|
+
should 'correctly handle replaced nested objects' do
|
450
|
+
acct = Stripe::Account.construct_from({
|
451
|
+
:id => 'myid',
|
452
|
+
:legal_entity => {
|
453
|
+
:last_name => 'Smith',
|
454
|
+
}
|
455
|
+
})
|
456
|
+
|
457
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[first_name]=Bob&legal_entity[last_name]=').returns(test_response({"id" => "myid"}))
|
458
|
+
|
459
|
+
acct.legal_entity = {:first_name => 'Bob'}
|
460
|
+
acct.save
|
461
|
+
end
|
462
|
+
|
463
|
+
should 'correctly handle array setting' do
|
464
|
+
acct = Stripe::Account.construct_from({
|
465
|
+
:id => 'myid',
|
466
|
+
:legal_entity => {}
|
467
|
+
})
|
468
|
+
|
469
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(test_response({"id" => "myid"}))
|
470
|
+
|
471
|
+
acct.legal_entity.additional_owners = [{:first_name => 'Bob'}]
|
472
|
+
acct.save
|
473
|
+
end
|
474
|
+
|
475
|
+
should 'correctly handle array insertion' do
|
476
|
+
acct = Stripe::Account.construct_from({
|
477
|
+
:id => 'myid',
|
478
|
+
:legal_entity => {
|
479
|
+
:additional_owners => []
|
480
|
+
}
|
481
|
+
})
|
482
|
+
|
483
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][0][first_name]=Bob').returns(test_response({"id" => "myid"}))
|
484
|
+
|
485
|
+
acct.legal_entity.additional_owners << {:first_name => 'Bob'}
|
486
|
+
acct.save
|
487
|
+
end
|
488
|
+
|
489
|
+
should 'correctly handle array updates' do
|
490
|
+
acct = Stripe::Account.construct_from({
|
491
|
+
:id => 'myid',
|
492
|
+
:legal_entity => {
|
493
|
+
:additional_owners => [{:first_name => 'Bob'}, {:first_name => 'Jane'}]
|
494
|
+
}
|
495
|
+
})
|
496
|
+
|
497
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, 'legal_entity[additional_owners][1][first_name]=Janet').returns(test_response({"id" => "myid"}))
|
498
|
+
|
499
|
+
acct.legal_entity.additional_owners[1].first_name = 'Janet'
|
500
|
+
acct.save
|
501
|
+
end
|
502
|
+
|
503
|
+
should 'correctly handle array noops' do
|
504
|
+
acct = Stripe::Account.construct_from({
|
505
|
+
:id => 'myid',
|
506
|
+
:legal_entity => {
|
507
|
+
:additional_owners => [{:first_name => 'Bob'}]
|
508
|
+
},
|
509
|
+
:currencies_supported => ['usd', 'cad']
|
510
|
+
})
|
511
|
+
|
512
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
|
513
|
+
|
514
|
+
acct.save
|
515
|
+
end
|
516
|
+
|
517
|
+
should 'correctly handle hash noops' do
|
518
|
+
acct = Stripe::Account.construct_from({
|
519
|
+
:id => 'myid',
|
520
|
+
:legal_entity => {
|
521
|
+
:address => {:line1 => '1 Two Three'}
|
522
|
+
}
|
523
|
+
})
|
524
|
+
|
525
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/accounts/myid", nil, '').returns(test_response({"id" => "myid"}))
|
526
|
+
|
527
|
+
acct.save
|
528
|
+
end
|
419
529
|
end
|
420
530
|
end
|
421
531
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class BalanceTest < Test::Unit::TestCase
|
5
|
+
should "balance should be retrievable" do
|
6
|
+
@mock.expects(:get).once.returns(test_response(test_balance))
|
7
|
+
balance = Stripe::Balance.retrieve
|
8
|
+
assert_equal('balance', balance['object'])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.20.
|
4
|
+
version: 1.20.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- test/stripe/api_resource_test.rb
|
201
201
|
- test/stripe/application_fee_refund_test.rb
|
202
202
|
- test/stripe/application_fee_test.rb
|
203
|
+
- test/stripe/balance_test.rb
|
203
204
|
- test/stripe/bitcoin_receiver_test.rb
|
204
205
|
- test/stripe/certificate_blacklist_test.rb
|
205
206
|
- test/stripe/charge_test.rb
|
@@ -249,6 +250,7 @@ test_files:
|
|
249
250
|
- test/stripe/api_resource_test.rb
|
250
251
|
- test/stripe/application_fee_refund_test.rb
|
251
252
|
- test/stripe/application_fee_test.rb
|
253
|
+
- test/stripe/balance_test.rb
|
252
254
|
- test/stripe/bitcoin_receiver_test.rb
|
253
255
|
- test/stripe/certificate_blacklist_test.rb
|
254
256
|
- test/stripe/charge_test.rb
|
@@ -268,3 +270,4 @@ test_files:
|
|
268
270
|
- test/stripe/util_test.rb
|
269
271
|
- test/test_data.rb
|
270
272
|
- test/test_helper.rb
|
273
|
+
has_rdoc:
|