stripe 1.44.0 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/History.txt +4 -0
- data/VERSION +1 -1
- data/lib/stripe.rb +7 -6
- data/lib/stripe/api_resource.rb +7 -0
- data/lib/stripe/customer.rb +17 -0
- data/lib/stripe/stripe_object.rb +19 -5
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/api_resource_test.rb +15 -0
- data/test/stripe/customer_test.rb +15 -0
- data/test/stripe/stripe_object_test.rb +21 -0
- data/test/test_helper.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: 5ed148072cc048ea24b62fc7a64645d8714eec90
|
4
|
+
data.tar.gz: 2f478d4c522c9cff1cf502328289233f0b71c8b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4035922aa5bd4d02bf82ea89c52c645cf761ebbedea8ca165b81a6a379af363b9a027911313d447c7db9e846e633774780a0e838b9771c3aaf0fa132992028e2
|
7
|
+
data.tar.gz: ee89f0e1140edeead9e86733d3467468dcdf94551b35878ae438e0acd7dd70ec3a68ca66e3acf5e29d23d194f8cd59bb4641e5d0e6c2eb8efd6ebbe8dc991f1e
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.45.0
|
data/lib/stripe.rb
CHANGED
@@ -424,15 +424,16 @@ module Stripe
|
|
424
424
|
end
|
425
425
|
|
426
426
|
def self.sleep_time(retry_count)
|
427
|
-
#
|
428
|
-
|
429
|
-
#
|
430
|
-
# max_sleep_seconds.
|
427
|
+
# Apply exponential backoff with initial_network_retry_delay on the number
|
428
|
+
# of attempts so far as inputs. Do not allow the number to exceed
|
429
|
+
# max_network_retry_delay.
|
431
430
|
sleep_seconds = [initial_network_retry_delay * (2 ** (retry_count - 1)), max_network_retry_delay].min
|
432
|
-
# Randomize to a random value in the range sleep_seconds/2 .. sleep_seconds
|
433
431
|
|
432
|
+
# Apply some jitter by randomizing the value in the range of (sleep_seconds
|
433
|
+
# / 2) to (sleep_seconds).
|
434
434
|
sleep_seconds = sleep_seconds * (0.5 * (1 + rand()))
|
435
|
-
|
435
|
+
|
436
|
+
# But never sleep less than the base sleep seconds.
|
436
437
|
sleep_seconds = [initial_network_retry_delay, sleep_seconds].max
|
437
438
|
|
438
439
|
sleep_seconds
|
data/lib/stripe/api_resource.rb
CHANGED
@@ -2,6 +2,13 @@ module Stripe
|
|
2
2
|
class APIResource < StripeObject
|
3
3
|
include Stripe::APIOperations::Request
|
4
4
|
|
5
|
+
# A flag that can be set a behavior that will cause this resource to be
|
6
|
+
# encoded and sent up along with an update of its parent resource. This is
|
7
|
+
# usually not desirable because resources are updated individually on their
|
8
|
+
# own endpoints, but there are certain cases, replacing a customer's source
|
9
|
+
# for example, where this is allowed.
|
10
|
+
attr_accessor :save_with_parent
|
11
|
+
|
5
12
|
def self.class_name
|
6
13
|
self.name.split('::')[-1]
|
7
14
|
end
|
data/lib/stripe/customer.rb
CHANGED
@@ -5,6 +5,23 @@ module Stripe
|
|
5
5
|
include Stripe::APIOperations::Save
|
6
6
|
extend Stripe::APIOperations::List
|
7
7
|
|
8
|
+
# Set or replace a customer's default source.
|
9
|
+
def source=(value)
|
10
|
+
super
|
11
|
+
|
12
|
+
# The parent setter will perform certain useful operations like
|
13
|
+
# converting to an APIResource if appropriate.
|
14
|
+
value = self.source
|
15
|
+
|
16
|
+
# Note that source may be a card, but could also be a tokenized card's ID
|
17
|
+
# (which is a string), and so we check its type here.
|
18
|
+
if value.is_a?(APIResource)
|
19
|
+
value.save_with_parent = true
|
20
|
+
end
|
21
|
+
|
22
|
+
value
|
23
|
+
end
|
24
|
+
|
8
25
|
def add_invoice_item(params, opts={})
|
9
26
|
opts = @opts.merge(Util.normalize_opts(opts))
|
10
27
|
InvoiceItem.create(params.merge(:customer => id), opts)
|
data/lib/stripe/stripe_object.rb
CHANGED
@@ -326,11 +326,25 @@ module Stripe
|
|
326
326
|
end
|
327
327
|
|
328
328
|
def serialize_params_value(value, original, unsaved, force)
|
329
|
-
case
|
330
|
-
when nil
|
329
|
+
case true
|
330
|
+
when value == nil
|
331
331
|
''
|
332
332
|
|
333
|
-
|
333
|
+
# The logic here is that essentially any object embedded in another
|
334
|
+
# object that had a `type` is actually an API resource of a different
|
335
|
+
# type that's been included in the response. These other resources must
|
336
|
+
# be updated from their proper endpoints, and therefore they are not
|
337
|
+
# included when serializing even if they've been modified.
|
338
|
+
#
|
339
|
+
# There are _some_ known exceptions though. For example, to save on API
|
340
|
+
# calls it's sometimes desirable to update a customer's default source by
|
341
|
+
# setting a new card (or other) object with `#source=` and then saving
|
342
|
+
# the customer. The `#save_with_parent` flag to override the default
|
343
|
+
# behavior allows us to handle these exceptions.
|
344
|
+
when value.is_a?(APIResource) && !value.save_with_parent
|
345
|
+
nil
|
346
|
+
|
347
|
+
when value.is_a?(Array)
|
334
348
|
update = value.map { |v| serialize_params_value(v, nil, true, force) }
|
335
349
|
|
336
350
|
# This prevents an array that's unchanged from being resent.
|
@@ -350,10 +364,10 @@ module Stripe
|
|
350
364
|
# existing array being held by a StripeObject. This could happen for
|
351
365
|
# example by appending a new hash onto `additional_owners` for an
|
352
366
|
# account.
|
353
|
-
when Hash
|
367
|
+
when value.is_a?(Hash)
|
354
368
|
Util.convert_to_stripe_object(value, @opts).serialize_params
|
355
369
|
|
356
|
-
when StripeObject
|
370
|
+
when value.is_a?(StripeObject)
|
357
371
|
update = value.serialize_params(:force => force)
|
358
372
|
|
359
373
|
# If the entire object was replaced, then we need blank each field of
|
data/lib/stripe/version.rb
CHANGED
@@ -551,6 +551,21 @@ module Stripe
|
|
551
551
|
acct.save
|
552
552
|
end
|
553
553
|
|
554
|
+
should 'not save nested API resources' do
|
555
|
+
ch = Stripe::Charge.construct_from({
|
556
|
+
:id => 'charge_id',
|
557
|
+
:customer => {
|
558
|
+
:object => 'customer',
|
559
|
+
:id => 'customer_id'
|
560
|
+
}
|
561
|
+
})
|
562
|
+
|
563
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/charges/charge_id", nil, '').returns(make_response({"id" => "charge_id"}))
|
564
|
+
|
565
|
+
ch.customer.description = 'Bob'
|
566
|
+
ch.save
|
567
|
+
end
|
568
|
+
|
554
569
|
should 'correctly handle replaced nested objects' do
|
555
570
|
acct = Stripe::Account.construct_from({
|
556
571
|
:id => 'myid',
|
@@ -92,5 +92,20 @@ module Stripe
|
|
92
92
|
c.delete_discount
|
93
93
|
assert_equal nil, c.discount
|
94
94
|
end
|
95
|
+
|
96
|
+
should "can have a token source set" do
|
97
|
+
c = Stripe::Customer.new("test_customer")
|
98
|
+
c.source = "tok_123"
|
99
|
+
assert_equal "tok_123", c.source
|
100
|
+
end
|
101
|
+
|
102
|
+
should "set a flag if given an object source" do
|
103
|
+
c = Stripe::Customer.new("test_customer")
|
104
|
+
c.source = {
|
105
|
+
:object => 'card'
|
106
|
+
}
|
107
|
+
assert_equal true, c.source.save_with_parent
|
108
|
+
end
|
95
109
|
end
|
96
110
|
end
|
111
|
+
|
@@ -240,6 +240,27 @@ module Stripe
|
|
240
240
|
assert_equal([{ :foo => "bar" }], serialized[:metadata])
|
241
241
|
end
|
242
242
|
|
243
|
+
should "#serialize_params and remove embedded APIResources" do
|
244
|
+
obj = Stripe::StripeObject.construct_from({
|
245
|
+
:customer => Customer.construct_from({})
|
246
|
+
})
|
247
|
+
|
248
|
+
serialized = obj.serialize_params
|
249
|
+
assert_equal({}, serialized)
|
250
|
+
end
|
251
|
+
|
252
|
+
should "#serialize_params and remove embedded APIResources unless flagged with save_with_parent" do
|
253
|
+
c = Customer.construct_from({})
|
254
|
+
c.save_with_parent = true
|
255
|
+
|
256
|
+
obj = Stripe::StripeObject.construct_from({
|
257
|
+
:customer => c,
|
258
|
+
})
|
259
|
+
|
260
|
+
serialized = obj.serialize_params
|
261
|
+
assert_equal({ :customer => {} }, serialized)
|
262
|
+
end
|
263
|
+
|
243
264
|
should "#serialize_params takes a force option" do
|
244
265
|
obj = Stripe::StripeObject.construct_from({
|
245
266
|
:id => 'id',
|
data/test/test_helper.rb
CHANGED
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.45.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-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|