stripe 4.10.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +10 -0
  3. data/.rubocop.yml +28 -4
  4. data/.rubocop_todo.yml +11 -22
  5. data/.travis.yml +3 -6
  6. data/.vscode/extensions.json +7 -0
  7. data/.vscode/settings.json +8 -0
  8. data/CHANGELOG.md +86 -1
  9. data/Gemfile +2 -10
  10. data/README.md +96 -40
  11. data/Rakefile +8 -7
  12. data/VERSION +1 -1
  13. data/lib/stripe/api_operations/delete.rb +23 -1
  14. data/lib/stripe/api_operations/list.rb +0 -6
  15. data/lib/stripe/api_operations/nested_resource.rb +14 -7
  16. data/lib/stripe/api_operations/request.rb +3 -7
  17. data/lib/stripe/api_operations/save.rb +1 -3
  18. data/lib/stripe/api_resource.rb +50 -2
  19. data/lib/stripe/connection_manager.rb +131 -0
  20. data/lib/stripe/error_object.rb +94 -0
  21. data/lib/stripe/errors.rb +22 -9
  22. data/lib/stripe/list_object.rb +11 -5
  23. data/lib/stripe/multipart_encoder.rb +131 -0
  24. data/lib/stripe/object_types.rb +94 -0
  25. data/lib/stripe/{account.rb → resources/account.rb} +49 -27
  26. data/lib/stripe/{account_link.rb → resources/account_link.rb} +1 -1
  27. data/lib/stripe/resources/alipay_account.rb +34 -0
  28. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +1 -1
  29. data/lib/stripe/resources/application_fee.rb +13 -0
  30. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  31. data/lib/stripe/{balance.rb → resources/balance.rb} +1 -1
  32. data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +1 -5
  33. data/lib/stripe/{bank_account.rb → resources/bank_account.rb} +14 -4
  34. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +3 -3
  35. data/lib/stripe/{bitcoin_transaction.rb → resources/bitcoin_transaction.rb} +1 -1
  36. data/lib/stripe/resources/capability.rb +33 -0
  37. data/lib/stripe/{card.rb → resources/card.rb} +12 -4
  38. data/lib/stripe/resources/charge.rb +22 -0
  39. data/lib/stripe/{checkout → resources/checkout}/session.rb +2 -2
  40. data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +1 -1
  41. data/lib/stripe/{coupon.rb → resources/coupon.rb} +2 -2
  42. data/lib/stripe/resources/credit_note.rb +22 -0
  43. data/lib/stripe/resources/customer.rb +35 -0
  44. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  45. data/lib/stripe/resources/discount.rb +7 -0
  46. data/lib/stripe/{dispute.rb → resources/dispute.rb} +9 -7
  47. data/lib/stripe/{ephemeral_key.rb → resources/ephemeral_key.rb} +5 -2
  48. data/lib/stripe/{event.rb → resources/event.rb} +1 -1
  49. data/lib/stripe/{exchange_rate.rb → resources/exchange_rate.rb} +1 -1
  50. data/lib/stripe/{file.rb → resources/file.rb} +8 -11
  51. data/lib/stripe/{file_link.rb → resources/file_link.rb} +2 -2
  52. data/lib/stripe/resources/invoice.rb +73 -0
  53. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +2 -2
  54. data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +1 -1
  55. data/lib/stripe/resources/issuing/authorization.rb +33 -0
  56. data/lib/stripe/resources/issuing/card.rb +24 -0
  57. data/lib/stripe/{issuing → resources/issuing}/card_details.rb +1 -1
  58. data/lib/stripe/{issuing → resources/issuing}/cardholder.rb +2 -2
  59. data/lib/stripe/{issuing → resources/issuing}/dispute.rb +2 -2
  60. data/lib/stripe/{issuing → resources/issuing}/transaction.rb +2 -2
  61. data/lib/stripe/resources/login_link.rb +14 -0
  62. data/lib/stripe/resources/order.rb +32 -0
  63. data/lib/stripe/{order_return.rb → resources/order_return.rb} +1 -1
  64. data/lib/stripe/resources/payment_intent.rb +42 -0
  65. data/lib/stripe/resources/payment_method.rb +32 -0
  66. data/lib/stripe/resources/payout.rb +22 -0
  67. data/lib/stripe/{person.rb → resources/person.rb} +8 -3
  68. data/lib/stripe/{plan.rb → resources/plan.rb} +1 -1
  69. data/lib/stripe/{product.rb → resources/product.rb} +3 -3
  70. data/lib/stripe/resources/radar/early_fraud_warning.rb +11 -0
  71. data/lib/stripe/{radar → resources/radar}/value_list.rb +2 -2
  72. data/lib/stripe/{radar → resources/radar}/value_list_item.rb +2 -2
  73. data/lib/stripe/{recipient.rb → resources/recipient.rb} +2 -6
  74. data/lib/stripe/{recipient_transfer.rb → resources/recipient_transfer.rb} +1 -1
  75. data/lib/stripe/{refund.rb → resources/refund.rb} +1 -1
  76. data/lib/stripe/{reporting → resources/reporting}/report_run.rb +2 -2
  77. data/lib/stripe/{reporting → resources/reporting}/report_type.rb +2 -2
  78. data/lib/stripe/resources/reversal.rb +29 -0
  79. data/lib/stripe/resources/review.rb +20 -0
  80. data/lib/stripe/resources/setup_intent.rb +32 -0
  81. data/lib/stripe/{sigma → resources/sigma}/scheduled_query_run.rb +2 -2
  82. data/lib/stripe/{sku.rb → resources/sku.rb} +3 -3
  83. data/lib/stripe/{source.rb → resources/source.rb} +17 -15
  84. data/lib/stripe/{source_transaction.rb → resources/source_transaction.rb} +1 -1
  85. data/lib/stripe/resources/subscription.rb +25 -0
  86. data/lib/stripe/{subscription_item.rb → resources/subscription_item.rb} +5 -2
  87. data/lib/stripe/resources/subscription_schedule.rb +32 -0
  88. data/lib/stripe/resources/tax_id.rb +26 -0
  89. data/lib/stripe/resources/tax_rate.rb +11 -0
  90. data/lib/stripe/{terminal → resources/terminal}/connection_token.rb +2 -2
  91. data/lib/stripe/{terminal → resources/terminal}/location.rb +2 -2
  92. data/lib/stripe/{terminal → resources/terminal}/reader.rb +2 -2
  93. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +1 -1
  94. data/lib/stripe/{token.rb → resources/token.rb} +1 -1
  95. data/lib/stripe/resources/topup.rb +22 -0
  96. data/lib/stripe/resources/transfer.rb +26 -0
  97. data/lib/stripe/resources/usage_record.rb +7 -0
  98. data/lib/stripe/{usage_record_summary.rb → resources/usage_record_summary.rb} +1 -1
  99. data/lib/stripe/{webhook_endpoint.rb → resources/webhook_endpoint.rb} +2 -2
  100. data/lib/stripe/resources.rb +77 -0
  101. data/lib/stripe/singleton_api_resource.rb +3 -1
  102. data/lib/stripe/stripe_client.rb +337 -218
  103. data/lib/stripe/stripe_object.rb +54 -59
  104. data/lib/stripe/stripe_response.rb +53 -21
  105. data/lib/stripe/util.rb +54 -110
  106. data/lib/stripe/version.rb +1 -1
  107. data/lib/stripe/webhook.rb +5 -3
  108. data/lib/stripe.rb +64 -86
  109. data/stripe.gemspec +14 -5
  110. data/test/stripe/account_link_test.rb +1 -1
  111. data/test/stripe/account_test.rb +186 -30
  112. data/test/stripe/alipay_account_test.rb +1 -1
  113. data/test/stripe/api_operations_test.rb +3 -4
  114. data/test/stripe/api_resource_test.rb +105 -18
  115. data/test/stripe/apple_pay_domain_test.rb +18 -5
  116. data/test/stripe/application_fee_refund_test.rb +1 -1
  117. data/test/stripe/application_fee_test.rb +45 -1
  118. data/test/stripe/balance_test.rb +1 -1
  119. data/test/stripe/balance_transaction_test.rb +20 -0
  120. data/test/stripe/bank_account_test.rb +1 -1
  121. data/test/stripe/capability_test.rb +45 -0
  122. data/test/stripe/charge_test.rb +13 -8
  123. data/test/stripe/checkout/session_test.rb +1 -1
  124. data/test/stripe/connection_manager_test.rb +138 -0
  125. data/test/stripe/country_spec_test.rb +1 -1
  126. data/test/stripe/coupon_test.rb +16 -6
  127. data/test/stripe/credit_note_test.rb +61 -0
  128. data/test/stripe/customer_balance_transaction_test.rb +37 -0
  129. data/test/stripe/customer_card_test.rb +1 -1
  130. data/test/stripe/customer_test.rb +151 -40
  131. data/test/stripe/dispute_test.rb +10 -1
  132. data/test/stripe/ephemeral_key_test.rb +8 -1
  133. data/test/stripe/errors_test.rb +30 -9
  134. data/test/stripe/exchange_rate_test.rb +1 -1
  135. data/test/stripe/file_link_test.rb +1 -1
  136. data/test/stripe/file_test.rb +19 -5
  137. data/test/stripe/invoice_item_test.rb +18 -7
  138. data/test/stripe/invoice_line_item_test.rb +1 -1
  139. data/test/stripe/invoice_test.rb +77 -9
  140. data/test/stripe/issuing/authorization_test.rb +33 -11
  141. data/test/stripe/issuing/card_test.rb +15 -6
  142. data/test/stripe/issuing/cardholder_test.rb +1 -1
  143. data/test/stripe/issuing/dispute_test.rb +1 -1
  144. data/test/stripe/issuing/transaction_test.rb +1 -1
  145. data/test/stripe/list_object_test.rb +1 -17
  146. data/test/stripe/login_link_test.rb +2 -2
  147. data/test/stripe/multipart_encoder_test.rb +130 -0
  148. data/test/stripe/oauth_test.rb +1 -1
  149. data/test/stripe/order_return_test.rb +1 -1
  150. data/test/stripe/order_test.rb +28 -3
  151. data/test/stripe/payment_intent_test.rb +31 -4
  152. data/test/stripe/payment_method_test.rb +19 -1
  153. data/test/stripe/payout_test.rb +8 -1
  154. data/test/stripe/person_test.rb +1 -1
  155. data/test/stripe/plan_test.rb +26 -20
  156. data/test/stripe/product_test.rb +16 -6
  157. data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
  158. data/test/stripe/radar/value_list_item_test.rb +16 -6
  159. data/test/stripe/radar/value_list_test.rb +16 -6
  160. data/test/stripe/recipient_test.rb +18 -5
  161. data/test/stripe/refund_test.rb +1 -1
  162. data/test/stripe/reporting/report_run_test.rb +1 -1
  163. data/test/stripe/reporting/report_type_test.rb +1 -1
  164. data/test/stripe/reversal_test.rb +1 -1
  165. data/test/stripe/review_test.rb +1 -1
  166. data/test/stripe/setup_intent_test.rb +84 -0
  167. data/test/stripe/sigma/scheduled_query_run_test.rb +1 -1
  168. data/test/stripe/sku_test.rb +16 -6
  169. data/test/stripe/source_test.rb +14 -19
  170. data/test/stripe/source_transaction_test.rb +1 -1
  171. data/test/stripe/stripe_client_test.rb +230 -26
  172. data/test/stripe/stripe_object_test.rb +8 -36
  173. data/test/stripe/stripe_response_test.rb +71 -25
  174. data/test/stripe/subscription_item_test.rb +28 -6
  175. data/test/stripe/subscription_schedule_test.rb +19 -1
  176. data/test/stripe/subscription_test.rb +29 -9
  177. data/test/stripe/tax_id_test.rb +31 -0
  178. data/test/stripe/tax_rate_test.rb +43 -0
  179. data/test/stripe/terminal/connection_token_test.rb +1 -1
  180. data/test/stripe/terminal/location_test.rb +16 -6
  181. data/test/stripe/terminal/reader_test.rb +16 -6
  182. data/test/stripe/three_d_secure_test.rb +1 -1
  183. data/test/stripe/topup_test.rb +9 -1
  184. data/test/stripe/transfer_test.rb +46 -1
  185. data/test/stripe/usage_record_summary_test.rb +1 -1
  186. data/test/stripe/util_test.rb +1 -1
  187. data/test/stripe/webhook_endpoint_test.rb +18 -1
  188. data/test/stripe/webhook_test.rb +4 -4
  189. data/test/stripe_mock.rb +4 -3
  190. data/test/stripe_test.rb +1 -14
  191. data/test/test_helper.rb +14 -11
  192. metadata +114 -124
  193. data/lib/stripe/alipay_account.rb +0 -27
  194. data/lib/stripe/application_fee.rb +0 -23
  195. data/lib/stripe/application_fee_refund.rb +0 -22
  196. data/lib/stripe/charge.rb +0 -84
  197. data/lib/stripe/customer.rb +0 -90
  198. data/lib/stripe/invoice.rb +0 -48
  199. data/lib/stripe/issuer_fraud_record.rb +0 -9
  200. data/lib/stripe/issuing/authorization.rb +0 -22
  201. data/lib/stripe/issuing/card.rb +0 -18
  202. data/lib/stripe/login_link.rb +0 -11
  203. data/lib/stripe/order.rb +0 -31
  204. data/lib/stripe/payment_intent.rb +0 -26
  205. data/lib/stripe/payment_method.rb +0 -23
  206. data/lib/stripe/payout.rb +0 -20
  207. data/lib/stripe/reversal.rb +0 -22
  208. data/lib/stripe/review.rb +0 -14
  209. data/lib/stripe/subscription.rb +0 -25
  210. data/lib/stripe/subscription_schedule.rb +0 -32
  211. data/lib/stripe/subscription_schedule_revision.rb +0 -25
  212. data/lib/stripe/topup.rb +0 -16
  213. data/lib/stripe/transfer.rb +0 -23
  214. data/lib/stripe/usage_record.rb +0 -14
  215. data/test/stripe/account_external_accounts_operations_test.rb +0 -69
  216. data/test/stripe/account_login_links_operations_test.rb +0 -21
  217. data/test/stripe/account_persons_operations_test.rb +0 -70
  218. data/test/stripe/application_fee_refunds_operations_test.rb +0 -56
  219. data/test/stripe/customer_sources_operations_test.rb +0 -64
  220. data/test/stripe/file_upload_test.rb +0 -76
  221. data/test/stripe/issuer_fraud_record_test.rb +0 -20
  222. data/test/stripe/subscription_schedule_revision_test.rb +0 -37
  223. data/test/stripe/subscription_schedule_revisions_operations_test.rb +0 -35
  224. data/test/stripe/transfer_reversals_operations_test.rb +0 -57
  225. data/test/stripe/usage_record_test.rb +0 -28
data/lib/stripe.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  # Stripe Ruby bindings
4
4
  # API spec at https://stripe.com/docs/api
5
5
  require "cgi"
6
- require "faraday"
7
6
  require "json"
8
7
  require "logger"
8
+ require "net/http"
9
9
  require "openssl"
10
10
  require "rbconfig"
11
11
  require "securerandom"
@@ -26,91 +26,27 @@ require "stripe/api_operations/save"
26
26
 
27
27
  # API resource support classes
28
28
  require "stripe/errors"
29
+ require "stripe/object_types"
29
30
  require "stripe/util"
31
+ require "stripe/connection_manager"
32
+ require "stripe/multipart_encoder"
30
33
  require "stripe/stripe_client"
31
34
  require "stripe/stripe_object"
32
35
  require "stripe/stripe_response"
33
36
  require "stripe/list_object"
37
+ require "stripe/error_object"
34
38
  require "stripe/api_resource"
35
39
  require "stripe/singleton_api_resource"
36
40
  require "stripe/webhook"
37
41
 
38
42
  # Named API resources
39
- require "stripe/account"
40
- require "stripe/account_link"
41
- require "stripe/alipay_account"
42
- require "stripe/apple_pay_domain"
43
- require "stripe/application_fee"
44
- require "stripe/application_fee_refund"
45
- require "stripe/balance"
46
- require "stripe/balance_transaction"
47
- require "stripe/bank_account"
48
- require "stripe/bitcoin_receiver"
49
- require "stripe/bitcoin_transaction"
50
- require "stripe/card"
51
- require "stripe/charge"
52
- require "stripe/checkout/session"
53
- require "stripe/country_spec"
54
- require "stripe/coupon"
55
- require "stripe/customer"
56
- require "stripe/dispute"
57
- require "stripe/ephemeral_key"
58
- require "stripe/event"
59
- require "stripe/exchange_rate"
60
- require "stripe/file"
61
- require "stripe/file_link"
62
- require "stripe/invoice"
63
- require "stripe/invoice_item"
64
- require "stripe/invoice_line_item"
65
- require "stripe/issuer_fraud_record"
66
- require "stripe/issuing/authorization"
67
- require "stripe/issuing/card"
68
- require "stripe/issuing/card_details"
69
- require "stripe/issuing/cardholder"
70
- require "stripe/issuing/dispute"
71
- require "stripe/issuing/transaction"
72
- require "stripe/login_link"
73
- require "stripe/order"
74
- require "stripe/order_return"
75
- require "stripe/payment_intent"
76
- require "stripe/payment_method"
77
- require "stripe/payout"
78
- require "stripe/person"
79
- require "stripe/plan"
80
- require "stripe/product"
81
- require "stripe/radar/value_list"
82
- require "stripe/radar/value_list_item"
83
- require "stripe/recipient"
84
- require "stripe/recipient_transfer"
85
- require "stripe/refund"
86
- require "stripe/reporting/report_run"
87
- require "stripe/reporting/report_type"
88
- require "stripe/reversal"
89
- require "stripe/review"
90
- require "stripe/sigma/scheduled_query_run"
91
- require "stripe/sku"
92
- require "stripe/source"
93
- require "stripe/source_transaction"
94
- require "stripe/subscription"
95
- require "stripe/subscription_item"
96
- require "stripe/subscription_schedule"
97
- require "stripe/subscription_schedule_revision"
98
- require "stripe/terminal/connection_token"
99
- require "stripe/terminal/location"
100
- require "stripe/terminal/reader"
101
- require "stripe/three_d_secure"
102
- require "stripe/token"
103
- require "stripe/topup"
104
- require "stripe/transfer"
105
- require "stripe/usage_record"
106
- require "stripe/usage_record_summary"
107
- require "stripe/webhook_endpoint"
43
+ require "stripe/resources"
108
44
 
109
45
  # OAuth
110
46
  require "stripe/oauth"
111
47
 
112
48
  module Stripe
113
- DEFAULT_CA_BUNDLE_PATH = ::File.dirname(__FILE__) + "/data/ca-certificates.crt"
49
+ DEFAULT_CA_BUNDLE_PATH = __dir__ + "/data/ca-certificates.crt"
114
50
 
115
51
  @app_info = nil
116
52
 
@@ -121,6 +57,8 @@ module Stripe
121
57
  @log_level = nil
122
58
  @logger = nil
123
59
 
60
+ @proxy = nil
61
+
124
62
  @max_network_retries = 0
125
63
  @max_network_retry_delay = 2
126
64
  @initial_network_retry_delay = 0.5
@@ -132,11 +70,23 @@ module Stripe
132
70
  @open_timeout = 30
133
71
  @read_timeout = 80
134
72
 
135
- @enable_telemetry = false
73
+ @enable_telemetry = true
136
74
 
137
75
  class << self
138
- attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :client_id, :connect_base, :uploads_base,
139
- :open_timeout, :read_timeout
76
+ attr_accessor :api_key
77
+ attr_accessor :api_version
78
+ attr_accessor :client_id
79
+ attr_accessor :stripe_account
80
+
81
+ # These all get manual attribute writers so that we can reset connections
82
+ # if they change.
83
+ attr_reader :api_base
84
+ attr_reader :connect_base
85
+ attr_reader :open_timeout
86
+ attr_reader :proxy
87
+ attr_reader :read_timeout
88
+ attr_reader :uploads_base
89
+ attr_reader :verify_ssl_certs
140
90
 
141
91
  attr_reader :max_network_retry_delay, :initial_network_retry_delay
142
92
  end
@@ -151,6 +101,11 @@ module Stripe
151
101
  @app_info = info
152
102
  end
153
103
 
104
+ def self.api_base=(api_base)
105
+ @api_base = api_base
106
+ StripeClient.clear_all_connection_managers
107
+ end
108
+
154
109
  # The location of a file containing a bundle of CA certificates. By default
155
110
  # the library will use an included bundle that can successfully validate
156
111
  # Stripe certificates.
@@ -163,6 +118,8 @@ module Stripe
163
118
 
164
119
  # empty this field so a new store is initialized
165
120
  @ca_store = nil
121
+
122
+ StripeClient.clear_all_connection_managers
166
123
  end
167
124
 
168
125
  # A certificate store initialized from the the bundle in #ca_bundle_path and
@@ -182,6 +139,19 @@ module Stripe
182
139
  end
183
140
  end
184
141
 
142
+ def self.connection_base=(connection_base)
143
+ @connection_base = connection_base
144
+ StripeClient.clear_all_connection_managers
145
+ end
146
+
147
+ def self.enable_telemetry?
148
+ @enable_telemetry
149
+ end
150
+
151
+ def self.enable_telemetry=(val)
152
+ @enable_telemetry = val
153
+ end
154
+
185
155
  # map to the same values as the standard library's logger
186
156
  LEVEL_DEBUG = Logger::DEBUG
187
157
  LEVEL_ERROR = Logger::ERROR
@@ -207,7 +177,8 @@ module Stripe
207
177
  end
208
178
 
209
179
  if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
210
- raise ArgumentError, "log_level should only be set to `nil`, `debug` or `info`"
180
+ raise ArgumentError,
181
+ "log_level should only be set to `nil`, `debug` or `info`"
211
182
  end
212
183
  @log_level = val
213
184
  end
@@ -235,12 +206,19 @@ module Stripe
235
206
  @max_network_retries = val.to_i
236
207
  end
237
208
 
238
- def self.enable_telemetry?
239
- @enable_telemetry
209
+ def self.open_timeout=(open_timeout)
210
+ @open_timeout = open_timeout
211
+ StripeClient.clear_all_connection_managers
240
212
  end
241
213
 
242
- def self.enable_telemetry=(val)
243
- @enable_telemetry = val
214
+ def self.proxy=(proxy)
215
+ @proxy = proxy
216
+ StripeClient.clear_all_connection_managers
217
+ end
218
+
219
+ def self.read_timeout=(read_timeout)
220
+ @read_timeout = read_timeout
221
+ StripeClient.clear_all_connection_managers
244
222
  end
245
223
 
246
224
  # Sets some basic information about the running application that's sent along
@@ -257,14 +235,14 @@ module Stripe
257
235
  }
258
236
  end
259
237
 
260
- # DEPRECATED. Use `Util#encode_parameters` instead.
261
- def self.uri_encode(params)
262
- Util.encode_parameters(params)
238
+ def self.uploads_base=(uploads_base)
239
+ @uploads_base = uploads_base
240
+ StripeClient.clear_all_connection_managers
263
241
  end
264
- private_class_method :uri_encode
265
- class << self
266
- extend Gem::Deprecate
267
- deprecate :uri_encode, "Stripe::Util#encode_parameters", 2016, 1
242
+
243
+ def self.verify_ssl_certs=(verify_ssl_certs)
244
+ @verify_ssl_certs = verify_ssl_certs
245
+ StripeClient.clear_all_connection_managers
268
246
  end
269
247
  end
270
248
 
data/stripe.gemspec CHANGED
@@ -7,19 +7,28 @@ require "stripe/version"
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "stripe"
9
9
  s.version = Stripe::VERSION
10
- s.required_ruby_version = ">= 2.1.0"
10
+ s.required_ruby_version = ">= 2.3.0"
11
11
  s.summary = "Ruby bindings for the Stripe API"
12
- s.description = "Stripe is the easiest way to accept payments online. See https://stripe.com for details."
12
+ s.description = "Stripe is the easiest way to accept payments online. " \
13
+ "See https://stripe.com for details."
13
14
  s.author = "Stripe"
14
15
  s.email = "support@stripe.com"
15
16
  s.homepage = "https://stripe.com/docs/api/ruby"
16
17
  s.license = "MIT"
17
18
 
18
- s.add_dependency("faraday", "~> 0.13")
19
- s.add_dependency("net-http-persistent", "~> 3.0")
19
+ s.metadata = {
20
+ "bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues",
21
+ "changelog_uri" =>
22
+ "https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md",
23
+ "documentation_uri" => "https://stripe.com/docs/api/ruby",
24
+ "github_repo" => "ssh://github.com/stripe/stripe-ruby",
25
+ "homepage_uri" => "https://stripe.com/docs/api/ruby",
26
+ "source_code_uri" => "https://github.com/stripe/stripe-ruby",
27
+ }
20
28
 
21
29
  s.files = `git ls-files`.split("\n")
22
30
  s.test_files = `git ls-files -- test/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| ::File.basename(f) }
31
+ s.executables = `git ls-files -- bin/*`.split("\n")
32
+ .map { |f| ::File.basename(f) }
24
33
  s.require_paths = ["lib"]
25
34
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require ::File.expand_path("../test_helper", __dir__)
4
4
 
5
5
  module Stripe
6
6
  class AccountLinkTest < Test::Unit::TestCase
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require ::File.expand_path("../test_helper", __dir__)
4
4
 
5
5
  module Stripe
6
6
  class AccountTest < Test::Unit::TestCase
@@ -24,15 +24,18 @@ module Stripe
24
24
  end
25
25
 
26
26
  should "be rejectable" do
27
- account_data = { id: "acct_foo" }
28
- stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo")
29
- .to_return(body: JSON.generate(account_data))
30
-
31
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject")
32
- .to_return(body: JSON.generate(account_data))
33
-
34
27
  account = Stripe::Account.retrieve("acct_foo")
35
- account.reject(reason: "fraud")
28
+ account = account.reject(reason: "fraud")
29
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
30
+ assert account.is_a?(Stripe::Account)
31
+ end
32
+
33
+ context ".reject" do
34
+ should "reject the account" do
35
+ account = Stripe::Account.reject("acct_foo", reason: "fraud")
36
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
37
+ assert account.is_a?(Stripe::Account)
38
+ end
36
39
  end
37
40
 
38
41
  should "be creatable" do
@@ -54,11 +57,21 @@ module Stripe
54
57
  assert account.is_a?(Stripe::Account)
55
58
  end
56
59
 
57
- should "be deletable" do
58
- account = Stripe::Account.retrieve("acct_123")
59
- account = account.delete
60
- assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{account.id}"
61
- assert account.is_a?(Stripe::Account)
60
+ context "#delete" do
61
+ should "be deletable" do
62
+ account = Stripe::Account.retrieve("acct_123")
63
+ account = account.delete
64
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{account.id}"
65
+ assert account.is_a?(Stripe::Account)
66
+ end
67
+ end
68
+
69
+ context ".delete" do
70
+ should "be deletable" do
71
+ account = Stripe::Account.delete("acct_123")
72
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/acct_123"
73
+ assert account.is_a?(Stripe::Account)
74
+ end
62
75
  end
63
76
 
64
77
  should "be able to list Persons" do
@@ -69,22 +82,6 @@ module Stripe
69
82
  assert persons.data[0].is_a?(Stripe::Person)
70
83
  end
71
84
 
72
- context "#bank_account=" do
73
- should "warn that #bank_account= is deprecated" do
74
- old_stderr = $stderr
75
- $stderr = StringIO.new
76
- begin
77
- account = Stripe::Account.retrieve("acct_123")
78
- account.bank_account = "tok_123"
79
- message = "NOTE: Stripe::Account#bank_account= is " \
80
- "deprecated; use #external_account= instead"
81
- assert_match Regexp.new(message), $stderr.string
82
- ensure
83
- $stderr = old_stderr
84
- end
85
- end
86
- end
87
-
88
85
  context "#deauthorize" do
89
86
  should "deauthorize an account" do
90
87
  account = Stripe::Account.retrieve("acct_123")
@@ -252,5 +249,164 @@ module Stripe
252
249
  assert_equal(expected, obj.serialize_params)
253
250
  end
254
251
  end
252
+
253
+ context "#retrieve_capability" do
254
+ should "retrieve a capability" do
255
+ capability = Stripe::Account.retrieve_capability(
256
+ "acct_123",
257
+ "acap_123"
258
+ )
259
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/capabilities/acap_123"
260
+ assert capability.is_a?(Stripe::Capability)
261
+ end
262
+ end
263
+
264
+ context "#update_capability" do
265
+ should "update a capability" do
266
+ capability = Stripe::Account.update_capability(
267
+ "acct_123",
268
+ "acap_123",
269
+ requested: true
270
+ )
271
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/capabilities/acap_123"
272
+ assert capability.is_a?(Stripe::Capability)
273
+ end
274
+ end
275
+
276
+ context "#list_capabilities" do
277
+ should "list the account's external accounts" do
278
+ capabilities = Stripe::Account.list_capabilities(
279
+ "acct_123"
280
+ )
281
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/capabilities"
282
+ assert capabilities.is_a?(Stripe::ListObject)
283
+ assert capabilities.data.is_a?(Array)
284
+ end
285
+ end
286
+
287
+ context "#create_external_account" do
288
+ should "create an external account" do
289
+ external_account = Stripe::Account.create_external_account(
290
+ "acct_123",
291
+ external_account: "btok_123"
292
+ )
293
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts"
294
+ assert external_account.is_a?(Stripe::BankAccount)
295
+ end
296
+ end
297
+
298
+ context "#retrieve_external_account" do
299
+ should "retrieve an external account" do
300
+ external_account = Stripe::Account.retrieve_external_account(
301
+ "acct_123",
302
+ "ba_123"
303
+ )
304
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts/ba_123"
305
+ assert external_account.is_a?(Stripe::BankAccount)
306
+ end
307
+ end
308
+
309
+ context "#update_external_account" do
310
+ should "update an external account" do
311
+ external_account = Stripe::Account.update_external_account(
312
+ "acct_123",
313
+ "ba_123",
314
+ metadata: { foo: "bar" }
315
+ )
316
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts/ba_123"
317
+ assert external_account.is_a?(Stripe::BankAccount)
318
+ end
319
+ end
320
+
321
+ context "#delete_external_account" do
322
+ should "delete an external_account" do
323
+ external_account = Stripe::Account.delete_external_account(
324
+ "acct_123",
325
+ "ba_123"
326
+ )
327
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts/ba_123"
328
+ assert external_account.deleted
329
+ assert_equal "ba_123", external_account.id
330
+ end
331
+ end
332
+
333
+ context "#list_external_accounts" do
334
+ should "list the account's external accounts" do
335
+ external_accounts = Stripe::Account.list_external_accounts(
336
+ "acct_123"
337
+ )
338
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts"
339
+ assert external_accounts.is_a?(Stripe::ListObject)
340
+ assert external_accounts.data.is_a?(Array)
341
+ end
342
+ end
343
+
344
+ context "#create_login_link" do
345
+ should "create a login link" do
346
+ login_link = Stripe::Account.create_login_link(
347
+ "acct_123"
348
+ )
349
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/login_links"
350
+ assert login_link.is_a?(Stripe::LoginLink)
351
+ end
352
+ end
353
+
354
+ context "#create_person" do
355
+ should "create a person" do
356
+ person = Stripe::Account.create_person(
357
+ "acct_123",
358
+ first_name: "John",
359
+ last_name: "Doe"
360
+ )
361
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/persons"
362
+ assert person.is_a?(Stripe::Person)
363
+ end
364
+ end
365
+
366
+ context "#retrieve_person" do
367
+ should "retrieve a person" do
368
+ person = Stripe::Account.retrieve_person(
369
+ "acct_123",
370
+ "person_123"
371
+ )
372
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/persons/person_123"
373
+ assert person.is_a?(Stripe::Person)
374
+ end
375
+ end
376
+
377
+ context "#update_person" do
378
+ should "update a person" do
379
+ person = Stripe::Account.update_person(
380
+ "acct_123",
381
+ "person_123",
382
+ first_name: "John"
383
+ )
384
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/persons/person_123"
385
+ assert person.is_a?(Stripe::Person)
386
+ end
387
+ end
388
+
389
+ context "#delete_person" do
390
+ should "delete an person" do
391
+ person = Stripe::Account.delete_person(
392
+ "acct_123",
393
+ "person_123"
394
+ )
395
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/acct_123/persons/person_123"
396
+ assert person.deleted
397
+ assert_equal "person_123", person.id
398
+ end
399
+ end
400
+
401
+ context "#list_persons" do
402
+ should "list the account's external accounts" do
403
+ persons = Stripe::Account.list_persons(
404
+ "acct_123"
405
+ )
406
+ assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/persons"
407
+ assert persons.is_a?(Stripe::ListObject)
408
+ assert persons.data.is_a?(Array)
409
+ end
410
+ end
255
411
  end
256
412
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require ::File.expand_path("../test_helper", __dir__)
4
4
 
5
5
  module Stripe
6
6
  class AlipayAccountTest < Test::Unit::TestCase
@@ -1,14 +1,13 @@
1
- # -*- coding: utf-8 -*-
2
1
  # frozen_string_literal: true
3
2
 
4
- require ::File.expand_path("../../test_helper", __FILE__)
3
+ require ::File.expand_path("../test_helper", __dir__)
5
4
 
6
5
  module Stripe
7
6
  class ApiOperationsTest < Test::Unit::TestCase
8
7
  class UpdateableResource < APIResource
9
8
  include Stripe::APIOperations::Save
10
9
 
11
- OBJECT_NAME = "updateableresource".freeze
10
+ OBJECT_NAME = "updateableresource"
12
11
 
13
12
  def self.protected_fields
14
13
  [:protected]
@@ -35,7 +34,7 @@ module Stripe
35
34
  context ".nested_resource_class_methods" do
36
35
  class MainResource < APIResource
37
36
  extend Stripe::APIOperations::NestedResource
38
- OBJECT_NAME = "mainresource".freeze
37
+ OBJECT_NAME = "mainresource"
39
38
  nested_resource_class_methods :nested,
40
39
  operations: %i[create retrieve update delete list]
41
40
  end