stripe 1.36.1 → 1.36.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +4 -0
  3. data/VERSION +1 -1
  4. data/lib/stripe/account.rb +25 -18
  5. data/lib/stripe/api_operations/create.rb +1 -1
  6. data/lib/stripe/api_operations/delete.rb +1 -1
  7. data/lib/stripe/api_operations/list.rb +1 -1
  8. data/lib/stripe/api_operations/update.rb +9 -13
  9. data/lib/stripe/api_resource.rb +4 -4
  10. data/lib/stripe/application_fee.rb +1 -1
  11. data/lib/stripe/application_fee_refund.rb +2 -2
  12. data/lib/stripe/balance_transaction.rb +1 -1
  13. data/lib/stripe/bank_account.rb +4 -4
  14. data/lib/stripe/bitcoin_receiver.rb +4 -4
  15. data/lib/stripe/bitcoin_transaction.rb +1 -1
  16. data/lib/stripe/card.rb +4 -4
  17. data/lib/stripe/charge.rb +6 -6
  18. data/lib/stripe/country_spec.rb +1 -1
  19. data/lib/stripe/customer.rb +3 -3
  20. data/lib/stripe/dispute.rb +1 -1
  21. data/lib/stripe/file_upload.rb +1 -1
  22. data/lib/stripe/invoice.rb +2 -2
  23. data/lib/stripe/list_object.rb +6 -1
  24. data/lib/stripe/order.rb +1 -1
  25. data/lib/stripe/product.rb +0 -9
  26. data/lib/stripe/reversal.rb +2 -2
  27. data/lib/stripe/singleton_api_resource.rb +3 -3
  28. data/lib/stripe/stripe_object.rb +128 -63
  29. data/lib/stripe/subscription.rb +3 -3
  30. data/lib/stripe/transfer.rb +1 -1
  31. data/lib/stripe/version.rb +1 -1
  32. data/test/stripe/account_test.rb +8 -8
  33. data/test/stripe/api_resource_test.rb +1 -1
  34. data/test/stripe/country_spec_test.rb +7 -7
  35. data/test/stripe/customer_card_test.rb +2 -2
  36. data/test/stripe/list_object_test.rb +35 -12
  37. data/test/stripe/recipient_card_test.rb +2 -2
  38. data/test/stripe/stripe_object_test.rb +83 -11
  39. data/test/test_data.rb +23 -23
  40. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c61dab0439a342a7b81c1891bcc86de16f1c2e2
4
- data.tar.gz: d703323b3ea491f50c7b2e3af3022593a4eec0e5
3
+ metadata.gz: 13034f2ff5896fc11dd19069e36bb5d28c29e065
4
+ data.tar.gz: 8a825283ac5be6e8d30415a111b149b67418892e
5
5
  SHA512:
6
- metadata.gz: 3f1b8e24a436c7aca910b09c4b39789c754a65894f5db8d9e7f3986d4f0c16eb79db4688fe5e8e1662873997cb6a867f9e6c90d4ecc983321e521ca5691fadd6
7
- data.tar.gz: 32c5d898c296c3a6b41e0aad9a306d5987a4ede989d3345326856ac5130dd67751faaf97d3551a884594b22c42e05063737518651ff83d81ad2f446533f76470
6
+ metadata.gz: fe4c1d03c1f87740d45bf360227c7bb54305fefda51edf9d491520cfa697c04efc08a061367a77b0114a68eac63328fa48c7a94e08e4d09d699fe567abdbf71c
7
+ data.tar.gz: 7209dab3a89095a82b94f454232fd9772d2b3523830b87fe52ecc774b2a5cf9cda23ebf0eddaaeaac0df1a0968ae70a3f31a2153d101d1b86e3436690fef9592
@@ -1,3 +1,7 @@
1
+ === 1.36.2 2016-03-14
2
+
3
+ * Fix reference to non-existent `#url` in `ListObject`
4
+
1
5
  === 1.36.1 2016-03-04
2
6
 
3
7
  * Fix serialization when subhash given to `#save` or `#update_attributes`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.36.1
1
+ 1.36.2
@@ -5,7 +5,7 @@ module Stripe
5
5
  extend Stripe::APIOperations::List
6
6
  include Stripe::APIOperations::Update
7
7
 
8
- def url
8
+ def resource_url
9
9
  if self['id']
10
10
  super
11
11
  else
@@ -25,7 +25,6 @@ module Stripe
25
25
  opts = id
26
26
  id = nil
27
27
  end
28
-
29
28
  super(id, opts)
30
29
  end
31
30
 
@@ -52,15 +51,16 @@ module Stripe
52
51
  #
53
52
  # We're trying to get this overturned on the server side, but for now,
54
53
  # patch in a special allowance.
55
- def self.serialize_params(obj, original_value=nil)
56
- update_hash = StripeObject.serialize_params(obj, original_value)
57
- case obj
58
- when StripeObject
59
- obj_values = obj.instance_variable_get(:@values)
60
- obj_values.each do |k, v|
61
- if k == :additional_owners && v.is_a?(Array)
62
- update_hash[k] = serialize_additional_owners(obj, v)
63
- end
54
+ def serialize_params(options = {})
55
+ serialize_params_account(self, super)
56
+ end
57
+
58
+ def serialize_params_account(obj, update_hash)
59
+ if entity = @values[:legal_entity]
60
+ if owners = entity[:additional_owners]
61
+ entity_update = update_hash[:legal_entity] ||= {}
62
+ entity_update[:additional_owners] =
63
+ serialize_additional_owners(entity, owners)
64
64
  end
65
65
  end
66
66
  update_hash
@@ -89,9 +89,9 @@ module Stripe
89
89
 
90
90
  private
91
91
 
92
- def self.serialize_additional_owners(obj, value)
93
- original_value = obj.instance_variable_get(:@original_values)[:additional_owners]
94
- if original_value && original_value.length > value.length
92
+ def serialize_additional_owners(legal_entity, additional_owners)
93
+ original_value = legal_entity.instance_variable_get(:@original_values)[:additional_owners]
94
+ if original_value && original_value.length > additional_owners.length
95
95
  # url params provide no mechanism for deleting an item in an array,
96
96
  # just overwriting the whole array or adding new items. So let's not
97
97
  # allow deleting without a full overwrite until we have a solution.
@@ -101,10 +101,17 @@ module Stripe
101
101
  end
102
102
 
103
103
  update_hash = {}
104
- value.each_with_index do |v, i|
105
- update = StripeObject.serialize_params(v)
106
- if update != {} && (!original_value || update != original_value[i])
107
- update_hash[i.to_s] = update
104
+ additional_owners.each_with_index do |v, i|
105
+ # We will almost always see a StripeObject except in the case of a Hash
106
+ # that's been appended to an array of `additional_owners`. We may be
107
+ # able to normalize that ugliness by using an array proxy object with
108
+ # StripeObjects that can detect appends and replace a hash with a
109
+ # StripeObject.
110
+ update = v.is_a?(StripeObject) ? v.serialize_params : v
111
+
112
+ if update != {} && (!original_value ||
113
+ update != legal_entity.serialize_params_value(original_value[i], nil, false, true))
114
+ update_hash[i.to_s] = update
108
115
  end
109
116
  end
110
117
  update_hash
@@ -2,7 +2,7 @@ module Stripe
2
2
  module APIOperations
3
3
  module Create
4
4
  def create(params={}, opts={})
5
- response, opts = request(:post, url, params, opts)
5
+ response, opts = request(:post, resource_url, params, opts)
6
6
  Util.convert_to_stripe_object(response, opts)
7
7
  end
8
8
  end
@@ -3,7 +3,7 @@ module Stripe
3
3
  module Delete
4
4
  def delete(params={}, opts={})
5
5
  opts = Util.normalize_opts(opts)
6
- response, opts = request(:delete, url, params, opts)
6
+ response, opts = request(:delete, resource_url, params, opts)
7
7
  initialize_from(response, opts)
8
8
  end
9
9
  end
@@ -5,7 +5,7 @@ module Stripe
5
5
  opts = Util.normalize_opts(opts)
6
6
  opts = @opts.merge(opts) if @opts
7
7
 
8
- response, opts = request(:get, url, filters, opts)
8
+ response, opts = request(:get, resource_url, filters, opts)
9
9
  obj = ListObject.construct_from(response, opts)
10
10
 
11
11
  # set filters so that we can fetch the same limit, expansions, and
@@ -14,9 +14,6 @@ module Stripe
14
14
  # in the list, it overrides the update URL used for the create or
15
15
  # update.
16
16
  def save(params={})
17
- # Let the caller override the URL but avoid serializing it.
18
- req_url = params.delete(:req_url) || save_url
19
-
20
17
  # We started unintentionally (sort of) allowing attributes sent to
21
18
  # +save+ to override values used during the update. So as not to break
22
19
  # the API, this makes that official here.
@@ -25,16 +22,15 @@ module Stripe
25
22
  # Now remove any parameters that look like object attributes.
26
23
  params = params.reject { |k, _| respond_to?(k) }
27
24
 
28
- values = self.class.serialize_params(self).merge(params)
25
+ values = self.serialize_params(self).merge(params)
29
26
 
30
- if values.length > 0
31
- # note that id gets removed here our call to #url above has already
32
- # generated a uri for this object with an identifier baked in
33
- values.delete(:id)
27
+ # note that id gets removed here our call to #url above has already
28
+ # generated a uri for this object with an identifier baked in
29
+ values.delete(:id)
30
+
31
+ response, opts = request(:post, save_url, values)
32
+ initialize_from(response, opts)
34
33
 
35
- response, opts = request(:post, req_url, values)
36
- initialize_from(response, opts)
37
- end
38
34
  self
39
35
  end
40
36
 
@@ -48,9 +44,9 @@ module Stripe
48
44
  # resource. Otherwise, generate a URL based on the object's identifier
49
45
  # for a normal update.
50
46
  if self[:id] == nil && self.class.respond_to?(:create)
51
- self.class.url
47
+ self.class.resource_url
52
48
  else
53
- url
49
+ resource_url
54
50
  end
55
51
  end
56
52
  end
@@ -6,22 +6,22 @@ module Stripe
6
6
  self.name.split('::')[-1]
7
7
  end
8
8
 
9
- def self.url
9
+ def self.resource_url
10
10
  if self == APIResource
11
11
  raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)')
12
12
  end
13
13
  "/v1/#{CGI.escape(class_name.downcase)}s"
14
14
  end
15
15
 
16
- def url
16
+ def resource_url
17
17
  unless id = self['id']
18
18
  raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
19
19
  end
20
- "#{self.class.url}/#{CGI.escape(id)}"
20
+ "#{self.class.resource_url}/#{CGI.escape(id)}"
21
21
  end
22
22
 
23
23
  def refresh
24
- response, opts = request(:get, url, @retrieve_params)
24
+ response, opts = request(:get, resource_url, @retrieve_params)
25
25
  initialize_from(response, opts)
26
26
  end
27
27
 
@@ -2,7 +2,7 @@ module Stripe
2
2
  class ApplicationFee < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- def self.url
5
+ def self.resource_url
6
6
  '/v1/application_fees'
7
7
  end
8
8
 
@@ -3,8 +3,8 @@ module Stripe
3
3
  include Stripe::APIOperations::Update
4
4
  extend Stripe::APIOperations::List
5
5
 
6
- def url
7
- "#{ApplicationFee.url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
6
+ def resource_url
7
+ "#{ApplicationFee.resource_url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
8
8
  end
9
9
 
10
10
  def self.retrieve(id, api_key=nil)
@@ -2,7 +2,7 @@ module Stripe
2
2
  class BalanceTransaction < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- def self.url
5
+ def self.resource_url
6
6
  '/v1/balance/history'
7
7
  end
8
8
  end
@@ -5,15 +5,15 @@ module Stripe
5
5
  extend Stripe::APIOperations::List
6
6
 
7
7
  def verify(params={}, opts={})
8
- response, opts = request(:post, url + '/verify', params, opts)
8
+ response, opts = request(:post, resource_url + '/verify', params, opts)
9
9
  initialize_from(response, opts)
10
10
  end
11
11
 
12
- def url
12
+ def resource_url
13
13
  if respond_to?(:customer)
14
- "#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
14
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
15
15
  elsif respond_to?(:account)
16
- "#{Account.url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
16
+ "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
17
17
  end
18
18
  end
19
19
 
@@ -5,15 +5,15 @@ module Stripe
5
5
  include Stripe::APIOperations::Delete
6
6
  extend Stripe::APIOperations::List
7
7
 
8
- def self.url
8
+ def self.resource_url
9
9
  "/v1/bitcoin/receivers"
10
10
  end
11
11
 
12
- def url
12
+ def resource_url
13
13
  if respond_to?(:customer) && !self.customer.nil?
14
- "#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
14
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
15
15
  else
16
- "#{self.class.url}/#{CGI.escape(id)}"
16
+ "#{self.class.resource_url}/#{CGI.escape(id)}"
17
17
  end
18
18
  end
19
19
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class BitcoinTransaction < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- def self.url
5
+ def self.resource_url
6
6
  "/v1/bitcoin/transactions"
7
7
  end
8
8
  end
@@ -4,13 +4,13 @@ module Stripe
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
6
 
7
- def url
7
+ def resource_url
8
8
  if respond_to?(:recipient)
9
- "#{Recipient.url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
9
+ "#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
10
10
  elsif respond_to?(:customer)
11
- "#{Customer.url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
11
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
12
12
  elsif respond_to?(:account)
13
- "#{Account.url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
13
+ "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
14
14
  end
15
15
  end
16
16
 
@@ -45,7 +45,7 @@ module Stripe
45
45
  params = {
46
46
  :fraud_details => { :user_report => 'fraudulent' }
47
47
  }
48
- response, opts = request(:post, url, params)
48
+ response, opts = request(:post, resource_url, params)
49
49
  initialize_from(response, opts)
50
50
  end
51
51
 
@@ -53,28 +53,28 @@ module Stripe
53
53
  params = {
54
54
  :fraud_details => { :user_report => 'safe' }
55
55
  }
56
- response, opts = request(:post, url, params)
56
+ response, opts = request(:post, resource_url, params)
57
57
  initialize_from(response, opts)
58
58
  end
59
59
 
60
60
  private
61
61
 
62
62
  def capture_url
63
- url + '/capture'
63
+ resource_url + '/capture'
64
64
  end
65
65
 
66
66
  def dispute_url
67
- url + '/dispute'
67
+ resource_url + '/dispute'
68
68
  end
69
69
 
70
70
  def close_dispute_url
71
- url + '/dispute/close'
71
+ resource_url + '/dispute/close'
72
72
  end
73
73
 
74
74
  # Note that this is actually the *old* refund URL and its use is no longer
75
75
  # preferred.
76
76
  def refund_url
77
- url + '/refund'
77
+ resource_url + '/refund'
78
78
  end
79
79
  end
80
80
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class CountrySpec < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- def self.url
5
+ def self.resource_url
6
6
  '/v1/country_specs'
7
7
  end
8
8
  end
@@ -61,15 +61,15 @@ module Stripe
61
61
  private
62
62
 
63
63
  def discount_url
64
- url + '/discount'
64
+ resource_url + '/discount'
65
65
  end
66
66
 
67
67
  def subscription_url
68
- url + '/subscription'
68
+ resource_url + '/subscription'
69
69
  end
70
70
 
71
71
  def subscriptions_url
72
- url + '/subscriptions'
72
+ resource_url + '/subscriptions'
73
73
  end
74
74
  end
75
75
  end
@@ -10,7 +10,7 @@ module Stripe
10
10
  end
11
11
 
12
12
  def close_url
13
- url + '/close'
13
+ resource_url + '/close'
14
14
  end
15
15
  end
16
16
  end
@@ -3,7 +3,7 @@ module Stripe
3
3
  extend Stripe::APIOperations::Create
4
4
  extend Stripe::APIOperations::List
5
5
 
6
- def self.url
6
+ def self.resource_url
7
7
  "/v1/files"
8
8
  end
9
9
 
@@ -17,11 +17,11 @@ module Stripe
17
17
  private
18
18
 
19
19
  def self.upcoming_url
20
- url + '/upcoming'
20
+ resource_url + '/upcoming'
21
21
  end
22
22
 
23
23
  def pay_url
24
- url + '/pay'
24
+ resource_url + '/pay'
25
25
  end
26
26
  end
27
27
  end
@@ -64,7 +64,7 @@ module Stripe
64
64
 
65
65
  def retrieve(id, opts={})
66
66
  id, retrieve_params = Util.normalize_id(id)
67
- response, opts = request(:get,"#{url}/#{CGI.escape(id)}", retrieve_params, opts)
67
+ response, opts = request(:get,"#{resource_url}/#{CGI.escape(id)}", retrieve_params, opts)
68
68
  Util.convert_to_stripe_object(response, opts)
69
69
  end
70
70
 
@@ -96,5 +96,10 @@ module Stripe
96
96
 
97
97
  list(params, opts)
98
98
  end
99
+
100
+ def resource_url
101
+ self.url ||
102
+ raise(ArgumentError, "List object does not contain a 'url' field.")
103
+ end
99
104
  end
100
105
  end
@@ -12,7 +12,7 @@ module Stripe
12
12
  private
13
13
 
14
14
  def pay_url
15
- url + "/pay"
15
+ resource_url + "/pay"
16
16
  end
17
17
 
18
18
  end
@@ -4,14 +4,5 @@ module Stripe
4
4
  extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
  include Stripe::APIOperations::Delete
7
-
8
- # Keep APIResource#url as `api_url` to avoid letting the external URL
9
- # replace the Stripe URL.
10
- alias_method :api_url, :url
11
-
12
- # Override Stripe::APIOperations::Update#save to explicitly pass URL.
13
- def save
14
- super(:req_url => api_url)
15
- end
16
7
  end
17
8
  end