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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baccff36bc3c05653ea6db905dbb388ab87127e4bf722930051e170ebe38b8e3
4
- data.tar.gz: 1a6e9187f2e9283d35313223dbf71c54637445af5153d26532bb8cc2b547e52b
3
+ metadata.gz: bb3814708d697a6e7d081dfeec39b1d54b4e32abc163a83c5e2b5d4e9934d623
4
+ data.tar.gz: ba8c9d94f78eab694cf55148e04de09ad390bc039537093df7a1c31d4c11234b
5
5
  SHA512:
6
- metadata.gz: 7f1d75169b9c872a3bfa3bcc81e01e3b311e37a0cb458e237e5dee15f9ed7c268c2d211d8c2302371b3570965cdab0a69205bc2fa842eed29323987c6ca079ee
7
- data.tar.gz: fa91a27ac219a9236ee2fa7443ac467b7e82640ea55fa90ad63ba9f8d965accf007aef216e1d2025e06176d109284e623c0f9889ede83ced264bef494c9df974
6
+ metadata.gz: 1f135698dc89345728ec5d73991ea0de8d2507632a2ad94a7b3cbbef206bf7b7f51b9c067d548d930a4ff6c904e91b0a3d4024c168fed9edbb539005ec7b477a
7
+ data.tar.gz: fc3e2a7bf5f31f9ab9d7d2415099bd913f0b7f37067a13a8cf3720a4f572f388bb507ac7dd99cbed392d68bb98e6cff6ac53ff25c7899c479cdc25b1c701ecee
data/CHANGELOG.md CHANGED
@@ -1,5 +1,92 @@
1
1
  # Changelog
2
2
 
3
+ ## 13.1.0-beta.2 - 2024-10-08
4
+ * [#1468](https://github.com/stripe/stripe-ruby/pull/1468) Update generated code for beta
5
+ * Add support for `submit_card` test helper method on resource `Issuing.Card`
6
+
7
+ ## 13.1.0-beta.1 - 2024-10-03
8
+ * [#1465](https://github.com/stripe/stripe-ruby/pull/1465) Updates to the `Preview` class
9
+ * Remove `Stripe::Preview`. Use `StripeClient#raw_request` instead (see below).
10
+ * Marked `Stripe.raw_request` and `Stripe.deserialize` as deprecated. Use `StripeClient#raw_request` and `StripeClient#deserialize` instead. In StripeClient, the params and opts parameters are passed as keyword arguments:
11
+ ```ruby
12
+ # Before
13
+ resp = Stripe.raw_request(:post, "v1/charges", , {p1: "p1"}, {stripe_account: "acct_123"})
14
+ charge = Stripe.deserialize(resp.data)
15
+
16
+ # After
17
+ client = StripeClient.new("sk_test_123")
18
+ resp = client.raw_request(:post, "/v1/charges", params: {p1: "p1"}, opts: {stripe_account: "acct_123"})
19
+ charge = client.deserialize(resp.data)
20
+ ```
21
+
22
+ ## 13.0.0 - 2024-10-01
23
+ * [#1458](https://github.com/stripe/stripe-ruby/pull/1458) Support for APIs in the new API version 2024-09-30.acacia
24
+
25
+ This release changes the pinned API version to `2024-09-30.acacia`. Please read the [API Upgrade Guide](https://stripe.com/docs/upgrades#2024-09-30.acacia) and carefully review the API changes before upgrading.
26
+
27
+ ### ⚠️ Breaking changes
28
+
29
+ Please refer to our [migration guide for v13](https://github.com/stripe/stripe-ruby/wiki/Migration-guide-for-v13) for more information about the backwards incompatible changes.
30
+
31
+ #### ❗ `StripeClient` and related changes
32
+ * Move `StripeClient` and requestor logic to `APIRequestor`.
33
+ * `StripeClient#request` is still available, but is deprecated and will be removed. We encourage `StripeClient#raw_request` as a replacement (see other breaking changes for more detail).
34
+ * Repurpose and introduce `StripeClient` as the the entry-point to the service-based pattern, a new interface for calling the Stripe API with many benefits over the existing resource-based paradigm. Services are available under the `v1` and `v2` accessors.
35
+ * No global config: you can simultaneously use multiple clients with different configuration options (such as API keys)
36
+ * No extra API calls. All API endpoints can be accessed with a single method call. You don't have to call `retrieve` before doing an `update`.
37
+ * No static methods. Much easier mocking.
38
+
39
+ #### Other breaking changes
40
+
41
+ * Adjust default values around retries for HTTP requests. You can use the old defaults by setting them explicitly. New values are:
42
+ - max retries: `0` -> `2`
43
+ - max retry delay (seconds) `2` -> `5`
44
+ * Remove `StripeClient#connection_manager`. This was a legacy method from years ago.
45
+ * Singleton `retrieve` method now requires `params` to be passed as the first argument. Existing calls to singleton `retrieve` method with only `opts` argument will have to be updated to account for the addition of `params` argument.
46
+ ```ruby
47
+ params = { expand: ["available"] }
48
+ opts = { stripe_account: "acct_123" }
49
+
50
+ # ❌ No longer works
51
+ Stripe::Balance.retrieve(opts)
52
+
53
+ # ✅ Correct way to call retrieve method
54
+ Stripe::Balance.retrieve(params, opts)
55
+ ```
56
+ * Moved the `Stripe.raw_request()` method that was recently added to `StripeClient`. This will use the configuration set on the StripeClient instead of the global configuration used before.
57
+ * Remove `APIResource.request`. Instead, use `StripeClient#raw_request` now.
58
+ ```ruby
59
+ # Instead of
60
+ Stripe::APIResource.request(:get, "/v1/endpoint", params, opts)
61
+
62
+ # do
63
+ client = Stripe::StripeClient.new(...)
64
+ resp = client.raw_request(:get, "/v1/endpoint", params: params, opts: opts)
65
+ ```
66
+ * Add an additional parameter to `APIResource.execute_resource_request`. However, we discourage use of this in favor of `StripeClient#raw_request`.
67
+ ```ruby
68
+ APIResource.execute_resource_request(method, url, params = {}, opts = {}, usage = [])
69
+ # is now, with base_address being one of [:api, :files, :connect, :meter_events]
70
+ APIResource.execute_resource_request(method, url, base_address = :api, params = {}, opts = {}, usage = [])
71
+ ```
72
+ * Change parameters to `APIRequestor.execute_request` (previously `StripeClient.execute_request`). It now returns all request options from our internal request framework as the second value in the returned tuple, instead of only the API key used:
73
+ ```ruby
74
+ # Before
75
+ obj, api_key = StripeClient.execute_request(method, path, api_base: nil,
76
+ api_key: nil, headers: {}, params: {}, usage: [])
77
+
78
+ # is now, with base_address being one of [:api, :files, :connect, :meter_events]
79
+
80
+ obj, opts = APIRequestor.execute_request(method, path, base_address,
81
+ params: {}, opts: {}, usage: [])
82
+ puts(opts) # will output {api_key: "sk_test_123", stripe_account: "acct_123"}
83
+ ```
84
+
85
+
86
+ ### Additions
87
+ * Add support for new Usage Billing APIs `Billing.MeterEvent`, `Billing.MeterEventAdjustments`, `Billing.MeterEventSession`, `Billing.MeterEventStream` and the new Events API `Core.Events` in the [v2 namespace ](https://docs.corp.stripe.com/api-v2-overview)
88
+ * Add method `parse_thin_event()` on the `StripeClient` class to parse [thin events](https://docs.corp.stripe.com/event-destinations#events-overview).
89
+
3
90
  ## 12.7.0-beta.2 - 2024-09-18
4
91
  * [#1449](https://github.com/stripe/stripe-ruby/pull/1449) Update generated code for beta
5
92
  * Remove support for resource `QuotePhase`
@@ -52,7 +139,7 @@
52
139
 
53
140
  * [#1433](https://github.com/stripe/stripe-ruby/pull/1433) Add usage to raw_request call
54
141
  * [#1431](https://github.com/stripe/stripe-ruby/pull/1431) Add `raw_request`
55
-
142
+
56
143
  - Adds the ability to make raw requests to the Stripe API, by providing an HTTP method and url. This is an alternative to using `Stripe::APIResource.request(...)` to make custom requests, which is discouraged and will be broken in a future major version.
57
144
 
58
145
  ## 12.2.0-beta.1 - 2024-07-05
@@ -65,14 +152,14 @@
65
152
  * [#1425](https://github.com/stripe/stripe-ruby/pull/1425) Update generated code
66
153
  * Add support for `add_lines`, `remove_lines`, and `update_lines` methods on resource `Invoice`
67
154
  * [#1420](https://github.com/stripe/stripe-ruby/pull/1420) Update static methods for delete/list on BankAccount/Card to throw NotImplementedError
68
- * The below methods have been throwing `InvalidRequestError` because the urls used to make the requests have been buggy. Updating them to throw `NotImplementedError` instead just like their counterparts for update & retrieve because they cannot be implemented without the parent id.
69
-
70
- Methods affected | Use these instead in the context of payment method | Use these in the context of external accounts
71
- ------ | ------ | ----
72
- Stripe:: BankAccount.delete | Stripe::Customer.delete_source | Stripe::Account.delete_external_account
73
- Stripe:: BankAccount.list | Stripe::Customer.list_sources | Stripe::Customer.list_external_accounts
74
- Stripe:: Card.delete | Stripe::Customer.delete_source | Stripe::Account.delete_external_account
75
- Stripe:: Card.list | Stripe::Customer.list_sources | Stripe::Customer.list_external_accounts
155
+ * The below methods have been throwing `InvalidRequestError` because the urls used to make the requests have been buggy. Updating them to throw `NotImplementedError` instead just like their counterparts for update & retrieve because they cannot be implemented without the parent id.
156
+
157
+ Methods affected | Use these instead in the context of payment method | Use these in the context of external accounts
158
+ ------ | ------ | ----
159
+ Stripe:: BankAccount.delete | Stripe::Customer.delete_source | Stripe::Account.delete_external_account
160
+ Stripe:: BankAccount.list | Stripe::Customer.list_sources | Stripe::Customer.list_external_accounts
161
+ Stripe:: Card.delete | Stripe::Customer.delete_source | Stripe::Account.delete_external_account
162
+ Stripe:: Card.list | Stripe::Customer.list_sources | Stripe::Customer.list_external_accounts
76
163
  * [#1427](https://github.com/stripe/stripe-ruby/pull/1427) Regenerate rbis
77
164
  * [#1426](https://github.com/stripe/stripe-ruby/pull/1426) Remove coveralls and re-added JRuby
78
165
 
data/OPENAPI_VERSION CHANGED
@@ -1 +1 @@
1
- v1267
1
+ v1273
data/README.md CHANGED
@@ -346,13 +346,14 @@ If you:
346
346
  - prefer to bypass the method definitions in the library and specify your request details directly,
347
347
  - used the method `Stripe::APIResource.request(...)` to specify your own requests, which will soon be broken
348
348
 
349
- you can now use the `raw_request` method on `Stripe`.
349
+ you can now use the `raw_request` method on `StripeClient`.
350
350
 
351
351
  ```ruby
352
- resp = Stripe.raw_request(:post, "/v1/beta_endpoint", {param: 123}, {stripe_version: "2022-11-15; feature_beta=v3"})
352
+ client = Stripe::StripeClient.new(...)
353
+ resp = client.raw_request(:post, "/v1/beta_endpoint", {param: 123}, {stripe_version: "2022-11-15; feature_beta=v3"})
353
354
 
354
355
  # (Optional) resp is a StripeResponse. You can use `Stripe.deserialize` to get a StripeObject.
355
- deserialized_resp = Stripe.deserialize(resp.http_body)
356
+ deserialized_resp = client.deserialize(resp.http_body)
356
357
  ```
357
358
 
358
359
  ## Support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 12.7.0-beta.2
1
+ 13.1.0-beta.2
@@ -0,0 +1,11 @@
1
+ ## Running an example
2
+
3
+ From the examples folder, run:
4
+ `RUBYLIB=../lib ruby your_example.rb`
5
+
6
+ ## Adding a new example
7
+
8
+ 1. Clone new_example.rb
9
+ 2. Implement your example
10
+ 3. Run it (as per above)
11
+ 4. 👍
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stripe"
4
+ require "date"
5
+
6
+ class MeterEventManager
7
+ attr_accessor :api_key, :meter_event_session
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ @meter_event_session = nil
12
+ end
13
+
14
+ def refresh_meter_event_session
15
+ return unless @meter_event_session.nil? || DateTime.parse(@meter_event_session.expires_at) <= DateTime.now
16
+
17
+ # Create a new meter event session in case the existing session expired
18
+ client = Stripe::StripeClient.new(api_key)
19
+ @meter_event_session = client.v2.billing.meter_event_session.create
20
+ end
21
+
22
+ def send_meter_event(meter_event)
23
+ # Refresh the meter event session if necessary
24
+ refresh_meter_event_session
25
+
26
+ # Create a meter event with the current session's authentication token
27
+ client = Stripe::StripeClient.new(meter_event_session.authentication_token)
28
+ client.v2.billing.meter_event_stream.create(
29
+ events: [meter_event]
30
+ )
31
+ end
32
+ end
33
+
34
+ # Send meter events
35
+ api_key = "{{API_KEY}}"
36
+ customer_id = "{{CUSTOMER_ID}}"
37
+
38
+ manager = MeterEventManager.new(api_key)
39
+ manager.send_meter_event(
40
+ {
41
+ event_name: "alpaca_ai_tokens",
42
+ payload: {
43
+ "stripe_customer_id" => customer_id,
44
+ "value" => "25",
45
+ },
46
+ }
47
+ )
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stripe"
4
+ require "date"
5
+
6
+ class NewExample
7
+ attr_accessor :api_key
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ def do_something_great
14
+ puts "Hello World"
15
+ # client = Stripe::StripeClient.new(api_key)
16
+ # client.v1
17
+ end
18
+ end
19
+
20
+ # Send meter events
21
+ api_key = "{{API_KEY}}"
22
+
23
+ example = NewExample.new(api_key)
24
+ example.do_something_great
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ require "stripe"
5
+ require "sinatra"
6
+
7
+ api_key = ENV.fetch("STRIPE_API_KEY", nil)
8
+ # Retrieve the webhook secret from the environment variable
9
+ webhook_secret = ENV.fetch("WEBHOOK_SECRET", nil)
10
+
11
+ client = Stripe::StripeClient.new(api_key)
12
+
13
+ post "/webhook" do
14
+ webhook_body = request.body.read
15
+ sig_header = request.env["HTTP_STRIPE_SIGNATURE"]
16
+ thin_event = client.parse_thin_event(webhook_body, sig_header, webhook_secret)
17
+
18
+ # Fetch the event data to understand the failure
19
+ event = client.v2.core.events.retrieve(thin_event.id)
20
+ if event.instance_of? Stripe::V1BillingMeterErrorReportTriggeredEvent
21
+ meter = event.fetch_related_object
22
+ meter_id = meter.id
23
+ puts "Success!", meter_id
24
+ end
25
+
26
+ # Record the failures and alert your team
27
+ status 200
28
+ end
@@ -35,7 +35,6 @@ module Stripe
35
35
  end
36
36
  end
37
37
 
38
- # rubocop:disable Metrics/MethodLength
39
38
  private def define_operation(
40
39
  resource,
41
40
  operation,
@@ -54,26 +53,8 @@ module Stripe
54
53
  )
55
54
  end
56
55
  when :retrieve
57
- # TODO: (Major) Split params_or_opts to params and opts and get rid of the complicated way to add params
58
56
  define_singleton_method(:"retrieve_#{resource}") \
59
- do |id, nested_id, params_or_opts = {}, definitely_opts = nil|
60
- opts = nil
61
- params = nil
62
- if definitely_opts.nil?
63
- unrecognized_key = params_or_opts.keys.find { |k| !Util::OPTS_USER_SPECIFIED.include?(k) }
64
- if unrecognized_key
65
- raise ArgumentError,
66
- "Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as " \
67
- "retrieve params? " \
68
- "If so, you must explicitly pass an opts hash as a fourth argument. " \
69
- "For example: .retrieve(#{id}, #{nested_id}, {#{unrecognized_key}: 'foo'}, {})"
70
- end
71
-
72
- opts = params_or_opts
73
- else
74
- opts = definitely_opts
75
- params = params_or_opts
76
- end
57
+ do |id, nested_id, params = {}, opts = {}|
77
58
  request_stripe_object(
78
59
  method: :get,
79
60
  path: send(resource_url_method, id, nested_id),
@@ -115,7 +96,6 @@ module Stripe
115
96
  raise ArgumentError, "Unknown operation: #{operation.inspect}"
116
97
  end
117
98
  end
118
- # rubocop:enable Metrics/MethodLength
119
99
  end
120
100
  end
121
101
  end
@@ -4,20 +4,21 @@ module Stripe
4
4
  module APIOperations
5
5
  module Request
6
6
  module ClassMethods
7
- def execute_resource_request(method, url,
7
+ def execute_resource_request(method, url, base_address = :api,
8
8
  params = {}, opts = {}, usage = [])
9
9
  execute_resource_request_internal(
10
- :execute_request, method, url, params, opts, usage
10
+ :execute_request, method, url, base_address, params, opts, usage
11
11
  )
12
12
  end
13
13
 
14
- def execute_resource_request_stream(method, url,
14
+ def execute_resource_request_stream(method, url, base_address = :api,
15
15
  params = {}, opts = {}, usage = [],
16
16
  &read_body_chunk_block)
17
17
  execute_resource_request_internal(
18
18
  :execute_request_stream,
19
19
  method,
20
20
  url,
21
+ base_address,
21
22
  params,
22
23
  opts,
23
24
  usage,
@@ -25,13 +26,12 @@ module Stripe
25
26
  )
26
27
  end
27
28
 
28
- private def request_stripe_object(method:, path:, params:, opts: {}, usage: [])
29
- resp, opts = execute_resource_request(method, path, params, opts, usage)
30
- Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
29
+ private def request_stripe_object(method:, path:, base_address: :api, params: {}, opts: {}, usage: [])
30
+ execute_resource_request(method, path, base_address, params, opts, usage)
31
31
  end
32
32
 
33
33
  private def execute_resource_request_internal(client_request_method_sym,
34
- method, url,
34
+ method, url, base_address,
35
35
  params, opts, usage,
36
36
  &read_body_chunk_block)
37
37
  params ||= {}
@@ -40,60 +40,15 @@ module Stripe
40
40
  warn_on_opts_in_params(params)
41
41
 
42
42
  opts = Util.normalize_opts(opts)
43
- error_on_non_string_user_opts(opts)
43
+ req_opts = RequestOptions.extract_opts_from_hash(opts)
44
44
 
45
- opts[:client] ||= StripeClient.active_client
46
-
47
- headers = opts.clone
48
- api_key = headers.delete(:api_key)
49
- api_base = headers.delete(:api_base)
50
- client = headers.delete(:client)
51
- api_mode = headers.delete(:api_mode)
52
- # Assume all remaining opts must be headers
53
-
54
- resp, opts[:api_key] = client.send(
45
+ APIRequestor.active_requestor.send(
55
46
  client_request_method_sym,
56
47
  method, url,
57
- api_base: api_base, api_key: api_key,
58
- headers: headers, params: params, usage: usage, api_mode: api_mode,
48
+ base_address,
49
+ params: params, opts: req_opts, usage: usage,
59
50
  &read_body_chunk_block
60
51
  )
61
-
62
- # Hash#select returns an array before 1.9
63
- opts_to_persist = {}
64
- opts.each do |k, v|
65
- opts_to_persist[k] = v if Util::OPTS_PERSISTABLE.include?(k)
66
- end
67
-
68
- [resp, opts_to_persist]
69
- end
70
-
71
- # TODO: (major)
72
- # This method used to be called `request`, but it's such a short name
73
- # that it eventually conflicted with the name of a field on an API
74
- # resource (specifically, `Event#request`), so it was renamed to
75
- # something more unique.
76
- #
77
- # The former name had been around for just about forever though, and
78
- # although all internal uses have been renamed, I've left this alias in
79
- # place for backwards compatibility. Consider removing it on the next
80
- # major.
81
- alias request execute_resource_request
82
- extend Gem::Deprecate
83
- deprecate :request, "Stripe.raw_request", 2024, 7
84
-
85
- private def error_on_non_string_user_opts(opts)
86
- Util::OPTS_USER_SPECIFIED.each do |opt|
87
- next unless opts.key?(opt)
88
-
89
- val = opts[opt]
90
- next if val.nil?
91
- next if val.is_a?(String)
92
-
93
- raise ArgumentError,
94
- "request option '#{opt}' should be a string value " \
95
- "(was a #{val.class})"
96
- end
97
52
  end
98
53
 
99
54
  private def error_on_invalid_params(params)
@@ -105,7 +60,7 @@ module Stripe
105
60
  end
106
61
 
107
62
  private def warn_on_opts_in_params(params)
108
- Util::OPTS_USER_SPECIFIED.each do |opt|
63
+ RequestOptions::OPTS_USER_SPECIFIED.each do |opt|
109
64
  warn("WARNING: '#{opt}' should be in opts instead of params.") if params.key?(opt)
110
65
  end
111
66
  end
@@ -115,30 +70,24 @@ module Stripe
115
70
  base.extend(ClassMethods)
116
71
  end
117
72
 
118
- protected def execute_resource_request(method, url,
73
+ protected def execute_resource_request(method, url, base_address = :api,
119
74
  params = {}, opts = {}, usage = [])
120
75
  opts = @opts.merge(Util.normalize_opts(opts))
121
- self.class.execute_resource_request(method, url, params, opts, usage)
76
+ self.class.execute_resource_request(method, url, base_address, params, opts, usage)
122
77
  end
123
78
 
124
- protected def execute_resource_request_stream(method, url,
125
- params = {}, opts = {},
79
+ protected def execute_resource_request_stream(method, url, base_address = :api,
80
+ params = {}, opts = {}, usage = [],
126
81
  &read_body_chunk_block)
127
82
  opts = @opts.merge(Util.normalize_opts(opts))
128
83
  self.class.execute_resource_request_stream(
129
- method, url, params, opts, &read_body_chunk_block
84
+ method, url, base_address, params, opts, usage, &read_body_chunk_block
130
85
  )
131
86
  end
132
87
 
133
- private def request_stripe_object(method:, path:, params:, opts: {}, usage: [])
134
- resp, opts = execute_resource_request(method, path, params, opts, usage)
135
- Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
88
+ private def request_stripe_object(method:, path:, params:, base_address: :api, opts: {}, usage: [])
89
+ execute_resource_request(method, path, base_address, params, opts, usage)
136
90
  end
137
-
138
- # See notes on `alias` above.
139
- alias request execute_resource_request
140
- extend Gem::Deprecate
141
- deprecate :request, "Stripe.raw_request", 2024, 7
142
91
  end
143
92
  end
144
93
  end
@@ -65,9 +65,10 @@ module Stripe
65
65
  # Please note that id gets removed here our call to #url above has already
66
66
  # generated a uri for this object with an identifier baked in
67
67
  values.delete(:id)
68
-
69
- resp, opts = execute_resource_request(:post, save_url, values, opts, ["save"])
70
- initialize_from(resp.data, opts, resp)
68
+ opts = Util.normalize_opts(opts)
69
+ APIRequestor.active_requestor.execute_request_initialize_from(:post, save_url, :api, self,
70
+ params: values, opts: opts,
71
+ usage: ["save"])
71
72
  end
72
73
  extend Gem::Deprecate
73
74
  deprecate :save, "the `update` class method (for examples " \
@@ -61,8 +61,11 @@ module Stripe
61
61
 
62
62
  values = serialize_params(self).merge(params)
63
63
 
64
- resp, opts = execute_resource_request(:post, resource_url, values, opts, ["save"])
65
- initialize_from(resp.data, opts, resp)
64
+ opts = Util.normalize_opts(opts)
65
+
66
+ APIRequestor.active_requestor.execute_request_initialize_from(:post, resource_url, :api, self,
67
+ params: values, opts: opts,
68
+ usage: ["save"])
66
69
  end
67
70
  extend Gem::Deprecate
68
71
  deprecate :save, "the `update` class method (for examples " \