stripe 3.3.2 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +20 -0
  4. data/.rubocop_todo.yml +62 -0
  5. data/.travis.yml +1 -1
  6. data/Gemfile +19 -12
  7. data/History.txt +10 -0
  8. data/README.md +5 -1
  9. data/Rakefile +8 -5
  10. data/VERSION +1 -1
  11. data/bin/stripe-console +2 -2
  12. data/lib/stripe.rb +72 -74
  13. data/lib/stripe/account.rb +15 -17
  14. data/lib/stripe/alipay_account.rb +10 -7
  15. data/lib/stripe/api_operations/create.rb +1 -1
  16. data/lib/stripe/api_operations/delete.rb +1 -1
  17. data/lib/stripe/api_operations/list.rb +2 -2
  18. data/lib/stripe/api_operations/request.rb +5 -12
  19. data/lib/stripe/api_operations/save.rb +6 -6
  20. data/lib/stripe/api_resource.rb +7 -9
  21. data/lib/stripe/apple_pay_domain.rb +2 -2
  22. data/lib/stripe/application_fee.rb +5 -5
  23. data/lib/stripe/application_fee_refund.rb +5 -5
  24. data/lib/stripe/balance.rb +1 -1
  25. data/lib/stripe/balance_transaction.rb +2 -2
  26. data/lib/stripe/bank_account.rb +7 -7
  27. data/lib/stripe/bitcoin_receiver.rb +4 -2
  28. data/lib/stripe/bitcoin_transaction.rb +3 -1
  29. data/lib/stripe/card.rb +5 -5
  30. data/lib/stripe/charge.rb +18 -18
  31. data/lib/stripe/country_spec.rb +2 -2
  32. data/lib/stripe/coupon.rb +1 -1
  33. data/lib/stripe/customer.rb +23 -23
  34. data/lib/stripe/dispute.rb +3 -3
  35. data/lib/stripe/ephemeral_key.rb +4 -4
  36. data/lib/stripe/errors.rb +4 -4
  37. data/lib/stripe/event.rb +1 -1
  38. data/lib/stripe/file_upload.rb +5 -5
  39. data/lib/stripe/invoice.rb +7 -7
  40. data/lib/stripe/invoice_item.rb +1 -1
  41. data/lib/stripe/invoice_line_item.rb +1 -1
  42. data/lib/stripe/list_object.rb +14 -18
  43. data/lib/stripe/login_link.rb +3 -3
  44. data/lib/stripe/oauth.rb +15 -13
  45. data/lib/stripe/order.rb +5 -5
  46. data/lib/stripe/order_return.rb +1 -1
  47. data/lib/stripe/payout.rb +3 -3
  48. data/lib/stripe/plan.rb +1 -1
  49. data/lib/stripe/product.rb +1 -1
  50. data/lib/stripe/recipient.rb +3 -2
  51. data/lib/stripe/recipient_transfer.rb +1 -2
  52. data/lib/stripe/refund.rb +1 -1
  53. data/lib/stripe/reversal.rb +5 -5
  54. data/lib/stripe/singleton_api_resource.rb +3 -3
  55. data/lib/stripe/sku.rb +1 -1
  56. data/lib/stripe/source.rb +13 -10
  57. data/lib/stripe/stripe_client.rb +149 -169
  58. data/lib/stripe/stripe_object.rb +77 -76
  59. data/lib/stripe/subscription.rb +5 -5
  60. data/lib/stripe/subscription_item.rb +2 -2
  61. data/lib/stripe/three_d_secure.rb +1 -1
  62. data/lib/stripe/token.rb +1 -1
  63. data/lib/stripe/transfer.rb +3 -3
  64. data/lib/stripe/util.rb +77 -62
  65. data/lib/stripe/version.rb +1 -1
  66. data/lib/stripe/webhook.rb +14 -10
  67. data/stripe.gemspec +14 -14
  68. data/test/stripe/account_test.rb +69 -81
  69. data/test/stripe/alipay_account_test.rb +19 -1
  70. data/test/stripe/api_operations_test.rb +7 -7
  71. data/test/stripe/api_resource_test.rb +224 -260
  72. data/test/stripe/apple_pay_domain_test.rb +8 -8
  73. data/test/stripe/application_fee_refund_test.rb +8 -8
  74. data/test/stripe/application_fee_test.rb +3 -3
  75. data/test/stripe/balance_test.rb +2 -2
  76. data/test/stripe/bank_account_test.rb +9 -11
  77. data/test/stripe/charge_test.rb +11 -11
  78. data/test/stripe/country_spec_test.rb +4 -4
  79. data/test/stripe/coupon_test.rb +10 -10
  80. data/test/stripe/customer_card_test.rb +11 -15
  81. data/test/stripe/customer_test.rb +26 -27
  82. data/test/stripe/dispute_test.rb +8 -8
  83. data/test/stripe/ephemeral_key_test.rb +14 -14
  84. data/test/stripe/errors_test.rb +2 -2
  85. data/test/stripe/file_upload_test.rb +26 -28
  86. data/test/stripe/invoice_item_test.rb +14 -14
  87. data/test/stripe/invoice_line_item_test.rb +1 -1
  88. data/test/stripe/invoice_test.rb +37 -37
  89. data/test/stripe/list_object_test.rb +60 -76
  90. data/test/stripe/login_link_test.rb +14 -14
  91. data/test/stripe/oauth_test.rb +42 -50
  92. data/test/stripe/order_return_test.rb +5 -5
  93. data/test/stripe/order_test.rb +12 -12
  94. data/test/stripe/payout_test.rb +9 -9
  95. data/test/stripe/plan_test.rb +9 -9
  96. data/test/stripe/product_test.rb +8 -8
  97. data/test/stripe/recipient_test.rb +9 -10
  98. data/test/stripe/refund_test.rb +9 -9
  99. data/test/stripe/reversal_test.rb +10 -10
  100. data/test/stripe/sku_test.rb +8 -8
  101. data/test/stripe/source_test.rb +14 -16
  102. data/test/stripe/stripe_client_test.rb +235 -266
  103. data/test/stripe/stripe_object_test.rb +163 -147
  104. data/test/stripe/stripe_response_test.rb +4 -3
  105. data/test/stripe/subscription_item_test.rb +11 -11
  106. data/test/stripe/subscription_test.rb +14 -14
  107. data/test/stripe/three_d_secure_test.rb +2 -2
  108. data/test/stripe/transfer_test.rb +8 -8
  109. data/test/stripe/util_test.rb +59 -57
  110. data/test/stripe/webhook_test.rb +18 -16
  111. data/test/stripe_test.rb +4 -4
  112. data/test/test_data.rb +26 -26
  113. data/test/test_helper.rb +29 -25
  114. metadata +6 -10
  115. data/test/stripe/bitcoin_receiver_test.rb +0 -67
  116. data/test/stripe/bitcoin_transaction_test.rb +0 -19
  117. data/test/stripe/recipient_card_test.rb +0 -44
@@ -3,20 +3,23 @@ module Stripe
3
3
  include Stripe::APIOperations::Save
4
4
  include Stripe::APIOperations::Delete
5
5
 
6
- OBJECT_NAME = 'alipay_account'
6
+ OBJECT_NAME = "alipay_account".freeze
7
7
 
8
8
  def resource_url
9
- if respond_to?(:customer) && !self.customer.nil?
10
- "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
9
+ if !respond_to?(:customer) || customer.nil?
10
+ raise NotImplementedError,
11
+ "Alipay accounts cannot be accessed without a customer ID."
11
12
  end
13
+
14
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
12
15
  end
13
16
 
14
- def self.update(id, params=nil, opts=nil)
15
- raise NotImplementedError.new("Alipay accounts cannot be updated without a customer ID. Update an Alipay account by `a = customer.sources.retrieve('alipay_account_id'); a.save`")
17
+ def self.update(_id, _params = nil, _opts = nil)
18
+ raise NotImplementedError, "Alipay accounts cannot be updated without a customer ID. Update an Alipay account by `a = customer.sources.retrieve('alipay_account_id'); a.save`"
16
19
  end
17
20
 
18
- def self.retrieve(id, opts=nil)
19
- raise NotImplementedError.new("Alipay accounts cannot be retrieved without a customer ID. Retrieve an Alipay account using customer.sources.retrieve('alipay_account_id')")
21
+ def self.retrieve(_id, _opts = nil)
22
+ raise NotImplementedError, "Alipay accounts cannot be retrieved without a customer ID. Retrieve an Alipay account using customer.sources.retrieve('alipay_account_id')"
20
23
  end
21
24
  end
22
25
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  module APIOperations
3
3
  module Create
4
- def create(params={}, opts={})
4
+ def create(params = {}, opts = {})
5
5
  resp, opts = request(:post, resource_url, params, opts)
6
6
  Util.convert_to_stripe_object(resp.data, opts)
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  module APIOperations
3
3
  module Delete
4
- def delete(params={}, opts={})
4
+ def delete(params = {}, opts = {})
5
5
  opts = Util.normalize_opts(opts)
6
6
  resp, opts = request(:delete, resource_url, params, opts)
7
7
  initialize_from(resp.data, opts)
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  module APIOperations
3
3
  module List
4
- def list(filters={}, opts={})
4
+ def list(filters = {}, opts = {})
5
5
  opts = Util.normalize_opts(opts)
6
6
 
7
7
  resp, opts = request(:get, resource_url, filters, opts)
@@ -22,7 +22,7 @@ module Stripe
22
22
  # #all, and this alias allows us to maintain backward compatibility (the
23
23
  # choice was somewhat misleading in the way that it only returned a single
24
24
  # page rather than all objects).
25
- alias :all :list
25
+ alias all list
26
26
  end
27
27
  end
28
28
  end
@@ -2,9 +2,7 @@ module Stripe
2
2
  module APIOperations
3
3
  module Request
4
4
  module ClassMethods
5
- OPTS_KEYS_TO_PERSIST = Set[:api_key, :api_base, :client, :stripe_account, :stripe_version]
6
-
7
- def request(method, url, params={}, opts={})
5
+ def request(method, url, params = {}, opts = {})
8
6
  warn_on_opts_in_params(params)
9
7
 
10
8
  opts = Util.normalize_opts(opts)
@@ -25,9 +23,7 @@ module Stripe
25
23
  # Hash#select returns an array before 1.9
26
24
  opts_to_persist = {}
27
25
  opts.each do |k, v|
28
- if OPTS_KEYS_TO_PERSIST.include?(k)
29
- opts_to_persist[k] = v
30
- end
26
+ opts_to_persist[k] = v if Util::OPTS_KEYS_TO_PERSIST.include?(k)
31
27
  end
32
28
 
33
29
  [resp, opts_to_persist]
@@ -35,12 +31,9 @@ module Stripe
35
31
 
36
32
  private
37
33
 
38
- KNOWN_OPTS = Set[:api_key, :idempotency_key, :stripe_account, :stripe_version]
39
- private_constant :KNOWN_OPTS
40
-
41
34
  def warn_on_opts_in_params(params)
42
- KNOWN_OPTS.each do |opt|
43
- if params.has_key?(opt)
35
+ Util::OPTS_USER_SPECIFIED.each do |opt|
36
+ if params.key?(opt)
44
37
  $stderr.puts("WARNING: #{opt} should be in opts instead of params.")
45
38
  end
46
39
  end
@@ -53,7 +46,7 @@ module Stripe
53
46
 
54
47
  protected
55
48
 
56
- def request(method, url, params={}, opts={})
49
+ def request(method, url, params = {}, opts = {})
57
50
  opts = @opts.merge(Util.normalize_opts(opts))
58
51
  self.class.request(method, url, params, opts)
59
52
  end
@@ -14,9 +14,9 @@ module Stripe
14
14
  # object values) to be added to the request. E.g. to allow for an
15
15
  # idempotency_key to be passed in the request headers, or for the
16
16
  # api_key to be overwritten. See {APIOperations::Request.request}.
17
- def update(id, params={}, opts={})
18
- params.each do |k, v|
19
- if self.protected_fields.include?(k)
17
+ def update(id, params = {}, opts = {})
18
+ params.each_key do |k|
19
+ if protected_fields.include?(k)
20
20
  raise ArgumentError, "Cannot update protected field: #{k}"
21
21
  end
22
22
  end
@@ -42,7 +42,7 @@ module Stripe
42
42
  # object values) to be added to the request. E.g. to allow for an
43
43
  # idempotency_key to be passed in the request headers, or for the
44
44
  # api_key to be overwritten. See {APIOperations::Request.request}.
45
- def save(params={}, opts={})
45
+ def save(params = {}, opts = {})
46
46
  # We started unintentionally (sort of) allowing attributes sent to
47
47
  # +save+ to override values used during the update. So as not to break
48
48
  # the API, this makes that official here.
@@ -51,7 +51,7 @@ module Stripe
51
51
  # Now remove any parameters that look like object attributes.
52
52
  params = params.reject { |k, _| respond_to?(k) }
53
53
 
54
- values = self.serialize_params(self).merge(params)
54
+ values = serialize_params(self).merge(params)
55
55
 
56
56
  # note that id gets removed here our call to #url above has already
57
57
  # generated a uri for this object with an identifier baked in
@@ -74,7 +74,7 @@ module Stripe
74
74
  # Stripe::APIOperations::Create), then use the URL to create a new
75
75
  # resource. Otherwise, generate a URL based on the object's identifier
76
76
  # for a normal update.
77
- if self[:id] == nil && self.class.respond_to?(:create)
77
+ if self[:id].nil? && self.class.respond_to?(:create)
78
78
  self.class.resource_url
79
79
  else
80
80
  resource_url
@@ -10,12 +10,12 @@ module Stripe
10
10
  attr_accessor :save_with_parent
11
11
 
12
12
  def self.class_name
13
- self.name.split('::')[-1]
13
+ name.split("::")[-1]
14
14
  end
15
15
 
16
16
  def self.resource_url
17
17
  if self == APIResource
18
- raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)')
18
+ raise NotImplementedError, "APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)"
19
19
  end
20
20
  "/v1/#{CGI.escape(class_name.downcase)}s"
21
21
  end
@@ -38,17 +38,15 @@ module Stripe
38
38
  # Note that the value may be subresource, but could also be a scalar
39
39
  # (like a tokenized card's ID for example), so we check the type before
40
40
  # setting #save_with_parent here.
41
- if value.is_a?(APIResource)
42
- value.save_with_parent = true
43
- end
41
+ value.save_with_parent = true if value.is_a?(APIResource)
44
42
 
45
43
  value
46
44
  end
47
45
  end
48
46
 
49
47
  def resource_url
50
- unless id = self['id']
51
- raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
48
+ unless (id = self["id"])
49
+ raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", "id")
52
50
  end
53
51
  "#{self.class.resource_url}/#{CGI.escape(id)}"
54
52
  end
@@ -58,9 +56,9 @@ module Stripe
58
56
  initialize_from(resp.data, opts)
59
57
  end
60
58
 
61
- def self.retrieve(id, opts={})
59
+ def self.retrieve(id, opts = {})
62
60
  opts = Util.normalize_opts(opts)
63
- instance = self.new(id, opts)
61
+ instance = new(id, opts)
64
62
  instance.refresh
65
63
  instance
66
64
  end
@@ -5,10 +5,10 @@ module Stripe
5
5
  include Stripe::APIOperations::Delete
6
6
  extend Stripe::APIOperations::List
7
7
 
8
- OBJECT_NAME = 'apple_pay_domain'
8
+ OBJECT_NAME = "apple_pay_domain".freeze
9
9
 
10
10
  def self.resource_url
11
- '/v1/apple_pay/domains'
11
+ "/v1/apple_pay/domains"
12
12
  end
13
13
  end
14
14
  end
@@ -2,21 +2,21 @@ module Stripe
2
2
  class ApplicationFee < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- OBJECT_NAME = 'application_fee'
5
+ OBJECT_NAME = "application_fee".freeze
6
6
 
7
7
  def self.resource_url
8
- '/v1/application_fees'
8
+ "/v1/application_fees"
9
9
  end
10
10
 
11
11
  # If you don't need access to an updated fee object after the refund, it's
12
12
  # more performant to just call `fee.refunds.create` directly.
13
- def refund(params={}, opts={})
14
- self.refunds.create(params, opts)
13
+ def refund(params = {}, opts = {})
14
+ refunds.create(params, opts)
15
15
 
16
16
  # now that a refund has been created, we expect the state of this object
17
17
  # to change as well (i.e. `refunded` will now be `true`) so refresh it
18
18
  # from the server
19
- self.refresh
19
+ refresh
20
20
  end
21
21
  end
22
22
  end
@@ -3,18 +3,18 @@ module Stripe
3
3
  include Stripe::APIOperations::Save
4
4
  extend Stripe::APIOperations::List
5
5
 
6
- OBJECT_NAME = 'fee_refund'
6
+ OBJECT_NAME = "fee_refund".freeze
7
7
 
8
8
  def resource_url
9
9
  "#{ApplicationFee.resource_url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
10
10
  end
11
11
 
12
- def self.update(id, params=nil, opts=nil)
13
- raise NotImplementedError.new("Refunds cannot be updated without an application fee ID. Update a refund by using `a = appfee.refunds.retrieve('refund_id'); a.save`")
12
+ def self.update(_id, _params = nil, _opts = nil)
13
+ raise NotImplementedError, "Refunds cannot be updated without an application fee ID. Update a refund by using `a = appfee.refunds.retrieve('refund_id'); a.save`"
14
14
  end
15
15
 
16
- def self.retrieve(id, api_key=nil)
17
- raise NotImplementedError.new("Refunds cannot be retrieved without an application fee ID. Retrieve a refund using appfee.refunds.retrieve('refund_id')")
16
+ def self.retrieve(_id, _api_key = nil)
17
+ raise NotImplementedError, "Refunds cannot be retrieved without an application fee ID. Retrieve a refund using appfee.refunds.retrieve('refund_id')"
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  class Balance < SingletonAPIResource
3
- OBJECT_NAME = 'balance'
3
+ OBJECT_NAME = "balance".freeze
4
4
  end
5
5
  end
@@ -2,10 +2,10 @@ module Stripe
2
2
  class BalanceTransaction < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
 
5
- OBJECT_NAME = 'balance_transaction'
5
+ OBJECT_NAME = "balance_transaction".freeze
6
6
 
7
7
  def self.resource_url
8
- '/v1/balance/history'
8
+ "/v1/balance/history"
9
9
  end
10
10
  end
11
11
  end
@@ -4,10 +4,10 @@ module Stripe
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
6
 
7
- OBJECT_NAME = 'bank_account'
7
+ OBJECT_NAME = "bank_account".freeze
8
8
 
9
- def verify(params={}, opts={})
10
- resp, opts = request(:post, resource_url + '/verify', params, opts)
9
+ def verify(params = {}, opts = {})
10
+ resp, opts = request(:post, resource_url + "/verify", params, opts)
11
11
  initialize_from(resp.data, opts)
12
12
  end
13
13
 
@@ -19,12 +19,12 @@ module Stripe
19
19
  end
20
20
  end
21
21
 
22
- def self.update(id, params=nil, opts=nil)
23
- raise NotImplementedError.new("Bank accounts cannot be updated without an account ID. Update a bank account by using `a = account.external_accounts.retrieve('card_id'); a.save`")
22
+ def self.update(_id, _params = nil, _opts = nil)
23
+ raise NotImplementedError, "Bank accounts cannot be updated without an account ID. Update a bank account by using `a = account.external_accounts.retrieve('card_id'); a.save`"
24
24
  end
25
25
 
26
- def self.retrieve(id, opts=nil)
27
- raise NotImplementedError.new("Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')")
26
+ def self.retrieve(_id, _opts = nil)
27
+ raise NotImplementedError, "Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')"
28
28
  end
29
29
  end
30
30
  end
@@ -1,18 +1,20 @@
1
1
  module Stripe
2
2
  class BitcoinReceiver < APIResource
3
+ # Directly creating or retrieving BitcoinReceivers is deprecated. Please use
4
+ # the Sources API instead: https://stripe.com/docs/sources/bitcoin
3
5
  extend Stripe::APIOperations::Create
4
6
  include Stripe::APIOperations::Save
5
7
  include Stripe::APIOperations::Delete
6
8
  extend Stripe::APIOperations::List
7
9
 
8
- OBJECT_NAME = 'bitcoin_receiver'
10
+ OBJECT_NAME = "bitcoin_receiver".freeze
9
11
 
10
12
  def self.resource_url
11
13
  "/v1/bitcoin/receivers"
12
14
  end
13
15
 
14
16
  def resource_url
15
- if respond_to?(:customer) && !self.customer.nil? && self.customer != ""
17
+ if respond_to?(:customer) && !customer.nil? && customer != ""
16
18
  "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
17
19
  else
18
20
  "#{self.class.resource_url}/#{CGI.escape(id)}"
@@ -1,8 +1,10 @@
1
1
  module Stripe
2
2
  class BitcoinTransaction < APIResource
3
+ # Directly retrieving BitcoinTransactions is deprecated. Please use the
4
+ # Sources API instead: https://stripe.com/docs/sources/bitcoin
3
5
  extend Stripe::APIOperations::List
4
6
 
5
- OBJECT_NAME = 'bitcoin_transaction'
7
+ OBJECT_NAME = "bitcoin_transaction".freeze
6
8
 
7
9
  def self.resource_url
8
10
  "/v1/bitcoin/transactions"
data/lib/stripe/card.rb CHANGED
@@ -4,7 +4,7 @@ module Stripe
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
6
 
7
- OBJECT_NAME = 'card'
7
+ OBJECT_NAME = "card".freeze
8
8
 
9
9
  def resource_url
10
10
  if respond_to?(:recipient) && !recipient.nil? && !recipient.empty?
@@ -16,12 +16,12 @@ module Stripe
16
16
  end
17
17
  end
18
18
 
19
- def self.update(id, params=nil, opts=nil)
20
- raise NotImplementedError.new("Cards cannot be updated without a customer ID. Update a card using `c = customer.sources.retrieve('card_id'); c.save`")
19
+ def self.update(_id, _params = nil, _opts = nil)
20
+ raise NotImplementedError, "Cards cannot be updated without a customer ID. Update a card using `c = customer.sources.retrieve('card_id'); c.save`"
21
21
  end
22
22
 
23
- def self.retrieve(id, opts=nil)
24
- raise NotImplementedError.new("Cards cannot be retrieved without a customer ID. Retrieve a card using customer.sources.retrieve('card_id')")
23
+ def self.retrieve(_id, _opts = nil)
24
+ raise NotImplementedError, "Cards cannot be retrieved without a customer ID. Retrieve a card using customer.sources.retrieve('card_id')"
25
25
  end
26
26
  end
27
27
  end
data/lib/stripe/charge.rb CHANGED
@@ -4,9 +4,9 @@ module Stripe
4
4
  extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Save
6
6
 
7
- OBJECT_NAME = 'charge'
7
+ OBJECT_NAME = "charge".freeze
8
8
 
9
- def refund(params={}, opts={})
9
+ def refund(params = {}, opts = {})
10
10
  # Old versions of charge objects included a `refunds` field that was just
11
11
  # a vanilla array instead of a Stripe list object.
12
12
  #
@@ -14,38 +14,38 @@ module Stripe
14
14
  # `self.refunds.create`), but detect the old API version by looking for
15
15
  # an `Array` and fall back to the old refund URL if necessary so as to
16
16
  # maintain internal compatibility.
17
- unless self.refunds.is_a?(Array)
18
- self.refunds.create(params, opts)
17
+ if refunds.is_a?(Array)
18
+ resp, opts = request(:post, refund_url, params, opts)
19
+ initialize_from(resp.data, opts)
20
+ else
21
+ refunds.create(params, opts)
19
22
 
20
23
  # now that a refund has been created, we expect the state of this object
21
24
  # to change as well (i.e. `refunded` will now be `true`) so refresh it
22
25
  # from the server
23
- self.refresh
24
- else
25
- resp, opts = request(:post, refund_url, params, opts)
26
- initialize_from(resp.data, opts)
26
+ refresh
27
27
  end
28
28
  end
29
29
 
30
- def capture(params={}, opts={})
30
+ def capture(params = {}, opts = {})
31
31
  resp, opts = request(:post, capture_url, params, opts)
32
32
  initialize_from(resp.data, opts)
33
33
  end
34
34
 
35
- def update_dispute(params={}, opts={})
35
+ def update_dispute(params = {}, opts = {})
36
36
  resp, opts = request(:post, dispute_url, params, opts)
37
- initialize_from({ :dispute => resp.data }, opts, true)
37
+ initialize_from({ dispute: resp.data }, opts, true)
38
38
  dispute
39
39
  end
40
40
 
41
- def close_dispute(params={}, opts={})
41
+ def close_dispute(params = {}, opts = {})
42
42
  resp, opts = request(:post, close_dispute_url, params, opts)
43
43
  initialize_from(resp.data, opts)
44
44
  end
45
45
 
46
46
  def mark_as_fraudulent
47
47
  params = {
48
- :fraud_details => { :user_report => 'fraudulent' }
48
+ fraud_details: { user_report: "fraudulent" },
49
49
  }
50
50
  resp, opts = request(:post, resource_url, params)
51
51
  initialize_from(resp.data, opts)
@@ -53,7 +53,7 @@ module Stripe
53
53
 
54
54
  def mark_as_safe
55
55
  params = {
56
- :fraud_details => { :user_report => 'safe' }
56
+ fraud_details: { user_report: "safe" },
57
57
  }
58
58
  resp, opts = request(:post, resource_url, params)
59
59
  initialize_from(resp.data, opts)
@@ -62,21 +62,21 @@ module Stripe
62
62
  private
63
63
 
64
64
  def capture_url
65
- resource_url + '/capture'
65
+ resource_url + "/capture"
66
66
  end
67
67
 
68
68
  def dispute_url
69
- resource_url + '/dispute'
69
+ resource_url + "/dispute"
70
70
  end
71
71
 
72
72
  def close_dispute_url
73
- resource_url + '/dispute/close'
73
+ resource_url + "/dispute/close"
74
74
  end
75
75
 
76
76
  # Note that this is actually the *old* refund URL and its use is no longer
77
77
  # preferred.
78
78
  def refund_url
79
- resource_url + '/refund'
79
+ resource_url + "/refund"
80
80
  end
81
81
  end
82
82
  end