stripe 12.7.0.pre.beta.2 → 13.1.0.pre.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +96 -9
  3. data/OPENAPI_VERSION +1 -1
  4. data/README.md +4 -3
  5. data/VERSION +1 -1
  6. data/examples/README.md +11 -0
  7. data/examples/meter_event_stream.rb +47 -0
  8. data/examples/new_example.rb +24 -0
  9. data/examples/stripe_webhook_handler.rb +28 -0
  10. data/lib/stripe/api_operations/nested_resource.rb +1 -21
  11. data/lib/stripe/api_operations/request.rb +19 -70
  12. data/lib/stripe/api_operations/save.rb +4 -3
  13. data/lib/stripe/api_operations/singleton_save.rb +5 -2
  14. data/lib/stripe/api_requestor.rb +1131 -0
  15. data/lib/stripe/api_resource.rb +22 -14
  16. data/lib/stripe/api_version.rb +1 -2
  17. data/lib/stripe/connection_manager.rb +1 -1
  18. data/lib/stripe/errors.rb +8 -2
  19. data/lib/stripe/event_types.rb +14 -0
  20. data/lib/stripe/events/v1_billing_meter_error_report_triggered_event.rb +23 -0
  21. data/lib/stripe/events/v1_billing_meter_no_meter_found_event.rb +13 -0
  22. data/lib/stripe/list_object.rb +2 -3
  23. data/lib/stripe/oauth.rb +8 -15
  24. data/lib/stripe/object_types.rb +16 -1
  25. data/lib/stripe/request_options.rb +128 -0
  26. data/lib/stripe/resources/billing/credit_balance_summary.rb +14 -0
  27. data/lib/stripe/resources/billing/credit_balance_transaction.rb +26 -0
  28. data/lib/stripe/resources/billing/credit_grant.rb +88 -0
  29. data/lib/stripe/resources/billing/meter.rb +2 -0
  30. data/lib/stripe/resources/customer.rb +2 -3
  31. data/lib/stripe/resources/file.rb +7 -5
  32. data/lib/stripe/resources/issuing/card.rb +20 -0
  33. data/lib/stripe/resources/quote.rb +4 -4
  34. data/lib/stripe/resources/source.rb +3 -2
  35. data/lib/stripe/resources/subscription.rb +6 -6
  36. data/lib/stripe/resources/tax/form.rb +4 -4
  37. data/lib/stripe/resources/usage_record_summary.rb +1 -0
  38. data/lib/stripe/resources/v2/billing/meter_event.rb +16 -0
  39. data/lib/stripe/resources/v2/billing/meter_event_adjustment.rb +15 -0
  40. data/lib/stripe/resources/v2/billing/meter_event_session.rb +15 -0
  41. data/lib/stripe/resources/v2/event.rb +13 -0
  42. data/lib/stripe/resources.rb +9 -0
  43. data/lib/stripe/search_result_object.rb +1 -1
  44. data/lib/stripe/services/account_capability_service.rb +39 -0
  45. data/lib/stripe/services/account_external_account_service.rb +68 -0
  46. data/lib/stripe/services/account_link_service.rb +17 -0
  47. data/lib/stripe/services/account_login_link_service.rb +19 -0
  48. data/lib/stripe/services/account_notice_service.rb +39 -0
  49. data/lib/stripe/services/account_person_service.rb +61 -0
  50. data/lib/stripe/services/account_service.rb +100 -0
  51. data/lib/stripe/services/account_session_service.rb +17 -0
  52. data/lib/stripe/services/apple_pay_domain_service.rb +50 -0
  53. data/lib/stripe/services/application_fee_refund_service.rb +60 -0
  54. data/lib/stripe/services/application_fee_service.rb +35 -0
  55. data/lib/stripe/services/apps/secret_service.rb +52 -0
  56. data/lib/stripe/services/apps_service.rb +13 -0
  57. data/lib/stripe/services/balance_service.rb +12 -0
  58. data/lib/stripe/services/balance_transaction_service.rb +32 -0
  59. data/lib/stripe/services/billing/alert_service.rb +74 -0
  60. data/lib/stripe/services/billing/credit_balance_summary_service.rb +19 -0
  61. data/lib/stripe/services/billing/credit_balance_transaction_service.rb +30 -0
  62. data/lib/stripe/services/billing/credit_grant_service.rb +74 -0
  63. data/lib/stripe/services/billing/meter_event_adjustment_service.rb +19 -0
  64. data/lib/stripe/services/billing/meter_event_service.rb +19 -0
  65. data/lib/stripe/services/billing/meter_event_summary_service.rb +19 -0
  66. data/lib/stripe/services/billing/meter_service.rb +81 -0
  67. data/lib/stripe/services/billing_portal/configuration_service.rb +52 -0
  68. data/lib/stripe/services/billing_portal/session_service.rb +19 -0
  69. data/lib/stripe/services/billing_portal_service.rb +14 -0
  70. data/lib/stripe/services/billing_service.rb +20 -0
  71. data/lib/stripe/services/capital/financing_offer_service.rb +42 -0
  72. data/lib/stripe/services/capital/financing_summary_service.rb +19 -0
  73. data/lib/stripe/services/capital/financing_transaction_service.rb +31 -0
  74. data/lib/stripe/services/capital_service.rb +15 -0
  75. data/lib/stripe/services/charge_service.rb +69 -0
  76. data/lib/stripe/services/checkout/session_line_item_service.rb +19 -0
  77. data/lib/stripe/services/checkout/session_service.rb +72 -0
  78. data/lib/stripe/services/checkout_service.rb +13 -0
  79. data/lib/stripe/services/climate/order_service.rb +68 -0
  80. data/lib/stripe/services/climate/product_service.rb +30 -0
  81. data/lib/stripe/services/climate/supplier_service.rb +30 -0
  82. data/lib/stripe/services/climate_service.rb +15 -0
  83. data/lib/stripe/services/confirmation_token_service.rb +17 -0
  84. data/lib/stripe/services/country_spec_service.rb +28 -0
  85. data/lib/stripe/services/coupon_service.rb +51 -0
  86. data/lib/stripe/services/credit_note_line_item_service.rb +17 -0
  87. data/lib/stripe/services/credit_note_preview_lines_service.rb +17 -0
  88. data/lib/stripe/services/credit_note_service.rb +93 -0
  89. data/lib/stripe/services/customer_balance_transaction_service.rb +50 -0
  90. data/lib/stripe/services/customer_cash_balance_service.rb +28 -0
  91. data/lib/stripe/services/customer_cash_balance_transaction_service.rb +28 -0
  92. data/lib/stripe/services/customer_funding_instructions_service.rb +19 -0
  93. data/lib/stripe/services/customer_payment_method_service.rb +28 -0
  94. data/lib/stripe/services/customer_payment_source_service.rb +76 -0
  95. data/lib/stripe/services/customer_service.rb +89 -0
  96. data/lib/stripe/services/customer_session_service.rb +17 -0
  97. data/lib/stripe/services/customer_tax_id_service.rb +50 -0
  98. data/lib/stripe/services/dispute_service.rb +48 -0
  99. data/lib/stripe/services/entitlements/active_entitlement_service.rb +30 -0
  100. data/lib/stripe/services/entitlements/feature_service.rb +52 -0
  101. data/lib/stripe/services/entitlements_service.rb +14 -0
  102. data/lib/stripe/services/ephemeral_key_service.rb +28 -0
  103. data/lib/stripe/services/event_service.rb +22 -0
  104. data/lib/stripe/services/exchange_rate_service.rb +28 -0
  105. data/lib/stripe/services/file_link_service.rb +38 -0
  106. data/lib/stripe/services/file_service.rb +35 -0
  107. data/lib/stripe/services/financial_connections/account_inferred_balance_service.rb +19 -0
  108. data/lib/stripe/services/financial_connections/account_owner_service.rb +19 -0
  109. data/lib/stripe/services/financial_connections/account_service.rb +83 -0
  110. data/lib/stripe/services/financial_connections/institution_service.rb +30 -0
  111. data/lib/stripe/services/financial_connections/session_service.rb +30 -0
  112. data/lib/stripe/services/financial_connections/transaction_service.rb +30 -0
  113. data/lib/stripe/services/financial_connections_service.rb +16 -0
  114. data/lib/stripe/services/forwarding/request_service.rb +41 -0
  115. data/lib/stripe/services/forwarding_service.rb +13 -0
  116. data/lib/stripe/services/gift_cards/card_service.rb +63 -0
  117. data/lib/stripe/services/gift_cards/transaction_service.rb +74 -0
  118. data/lib/stripe/services/gift_cards_service.rb +14 -0
  119. data/lib/stripe/services/identity/verification_report_service.rb +30 -0
  120. data/lib/stripe/services/identity/verification_session_service.rb +106 -0
  121. data/lib/stripe/services/identity_service.rb +14 -0
  122. data/lib/stripe/services/invoice_item_service.rb +61 -0
  123. data/lib/stripe/services/invoice_line_item_service.rb +31 -0
  124. data/lib/stripe/services/invoice_payment_service.rb +28 -0
  125. data/lib/stripe/services/invoice_rendering_template_service.rb +50 -0
  126. data/lib/stripe/services/invoice_service.rb +245 -0
  127. data/lib/stripe/services/invoice_upcoming_lines_service.rb +17 -0
  128. data/lib/stripe/services/issuing/authorization_service.rb +65 -0
  129. data/lib/stripe/services/issuing/card_service.rb +52 -0
  130. data/lib/stripe/services/issuing/cardholder_service.rb +52 -0
  131. data/lib/stripe/services/issuing/credit_underwriting_record_service.rb +74 -0
  132. data/lib/stripe/services/issuing/dispute_service.rb +63 -0
  133. data/lib/stripe/services/issuing/dispute_settlement_detail_service.rb +30 -0
  134. data/lib/stripe/services/issuing/personalization_design_service.rb +52 -0
  135. data/lib/stripe/services/issuing/physical_bundle_service.rb +30 -0
  136. data/lib/stripe/services/issuing/token_service.rb +41 -0
  137. data/lib/stripe/services/issuing/transaction_service.rb +41 -0
  138. data/lib/stripe/services/issuing_service.rb +23 -0
  139. data/lib/stripe/services/mandate_service.rb +17 -0
  140. data/lib/stripe/services/margin_service.rb +50 -0
  141. data/lib/stripe/services/oauth_service.rb +63 -0
  142. data/lib/stripe/services/order_line_item_service.rb +17 -0
  143. data/lib/stripe/services/order_service.rb +78 -0
  144. data/lib/stripe/services/payment_intent_service.rb +230 -0
  145. data/lib/stripe/services/payment_link_line_item_service.rb +17 -0
  146. data/lib/stripe/services/payment_link_service.rb +57 -0
  147. data/lib/stripe/services/payment_method_configuration_service.rb +50 -0
  148. data/lib/stripe/services/payment_method_domain_service.rb +66 -0
  149. data/lib/stripe/services/payment_method_service.rb +86 -0
  150. data/lib/stripe/services/payout_service.rb +66 -0
  151. data/lib/stripe/services/plan_service.rb +49 -0
  152. data/lib/stripe/services/price_service.rb +52 -0
  153. data/lib/stripe/services/product_feature_service.rb +50 -0
  154. data/lib/stripe/services/product_service.rb +70 -0
  155. data/lib/stripe/services/promotion_code_service.rb +50 -0
  156. data/lib/stripe/services/quote_computed_upfront_line_items_service.rb +17 -0
  157. data/lib/stripe/services/quote_line_item_service.rb +17 -0
  158. data/lib/stripe/services/quote_line_service.rb +17 -0
  159. data/lib/stripe/services/quote_preview_invoice_service.rb +17 -0
  160. data/lib/stripe/services/quote_preview_subscription_schedule_service.rb +17 -0
  161. data/lib/stripe/services/quote_service.rb +140 -0
  162. data/lib/stripe/services/radar/early_fraud_warning_service.rb +32 -0
  163. data/lib/stripe/services/radar/value_list_item_service.rb +52 -0
  164. data/lib/stripe/services/radar/value_list_service.rb +63 -0
  165. data/lib/stripe/services/radar_service.rb +15 -0
  166. data/lib/stripe/services/refund_service.rb +63 -0
  167. data/lib/stripe/services/reporting/report_run_service.rb +41 -0
  168. data/lib/stripe/services/reporting/report_type_service.rb +30 -0
  169. data/lib/stripe/services/reporting_service.rb +14 -0
  170. data/lib/stripe/services/review_service.rb +33 -0
  171. data/lib/stripe/services/setup_attempt_service.rb +17 -0
  172. data/lib/stripe/services/setup_intent_service.rb +105 -0
  173. data/lib/stripe/services/shipping_rate_service.rb +50 -0
  174. data/lib/stripe/services/sigma/scheduled_query_run_service.rb +30 -0
  175. data/lib/stripe/services/sigma_service.rb +13 -0
  176. data/lib/stripe/services/source_service.rb +64 -0
  177. data/lib/stripe/services/source_transaction_service.rb +17 -0
  178. data/lib/stripe/services/subscription_item_service.rb +69 -0
  179. data/lib/stripe/services/subscription_item_usage_record_service.rb +23 -0
  180. data/lib/stripe/services/subscription_item_usage_record_summary_service.rb +19 -0
  181. data/lib/stripe/services/subscription_schedule_service.rb +83 -0
  182. data/lib/stripe/services/subscription_service.rb +127 -0
  183. data/lib/stripe/services/tax/association_service.rb +19 -0
  184. data/lib/stripe/services/tax/calculation_line_item_service.rb +19 -0
  185. data/lib/stripe/services/tax/calculation_service.rb +37 -0
  186. data/lib/stripe/services/tax/form_service.rb +37 -0
  187. data/lib/stripe/services/tax/registration_service.rb +54 -0
  188. data/lib/stripe/services/tax/settings_service.rb +30 -0
  189. data/lib/stripe/services/tax/transaction_line_item_service.rb +19 -0
  190. data/lib/stripe/services/tax/transaction_service.rb +48 -0
  191. data/lib/stripe/services/tax_code_service.rb +22 -0
  192. data/lib/stripe/services/tax_id_service.rb +38 -0
  193. data/lib/stripe/services/tax_rate_service.rb +38 -0
  194. data/lib/stripe/services/tax_service.rb +18 -0
  195. data/lib/stripe/services/terminal/configuration_service.rb +63 -0
  196. data/lib/stripe/services/terminal/connection_token_service.rb +19 -0
  197. data/lib/stripe/services/terminal/location_service.rb +64 -0
  198. data/lib/stripe/services/terminal/reader_collected_data_service.rb +19 -0
  199. data/lib/stripe/services/terminal/reader_service.rb +151 -0
  200. data/lib/stripe/services/terminal_service.rb +17 -0
  201. data/lib/stripe/services/test_helpers/confirmation_token_service.rb +19 -0
  202. data/lib/stripe/services/test_helpers/customer_service.rb +19 -0
  203. data/lib/stripe/services/test_helpers/issuing/authorization_service.rb +76 -0
  204. data/lib/stripe/services/test_helpers/issuing/card_service.rb +65 -0
  205. data/lib/stripe/services/test_helpers/issuing/personalization_design_service.rb +43 -0
  206. data/lib/stripe/services/test_helpers/issuing/transaction_service.rb +43 -0
  207. data/lib/stripe/services/test_helpers/issuing_service.rb +19 -0
  208. data/lib/stripe/services/test_helpers/refund_service.rb +19 -0
  209. data/lib/stripe/services/test_helpers/terminal/reader_service.rb +21 -0
  210. data/lib/stripe/services/test_helpers/terminal_service.rb +15 -0
  211. data/lib/stripe/services/test_helpers/test_clock_service.rb +63 -0
  212. data/lib/stripe/services/test_helpers/treasury/inbound_transfer_service.rb +43 -0
  213. data/lib/stripe/services/test_helpers/treasury/outbound_payment_service.rb +54 -0
  214. data/lib/stripe/services/test_helpers/treasury/outbound_transfer_service.rb +54 -0
  215. data/lib/stripe/services/test_helpers/treasury/received_credit_service.rb +21 -0
  216. data/lib/stripe/services/test_helpers/treasury/received_debit_service.rb +21 -0
  217. data/lib/stripe/services/test_helpers/treasury_service.rb +19 -0
  218. data/lib/stripe/services/test_helpers_service.rb +19 -0
  219. data/lib/stripe/services/token_service.rb +23 -0
  220. data/lib/stripe/services/topup_service.rb +49 -0
  221. data/lib/stripe/services/transfer_reversal_service.rb +56 -0
  222. data/lib/stripe/services/transfer_service.rb +47 -0
  223. data/lib/stripe/services/treasury/credit_reversal_service.rb +41 -0
  224. data/lib/stripe/services/treasury/debit_reversal_service.rb +41 -0
  225. data/lib/stripe/services/treasury/financial_account_features_service.rb +30 -0
  226. data/lib/stripe/services/treasury/financial_account_service.rb +59 -0
  227. data/lib/stripe/services/treasury/inbound_transfer_service.rb +52 -0
  228. data/lib/stripe/services/treasury/outbound_payment_service.rb +52 -0
  229. data/lib/stripe/services/treasury/outbound_transfer_service.rb +52 -0
  230. data/lib/stripe/services/treasury/received_credit_service.rb +30 -0
  231. data/lib/stripe/services/treasury/received_debit_service.rb +30 -0
  232. data/lib/stripe/services/treasury/transaction_entry_service.rb +30 -0
  233. data/lib/stripe/services/treasury/transaction_service.rb +30 -0
  234. data/lib/stripe/services/treasury_service.rb +22 -0
  235. data/lib/stripe/services/v1_services.rb +94 -0
  236. data/lib/stripe/services/v2/billing/meter_event_adjustment_service.rb +21 -0
  237. data/lib/stripe/services/v2/billing/meter_event_service.rb +21 -0
  238. data/lib/stripe/services/v2/billing/meter_event_session_service.rb +21 -0
  239. data/lib/stripe/services/v2/billing/meter_event_stream_service.rb +23 -0
  240. data/lib/stripe/services/v2/billing_service.rb +18 -0
  241. data/lib/stripe/services/v2/core/event_service.rb +32 -0
  242. data/lib/stripe/services/v2/core_service.rb +15 -0
  243. data/lib/stripe/services/v2_services.rb +14 -0
  244. data/lib/stripe/services/webhook_endpoint_service.rb +61 -0
  245. data/lib/stripe/services.rb +203 -0
  246. data/lib/stripe/singleton_api_resource.rb +1 -18
  247. data/lib/stripe/stripe_client.rb +51 -1067
  248. data/lib/stripe/stripe_configuration.rb +33 -19
  249. data/lib/stripe/stripe_object.rb +37 -18
  250. data/lib/stripe/stripe_service.rb +32 -0
  251. data/lib/stripe/thin_event.rb +17 -0
  252. data/lib/stripe/util.rb +68 -39
  253. data/lib/stripe/v2_list_object.rb +84 -0
  254. data/lib/stripe/version.rb +1 -1
  255. data/lib/stripe/webhook.rb +1 -1
  256. data/lib/stripe.rb +33 -27
  257. metadata +223 -2
@@ -25,6 +25,12 @@ module Stripe
25
25
  end
26
26
 
27
27
  def self.resource_url
28
+ if name.include?("Stripe::V2")
29
+ raise NotImplementedError,
30
+ "V2 resources do not have a defined URL. Please use the StripeClient " \
31
+ "to make V2 requests"
32
+ end
33
+
28
34
  if self == APIResource
29
35
  raise NotImplementedError,
30
36
  "APIResource is an abstract class. You should perform actions " \
@@ -87,33 +93,35 @@ module Stripe
87
93
  end
88
94
 
89
95
  def refresh
90
- resp, opts = execute_resource_request(:get, resource_url,
91
- @retrieve_params)
92
- initialize_from(resp.data, opts, resp)
96
+ if self.class.name.include?("Stripe::V2")
97
+ raise NotImplementedError,
98
+ "It is not possible to refresh v2 objects. Please retrieve the object using the StripeClient instead."
99
+ end
100
+
101
+ @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params)
93
102
  end
94
103
 
95
104
  def self.retrieve(id, opts = {})
105
+ if name.include?("Stripe::V2")
106
+ raise NotImplementedError,
107
+ "It is not possible to retrieve v2 objects on the resource. Please use the StripeClient instead."
108
+ end
109
+
96
110
  opts = Util.normalize_opts(opts)
97
111
  instance = new(id, opts)
98
112
  instance.refresh
99
113
  instance
100
114
  end
101
115
 
102
- def request_stripe_object(method:, path:, params:, opts: {})
103
- resp, opts = execute_resource_request(method, path, params, opts)
104
-
105
- # If we're getting back this thing, update; otherwise, instantiate.
106
- if Util.object_name_matches_class?(resp.data[:object], self.class)
107
- initialize_from(resp.data, opts, resp)
108
- else
109
- Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
110
- end
116
+ def request_stripe_object(method:, path:, params:, base_address: :api, opts: {})
117
+ APIRequestor.active_requestor.execute_request_initialize_from(method, path, base_address, self,
118
+ params: params, opts: opts)
111
119
  end
112
120
 
113
- protected def request_stream(method:, path:, params:, opts: {},
121
+ protected def request_stream(method:, path:, params:, base_address: :api, opts: {},
114
122
  &read_body_chunk_block)
115
123
  resp, = execute_resource_request_stream(
116
- method, path, params, opts, &read_body_chunk_block
124
+ method, path, base_address, params, opts, &read_body_chunk_block
117
125
  )
118
126
  resp
119
127
  end
@@ -3,7 +3,6 @@
3
3
 
4
4
  module Stripe
5
5
  module ApiVersion
6
- CURRENT = "2024-06-20"
7
- PREVIEW = "cs_ubb_launch"
6
+ CURRENT = "2024-09-30.acacia"
8
7
  end
9
8
  end
@@ -12,7 +12,7 @@ module Stripe
12
12
  class ConnectionManager
13
13
  # Timestamp (in seconds procured from the system's monotonic clock)
14
14
  # indicating when the connection manager last made a request. This is used
15
- # by `StripeClient` to determine whether a connection manager should be
15
+ # by `APIRequestor` to determine whether a connection manager should be
16
16
  # garbage collected or not.
17
17
  attr_reader :last_used
18
18
  attr_reader :config
data/lib/stripe/errors.rb CHANGED
@@ -27,7 +27,8 @@ module Stripe
27
27
  def construct_error_object
28
28
  return nil if @json_body.nil? || !@json_body.key?(:error)
29
29
 
30
- ErrorObject.construct_from(@json_body[:error])
30
+ # ErrorObject is shared between v1 and v2, so use original object_classes to find
31
+ ErrorObject.construct_from(@json_body[:error], {}, nil, :v1)
31
32
  end
32
33
 
33
34
  # Whether the error was the result of an idempotent replay, meaning that it
@@ -130,7 +131,7 @@ module Stripe
130
131
  def construct_error_object
131
132
  return nil if @json_body.nil?
132
133
 
133
- OAuthErrorObject.construct_from(@json_body)
134
+ OAuthErrorObject.construct_from(@json_body, {}, nil, :v1)
134
135
  end
135
136
  end
136
137
 
@@ -166,4 +167,9 @@ module Stripe
166
167
  class UnsupportedResponseTypeError < OAuthError
167
168
  end
168
169
  end
170
+
171
+ # class definitions: The beginning of the section generated from our OpenAPI spec
172
+ class TemporarySessionExpiredError < StripeError
173
+ end
174
+ # class definitions: The end of the section generated from our OpenAPI spec
169
175
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ module EventTypes
5
+ def self.thin_event_names_to_classes
6
+ {
7
+ # The beginning of the section generated from our OpenAPI spec
8
+ V1BillingMeterErrorReportTriggeredEvent.lookup_type => V1BillingMeterErrorReportTriggeredEvent,
9
+ V1BillingMeterNoMeterFoundEvent.lookup_type => V1BillingMeterNoMeterFoundEvent,
10
+ # The end of the section generated from our OpenAPI spec
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ # This event occurs when there are invalid async usage events for a given meter.
6
+ class V1BillingMeterErrorReportTriggeredEvent < Stripe::V2::Event
7
+ def self.lookup_type
8
+ "v1.billing.meter.error_report_triggered"
9
+ end
10
+ # There is additional data present for this event, accessible with the `data` property.
11
+ # See the Stripe API docs for more information.
12
+
13
+ # Retrieves the related object from the API. Make an API request on every call.
14
+ def fetch_related_object
15
+ _request(
16
+ method: :get,
17
+ path: related_object.url,
18
+ base_address: :api,
19
+ opts: { stripe_account: context }
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ # This event occurs when async usage events have missing or invalid meter ids.
6
+ class V1BillingMeterNoMeterFoundEvent < Stripe::V2::Event
7
+ def self.lookup_type
8
+ "v1.billing.meter.no_meter_found"
9
+ end
10
+ # There is additional data present for this event, accessible with the `data` property.
11
+ # See the Stripe API docs for more information.
12
+ end
13
+ end
@@ -21,7 +21,7 @@ module Stripe
21
21
  # there isn't a next page in order to replicate the behavior of the API
22
22
  # when it attempts to return a page beyond the last.
23
23
  def self.empty_list(opts = {})
24
- ListObject.construct_from({ data: [] }, opts)
24
+ ListObject.construct_from({ data: [] }, opts, nil, :v1)
25
25
  end
26
26
 
27
27
  def initialize(*args)
@@ -96,8 +96,7 @@ module Stripe
96
96
  def retrieve(id, opts = {})
97
97
  id, retrieve_params = Util.normalize_id(id)
98
98
  url = "#{resource_url}/#{CGI.escape(id)}"
99
- resp, opts = execute_resource_request(:get, url, retrieve_params, opts)
100
- Util.convert_to_stripe_object(resp.data, opts)
99
+ execute_resource_request(:get, url, :api, retrieve_params, opts)
101
100
  end
102
101
 
103
102
  # Fetches the next page in the resource list (if there is one).
data/lib/stripe/oauth.rb CHANGED
@@ -5,12 +5,10 @@ module Stripe
5
5
  module OAuthOperations
6
6
  extend APIOperations::Request::ClassMethods
7
7
 
8
- def self.execute_resource_request(method, url, params, opts)
8
+ def self.execute_resource_request(method, url, base_address, params, opts)
9
9
  opts = Util.normalize_opts(opts)
10
- opts[:client] ||= opts[:client] || StripeClient.active_client
11
- opts[:api_base] ||= opts[:client].config.connect_base
12
10
 
13
- super(method, url, params, opts)
11
+ super(method, url, base_address, params, opts)
14
12
  end
15
13
  end
16
14
 
@@ -29,15 +27,14 @@ module Stripe
29
27
  end
30
28
 
31
29
  def self.authorize_url(params = {}, opts = {})
32
- client = opts[:client] || StripeClient.active_client
33
- base = opts[:connect_base] || client.config.connect_base
30
+ base = opts[:connect_base] || APIRequestor.active_requestor.config.connect_base
34
31
 
35
32
  path = "/oauth/authorize"
36
33
  path = "/express" + path if opts[:express]
37
34
 
38
35
  params[:client_id] = get_client_id(params)
39
36
  params[:response_type] ||= "code"
40
- query = Util.encode_parameters(params)
37
+ query = Util.encode_parameters(params, :v1)
41
38
 
42
39
  "#{base}#{path}?#{query}"
43
40
  end
@@ -45,21 +42,17 @@ module Stripe
45
42
  def self.token(params = {}, opts = {})
46
43
  opts = Util.normalize_opts(opts)
47
44
  opts[:api_key] = params[:client_secret] if params[:client_secret]
48
- resp, opts = OAuthOperations.execute_resource_request(
49
- :post, "/oauth/token", params, opts
45
+ OAuthOperations.execute_resource_request(
46
+ :post, "/oauth/token", :connect, params, opts
50
47
  )
51
- # This is just going to return a generic StripeObject, but that's okay
52
- Util.convert_to_stripe_object(resp.data, opts)
53
48
  end
54
49
 
55
50
  def self.deauthorize(params = {}, opts = {})
56
51
  opts = Util.normalize_opts(opts)
57
52
  params[:client_id] = get_client_id(params)
58
- resp, opts = OAuthOperations.execute_resource_request(
59
- :post, "/oauth/deauthorize", params, opts
53
+ OAuthOperations.execute_resource_request(
54
+ :post, "/oauth/deauthorize", :connect, params, opts
60
55
  )
61
- # This is just going to return a generic StripeObject, but that's okay
62
- Util.convert_to_stripe_object(resp.data, opts)
63
56
  end
64
57
  end
65
58
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # rubocop:disable Metrics/MethodLength
4
- # rubocop:disable Metrics/AbcSize
5
4
 
6
5
  module Stripe
7
6
  module ObjectTypes
@@ -25,6 +24,9 @@ module Stripe
25
24
  BalanceTransaction.object_name => BalanceTransaction,
26
25
  BankAccount.object_name => BankAccount,
27
26
  Billing::Alert.object_name => Billing::Alert,
27
+ Billing::CreditBalanceSummary.object_name => Billing::CreditBalanceSummary,
28
+ Billing::CreditBalanceTransaction.object_name => Billing::CreditBalanceTransaction,
29
+ Billing::CreditGrant.object_name => Billing::CreditGrant,
28
30
  Billing::Meter.object_name => Billing::Meter,
29
31
  Billing::MeterEvent.object_name => Billing::MeterEvent,
30
32
  Billing::MeterEventAdjustment.object_name => Billing::MeterEventAdjustment,
@@ -163,6 +165,19 @@ module Stripe
163
165
  # object classes: The end of the section generated from our OpenAPI spec
164
166
  }
165
167
  end
168
+
169
+ def self.v2_object_names_to_classes
170
+ {
171
+ V2::ListObject.object_name => V2::ListObject,
172
+
173
+ # v2 object classes: The beginning of the section generated from our OpenAPI spec
174
+ V2::Billing::MeterEvent.object_name => V2::Billing::MeterEvent,
175
+ V2::Billing::MeterEventAdjustment.object_name => V2::Billing::MeterEventAdjustment,
176
+ V2::Billing::MeterEventSession.object_name => V2::Billing::MeterEventSession,
177
+ V2::Event.object_name => V2::Event,
178
+ # v2 object classes: The end of the section generated from our OpenAPI spec
179
+ }
180
+ end
166
181
  end
167
182
  end
168
183
 
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module Stripe
5
+ # RequestOptions is a class that encapsulates configurable options
6
+ # for requests made to the Stripe API. It is used by the APIRequestor
7
+ # to set per-request options.
8
+ #
9
+ # For internal use only. Does not provide a stable API and may be broken
10
+ # with future non-major changes.
11
+ module RequestOptions
12
+ # Options that a user is allowed to specify.
13
+ OPTS_USER_SPECIFIED = Set[
14
+ :api_key,
15
+ :idempotency_key,
16
+ :stripe_account,
17
+ :stripe_context,
18
+ :stripe_version
19
+ ].freeze
20
+
21
+ # Options that should be copyable from one StripeObject to another
22
+ # including options that may be internal.
23
+ OPTS_COPYABLE = (
24
+ OPTS_USER_SPECIFIED + Set[:api_base]
25
+ ).freeze
26
+
27
+ # Options that should be persisted between API requests.
28
+ OPTS_PERSISTABLE = (
29
+ OPTS_USER_SPECIFIED - Set[:idempotency_key, :stripe_context]
30
+ ).freeze
31
+
32
+ # Merges requestor options on a StripeConfiguration object
33
+ # with a per-request options hash, giving precedence
34
+ # to the per-request options. Expects StripeConfiguration and hash.
35
+ def self.merge_config_and_opts(config, req_opts)
36
+ # Raise an error if config is not a StripeConfiguration object
37
+ unless config.is_a?(StripeConfiguration)
38
+ raise ArgumentError, "config must be a Stripe::StripeConfiguration object"
39
+ end
40
+
41
+ merged_opts = {
42
+ api_key: req_opts[:api_key] || config.api_key,
43
+ idempotency_key: req_opts[:idempotency_key],
44
+ stripe_account: req_opts[:stripe_account] || config.stripe_account,
45
+ stripe_context: req_opts[:stripe_context] || config.stripe_context,
46
+ stripe_version: req_opts[:stripe_version] || config.api_version,
47
+ headers: req_opts[:headers] || {},
48
+ }
49
+
50
+ # Remove nil values from headers
51
+ merged_opts.delete_if { |_, v| v.nil? }
52
+
53
+ merged_opts
54
+ end
55
+
56
+ # Merges requestor options hash on a StripeObject
57
+ # with a per-request options hash, giving precedence
58
+ # to the per-request options. Returns the merged request options.
59
+ # Expects two hashes.
60
+ def self.combine_opts(object_opts, req_opts)
61
+ merged_opts = {
62
+ api_key: req_opts[:api_key] || object_opts[:api_key],
63
+ idempotency_key: req_opts[:idempotency_key],
64
+ stripe_account: req_opts[:stripe_account] || object_opts[:stripe_account],
65
+ stripe_context: req_opts[:stripe_context] || object_opts[:stripe_context],
66
+ stripe_version: req_opts[:stripe_version] || object_opts[:api_version],
67
+ }
68
+
69
+ # Remove nil values from headers
70
+ merged_opts.delete_if { |_, v| v.nil? }
71
+
72
+ merged_opts
73
+ end
74
+
75
+ # Extracts options from a user-provided hash, returning a new request options hash
76
+ # containing the recognized request options and a `headers` entry for the remaining options.
77
+ def self.extract_opts_from_hash(opts)
78
+ req_opts = {}
79
+ normalized_opts = Util.normalize_opts(opts.clone)
80
+
81
+ RequestOptions.error_on_non_string_user_opts(normalized_opts)
82
+
83
+ OPTS_USER_SPECIFIED.each do |opt|
84
+ req_opts[opt] = normalized_opts[opt] if normalized_opts.key?(opt)
85
+ normalized_opts.delete(opt)
86
+ end
87
+
88
+ # Remaining user-provided opts should be treated as headers
89
+ req_opts[:headers] = Util.normalize_headers(normalized_opts) if normalized_opts.any?
90
+
91
+ req_opts
92
+ end
93
+
94
+ # Validates a normalized opts hash.
95
+ def self.error_on_non_string_user_opts(normalized_opts)
96
+ OPTS_USER_SPECIFIED.each do |opt|
97
+ next unless normalized_opts.key?(opt)
98
+
99
+ val = normalized_opts[opt]
100
+ next if val.nil?
101
+ next if val.is_a?(String)
102
+
103
+ raise ArgumentError,
104
+ "request option '#{opt}' should be a string value " \
105
+ "(was a #{val.class})"
106
+ end
107
+ end
108
+
109
+ # Get options that persist between requests
110
+ def self.persistable(req_opts)
111
+ opts_to_persist = {}
112
+
113
+ # Hash#select returns an array before 1.9
114
+ req_opts.each do |k, v|
115
+ opts_to_persist[k] = v if RequestOptions::OPTS_PERSISTABLE.include?(k)
116
+ end
117
+
118
+ opts_to_persist
119
+ end
120
+
121
+ # Get options that are copyable from StripeObject to StripeObject
122
+ def self.copyable(req_opts)
123
+ req_opts.select do |k, _v|
124
+ RequestOptions::OPTS_COPYABLE.include?(k)
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Billing
6
+ # Indicates the credit balance for credits granted to a customer.
7
+ class CreditBalanceSummary < SingletonAPIResource
8
+ OBJECT_NAME = "billing.credit_balance_summary"
9
+ def self.object_name
10
+ "billing.credit_balance_summary"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Billing
6
+ # A credit balance transaction is a resource representing a transaction (either a credit or a debit) against an existing credit grant.
7
+ class CreditBalanceTransaction < APIResource
8
+ extend Stripe::APIOperations::List
9
+
10
+ OBJECT_NAME = "billing.credit_balance_transaction"
11
+ def self.object_name
12
+ "billing.credit_balance_transaction"
13
+ end
14
+
15
+ # Retrieve a list of credit balance transactions
16
+ def self.list(filters = {}, opts = {})
17
+ request_stripe_object(
18
+ method: :get,
19
+ path: "/v1/billing/credit_balance_transactions",
20
+ params: filters,
21
+ opts: opts
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Billing
6
+ # A credit grant is a resource that records a grant of some credit to a customer.
7
+ class CreditGrant < APIResource
8
+ extend Stripe::APIOperations::Create
9
+ extend Stripe::APIOperations::List
10
+ include Stripe::APIOperations::Save
11
+
12
+ OBJECT_NAME = "billing.credit_grant"
13
+ def self.object_name
14
+ "billing.credit_grant"
15
+ end
16
+
17
+ # Creates a credit grant
18
+ def self.create(params = {}, opts = {})
19
+ request_stripe_object(
20
+ method: :post,
21
+ path: "/v1/billing/credit_grants",
22
+ params: params,
23
+ opts: opts
24
+ )
25
+ end
26
+
27
+ # Expires a credit grant
28
+ def expire(params = {}, opts = {})
29
+ request_stripe_object(
30
+ method: :post,
31
+ path: format("/v1/billing/credit_grants/%<id>s/expire", { id: CGI.escape(self["id"]) }),
32
+ params: params,
33
+ opts: opts
34
+ )
35
+ end
36
+
37
+ # Expires a credit grant
38
+ def self.expire(id, params = {}, opts = {})
39
+ request_stripe_object(
40
+ method: :post,
41
+ path: format("/v1/billing/credit_grants/%<id>s/expire", { id: CGI.escape(id) }),
42
+ params: params,
43
+ opts: opts
44
+ )
45
+ end
46
+
47
+ # Retrieve a list of credit grants
48
+ def self.list(filters = {}, opts = {})
49
+ request_stripe_object(
50
+ method: :get,
51
+ path: "/v1/billing/credit_grants",
52
+ params: filters,
53
+ opts: opts
54
+ )
55
+ end
56
+
57
+ # Updates a credit grant
58
+ def self.update(id, params = {}, opts = {})
59
+ request_stripe_object(
60
+ method: :post,
61
+ path: format("/v1/billing/credit_grants/%<id>s", { id: CGI.escape(id) }),
62
+ params: params,
63
+ opts: opts
64
+ )
65
+ end
66
+
67
+ # Voids a credit grant
68
+ def void_grant(params = {}, opts = {})
69
+ request_stripe_object(
70
+ method: :post,
71
+ path: format("/v1/billing/credit_grants/%<id>s/void", { id: CGI.escape(self["id"]) }),
72
+ params: params,
73
+ opts: opts
74
+ )
75
+ end
76
+
77
+ # Voids a credit grant
78
+ def self.void_grant(id, params = {}, opts = {})
79
+ request_stripe_object(
80
+ method: :post,
81
+ path: format("/v1/billing/credit_grants/%<id>s/void", { id: CGI.escape(id) }),
82
+ params: params,
83
+ opts: opts
84
+ )
85
+ end
86
+ end
87
+ end
88
+ end
@@ -4,6 +4,8 @@
4
4
  module Stripe
5
5
  module Billing
6
6
  # A billing meter is a resource that allows you to track usage of a particular event. For example, you might create a billing meter to track the number of API calls made by a particular user. You can then attach the billing meter to a price and attach the price to a subscription to charge the user for the number of API calls they make.
7
+ #
8
+ # Related guide: [Usage based billing](https://docs.stripe.com/billing/subscriptions/usage-based)
7
9
  class Meter < APIResource
8
10
  extend Stripe::APIOperations::Create
9
11
  extend Stripe::APIOperations::List
@@ -2,9 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
- # This object represents a customer of your business. Use it to create recurring charges and track payments that belong to the same customer.
6
- #
7
- # Related guide: [Save a card during payment](https://stripe.com/docs/payments/save-during-payment)
5
+ # This object represents a customer of your business. Use it to [create recurring charges](https://stripe.com/docs/invoicing/customer), [save payment](https://stripe.com/docs/payments/save-during-payment) and contact information,
6
+ # and track payments that belong to the same customer.
8
7
  class Customer < APIResource
9
8
  extend Stripe::APIOperations::Create
10
9
  include Stripe::APIOperations::Delete
@@ -22,17 +22,19 @@ module Stripe
22
22
  #
23
23
  # All of Stripe's officially supported Client libraries support sending multipart/form-data.
24
24
  def self.create(params = {}, opts = {})
25
- config = opts[:client]&.config || Stripe.config
26
- upload_base = config.uploads_base
27
- opts = { api_base: upload_base }.merge(Util.normalize_opts(opts))
28
-
29
25
  if params[:file] && !params[:file].is_a?(String) && !params[:file].respond_to?(:read)
30
26
  raise ArgumentError, "file must respond to `#read`"
31
27
  end
32
28
 
33
29
  opts = { content_type: MultipartEncoder::MULTIPART_FORM_DATA }.merge(Util.normalize_opts(opts))
34
30
 
35
- request_stripe_object(method: :post, path: "/v1/files", params: params, opts: opts)
31
+ request_stripe_object(
32
+ method: :post,
33
+ path: "/v1/files",
34
+ params: params,
35
+ opts: opts,
36
+ base_address: :files
37
+ )
36
38
  end
37
39
 
38
40
  # Returns a list of the files that your account has access to. Stripe sorts and returns the files by their creation dates, placing the most recently created files at the top.
@@ -123,6 +123,26 @@ module Stripe
123
123
  opts: opts
124
124
  )
125
125
  end
126
+
127
+ # Updates the shipping status of the specified Issuing Card object to submitted. This method is only available with Stripe Version ‘2024-09-30.acacia' or above.
128
+ def self.submit_card(card, params = {}, opts = {})
129
+ request_stripe_object(
130
+ method: :post,
131
+ path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/submit", { card: CGI.escape(card) }),
132
+ params: params,
133
+ opts: opts
134
+ )
135
+ end
136
+
137
+ # Updates the shipping status of the specified Issuing Card object to submitted. This method is only available with Stripe Version ‘2024-09-30.acacia' or above.
138
+ def submit_card(params = {}, opts = {})
139
+ @resource.request_stripe_object(
140
+ method: :post,
141
+ path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/submit", { card: CGI.escape(@resource["id"]) }),
142
+ params: params,
143
+ opts: opts
144
+ )
145
+ end
126
146
  end
127
147
  end
128
148
  end
@@ -210,24 +210,24 @@ module Stripe
210
210
 
211
211
  # Download the PDF for a finalized quote. Explanation for special handling can be found [here](https://docs.stripe.com/quotes/overview#quote_pdf)
212
212
  def pdf(params = {}, opts = {}, &read_body_chunk_block)
213
- config = opts[:client]&.config || Stripe.config
214
- opts = { api_base: config.uploads_base }.merge(opts)
213
+ opts = { api_base: APIRequestor.active_requestor.config.uploads_base }.merge(opts)
215
214
  request_stream(
216
215
  method: :get,
217
216
  path: format("/v1/quotes/%<quote>s/pdf", { quote: CGI.escape(self["id"]) }),
218
217
  params: params,
219
218
  opts: opts,
219
+ base_address: :files,
220
220
  &read_body_chunk_block
221
221
  )
222
222
  end
223
223
 
224
224
  # Download the PDF for a finalized quote. Explanation for special handling can be found [here](https://docs.stripe.com/quotes/overview#quote_pdf)
225
225
  def self.pdf(quote, params = {}, opts = {}, &read_body_chunk_block)
226
- config = opts[:client]&.config || Stripe.config
227
- opts = { api_base: config.uploads_base }.merge(opts)
226
+ opts = { api_base: APIRequestor.active_requestor.config.uploads_base }.merge(opts)
228
227
  execute_resource_request_stream(
229
228
  :get,
230
229
  format("/v1/quotes/%<quote>s/pdf", { quote: CGI.escape(quote) }),
230
+ :files,
231
231
  params,
232
232
  opts,
233
233
  &read_body_chunk_block
@@ -70,8 +70,9 @@ module Stripe
70
70
 
71
71
  url = "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
72
72
  "/#{CGI.escape(id)}"
73
- resp, opts = execute_resource_request(:delete, url, params, opts)
74
- initialize_from(resp.data, opts)
73
+ opts = Util.normalize_opts(opts)
74
+ APIRequestor.active_requestor.execute_request_initialize_from(:delete, url, :api, self,
75
+ params: params, opts: opts)
75
76
  end
76
77
 
77
78
  def source_transactions(params = {}, opts = {})