stripe 4.18.1 → 4.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +3 -0
  5. data/README.md +9 -9
  6. data/VERSION +1 -1
  7. data/lib/stripe.rb +2 -75
  8. data/lib/stripe/object_types.rb +97 -0
  9. data/lib/stripe/resources.rb +78 -0
  10. data/lib/stripe/{account.rb → resources/account.rb} +13 -12
  11. data/lib/stripe/{account_link.rb → resources/account_link.rb} +0 -0
  12. data/lib/stripe/{alipay_account.rb → resources/alipay_account.rb} +0 -0
  13. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +0 -0
  14. data/lib/stripe/{application_fee.rb → resources/application_fee.rb} +0 -0
  15. data/lib/stripe/{application_fee_refund.rb → resources/application_fee_refund.rb} +0 -0
  16. data/lib/stripe/{balance.rb → resources/balance.rb} +0 -0
  17. data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +0 -0
  18. data/lib/stripe/{bank_account.rb → resources/bank_account.rb} +2 -4
  19. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +3 -4
  20. data/lib/stripe/{bitcoin_transaction.rb → resources/bitcoin_transaction.rb} +0 -0
  21. data/lib/stripe/{capability.rb → resources/capability.rb} +0 -0
  22. data/lib/stripe/{card.rb → resources/card.rb} +3 -6
  23. data/lib/stripe/{charge.rb → resources/charge.rb} +0 -0
  24. data/lib/stripe/{checkout → resources/checkout}/session.rb +0 -0
  25. data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +0 -0
  26. data/lib/stripe/{coupon.rb → resources/coupon.rb} +0 -0
  27. data/lib/stripe/{credit_note.rb → resources/credit_note.rb} +1 -1
  28. data/lib/stripe/{customer.rb → resources/customer.rb} +8 -5
  29. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  30. data/lib/stripe/{discount.rb → resources/discount.rb} +0 -0
  31. data/lib/stripe/{dispute.rb → resources/dispute.rb} +1 -1
  32. data/lib/stripe/{ephemeral_key.rb → resources/ephemeral_key.rb} +0 -0
  33. data/lib/stripe/{event.rb → resources/event.rb} +0 -0
  34. data/lib/stripe/{exchange_rate.rb → resources/exchange_rate.rb} +0 -0
  35. data/lib/stripe/{file.rb → resources/file.rb} +4 -1
  36. data/lib/stripe/{file_link.rb → resources/file_link.rb} +0 -0
  37. data/lib/stripe/{invoice.rb → resources/invoice.rb} +6 -7
  38. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +0 -0
  39. data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +0 -0
  40. data/lib/stripe/{issuer_fraud_record.rb → resources/issuer_fraud_record.rb} +0 -0
  41. data/lib/stripe/{issuing → resources/issuing}/authorization.rb +2 -2
  42. data/lib/stripe/{issuing → resources/issuing}/card.rb +0 -0
  43. data/lib/stripe/{issuing → resources/issuing}/card_details.rb +0 -0
  44. data/lib/stripe/{issuing → resources/issuing}/cardholder.rb +0 -0
  45. data/lib/stripe/{issuing → resources/issuing}/dispute.rb +0 -0
  46. data/lib/stripe/{issuing → resources/issuing}/transaction.rb +0 -0
  47. data/lib/stripe/{login_link.rb → resources/login_link.rb} +0 -0
  48. data/lib/stripe/{order.rb → resources/order.rb} +4 -4
  49. data/lib/stripe/{order_return.rb → resources/order_return.rb} +0 -0
  50. data/lib/stripe/{payment_intent.rb → resources/payment_intent.rb} +3 -3
  51. data/lib/stripe/{payment_method.rb → resources/payment_method.rb} +2 -2
  52. data/lib/stripe/{payout.rb → resources/payout.rb} +1 -1
  53. data/lib/stripe/{person.rb → resources/person.rb} +0 -0
  54. data/lib/stripe/{plan.rb → resources/plan.rb} +0 -0
  55. data/lib/stripe/{product.rb → resources/product.rb} +0 -0
  56. data/lib/stripe/{radar → resources/radar}/early_fraud_warning.rb +0 -0
  57. data/lib/stripe/{radar → resources/radar}/value_list.rb +0 -0
  58. data/lib/stripe/{radar → resources/radar}/value_list_item.rb +0 -0
  59. data/lib/stripe/{recipient.rb → resources/recipient.rb} +0 -0
  60. data/lib/stripe/{recipient_transfer.rb → resources/recipient_transfer.rb} +0 -0
  61. data/lib/stripe/{refund.rb → resources/refund.rb} +0 -0
  62. data/lib/stripe/{reporting → resources/reporting}/report_run.rb +0 -0
  63. data/lib/stripe/{reporting → resources/reporting}/report_type.rb +0 -0
  64. data/lib/stripe/{reversal.rb → resources/reversal.rb} +0 -0
  65. data/lib/stripe/{review.rb → resources/review.rb} +1 -1
  66. data/lib/stripe/{sigma → resources/sigma}/scheduled_query_run.rb +0 -0
  67. data/lib/stripe/{sku.rb → resources/sku.rb} +0 -0
  68. data/lib/stripe/{source.rb → resources/source.rb} +5 -5
  69. data/lib/stripe/{source_transaction.rb → resources/source_transaction.rb} +0 -0
  70. data/lib/stripe/{subscription.rb → resources/subscription.rb} +2 -2
  71. data/lib/stripe/{subscription_item.rb → resources/subscription_item.rb} +1 -2
  72. data/lib/stripe/{subscription_schedule.rb → resources/subscription_schedule.rb} +5 -8
  73. data/lib/stripe/{subscription_schedule_revision.rb → resources/subscription_schedule_revision.rb} +0 -0
  74. data/lib/stripe/{tax_id.rb → resources/tax_id.rb} +0 -0
  75. data/lib/stripe/{tax_rate.rb → resources/tax_rate.rb} +0 -0
  76. data/lib/stripe/{terminal → resources/terminal}/connection_token.rb +0 -0
  77. data/lib/stripe/{terminal → resources/terminal}/location.rb +0 -0
  78. data/lib/stripe/{terminal → resources/terminal}/reader.rb +0 -0
  79. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +0 -0
  80. data/lib/stripe/{token.rb → resources/token.rb} +0 -0
  81. data/lib/stripe/{topup.rb → resources/topup.rb} +1 -1
  82. data/lib/stripe/{transfer.rb → resources/transfer.rb} +4 -3
  83. data/lib/stripe/{usage_record.rb → resources/usage_record.rb} +0 -0
  84. data/lib/stripe/{usage_record_summary.rb → resources/usage_record_summary.rb} +0 -0
  85. data/lib/stripe/{webhook_endpoint.rb → resources/webhook_endpoint.rb} +0 -0
  86. data/lib/stripe/util.rb +2 -85
  87. data/lib/stripe/version.rb +1 -1
  88. data/test/stripe/customer_balance_transaction_test.rb +37 -0
  89. data/test/stripe/customer_test.rb +43 -0
  90. data/test/test_helper.rb +1 -1
  91. metadata +82 -77
@@ -10,14 +10,11 @@ module Stripe
10
10
 
11
11
  def resource_url
12
12
  if respond_to?(:recipient) && !recipient.nil? && !recipient.empty?
13
- "#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards" \
14
- "/#{CGI.escape(id)}"
13
+ "#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
15
14
  elsif respond_to?(:customer) && !customer.nil? && !customer.empty?
16
- "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
17
- "/#{CGI.escape(id)}"
15
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
18
16
  elsif respond_to?(:account) && !account.nil? && !account.empty?
19
- "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts" \
20
- "/#{CGI.escape(id)}"
17
+ "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
21
18
  end
22
19
  end
23
20
 
@@ -12,7 +12,7 @@ module Stripe
12
12
 
13
13
  def void_credit_note(params = {}, opts = {})
14
14
  resp, opts = request(:post, resource_url + "/void", params, opts)
15
- initialize_from(resp.data, opts)
15
+ Util.convert_to_stripe_object(resp.data, opts)
16
16
  end
17
17
  end
18
18
  end
@@ -4,20 +4,23 @@ module Stripe
4
4
  class Customer < APIResource
5
5
  extend Stripe::APIOperations::Create
6
6
  include Stripe::APIOperations::Delete
7
- include Stripe::APIOperations::Save
8
7
  extend Stripe::APIOperations::List
8
+ include Stripe::APIOperations::Save
9
9
  extend Stripe::APIOperations::NestedResource
10
10
 
11
11
  OBJECT_NAME = "customer".freeze
12
12
 
13
+ nested_resource_class_methods :tax_id,
14
+ operations: %i[create retrieve delete list]
15
+
13
16
  custom_method :delete_discount, http_verb: :delete, http_path: "discount"
14
17
 
15
18
  save_nested_resource :source
16
19
  nested_resource_class_methods :source,
17
- operations: %i[create retrieve update delete
18
- list]
19
- nested_resource_class_methods :tax_id,
20
- operations: %i[create retrieve delete list]
20
+ operations: %i[create retrieve update delete list]
21
+
22
+ nested_resource_class_methods :balance_transaction,
23
+ operations: %i[create retrieve update list]
21
24
 
22
25
  # The API request for deleting a card or bank account and for detaching a
23
26
  # source object are the same.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class CustomerBalanceTransaction < APIResource
5
+ extend Stripe::APIOperations::List
6
+ include Stripe::APIOperations::Save
7
+
8
+ OBJECT_NAME = "customer_balance_transaction".freeze
9
+
10
+ def resource_url
11
+ if !respond_to?(:customer) || customer.nil?
12
+ raise NotImplementedError,
13
+ "Customer Balance Transactions cannot be accessed without a customer ID."
14
+ end
15
+ "#{Customer.resource_url}/#{CGI.escape(customer)}/balance_transactions/#{CGI.escape(id)}"
16
+ end
17
+
18
+ def self.retrieve(_id, _opts = {})
19
+ raise NotImplementedError,
20
+ "Customer Balance Transactions cannot be retrieved without a customer ID. " \
21
+ "Retrieve a Customer Balance Transaction using Customer.retrieve_balance_transaction('cus_123', 'cbtxn_123')"
22
+ end
23
+
24
+ def self.update(_id, _params = nil, _opts = nil)
25
+ raise NotImplementedError,
26
+ "Customer Balance Transactions cannot be retrieved without a customer ID. " \
27
+ "Update a Customer Balance Transaction using Customer.update_balance_transaction('cus_123', 'cbtxn_123', params)"
28
+ end
29
+ end
30
+ end
@@ -11,7 +11,7 @@ module Stripe
11
11
 
12
12
  def close(params = {}, opts = {})
13
13
  resp, opts = request(:post, resource_url + "/close", params, opts)
14
- initialize_from(resp.data, opts)
14
+ Util.convert_to_stripe_object(resp.data, opts)
15
15
  end
16
16
 
17
17
  def close_url
@@ -5,11 +5,12 @@ module Stripe
5
5
  extend Stripe::APIOperations::Create
6
6
  extend Stripe::APIOperations::List
7
7
 
8
+ OBJECT_NAME = "file".freeze
9
+
8
10
  # This resource can have two different object names. In latter API
9
11
  # versions, only `file` is used, but since stripe-ruby may be used with
10
12
  # any API version, we need to support deserializing the older
11
13
  # `file_upload` object into the same class.
12
- OBJECT_NAME = "file".freeze
13
14
  OBJECT_NAME_ALT = "file_upload".freeze
14
15
 
15
16
  def self.resource_url
@@ -35,7 +36,9 @@ module Stripe
35
36
  super
36
37
  end
37
38
  end
39
+ end
38
40
 
41
+ module Stripe
39
42
  # For backwards compatibility, the `File` class is aliased to `FileUpload`.
40
43
  FileUpload = File
41
44
  end
@@ -17,28 +17,27 @@ module Stripe
17
17
 
18
18
  def finalize_invoice(params = {}, opts = {})
19
19
  resp, opts = request(:post, resource_url + "/finalize", params, opts)
20
- initialize_from(resp.data, opts)
20
+ Util.convert_to_stripe_object(resp.data, opts)
21
21
  end
22
22
 
23
23
  def mark_uncollectible(params = {}, opts = {})
24
- resp, opts = request(:post, resource_url + "/mark_uncollectible", params,
25
- opts)
26
- initialize_from(resp.data, opts)
24
+ resp, opts = request(:post, resource_url + "/mark_uncollectible", params, opts)
25
+ Util.convert_to_stripe_object(resp.data, opts)
27
26
  end
28
27
 
29
28
  def pay(params = {}, opts = {})
30
29
  resp, opts = request(:post, resource_url + "/pay", params, opts)
31
- initialize_from(resp.data, opts)
30
+ Util.convert_to_stripe_object(resp.data, opts)
32
31
  end
33
32
 
34
33
  def send_invoice(params = {}, opts = {})
35
34
  resp, opts = request(:post, resource_url + "/send", params, opts)
36
- initialize_from(resp.data, opts)
35
+ Util.convert_to_stripe_object(resp.data, opts)
37
36
  end
38
37
 
39
38
  def void_invoice(params = {}, opts = {})
40
39
  resp, opts = request(:post, resource_url + "/void", params, opts)
41
- initialize_from(resp.data, opts)
40
+ Util.convert_to_stripe_object(resp.data, opts)
42
41
  end
43
42
 
44
43
  def self.upcoming(params, opts = {})
@@ -13,12 +13,12 @@ module Stripe
13
13
 
14
14
  def approve(params = {}, opts = {})
15
15
  resp, opts = request(:post, resource_url + "/approve", params, opts)
16
- initialize_from(resp.data, opts)
16
+ Util.convert_to_stripe_object(resp.data, opts)
17
17
  end
18
18
 
19
19
  def decline(params = {}, opts = {})
20
20
  resp, opts = request(:post, resource_url + "/decline", params, opts)
21
- initialize_from(resp.data, opts)
21
+ Util.convert_to_stripe_object(resp.data, opts)
22
22
  end
23
23
  end
24
24
  end
@@ -12,12 +12,12 @@ module Stripe
12
12
  custom_method :return_order, http_verb: :post, http_path: "returns"
13
13
 
14
14
  def pay(params = {}, opts = {})
15
- resp, opts = request(:post, pay_url, params, opts)
16
- initialize_from(resp.data, opts)
15
+ resp, opts = request(:post, resource_url + "/pay", params, opts)
16
+ Util.convert_to_stripe_object(resp.data, opts)
17
17
  end
18
18
 
19
- def return_order(params, opts = {})
20
- resp, opts = request(:post, returns_url, params, opts)
19
+ def return_order(params = {}, opts = {})
20
+ resp, opts = request(:post, resource_url + "/returns", params, opts)
21
21
  Util.convert_to_stripe_object(resp.data, opts)
22
22
  end
23
23
 
@@ -14,17 +14,17 @@ module Stripe
14
14
 
15
15
  def cancel(params = {}, opts = {})
16
16
  resp, opts = request(:post, resource_url + "/cancel", params, opts)
17
- initialize_from(resp.data, opts)
17
+ Util.convert_to_stripe_object(resp.data, opts)
18
18
  end
19
19
 
20
20
  def capture(params = {}, opts = {})
21
21
  resp, opts = request(:post, resource_url + "/capture", params, opts)
22
- initialize_from(resp.data, opts)
22
+ Util.convert_to_stripe_object(resp.data, opts)
23
23
  end
24
24
 
25
25
  def confirm(params = {}, opts = {})
26
26
  resp, opts = request(:post, resource_url + "/confirm", params, opts)
27
- initialize_from(resp.data, opts)
27
+ Util.convert_to_stripe_object(resp.data, opts)
28
28
  end
29
29
  end
30
30
  end
@@ -13,12 +13,12 @@ module Stripe
13
13
 
14
14
  def attach(params = {}, opts = {})
15
15
  resp, opts = request(:post, resource_url + "/attach", params, opts)
16
- initialize_from(resp.data, opts)
16
+ Util.convert_to_stripe_object(resp.data, opts)
17
17
  end
18
18
 
19
19
  def detach(params = {}, opts = {})
20
20
  resp, opts = request(:post, resource_url + "/detach", params, opts)
21
- initialize_from(resp.data, opts)
21
+ Util.convert_to_stripe_object(resp.data, opts)
22
22
  end
23
23
  end
24
24
  end
@@ -12,7 +12,7 @@ module Stripe
12
12
 
13
13
  def cancel(params = {}, opts = {})
14
14
  resp, opts = request(:post, resource_url + "/cancel", params, opts)
15
- initialize_from(resp.data, opts)
15
+ Util.convert_to_stripe_object(resp.data, opts)
16
16
  end
17
17
 
18
18
  def cancel_url
@@ -10,7 +10,7 @@ module Stripe
10
10
 
11
11
  def approve(params = {}, opts = {})
12
12
  resp, opts = request(:post, resource_url + "/approve", params, opts)
13
- initialize_from(resp.data, opts)
13
+ Util.convert_to_stripe_object(resp.data, opts)
14
14
  end
15
15
  end
16
16
  end
File without changes
@@ -9,6 +9,11 @@ module Stripe
9
9
 
10
10
  custom_method :verify, http_verb: :post
11
11
 
12
+ def verify(params = {}, opts = {})
13
+ resp, opts = request(:post, resource_url + "/verify", params, opts)
14
+ Util.convert_to_stripe_object(resp.data, opts)
15
+ end
16
+
12
17
  def detach(params = {}, opts = {})
13
18
  if !respond_to?(:customer) || customer.nil? || customer.empty?
14
19
  raise NotImplementedError,
@@ -33,10 +38,5 @@ module Stripe
33
38
  opts)
34
39
  Util.convert_to_stripe_object(resp.data, opts)
35
40
  end
36
-
37
- def verify(params = {}, opts = {})
38
- resp, opts = request(:post, resource_url + "/verify", params, opts)
39
- initialize_from(resp.data, opts)
40
- end
41
41
  end
42
42
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Stripe
4
4
  class Subscription < APIResource
5
- extend Stripe::APIOperations::List
6
5
  extend Stripe::APIOperations::Create
7
- include Stripe::APIOperations::Save
8
6
  include Stripe::APIOperations::Delete
7
+ extend Stripe::APIOperations::List
8
+ include Stripe::APIOperations::Save
9
9
 
10
10
  OBJECT_NAME = "subscription".freeze
11
11
 
@@ -10,8 +10,7 @@ module Stripe
10
10
  OBJECT_NAME = "subscription_item".freeze
11
11
 
12
12
  def usage_record_summaries(params = {}, opts = {})
13
- resp, opts = request(:get, resource_url + "/usage_record_summaries",
14
- params, opts)
13
+ resp, opts = request(:get, resource_url + "/usage_record_summaries", params, opts)
15
14
  Util.convert_to_stripe_object(resp.data, opts)
16
15
  end
17
16
  end
@@ -12,19 +12,16 @@ module Stripe
12
12
  custom_method :cancel, http_verb: :post
13
13
  custom_method :release, http_verb: :post
14
14
 
15
- nested_resource_class_methods :revision,
16
- operations: %i[retrieve list]
15
+ nested_resource_class_methods :revision, operations: %i[retrieve list]
17
16
 
18
17
  def cancel(params = {}, opts = {})
19
- url = resource_url + "/cancel"
20
- resp, opts = request(:post, url, params, opts)
21
- initialize_from(resp.data, opts)
18
+ resp, opts = request(:post, resource_url + "/cancel", params, opts)
19
+ Util.convert_to_stripe_object(resp.data, opts)
22
20
  end
23
21
 
24
22
  def release(params = {}, opts = {})
25
- url = resource_url + "/release"
26
- resp, opts = request(:post, url, params, opts)
27
- initialize_from(resp.data, opts)
23
+ resp, opts = request(:post, resource_url + "/release", params, opts)
24
+ Util.convert_to_stripe_object(resp.data, opts)
28
25
  end
29
26
 
30
27
  def revisions(params = {}, opts = {})
@@ -12,7 +12,7 @@ module Stripe
12
12
 
13
13
  def cancel(params = {}, opts = {})
14
14
  resp, opts = request(:post, resource_url + "/cancel", params, opts)
15
- initialize_from(resp.data, opts)
15
+ Util.convert_to_stripe_object(resp.data, opts)
16
16
  end
17
17
  end
18
18
  end
@@ -14,13 +14,14 @@ module Stripe
14
14
  nested_resource_class_methods :reversal,
15
15
  operations: %i[create retrieve update list]
16
16
 
17
- def cancel
18
- resp, api_key = request(:post, cancel_url)
19
- initialize_from(resp.data, api_key)
17
+ def cancel(params = {}, opts = {})
18
+ resp, opts = request(:post, resource_url + "/cancel", params, opts)
19
+ Util.convert_to_stripe_object(resp.data, opts)
20
20
  end
21
21
 
22
22
  def cancel_url
23
23
  resource_url + "/cancel"
24
24
  end
25
+ deprecate :cancel_url, :none, 2019, 11
25
26
  end
26
27
  end