stripe 1.44.0 → 1.45.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 119a28c4474b441d0acfc5e6ebbbf47038e9e509
4
- data.tar.gz: 14c9aeb9e6f6a78a73b7bfa2cd94b4135a627eff
3
+ metadata.gz: 5ed148072cc048ea24b62fc7a64645d8714eec90
4
+ data.tar.gz: 2f478d4c522c9cff1cf502328289233f0b71c8b2
5
5
  SHA512:
6
- metadata.gz: 0f7809e7801f9a9f32b82680b8d0ff02fa90348cd7753a08c46aa61745e8b70900465fe263635e07ac01df29abc424b5bfe38320bd82ea723cf652edb4101430
7
- data.tar.gz: efede3fa5a4f1e3f4ffbb3c2f21820aa4f7b948442d1ab83acf79485826735068bce355331bfc005770a8ad0d77611c106ae156faae4bcc998576abafdfc269d
6
+ metadata.gz: 4035922aa5bd4d02bf82ea89c52c645cf761ebbedea8ca165b81a6a379af363b9a027911313d447c7db9e846e633774780a0e838b9771c3aaf0fa132992028e2
7
+ data.tar.gz: ee89f0e1140edeead9e86733d3467468dcdf94551b35878ae438e0acd7dd70ec3a68ca66e3acf5e29d23d194f8cd59bb4641e5d0e6c2eb8efd6ebbe8dc991f1e
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ group :development do
6
6
  gem 'mocha', '~> 0.13.2'
7
7
  gem 'pry'
8
8
  gem 'rake'
9
- gem 'shoulda', '~> 3.4.0'
9
+ gem 'shoulda-context'
10
10
  gem 'test-unit'
11
11
 
12
12
  platforms :mri do
@@ -1,3 +1,7 @@
1
+ === 1.45.0 2016-07-07
2
+
3
+ * Do not send subresources when updating except when explicitly told to do so (see #433)
4
+
1
5
  === 1.44.0 2016-06-29
2
6
 
3
7
  * Add `update` class method to all resources that can be updated
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.44.0
1
+ 1.45.0
@@ -424,15 +424,16 @@ module Stripe
424
424
  end
425
425
 
426
426
  def self.sleep_time(retry_count)
427
- # This method was adapted from https://github.com/ooyala/retries/blob/master/lib/retries.rb
428
-
429
- # The sleep time is an exponentially-increasing function of base_sleep_seconds. But, it never exceeds
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
- # But never sleep less than base_sleep_seconds
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
@@ -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
@@ -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)
@@ -326,11 +326,25 @@ module Stripe
326
326
  end
327
327
 
328
328
  def serialize_params_value(value, original, unsaved, force)
329
- case value
330
- when nil
329
+ case true
330
+ when value == nil
331
331
  ''
332
332
 
333
- when Array
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
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.44.0'
2
+ VERSION = '1.45.0'
3
3
  end
@@ -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',
@@ -2,7 +2,7 @@ require 'stripe'
2
2
  require 'test/unit'
3
3
  require 'mocha/setup'
4
4
  require 'stringio'
5
- require 'shoulda'
5
+ require 'shoulda/context'
6
6
  require File.expand_path('../test_data', __FILE__)
7
7
 
8
8
  # monkeypatch request methods
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.44.0
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-06-29 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client