stripe 4.20.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -4
  3. data/.rubocop_todo.yml +10 -9
  4. data/.travis.yml +2 -6
  5. data/CHANGELOG.md +52 -1
  6. data/Gemfile +2 -12
  7. data/README.md +10 -10
  8. data/Rakefile +8 -7
  9. data/VERSION +1 -1
  10. data/lib/stripe/api_operations/list.rb +0 -6
  11. data/lib/stripe/api_resource.rb +16 -0
  12. data/lib/stripe/connection_manager.rb +131 -0
  13. data/lib/stripe/error_object.rb +94 -0
  14. data/lib/stripe/errors.rb +15 -2
  15. data/lib/stripe/list_object.rb +2 -1
  16. data/lib/stripe/multipart_encoder.rb +131 -0
  17. data/lib/stripe/object_types.rb +1 -4
  18. data/lib/stripe/resources/account.rb +7 -7
  19. data/lib/stripe/resources/account_link.rb +1 -1
  20. data/lib/stripe/resources/alipay_account.rb +1 -1
  21. data/lib/stripe/resources/apple_pay_domain.rb +1 -1
  22. data/lib/stripe/resources/application_fee.rb +1 -12
  23. data/lib/stripe/resources/application_fee_refund.rb +1 -1
  24. data/lib/stripe/resources/balance.rb +1 -1
  25. data/lib/stripe/resources/balance_transaction.rb +1 -5
  26. data/lib/stripe/resources/bank_account.rb +1 -1
  27. data/lib/stripe/resources/bitcoin_receiver.rb +1 -1
  28. data/lib/stripe/resources/bitcoin_transaction.rb +1 -1
  29. data/lib/stripe/resources/capability.rb +1 -1
  30. data/lib/stripe/resources/card.rb +1 -1
  31. data/lib/stripe/resources/charge.rb +7 -69
  32. data/lib/stripe/resources/checkout/session.rb +1 -1
  33. data/lib/stripe/resources/country_spec.rb +1 -1
  34. data/lib/stripe/resources/coupon.rb +1 -1
  35. data/lib/stripe/resources/credit_note.rb +7 -3
  36. data/lib/stripe/resources/customer.rb +5 -66
  37. data/lib/stripe/resources/customer_balance_transaction.rb +1 -1
  38. data/lib/stripe/resources/discount.rb +1 -1
  39. data/lib/stripe/resources/dispute.rb +7 -9
  40. data/lib/stripe/resources/ephemeral_key.rb +1 -1
  41. data/lib/stripe/resources/event.rb +1 -1
  42. data/lib/stripe/resources/exchange_rate.rb +1 -1
  43. data/lib/stripe/resources/file.rb +3 -13
  44. data/lib/stripe/resources/file_link.rb +1 -1
  45. data/lib/stripe/resources/invoice.rb +36 -11
  46. data/lib/stripe/resources/invoice_item.rb +1 -1
  47. data/lib/stripe/resources/invoice_line_item.rb +1 -1
  48. data/lib/stripe/resources/issuing/authorization.rb +13 -5
  49. data/lib/stripe/resources/issuing/card.rb +7 -3
  50. data/lib/stripe/resources/issuing/card_details.rb +1 -1
  51. data/lib/stripe/resources/issuing/cardholder.rb +1 -1
  52. data/lib/stripe/resources/issuing/dispute.rb +1 -1
  53. data/lib/stripe/resources/issuing/transaction.rb +1 -1
  54. data/lib/stripe/resources/login_link.rb +1 -1
  55. data/lib/stripe/resources/order.rb +13 -13
  56. data/lib/stripe/resources/order_return.rb +1 -1
  57. data/lib/stripe/resources/payment_intent.rb +19 -7
  58. data/lib/stripe/resources/payment_method.rb +13 -5
  59. data/lib/stripe/resources/payout.rb +7 -9
  60. data/lib/stripe/resources/person.rb +1 -1
  61. data/lib/stripe/resources/plan.rb +1 -1
  62. data/lib/stripe/resources/product.rb +1 -1
  63. data/lib/stripe/resources/radar/early_fraud_warning.rb +1 -1
  64. data/lib/stripe/resources/radar/value_list.rb +1 -1
  65. data/lib/stripe/resources/radar/value_list_item.rb +1 -1
  66. data/lib/stripe/resources/recipient.rb +1 -5
  67. data/lib/stripe/resources/recipient_transfer.rb +1 -1
  68. data/lib/stripe/resources/refund.rb +1 -1
  69. data/lib/stripe/resources/reporting/report_run.rb +1 -1
  70. data/lib/stripe/resources/reporting/report_type.rb +1 -1
  71. data/lib/stripe/resources/reversal.rb +1 -1
  72. data/lib/stripe/resources/review.rb +7 -3
  73. data/lib/stripe/resources/setup_intent.rb +32 -0
  74. data/lib/stripe/resources/sigma/scheduled_query_run.rb +1 -1
  75. data/lib/stripe/resources/sku.rb +1 -1
  76. data/lib/stripe/resources/source.rb +7 -9
  77. data/lib/stripe/resources/source_transaction.rb +1 -1
  78. data/lib/stripe/resources/subscription.rb +9 -9
  79. data/lib/stripe/resources/subscription_item.rb +4 -1
  80. data/lib/stripe/resources/subscription_schedule.rb +13 -13
  81. data/lib/stripe/resources/tax_id.rb +1 -1
  82. data/lib/stripe/resources/tax_rate.rb +1 -1
  83. data/lib/stripe/resources/terminal/connection_token.rb +1 -1
  84. data/lib/stripe/resources/terminal/location.rb +1 -1
  85. data/lib/stripe/resources/terminal/reader.rb +1 -1
  86. data/lib/stripe/resources/three_d_secure.rb +1 -1
  87. data/lib/stripe/resources/token.rb +1 -1
  88. data/lib/stripe/resources/topup.rb +7 -3
  89. data/lib/stripe/resources/transfer.rb +7 -8
  90. data/lib/stripe/resources/usage_record.rb +1 -17
  91. data/lib/stripe/resources/usage_record_summary.rb +1 -1
  92. data/lib/stripe/resources/webhook_endpoint.rb +1 -1
  93. data/lib/stripe/resources.rb +1 -2
  94. data/lib/stripe/stripe_client.rb +281 -183
  95. data/lib/stripe/stripe_object.rb +4 -23
  96. data/lib/stripe/stripe_response.rb +53 -21
  97. data/lib/stripe/util.rb +14 -11
  98. data/lib/stripe/version.rb +1 -1
  99. data/lib/stripe/webhook.rb +1 -1
  100. data/lib/stripe.rb +56 -15
  101. data/stripe.gemspec +10 -3
  102. data/test/stripe/account_test.rb +0 -16
  103. data/test/stripe/api_operations_test.rb +2 -2
  104. data/test/stripe/api_resource_test.rb +98 -8
  105. data/test/stripe/balance_transaction_test.rb +20 -0
  106. data/test/stripe/charge_test.rb +0 -16
  107. data/test/stripe/connection_manager_test.rb +138 -0
  108. data/test/stripe/customer_test.rb +1 -44
  109. data/test/stripe/errors_test.rb +29 -8
  110. data/test/stripe/file_test.rb +0 -10
  111. data/test/stripe/invoice_test.rb +17 -1
  112. data/test/stripe/list_object_test.rb +0 -16
  113. data/test/stripe/login_link_test.rb +1 -1
  114. data/test/stripe/multipart_encoder_test.rb +130 -0
  115. data/test/stripe/payment_intent_test.rb +2 -2
  116. data/test/stripe/setup_intent_test.rb +84 -0
  117. data/test/stripe/source_test.rb +0 -18
  118. data/test/stripe/stripe_client_test.rb +214 -29
  119. data/test/stripe/stripe_object_test.rb +7 -35
  120. data/test/stripe/stripe_response_test.rb +70 -24
  121. data/test/stripe/subscription_item_test.rb +12 -0
  122. data/test/stripe/subscription_schedule_test.rb +0 -34
  123. data/test/stripe/subscription_test.rb +2 -2
  124. data/test/stripe/webhook_test.rb +2 -2
  125. data/test/stripe_mock.rb +4 -3
  126. data/test/stripe_test.rb +0 -13
  127. data/test/test_helper.rb +10 -5
  128. metadata +23 -43
  129. data/lib/stripe/resources/issuer_fraud_record.rb +0 -9
  130. data/lib/stripe/resources/subscription_schedule_revision.rb +0 -34
  131. data/test/stripe/file_upload_test.rb +0 -79
  132. data/test/stripe/issuer_fraud_record_test.rb +0 -20
  133. data/test/stripe/subscription_schedule_revision_test.rb +0 -37
  134. data/test/stripe/usage_record_test.rb +0 -28
@@ -7,19 +7,19 @@ module Stripe
7
7
  extend Stripe::APIOperations::List
8
8
  include Stripe::APIOperations::Save
9
9
 
10
- OBJECT_NAME = "subscription".freeze
10
+ OBJECT_NAME = "subscription"
11
11
 
12
12
  custom_method :delete_discount, http_verb: :delete, http_path: "discount"
13
13
 
14
- save_nested_resource :source
15
-
16
- def delete_discount
17
- _, opts = request(:delete, discount_url)
18
- initialize_from({ discount: nil }, opts, true)
14
+ def delete_discount(params = {}, opts = {})
15
+ request_stripe_object(
16
+ method: :delete,
17
+ path: resource_url + "/discount",
18
+ params: params,
19
+ opts: opts
20
+ )
19
21
  end
20
22
 
21
- private def discount_url
22
- resource_url + "/discount"
23
- end
23
+ save_nested_resource :source
24
24
  end
25
25
  end
@@ -6,8 +6,11 @@ module Stripe
6
6
  include Stripe::APIOperations::Delete
7
7
  extend Stripe::APIOperations::List
8
8
  include Stripe::APIOperations::Save
9
+ extend Stripe::APIOperations::NestedResource
9
10
 
10
- OBJECT_NAME = "subscription_item".freeze
11
+ OBJECT_NAME = "subscription_item"
12
+
13
+ nested_resource_class_methods :usage_record, operations: %i[create]
11
14
 
12
15
  def usage_record_summaries(params = {}, opts = {})
13
16
  resp, opts = request(:get, resource_url + "/usage_record_summaries", params, opts)
@@ -5,28 +5,28 @@ module Stripe
5
5
  extend Stripe::APIOperations::Create
6
6
  extend Stripe::APIOperations::List
7
7
  include Stripe::APIOperations::Save
8
- extend Stripe::APIOperations::NestedResource
9
8
 
10
- OBJECT_NAME = "subscription_schedule".freeze
9
+ OBJECT_NAME = "subscription_schedule"
11
10
 
12
11
  custom_method :cancel, http_verb: :post
13
12
  custom_method :release, http_verb: :post
14
13
 
15
- nested_resource_class_methods :revision, operations: %i[retrieve list]
16
-
17
14
  def cancel(params = {}, opts = {})
18
- resp, opts = request(:post, resource_url + "/cancel", params, opts)
19
- Util.convert_to_stripe_object(resp.data, opts)
15
+ request_stripe_object(
16
+ method: :post,
17
+ path: resource_url + "/cancel",
18
+ params: params,
19
+ opts: opts
20
+ )
20
21
  end
21
22
 
22
23
  def release(params = {}, opts = {})
23
- resp, opts = request(:post, resource_url + "/release", params, opts)
24
- Util.convert_to_stripe_object(resp.data, opts)
25
- end
26
-
27
- def revisions(params = {}, opts = {})
28
- resp, opts = request(:get, resource_url + "/revisions", params, opts)
29
- Util.convert_to_stripe_object(resp.data, opts)
24
+ request_stripe_object(
25
+ method: :post,
26
+ path: resource_url + "/release",
27
+ params: params,
28
+ opts: opts
29
+ )
30
30
  end
31
31
  end
32
32
  end
@@ -5,7 +5,7 @@ module Stripe
5
5
  include Stripe::APIOperations::Delete
6
6
  extend Stripe::APIOperations::List
7
7
 
8
- OBJECT_NAME = "tax_id".freeze
8
+ OBJECT_NAME = "tax_id"
9
9
 
10
10
  def resource_url
11
11
  if !respond_to?(:customer) || customer.nil?
@@ -6,6 +6,6 @@ module Stripe
6
6
  extend Stripe::APIOperations::List
7
7
  include Stripe::APIOperations::Save
8
8
 
9
- OBJECT_NAME = "tax_rate".freeze
9
+ OBJECT_NAME = "tax_rate"
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Stripe
5
5
  class ConnectionToken < APIResource
6
6
  extend Stripe::APIOperations::Create
7
7
 
8
- OBJECT_NAME = "terminal.connection_token".freeze
8
+ OBJECT_NAME = "terminal.connection_token"
9
9
  end
10
10
  end
11
11
  end
@@ -8,7 +8,7 @@ module Stripe
8
8
  extend Stripe::APIOperations::List
9
9
  include Stripe::APIOperations::Save
10
10
 
11
- OBJECT_NAME = "terminal.location".freeze
11
+ OBJECT_NAME = "terminal.location"
12
12
  end
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module Stripe
8
8
  extend Stripe::APIOperations::List
9
9
  include Stripe::APIOperations::Save
10
10
 
11
- OBJECT_NAME = "terminal.reader".freeze
11
+ OBJECT_NAME = "terminal.reader"
12
12
  end
13
13
  end
14
14
  end
@@ -4,7 +4,7 @@ module Stripe
4
4
  class ThreeDSecure < APIResource
5
5
  extend Stripe::APIOperations::Create
6
6
 
7
- OBJECT_NAME = "three_d_secure".freeze
7
+ OBJECT_NAME = "three_d_secure"
8
8
 
9
9
  def self.resource_url
10
10
  "/v1/3d_secure"
@@ -4,6 +4,6 @@ module Stripe
4
4
  class Token < APIResource
5
5
  extend Stripe::APIOperations::Create
6
6
 
7
- OBJECT_NAME = "token".freeze
7
+ OBJECT_NAME = "token"
8
8
  end
9
9
  end
@@ -6,13 +6,17 @@ module Stripe
6
6
  extend Stripe::APIOperations::List
7
7
  include Stripe::APIOperations::Save
8
8
 
9
- OBJECT_NAME = "topup".freeze
9
+ OBJECT_NAME = "topup"
10
10
 
11
11
  custom_method :cancel, http_verb: :post
12
12
 
13
13
  def cancel(params = {}, opts = {})
14
- resp, opts = request(:post, resource_url + "/cancel", params, opts)
15
- Util.convert_to_stripe_object(resp.data, opts)
14
+ request_stripe_object(
15
+ method: :post,
16
+ path: resource_url + "/cancel",
17
+ params: params,
18
+ opts: opts
19
+ )
16
20
  end
17
21
  end
18
22
  end
@@ -7,7 +7,7 @@ module Stripe
7
7
  include Stripe::APIOperations::Save
8
8
  extend Stripe::APIOperations::NestedResource
9
9
 
10
- OBJECT_NAME = "transfer".freeze
10
+ OBJECT_NAME = "transfer"
11
11
 
12
12
  custom_method :cancel, http_verb: :post
13
13
 
@@ -15,13 +15,12 @@ module Stripe
15
15
  operations: %i[create retrieve update list]
16
16
 
17
17
  def cancel(params = {}, opts = {})
18
- resp, opts = request(:post, resource_url + "/cancel", params, opts)
19
- Util.convert_to_stripe_object(resp.data, opts)
18
+ request_stripe_object(
19
+ method: :post,
20
+ path: resource_url + "/cancel",
21
+ params: params,
22
+ opts: opts
23
+ )
20
24
  end
21
-
22
- def cancel_url
23
- resource_url + "/cancel"
24
- end
25
- deprecate :cancel_url, :none, 2019, 11
26
25
  end
27
26
  end
@@ -2,22 +2,6 @@
2
2
 
3
3
  module Stripe
4
4
  class UsageRecord < APIResource
5
- OBJECT_NAME = "usage_record".freeze
6
-
7
- def self.create(params = {}, opts = {})
8
- unless params.key?(:subscription_item)
9
- raise ArgumentError, "Params must have a subscription_item key"
10
- end
11
- req_params = params.clone.delete_if do |key, _value|
12
- key == :subscription_item
13
- end
14
- resp, opts = request(
15
- :post,
16
- "/v1/subscription_items/#{params[:subscription_item]}/usage_records",
17
- req_params,
18
- opts
19
- )
20
- Util.convert_to_stripe_object(resp.data, opts)
21
- end
5
+ OBJECT_NAME = "usage_record"
22
6
  end
23
7
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Stripe
4
4
  class UsageRecordSummary < StripeObject
5
- OBJECT_NAME = "usage_record_summary".freeze
5
+ OBJECT_NAME = "usage_record_summary"
6
6
  end
7
7
  end
@@ -7,6 +7,6 @@ module Stripe
7
7
  extend Stripe::APIOperations::List
8
8
  include Stripe::APIOperations::Save
9
9
 
10
- OBJECT_NAME = "webhook_endpoint".freeze
10
+ OBJECT_NAME = "webhook_endpoint"
11
11
  end
12
12
  end
@@ -30,7 +30,6 @@ require "stripe/resources/file_link"
30
30
  require "stripe/resources/invoice"
31
31
  require "stripe/resources/invoice_item"
32
32
  require "stripe/resources/invoice_line_item"
33
- require "stripe/resources/issuer_fraud_record"
34
33
  require "stripe/resources/issuing/authorization"
35
34
  require "stripe/resources/issuing/card"
36
35
  require "stripe/resources/issuing/card_details"
@@ -56,6 +55,7 @@ require "stripe/resources/reporting/report_run"
56
55
  require "stripe/resources/reporting/report_type"
57
56
  require "stripe/resources/reversal"
58
57
  require "stripe/resources/review"
58
+ require "stripe/resources/setup_intent"
59
59
  require "stripe/resources/sigma/scheduled_query_run"
60
60
  require "stripe/resources/sku"
61
61
  require "stripe/resources/source"
@@ -63,7 +63,6 @@ require "stripe/resources/source_transaction"
63
63
  require "stripe/resources/subscription"
64
64
  require "stripe/resources/subscription_item"
65
65
  require "stripe/resources/subscription_schedule"
66
- require "stripe/resources/subscription_schedule_revision"
67
66
  require "stripe/resources/tax_id"
68
67
  require "stripe/resources/tax_rate"
69
68
  require "stripe/resources/terminal/connection_token"