stripe 5.28.0 → 8.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +286 -0
  3. data/Gemfile +5 -3
  4. data/Makefile +13 -0
  5. data/OPENAPI_VERSION +1 -0
  6. data/README.md +43 -5
  7. data/VERSION +1 -1
  8. data/lib/data/ca-certificates.crt +1241 -1937
  9. data/lib/stripe/api_operations/create.rb +6 -2
  10. data/lib/stripe/api_operations/delete.rb +12 -7
  11. data/lib/stripe/api_operations/list.rb +6 -9
  12. data/lib/stripe/api_operations/nested_resource.rb +62 -34
  13. data/lib/stripe/api_operations/request.rb +45 -2
  14. data/lib/stripe/api_operations/save.rb +13 -3
  15. data/lib/stripe/api_operations/search.rb +16 -0
  16. data/lib/stripe/api_resource.rb +11 -18
  17. data/lib/stripe/api_resource_test_helpers.rb +49 -0
  18. data/lib/stripe/api_version.rb +8 -0
  19. data/lib/stripe/connection_manager.rb +49 -11
  20. data/lib/stripe/error_object.rb +2 -3
  21. data/lib/stripe/instrumentation.rb +46 -6
  22. data/lib/stripe/oauth.rb +4 -3
  23. data/lib/stripe/object_types.rb +36 -10
  24. data/lib/stripe/resources/account.rb +39 -17
  25. data/lib/stripe/resources/account_link.rb +4 -0
  26. data/lib/stripe/resources/application_fee_refund.rb +7 -1
  27. data/lib/stripe/resources/apps/secret.rb +40 -0
  28. data/lib/stripe/resources/balance.rb +11 -0
  29. data/lib/stripe/resources/balance_transaction.rb +4 -0
  30. data/lib/stripe/resources/bank_account.rb +7 -0
  31. data/lib/stripe/resources/billing_portal/configuration.rb +15 -0
  32. data/lib/stripe/resources/billing_portal/session.rb +14 -0
  33. data/lib/stripe/resources/capability.rb +5 -1
  34. data/lib/stripe/resources/card.rb +6 -3
  35. data/lib/stripe/resources/cash_balance.rb +23 -0
  36. data/lib/stripe/resources/charge.rb +23 -3
  37. data/lib/stripe/resources/checkout/session.rb +49 -2
  38. data/lib/stripe/resources/country_spec.rb +6 -0
  39. data/lib/stripe/resources/coupon.rb +3 -0
  40. data/lib/stripe/resources/credit_note.rb +27 -9
  41. data/lib/stripe/resources/credit_note_line_item.rb +2 -0
  42. data/lib/stripe/resources/customer.rb +132 -4
  43. data/lib/stripe/resources/customer_balance_transaction.rb +9 -2
  44. data/lib/stripe/resources/customer_cash_balance_transaction.rb +14 -0
  45. data/lib/stripe/resources/discount.rb +5 -0
  46. data/lib/stripe/resources/dispute.rb +17 -3
  47. data/lib/stripe/resources/event.rb +29 -0
  48. data/lib/stripe/resources/exchange_rate.rb +11 -0
  49. data/lib/stripe/resources/file.rb +9 -1
  50. data/lib/stripe/resources/file_link.rb +3 -0
  51. data/lib/stripe/resources/financial_connections/account.rb +67 -0
  52. data/lib/stripe/resources/financial_connections/account_owner.rb +11 -0
  53. data/lib/stripe/resources/financial_connections/account_ownership.rb +11 -0
  54. data/lib/stripe/resources/financial_connections/session.rb +13 -0
  55. data/lib/stripe/resources/funding_instructions.rb +21 -0
  56. data/lib/stripe/resources/identity/verification_report.rb +23 -0
  57. data/lib/stripe/resources/identity/verification_session.rb +61 -0
  58. data/lib/stripe/resources/invoice.rb +105 -17
  59. data/lib/stripe/resources/invoice_item.rb +11 -0
  60. data/lib/stripe/resources/invoice_line_item.rb +1 -0
  61. data/lib/stripe/resources/issuing/authorization.rb +25 -5
  62. data/lib/stripe/resources/issuing/card.rb +78 -8
  63. data/lib/stripe/resources/issuing/cardholder.rb +3 -0
  64. data/lib/stripe/resources/issuing/dispute.rb +13 -3
  65. data/lib/stripe/resources/issuing/transaction.rb +5 -0
  66. data/lib/stripe/resources/line_item.rb +2 -0
  67. data/lib/stripe/resources/login_link.rb +2 -0
  68. data/lib/stripe/resources/mandate.rb +1 -0
  69. data/lib/stripe/resources/payment_intent.rb +103 -6
  70. data/lib/stripe/resources/payment_link.rb +35 -0
  71. data/lib/stripe/resources/payment_method.rb +25 -5
  72. data/lib/stripe/resources/payout.rb +28 -5
  73. data/lib/stripe/resources/person.rb +7 -0
  74. data/lib/stripe/resources/plan.rb +8 -0
  75. data/lib/stripe/resources/price.rb +15 -0
  76. data/lib/stripe/resources/product.rb +17 -0
  77. data/lib/stripe/resources/promotion_code.rb +2 -0
  78. data/lib/stripe/resources/quote.rb +128 -0
  79. data/lib/stripe/resources/radar/early_fraud_warning.rb +4 -0
  80. data/lib/stripe/resources/radar/value_list.rb +3 -0
  81. data/lib/stripe/resources/radar/value_list_item.rb +3 -0
  82. data/lib/stripe/resources/refund.rb +49 -0
  83. data/lib/stripe/resources/reporting/report_run.rb +8 -0
  84. data/lib/stripe/resources/reporting/report_type.rb +8 -1
  85. data/lib/stripe/resources/reversal.rb +16 -2
  86. data/lib/stripe/resources/review.rb +14 -3
  87. data/lib/stripe/resources/setup_attempt.rb +4 -0
  88. data/lib/stripe/resources/setup_intent.rb +60 -5
  89. data/lib/stripe/resources/shipping_rate.rb +14 -0
  90. data/lib/stripe/resources/sigma/scheduled_query_run.rb +4 -0
  91. data/lib/stripe/resources/source.rb +26 -6
  92. data/lib/stripe/resources/source_transaction.rb +5 -0
  93. data/lib/stripe/resources/subscription.rb +57 -3
  94. data/lib/stripe/resources/subscription_item.rb +2 -7
  95. data/lib/stripe/resources/subscription_schedule.rb +23 -5
  96. data/lib/stripe/resources/tax/calculation.rb +33 -0
  97. data/lib/stripe/resources/tax/calculation_line_item.rb +10 -0
  98. data/lib/stripe/resources/tax/settings.rb +15 -0
  99. data/lib/stripe/resources/tax/transaction.rb +49 -0
  100. data/lib/stripe/resources/tax/transaction_line_item.rb +10 -0
  101. data/lib/stripe/resources/tax_code.rb +11 -0
  102. data/lib/stripe/resources/tax_id.rb +5 -0
  103. data/lib/stripe/resources/tax_rate.rb +3 -0
  104. data/lib/stripe/resources/terminal/configuration.rb +16 -0
  105. data/lib/stripe/resources/terminal/connection_token.rb +3 -0
  106. data/lib/stripe/resources/terminal/location.rb +3 -0
  107. data/lib/stripe/resources/terminal/reader.rb +119 -0
  108. data/lib/stripe/resources/test_helpers/test_clock.rb +35 -0
  109. data/lib/stripe/resources/token.rb +20 -0
  110. data/lib/stripe/resources/topup.rb +15 -3
  111. data/lib/stripe/resources/transfer.rb +10 -11
  112. data/lib/stripe/resources/treasury/credit_reversal.rb +14 -0
  113. data/lib/stripe/resources/treasury/debit_reversal.rb +14 -0
  114. data/lib/stripe/resources/treasury/financial_account.rb +52 -0
  115. data/lib/stripe/resources/treasury/financial_account_features.rb +12 -0
  116. data/lib/stripe/resources/treasury/inbound_transfer.rb +94 -0
  117. data/lib/stripe/resources/treasury/outbound_payment.rb +96 -0
  118. data/lib/stripe/resources/treasury/outbound_transfer.rb +100 -0
  119. data/lib/stripe/resources/treasury/received_credit.rb +30 -0
  120. data/lib/stripe/resources/treasury/received_debit.rb +30 -0
  121. data/lib/stripe/resources/treasury/transaction.rb +13 -0
  122. data/lib/stripe/resources/treasury/transaction_entry.rb +17 -0
  123. data/lib/stripe/resources/usage_record.rb +5 -0
  124. data/lib/stripe/resources/usage_record_summary.rb +1 -0
  125. data/lib/stripe/resources/webhook_endpoint.rb +7 -0
  126. data/lib/stripe/resources.rb +34 -10
  127. data/lib/stripe/search_result_object.rb +86 -0
  128. data/lib/stripe/stripe_client.rb +267 -121
  129. data/lib/stripe/stripe_configuration.rb +29 -10
  130. data/lib/stripe/stripe_object.rb +25 -2
  131. data/lib/stripe/stripe_response.rb +80 -52
  132. data/lib/stripe/util.rb +100 -9
  133. data/lib/stripe/version.rb +1 -1
  134. data/lib/stripe.rb +27 -23
  135. data/stripe.gemspec +12 -5
  136. metadata +46 -204
  137. data/.editorconfig +0 -10
  138. data/.gitattributes +0 -4
  139. data/.github/ISSUE_TEMPLATE.md +0 -5
  140. data/.gitignore +0 -8
  141. data/.rubocop.yml +0 -80
  142. data/.rubocop_todo.yml +0 -33
  143. data/.travis.yml +0 -38
  144. data/.vscode/extensions.json +0 -7
  145. data/.vscode/settings.json +0 -8
  146. data/lib/stripe/resources/bitcoin_receiver.rb +0 -24
  147. data/lib/stripe/resources/bitcoin_transaction.rb +0 -15
  148. data/lib/stripe/resources/issuing/card_details.rb +0 -9
  149. data/lib/stripe/resources/order.rb +0 -33
  150. data/lib/stripe/resources/order_return.rb +0 -10
  151. data/lib/stripe/resources/recipient.rb +0 -14
  152. data/lib/stripe/resources/sku.rb +0 -13
  153. data/lib/stripe/resources/three_d_secure.rb +0 -14
  154. data/test/openapi/README.md +0 -9
  155. data/test/stripe/account_link_test.rb +0 -18
  156. data/test/stripe/account_test.rb +0 -412
  157. data/test/stripe/alipay_account_test.rb +0 -37
  158. data/test/stripe/api_operations_test.rb +0 -80
  159. data/test/stripe/api_resource_test.rb +0 -646
  160. data/test/stripe/apple_pay_domain_test.rb +0 -46
  161. data/test/stripe/application_fee_refund_test.rb +0 -37
  162. data/test/stripe/application_fee_test.rb +0 -58
  163. data/test/stripe/balance_test.rb +0 -13
  164. data/test/stripe/balance_transaction_test.rb +0 -20
  165. data/test/stripe/bank_account_test.rb +0 -36
  166. data/test/stripe/billing_portal/session_test.rb +0 -18
  167. data/test/stripe/capability_test.rb +0 -45
  168. data/test/stripe/charge_test.rb +0 -64
  169. data/test/stripe/checkout/session_test.rb +0 -53
  170. data/test/stripe/connection_manager_test.rb +0 -167
  171. data/test/stripe/country_spec_test.rb +0 -20
  172. data/test/stripe/coupon_test.rb +0 -61
  173. data/test/stripe/credit_note_test.rb +0 -90
  174. data/test/stripe/customer_balance_transaction_test.rb +0 -37
  175. data/test/stripe/customer_card_test.rb +0 -48
  176. data/test/stripe/customer_test.rb +0 -226
  177. data/test/stripe/dispute_test.rb +0 -51
  178. data/test/stripe/ephemeral_key_test.rb +0 -93
  179. data/test/stripe/errors_test.rb +0 -53
  180. data/test/stripe/exchange_rate_test.rb +0 -20
  181. data/test/stripe/file_link_test.rb +0 -41
  182. data/test/stripe/file_test.rb +0 -87
  183. data/test/stripe/instrumentation_test.rb +0 -74
  184. data/test/stripe/invoice_item_test.rb +0 -66
  185. data/test/stripe/invoice_line_item_test.rb +0 -8
  186. data/test/stripe/invoice_test.rb +0 -229
  187. data/test/stripe/issuing/authorization_test.rb +0 -72
  188. data/test/stripe/issuing/card_test.rb +0 -74
  189. data/test/stripe/issuing/cardholder_test.rb +0 -53
  190. data/test/stripe/issuing/dispute_test.rb +0 -54
  191. data/test/stripe/issuing/transaction_test.rb +0 -48
  192. data/test/stripe/list_object_test.rb +0 -202
  193. data/test/stripe/login_link_test.rb +0 -37
  194. data/test/stripe/mandate_test.rb +0 -14
  195. data/test/stripe/multipart_encoder_test.rb +0 -130
  196. data/test/stripe/oauth_test.rb +0 -104
  197. data/test/stripe/order_return_test.rb +0 -21
  198. data/test/stripe/order_test.rb +0 -82
  199. data/test/stripe/payment_intent_test.rb +0 -107
  200. data/test/stripe/payment_method_test.rb +0 -84
  201. data/test/stripe/payout_test.rb +0 -72
  202. data/test/stripe/person_test.rb +0 -46
  203. data/test/stripe/plan_test.rb +0 -98
  204. data/test/stripe/price_test.rb +0 -48
  205. data/test/stripe/product_test.rb +0 -58
  206. data/test/stripe/promotion_code_test.rb +0 -42
  207. data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
  208. data/test/stripe/radar/value_list_item_test.rb +0 -48
  209. data/test/stripe/radar/value_list_test.rb +0 -61
  210. data/test/stripe/recipient_test.rb +0 -62
  211. data/test/stripe/refund_test.rb +0 -39
  212. data/test/stripe/reporting/report_run_test.rb +0 -33
  213. data/test/stripe/reporting/report_type_test.rb +0 -22
  214. data/test/stripe/reversal_test.rb +0 -43
  215. data/test/stripe/review_test.rb +0 -27
  216. data/test/stripe/setup_attempt_test.rb +0 -16
  217. data/test/stripe/setup_intent_test.rb +0 -84
  218. data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
  219. data/test/stripe/sku_test.rb +0 -60
  220. data/test/stripe/source_test.rb +0 -119
  221. data/test/stripe/stripe_client_test.rb +0 -1291
  222. data/test/stripe/stripe_configuration_test.rb +0 -131
  223. data/test/stripe/stripe_object_test.rb +0 -500
  224. data/test/stripe/stripe_response_test.rb +0 -95
  225. data/test/stripe/subscription_item_test.rb +0 -84
  226. data/test/stripe/subscription_schedule_test.rb +0 -82
  227. data/test/stripe/subscription_test.rb +0 -80
  228. data/test/stripe/tax_id_test.rb +0 -31
  229. data/test/stripe/tax_rate_test.rb +0 -43
  230. data/test/stripe/terminal/connection_token_test.rb +0 -16
  231. data/test/stripe/terminal/location_test.rb +0 -68
  232. data/test/stripe/terminal/reader_test.rb +0 -62
  233. data/test/stripe/three_d_secure_test.rb +0 -23
  234. data/test/stripe/topup_test.rb +0 -62
  235. data/test/stripe/transfer_test.rb +0 -88
  236. data/test/stripe/usage_record_summary_test.rb +0 -29
  237. data/test/stripe/util_test.rb +0 -402
  238. data/test/stripe/webhook_endpoint_test.rb +0 -59
  239. data/test/stripe/webhook_test.rb +0 -135
  240. data/test/stripe_mock.rb +0 -78
  241. data/test/stripe_test.rb +0 -132
  242. data/test/test_data.rb +0 -61
  243. data/test/test_helper.rb +0 -77
@@ -4,8 +4,12 @@ module Stripe
4
4
  module APIOperations
5
5
  module Create
6
6
  def create(params = {}, opts = {})
7
- resp, opts = execute_resource_request(:post, resource_url, params, opts)
8
- Util.convert_to_stripe_object(resp.data, opts)
7
+ request_stripe_object(
8
+ method: :post,
9
+ path: resource_url,
10
+ params: params,
11
+ opts: opts
12
+ )
9
13
  end
10
14
  end
11
15
  end
@@ -18,17 +18,22 @@ module Stripe
18
18
  # api_key to be overwritten. See
19
19
  # {APIOperations::Request.execute_resource_request}.
20
20
  def delete(id, params = {}, opts = {})
21
- resp, opts = execute_resource_request(:delete,
22
- "#{resource_url}/#{id}",
23
- params, opts)
24
- Util.convert_to_stripe_object(resp.data, opts)
21
+ request_stripe_object(
22
+ method: :delete,
23
+ path: "#{resource_url}/#{id}",
24
+ params: params,
25
+ opts: opts
26
+ )
25
27
  end
26
28
  end
27
29
 
28
30
  def delete(params = {}, opts = {})
29
- resp, opts = execute_resource_request(:delete, resource_url,
30
- params, opts)
31
- initialize_from(resp.data, opts)
31
+ request_stripe_object(
32
+ method: :delete,
33
+ path: resource_url,
34
+ params: params,
35
+ opts: opts
36
+ )
32
37
  end
33
38
 
34
39
  def self.included(base)
@@ -4,15 +4,12 @@ module Stripe
4
4
  module APIOperations
5
5
  module List
6
6
  def list(filters = {}, opts = {})
7
- opts = Util.normalize_opts(opts)
8
-
9
- resp, opts = execute_resource_request(:get, resource_url, filters, opts)
10
- obj = ListObject.construct_from(resp.data, opts)
11
-
12
- # set filters so that we can fetch the same limit, expansions, and
13
- # predicates when accessing the next and previous pages
14
- obj.filters = filters.dup
15
- obj
7
+ request_stripe_object(
8
+ method: :get,
9
+ path: resource_url,
10
+ params: filters,
11
+ opts: opts
12
+ )
16
13
  end
17
14
  end
18
15
  end
@@ -26,46 +26,74 @@ module Stripe
26
26
  end
27
27
 
28
28
  operations.each do |operation|
29
- case operation
30
- when :create
31
- define_singleton_method(:"create_#{resource}") \
29
+ define_operation(
30
+ resource,
31
+ operation,
32
+ resource_url_method,
33
+ resource_plural
34
+ )
35
+ end
36
+ end
37
+
38
+ private def define_operation(
39
+ resource,
40
+ operation,
41
+ resource_url_method,
42
+ resource_plural
43
+ )
44
+ case operation
45
+ when :create
46
+ define_singleton_method(:"create_#{resource}") \
32
47
  do |id, params = {}, opts = {}|
33
- url = send(resource_url_method, id)
34
- resp, opts = execute_resource_request(:post, url, params, opts)
35
- Util.convert_to_stripe_object(resp.data, opts)
36
- end
37
- when :retrieve
38
- define_singleton_method(:"retrieve_#{resource}") \
48
+ request_stripe_object(
49
+ method: :post,
50
+ path: send(resource_url_method, id),
51
+ params: params,
52
+ opts: opts
53
+ )
54
+ end
55
+ when :retrieve
56
+ define_singleton_method(:"retrieve_#{resource}") \
39
57
  do |id, nested_id, opts = {}|
40
- url = send(resource_url_method, id, nested_id)
41
- resp, opts = execute_resource_request(:get, url, {}, opts)
42
- Util.convert_to_stripe_object(resp.data, opts)
43
- end
44
- when :update
45
- define_singleton_method(:"update_#{resource}") \
58
+ request_stripe_object(
59
+ method: :get,
60
+ path: send(resource_url_method, id, nested_id),
61
+ params: {},
62
+ opts: opts
63
+ )
64
+ end
65
+ when :update
66
+ define_singleton_method(:"update_#{resource}") \
46
67
  do |id, nested_id, params = {}, opts = {}|
47
- url = send(resource_url_method, id, nested_id)
48
- resp, opts = execute_resource_request(:post, url, params, opts)
49
- Util.convert_to_stripe_object(resp.data, opts)
50
- end
51
- when :delete
52
- define_singleton_method(:"delete_#{resource}") \
68
+ request_stripe_object(
69
+ method: :post,
70
+ path: send(resource_url_method, id, nested_id),
71
+ params: params,
72
+ opts: opts
73
+ )
74
+ end
75
+ when :delete
76
+ define_singleton_method(:"delete_#{resource}") \
53
77
  do |id, nested_id, params = {}, opts = {}|
54
- url = send(resource_url_method, id, nested_id)
55
- resp, opts = execute_resource_request(:delete, url, params,
56
- opts)
57
- Util.convert_to_stripe_object(resp.data, opts)
58
- end
59
- when :list
60
- define_singleton_method(:"list_#{resource_plural}") \
78
+ request_stripe_object(
79
+ method: :delete,
80
+ path: send(resource_url_method, id, nested_id),
81
+ params: params,
82
+ opts: opts
83
+ )
84
+ end
85
+ when :list
86
+ define_singleton_method(:"list_#{resource_plural}") \
61
87
  do |id, params = {}, opts = {}|
62
- url = send(resource_url_method, id)
63
- resp, opts = execute_resource_request(:get, url, params, opts)
64
- Util.convert_to_stripe_object(resp.data, opts)
65
- end
66
- else
67
- raise ArgumentError, "Unknown operation: #{operation.inspect}"
88
+ request_stripe_object(
89
+ method: :get,
90
+ path: send(resource_url_method, id),
91
+ params: params,
92
+ opts: opts
93
+ )
68
94
  end
95
+ else
96
+ raise ArgumentError, "Unknown operation: #{operation.inspect}"
69
97
  end
70
98
  end
71
99
  end
@@ -6,6 +6,33 @@ module Stripe
6
6
  module ClassMethods
7
7
  def execute_resource_request(method, url,
8
8
  params = {}, opts = {})
9
+ execute_resource_request_internal(
10
+ :execute_request, method, url, params, opts
11
+ )
12
+ end
13
+
14
+ def execute_resource_request_stream(method, url,
15
+ params = {}, opts = {},
16
+ &read_body_chunk_block)
17
+ execute_resource_request_internal(
18
+ :execute_request_stream,
19
+ method,
20
+ url,
21
+ params,
22
+ opts,
23
+ &read_body_chunk_block
24
+ )
25
+ end
26
+
27
+ private def request_stripe_object(method:, path:, params:, opts: {})
28
+ resp, opts = execute_resource_request(method, path, params, opts)
29
+ Util.convert_to_stripe_object_with_params(resp.data, params, opts)
30
+ end
31
+
32
+ private def execute_resource_request_internal(client_request_method_sym,
33
+ method, url,
34
+ params, opts,
35
+ &read_body_chunk_block)
9
36
  params ||= {}
10
37
 
11
38
  error_on_invalid_params(params)
@@ -22,10 +49,12 @@ module Stripe
22
49
  client = headers.delete(:client)
23
50
  # Assume all remaining opts must be headers
24
51
 
25
- resp, opts[:api_key] = client.execute_request(
52
+ resp, opts[:api_key] = client.send(
53
+ client_request_method_sym,
26
54
  method, url,
27
55
  api_base: api_base, api_key: api_key,
28
- headers: headers, params: params
56
+ headers: headers, params: params,
57
+ &read_body_chunk_block
29
58
  )
30
59
 
31
60
  # Hash#select returns an array before 1.9
@@ -89,6 +118,20 @@ module Stripe
89
118
  self.class.execute_resource_request(method, url, params, opts)
90
119
  end
91
120
 
121
+ protected def execute_resource_request_stream(method, url,
122
+ params = {}, opts = {},
123
+ &read_body_chunk_block)
124
+ opts = @opts.merge(Util.normalize_opts(opts))
125
+ self.class.execute_resource_request_stream(
126
+ method, url, params, opts, &read_body_chunk_block
127
+ )
128
+ end
129
+
130
+ private def request_stripe_object(method:, path:, params:, opts: {})
131
+ resp, opts = execute_resource_request(method, path, params, opts)
132
+ Util.convert_to_stripe_object_with_params(resp.data, params, opts)
133
+ end
134
+
92
135
  # See notes on `alias` above.
93
136
  alias request execute_resource_request
94
137
  end
@@ -24,12 +24,18 @@ module Stripe
24
24
  end
25
25
  end
26
26
 
27
- resp, opts = execute_resource_request(:post, "#{resource_url}/#{id}",
28
- params, opts)
29
- Util.convert_to_stripe_object(resp.data, opts)
27
+ request_stripe_object(
28
+ method: :post,
29
+ path: "#{resource_url}/#{id}",
30
+ params: params,
31
+ opts: opts
32
+ )
30
33
  end
31
34
  end
32
35
 
36
+ # The `save` method is DEPRECATED and will be removed in a future major
37
+ # version of the library. Use the `update` method on the resource instead.
38
+ #
33
39
  # Creates or updates an API resource.
34
40
  #
35
41
  # If the resource doesn't yet have an assigned ID and the resource is one
@@ -65,6 +71,10 @@ module Stripe
65
71
  resp, opts = execute_resource_request(:post, save_url, values, opts)
66
72
  initialize_from(resp.data, opts)
67
73
  end
74
+ extend Gem::Deprecate
75
+ deprecate :save, "the `update` class method (for examples"\
76
+ " see https://github.com/stripe/stripe-ruby"\
77
+ "/wiki/Migration-guide-for-v8)", 2022, 11
68
78
 
69
79
  def self.included(base)
70
80
  # Set `metadata` as additive so that when it's set directly we remember
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ module APIOperations
5
+ module Search
6
+ def _search(search_url, filters = {}, opts = {})
7
+ request_stripe_object(
8
+ method: :get,
9
+ path: search_url,
10
+ params: filters,
11
+ opts: opts
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -63,22 +63,7 @@ module Stripe
63
63
  # adds a `capture` class method to the resource class that, when called,
64
64
  # will send a POST request to `/v1/<object_name>/capture`.
65
65
  def self.custom_method(name, http_verb:, http_path: nil)
66
- unless %i[get post delete].include?(http_verb)
67
- raise ArgumentError,
68
- "Invalid http_verb value: #{http_verb.inspect}. Should be one " \
69
- "of :get, :post or :delete."
70
- end
71
- http_path ||= name.to_s
72
- define_singleton_method(name) do |id, params = {}, opts = {}|
73
- unless id.is_a?(String)
74
- raise ArgumentError,
75
- "id should be a string representing the ID of an API resource"
76
- end
77
-
78
- url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(http_path)}"
79
- resp, opts = execute_resource_request(http_verb, url, params, opts)
80
- Util.convert_to_stripe_object(resp.data, opts)
81
- end
66
+ Util.custom_method self, self, name, http_verb, http_path
82
67
  end
83
68
 
84
69
  def resource_url
@@ -105,15 +90,23 @@ module Stripe
105
90
  instance
106
91
  end
107
92
 
108
- protected def request_stripe_object(method:, path:, params:, opts: {})
93
+ def request_stripe_object(method:, path:, params:, opts: {})
109
94
  resp, opts = execute_resource_request(method, path, params, opts)
110
95
 
111
96
  # If we're getting back this thing, update; otherwise, instantiate.
112
97
  if Util.object_name_matches_class?(resp.data[:object], self.class)
113
98
  initialize_from(resp.data, opts)
114
99
  else
115
- Util.convert_to_stripe_object(resp.data, opts)
100
+ Util.convert_to_stripe_object_with_params(resp.data, params, opts)
116
101
  end
117
102
  end
103
+
104
+ protected def request_stream(method:, path:, params:, opts: {},
105
+ &read_body_chunk_block)
106
+ resp, = execute_resource_request_stream(
107
+ method, path, params, opts, &read_body_chunk_block
108
+ )
109
+ resp
110
+ end
118
111
  end
119
112
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ # The base class for nested TestHelpers classes in resource objects.
5
+ # The APIResourceTestHelpers handles URL generation and custom method
6
+ # support for test-helper methods.
7
+ #
8
+ # class MyAPIResource < APIResource
9
+ # class TestHelpers < APIResourceTestHelpers
10
+ class APIResourceTestHelpers
11
+ include Stripe::APIOperations::Request
12
+
13
+ def initialize(resource)
14
+ @resource = resource
15
+ end
16
+
17
+ # Adds a custom method to a test helper. This is used to add support for
18
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
19
+ # following parameters:
20
+ # - name: the name of the custom method to create (as a symbol)
21
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
22
+ # - http_path: the path to append to the resource's URL. If not provided,
23
+ # the name is used as the path
24
+ #
25
+ # For example, this call:
26
+ # custom_method :capture, http_verb: post
27
+ # adds a `capture` class method to the resource class that, when called,
28
+ # will send a POST request to `/v1/<object_name>/capture`.
29
+ def self.custom_method(name, http_verb:, http_path: nil)
30
+ Util.custom_method self::RESOURCE_CLASS, self, name, http_verb, http_path
31
+ end
32
+
33
+ def self.resource_url
34
+ "/v1/test_helpers/"\
35
+ "#{self::RESOURCE_CLASS::OBJECT_NAME.downcase.tr('.', '/')}s"
36
+ end
37
+
38
+ def resource_url
39
+ unless (id = @resource["id"])
40
+ raise InvalidRequestError.new(
41
+ "Could not determine which URL to request: #{self.class} instance " \
42
+ "has invalid ID: #{id.inspect}",
43
+ "id"
44
+ )
45
+ end
46
+ "#{self.class.resource_url}/#{CGI.escape(id)}"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,8 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module ApiVersion
6
+ CURRENT = "2022-11-15"
7
+ end
8
+ end
@@ -15,8 +15,10 @@ module Stripe
15
15
  # by `StripeClient` to determine whether a connection manager should be
16
16
  # garbage collected or not.
17
17
  attr_reader :last_used
18
+ attr_reader :config
18
19
 
19
- def initialize
20
+ def initialize(config = Stripe.config)
21
+ @config = config
20
22
  @active_connections = {}
21
23
  @last_used = Util.monotonic_time
22
24
 
@@ -64,7 +66,8 @@ module Stripe
64
66
 
65
67
  # Executes an HTTP request to the given URI with the given method. Also
66
68
  # allows a request body, headers, and query string to be specified.
67
- def execute_request(method, uri, body: nil, headers: nil, query: nil)
69
+ def execute_request(method, uri, body: nil, headers: nil, query: nil,
70
+ &block)
68
71
  # Perform some basic argument validation because it's easy to get
69
72
  # confused between strings and hashes for things like body and query
70
73
  # parameters.
@@ -90,9 +93,44 @@ module Stripe
90
93
  u.path
91
94
  end
92
95
 
93
- @mutex.synchronize do
94
- connection.send_request(method.to_s.upcase, path, body, headers)
96
+ method_name = method.to_s.upcase
97
+ has_response_body = method_name != "HEAD"
98
+ request = Net::HTTPGenericRequest.new(
99
+ method_name,
100
+ (body ? true : false),
101
+ has_response_body,
102
+ path,
103
+ headers
104
+ )
105
+
106
+ Util.log_debug("ConnectionManager starting request",
107
+ method_name: method_name,
108
+ path: path,
109
+ process_id: Process.pid,
110
+ thread_object_id: Thread.current.object_id,
111
+ connection_manager_object_id: object_id,
112
+ connection_object_id: connection.object_id,
113
+ log_timestamp: Util.monotonic_time)
114
+
115
+ resp = @mutex.synchronize do
116
+ # The block parameter is special here. If a block is provided, the block
117
+ # is invoked with the Net::HTTPResponse. However, the body will not have
118
+ # been read yet in the block, and can be streamed by calling
119
+ # HTTPResponse#read_body.
120
+ connection.request(request, body, &block)
95
121
  end
122
+
123
+ Util.log_debug("ConnectionManager request complete",
124
+ method_name: method_name,
125
+ path: path,
126
+ process_id: Process.pid,
127
+ thread_object_id: Thread.current.object_id,
128
+ connection_manager_object_id: object_id,
129
+ connection_object_id: connection.object_id,
130
+ response_object_id: resp.object_id,
131
+ log_timestamp: Util.monotonic_time)
132
+
133
+ resp
96
134
  end
97
135
 
98
136
  #
@@ -117,17 +155,17 @@ module Stripe
117
155
  # reused Go's default for `DefaultTransport`.
118
156
  connection.keep_alive_timeout = 30
119
157
 
120
- connection.open_timeout = Stripe.open_timeout
121
- connection.read_timeout = Stripe.read_timeout
158
+ connection.open_timeout = config.open_timeout
159
+ connection.read_timeout = config.read_timeout
122
160
  if connection.respond_to?(:write_timeout=)
123
- connection.write_timeout = Stripe.write_timeout
161
+ connection.write_timeout = config.write_timeout
124
162
  end
125
163
 
126
164
  connection.use_ssl = uri.scheme == "https"
127
165
 
128
- if Stripe.verify_ssl_certs
166
+ if config.verify_ssl_certs
129
167
  connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
130
- connection.cert_store = Stripe.ca_store
168
+ connection.cert_store = config.ca_store
131
169
  else
132
170
  connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
133
171
  warn_ssl_verify_none
@@ -141,10 +179,10 @@ module Stripe
141
179
  # out those pieces to make passing them into a new connection a little less
142
180
  # ugly.
143
181
  private def proxy_parts
144
- if Stripe.proxy.nil?
182
+ if config.proxy.nil?
145
183
  [nil, nil, nil, nil]
146
184
  else
147
- u = URI.parse(Stripe.proxy)
185
+ u = URI.parse(config.proxy)
148
186
  [u.host, u.port, u.user, u.password]
149
187
  end
150
188
  end
@@ -69,9 +69,8 @@ module Stripe
69
69
  @values[:source]
70
70
  end
71
71
 
72
- # The type of error returned. One of `api_connection_error`, `api_error`,
73
- # `authentication_error`, `card_error`, `idempotency_error`,
74
- # `invalid_request_error`, or `rate_limit_error`.
72
+ # The type of error returned. One of `api_error`, `card_error`,
73
+ # `idempotency_error`, or `invalid_request_error`.
75
74
  def type
76
75
  @values[:type]
77
76
  end
@@ -32,6 +32,11 @@ module Stripe
32
32
  attr_reader :method
33
33
  attr_reader :num_retries
34
34
  attr_reader :path
35
+ attr_reader :request_id
36
+ attr_reader :response_header
37
+ attr_reader :response_body
38
+ attr_reader :request_header
39
+ attr_reader :request_body
35
40
 
36
41
  # Arbitrary user-provided data in the form of a Ruby hash that's passed
37
42
  # from subscribers on `request_begin` to subscribers on `request_end`.
@@ -39,18 +44,53 @@ module Stripe
39
44
  # in `request_end`.
40
45
  attr_reader :user_data
41
46
 
42
- def initialize(duration:, http_status:, method:, num_retries:, path:,
43
- user_data: nil)
44
- @duration = duration
45
- @http_status = http_status
46
- @method = method
47
+ def initialize(request_context:, response_context:,
48
+ num_retries:, user_data: nil)
49
+ @duration = request_context.duration
50
+ @http_status = response_context.http_status
51
+ @method = request_context.method
47
52
  @num_retries = num_retries
48
- @path = path
53
+ @path = request_context.path
54
+ @request_id = request_context.request_id
49
55
  @user_data = user_data
56
+ @response_header = response_context.header
57
+ @response_body = response_context.body
58
+ @request_header = request_context.header
59
+ @request_body = request_context.body
50
60
  freeze
51
61
  end
52
62
  end
53
63
 
64
+ class RequestContext
65
+ attr_reader :duration
66
+ attr_reader :method
67
+ attr_reader :path
68
+ attr_reader :request_id
69
+ attr_reader :body
70
+ attr_reader :header
71
+
72
+ def initialize(duration:, context:, header:)
73
+ @duration = duration
74
+ @method = context.method
75
+ @path = context.path
76
+ @request_id = context.request_id
77
+ @body = context.body
78
+ @header = header
79
+ end
80
+ end
81
+
82
+ class ResponseContext
83
+ attr_reader :http_status
84
+ attr_reader :body
85
+ attr_reader :header
86
+
87
+ def initialize(http_status:, response:)
88
+ @http_status = http_status
89
+ @header = response ? response.to_hash : nil
90
+ @body = response ? response.body : nil
91
+ end
92
+ end
93
+
54
94
  # This class was renamed for consistency. This alias is here for backwards
55
95
  # compatibility.
56
96
  RequestEvent = RequestEndEvent
data/lib/stripe/oauth.rb CHANGED
@@ -7,8 +7,8 @@ module Stripe
7
7
 
8
8
  def self.execute_resource_request(method, url, params, opts)
9
9
  opts = Util.normalize_opts(opts)
10
- opts[:client] ||= StripeClient.active_client
11
- opts[:api_base] ||= Stripe.connect_base
10
+ opts[:client] ||= opts[:client] || StripeClient.active_client
11
+ opts[:api_base] ||= opts[:client].config.connect_base
12
12
 
13
13
  super(method, url, params, opts)
14
14
  end
@@ -29,7 +29,8 @@ module Stripe
29
29
  end
30
30
 
31
31
  def self.authorize_url(params = {}, opts = {})
32
- base = opts[:connect_base] || Stripe.connect_base
32
+ client = opts[:client] || StripeClient.active_client
33
+ base = opts[:connect_base] || client.config.connect_base
33
34
 
34
35
  path = "/oauth/authorize"
35
36
  path = "/express" + path if opts[:express]