stripe 12.5.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (688) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +197 -9
  3. data/Gemfile +4 -0
  4. data/Makefile +2 -0
  5. data/OPENAPI_VERSION +1 -1
  6. data/README.md +48 -13
  7. data/Rakefile +0 -5
  8. data/VERSION +1 -1
  9. data/examples/README.md +16 -0
  10. data/examples/example_template.rb +36 -0
  11. data/examples/meter_event_stream.rb +57 -0
  12. data/examples/thinevent_webhook_handler.rb +39 -0
  13. data/justfile +43 -0
  14. data/lib/stripe/api_operations/nested_resource.rb +1 -21
  15. data/lib/stripe/api_operations/request.rb +20 -69
  16. data/lib/stripe/api_operations/save.rb +5 -3
  17. data/lib/stripe/api_operations/singleton_save.rb +6 -2
  18. data/lib/stripe/api_requestor.rb +1136 -0
  19. data/lib/stripe/api_resource.rb +38 -17
  20. data/lib/stripe/api_version.rb +1 -1
  21. data/lib/stripe/connection_manager.rb +1 -1
  22. data/lib/stripe/errors.rb +8 -9
  23. data/lib/stripe/event_types.rb +14 -0
  24. data/lib/stripe/events/v1_billing_meter_error_report_triggered_event.rb +23 -0
  25. data/lib/stripe/events/v1_billing_meter_no_meter_found_event.rb +13 -0
  26. data/lib/stripe/list_object.rb +2 -3
  27. data/lib/stripe/oauth.rb +8 -15
  28. data/lib/stripe/object_types.rb +26 -3
  29. data/lib/stripe/request_options.rb +129 -0
  30. data/lib/stripe/request_params.rb +24 -0
  31. data/lib/stripe/resources/account.rb +4642 -8
  32. data/lib/stripe/resources/account_link.rb +54 -0
  33. data/lib/stripe/resources/account_session.rb +739 -0
  34. data/lib/stripe/resources/apple_pay_domain.rb +58 -9
  35. data/lib/stripe/resources/application.rb +20 -0
  36. data/lib/stripe/resources/application_fee.rb +89 -2
  37. data/lib/stripe/resources/application_fee_refund.rb +17 -0
  38. data/lib/stripe/resources/apps/secret.rb +143 -2
  39. data/lib/stripe/resources/balance.rb +122 -0
  40. data/lib/stripe/resources/balance_transaction.rb +105 -2
  41. data/lib/stripe/resources/bank_account.rb +85 -3
  42. data/lib/stripe/resources/billing/alert.rb +137 -2
  43. data/lib/stripe/resources/billing/alert_triggered.rb +26 -0
  44. data/lib/stripe/resources/billing/credit_balance_summary.rb +54 -0
  45. data/lib/stripe/resources/billing/credit_balance_transaction.rb +133 -0
  46. data/lib/stripe/resources/billing/credit_grant.rb +307 -0
  47. data/lib/stripe/resources/billing/meter.rb +180 -9
  48. data/lib/stripe/resources/billing/meter_event.rb +37 -3
  49. data/lib/stripe/resources/billing/meter_event_adjustment.rb +44 -1
  50. data/lib/stripe/resources/billing/meter_event_summary.rb +17 -0
  51. data/lib/stripe/resources/billing_portal/configuration.rb +557 -4
  52. data/lib/stripe/resources/billing_portal/session.rb +271 -0
  53. data/lib/stripe/resources/capability.rb +84 -0
  54. data/lib/stripe/resources/card.rb +78 -1
  55. data/lib/stripe/resources/cash_balance.rb +17 -0
  56. data/lib/stripe/resources/charge.rb +1616 -4
  57. data/lib/stripe/resources/checkout/session.rb +3534 -10
  58. data/lib/stripe/resources/climate/order.rb +171 -4
  59. data/lib/stripe/resources/climate/product.rb +49 -2
  60. data/lib/stripe/resources/climate/supplier.rb +47 -2
  61. data/lib/stripe/resources/confirmation_token.rb +1448 -0
  62. data/lib/stripe/resources/connect_collection_transfer.rb +24 -0
  63. data/lib/stripe/resources/country_spec.rb +56 -2
  64. data/lib/stripe/resources/coupon.rb +195 -6
  65. data/lib/stripe/resources/credit_note.rb +641 -2
  66. data/lib/stripe/resources/credit_note_line_item.rb +67 -0
  67. data/lib/stripe/resources/customer.rb +832 -9
  68. data/lib/stripe/resources/customer_balance_transaction.rb +29 -0
  69. data/lib/stripe/resources/customer_cash_balance_transaction.rb +109 -0
  70. data/lib/stripe/resources/customer_session.rb +163 -0
  71. data/lib/stripe/resources/discount.rb +29 -0
  72. data/lib/stripe/resources/dispute.rb +614 -4
  73. data/lib/stripe/resources/entitlements/active_entitlement.rb +39 -2
  74. data/lib/stripe/resources/entitlements/active_entitlement_summary.rb +23 -0
  75. data/lib/stripe/resources/entitlements/feature.rb +83 -2
  76. data/lib/stripe/resources/ephemeral_key.rb +23 -2
  77. data/lib/stripe/resources/event.rb +92 -2
  78. data/lib/stripe/resources/exchange_rate.rb +26 -2
  79. data/lib/stripe/resources/file.rb +123 -15
  80. data/lib/stripe/resources/file_link.rb +107 -4
  81. data/lib/stripe/resources/financial_connections/account.rb +239 -2
  82. data/lib/stripe/resources/financial_connections/account_owner.rb +17 -0
  83. data/lib/stripe/resources/financial_connections/account_ownership.rb +9 -0
  84. data/lib/stripe/resources/financial_connections/session.rb +95 -0
  85. data/lib/stripe/resources/financial_connections/transaction.rb +94 -2
  86. data/lib/stripe/resources/forwarding/request.rb +158 -2
  87. data/lib/stripe/resources/funding_instructions.rb +308 -0
  88. data/lib/stripe/resources/identity/verification_report.rb +259 -2
  89. data/lib/stripe/resources/identity/verification_session.rb +356 -4
  90. data/lib/stripe/resources/invoice.rb +3210 -27
  91. data/lib/stripe/resources/invoice_item.rb +406 -6
  92. data/lib/stripe/resources/invoice_line_item.rb +356 -3
  93. data/lib/stripe/resources/invoice_payment.rb +105 -0
  94. data/lib/stripe/resources/invoice_rendering_template.rb +120 -0
  95. data/lib/stripe/resources/issuing/authorization.rb +1132 -6
  96. data/lib/stripe/resources/issuing/card.rb +682 -5
  97. data/lib/stripe/resources/issuing/cardholder.rb +653 -5
  98. data/lib/stripe/resources/issuing/dispute.rb +785 -4
  99. data/lib/stripe/resources/issuing/personalization_design.rb +280 -4
  100. data/lib/stripe/resources/issuing/physical_bundle.rb +56 -2
  101. data/lib/stripe/resources/issuing/token.rb +170 -4
  102. data/lib/stripe/resources/issuing/transaction.rb +916 -4
  103. data/lib/stripe/resources/line_item.rb +47 -0
  104. data/lib/stripe/resources/login_link.rb +7 -0
  105. data/lib/stripe/resources/mandate.rb +142 -0
  106. data/lib/stripe/resources/payment_intent.rb +8660 -4
  107. data/lib/stripe/resources/payment_link.rb +1636 -4
  108. data/lib/stripe/resources/payment_method.rb +1546 -4
  109. data/lib/stripe/resources/payment_method_configuration.rb +2780 -4
  110. data/lib/stripe/resources/payment_method_domain.rb +154 -10
  111. data/lib/stripe/resources/payout.rb +213 -4
  112. data/lib/stripe/resources/person.rb +264 -1
  113. data/lib/stripe/resources/plan.rb +308 -6
  114. data/lib/stripe/resources/price.rb +609 -5
  115. data/lib/stripe/resources/product.rb +474 -2
  116. data/lib/stripe/resources/product_feature.rb +12 -0
  117. data/lib/stripe/resources/promotion_code.rb +216 -4
  118. data/lib/stripe/resources/quote.rb +927 -10
  119. data/lib/stripe/resources/radar/early_fraud_warning.rb +70 -2
  120. data/lib/stripe/resources/radar/value_list.rb +122 -6
  121. data/lib/stripe/resources/radar/value_list_item.rb +90 -4
  122. data/lib/stripe/resources/refund.rb +396 -4
  123. data/lib/stripe/resources/reporting/report_run.rb +143 -2
  124. data/lib/stripe/resources/reporting/report_type.rb +29 -2
  125. data/lib/stripe/resources/reserve_transaction.rb +22 -0
  126. data/lib/stripe/resources/reversal.rb +21 -0
  127. data/lib/stripe/resources/review.rb +101 -2
  128. data/lib/stripe/resources/setup_attempt.rb +370 -2
  129. data/lib/stripe/resources/setup_intent.rb +3477 -4
  130. data/lib/stripe/resources/shipping_rate.rb +254 -4
  131. data/lib/stripe/resources/sigma/scheduled_query_run.rb +47 -2
  132. data/lib/stripe/resources/source.rb +1203 -4
  133. data/lib/stripe/resources/source_mandate_notification.rb +66 -0
  134. data/lib/stripe/resources/source_transaction.rb +85 -0
  135. data/lib/stripe/resources/subscription.rb +1697 -11
  136. data/lib/stripe/resources/subscription_item.rb +319 -11
  137. data/lib/stripe/resources/subscription_schedule.rb +1285 -4
  138. data/lib/stripe/resources/tax/calculation.rb +378 -0
  139. data/lib/stripe/resources/tax/calculation_line_item.rb +56 -0
  140. data/lib/stripe/resources/tax/registration.rb +2375 -2
  141. data/lib/stripe/resources/tax/settings.rb +117 -0
  142. data/lib/stripe/resources/tax/transaction.rb +258 -0
  143. data/lib/stripe/resources/tax/transaction_line_item.rb +31 -0
  144. data/lib/stripe/resources/tax_code.rb +28 -2
  145. data/lib/stripe/resources/tax_deducted_at_source.rb +22 -0
  146. data/lib/stripe/resources/tax_id.rb +114 -2
  147. data/lib/stripe/resources/tax_rate.rb +197 -6
  148. data/lib/stripe/resources/terminal/configuration.rb +1266 -6
  149. data/lib/stripe/resources/terminal/connection_token.rb +18 -0
  150. data/lib/stripe/resources/terminal/location.rb +172 -6
  151. data/lib/stripe/resources/terminal/reader.rb +433 -6
  152. data/lib/stripe/resources/test_helpers/test_clock.rb +81 -4
  153. data/lib/stripe/resources/token.rb +1160 -1
  154. data/lib/stripe/resources/topup.rb +169 -4
  155. data/lib/stripe/resources/transfer.rb +148 -4
  156. data/lib/stripe/resources/treasury/credit_reversal.rb +85 -2
  157. data/lib/stripe/resources/treasury/debit_reversal.rb +96 -2
  158. data/lib/stripe/resources/treasury/financial_account.rb +749 -5
  159. data/lib/stripe/resources/treasury/financial_account_features.rb +189 -0
  160. data/lib/stripe/resources/treasury/inbound_transfer.rb +231 -3
  161. data/lib/stripe/resources/treasury/outbound_payment.rb +491 -3
  162. data/lib/stripe/resources/treasury/outbound_transfer.rb +346 -3
  163. data/lib/stripe/resources/treasury/received_credit.rb +239 -2
  164. data/lib/stripe/resources/treasury/received_debit.rb +198 -2
  165. data/lib/stripe/resources/treasury/transaction.rb +169 -2
  166. data/lib/stripe/resources/treasury/transaction_entry.rb +150 -2
  167. data/lib/stripe/resources/v2/amount.rb +9 -0
  168. data/lib/stripe/resources/v2/billing/meter_event.rb +34 -0
  169. data/lib/stripe/resources/v2/billing/meter_event_adjustment.rb +36 -0
  170. data/lib/stripe/resources/v2/billing/meter_event_session.rb +29 -0
  171. data/lib/stripe/resources/v2/event.rb +41 -0
  172. data/lib/stripe/resources/v2/event_destination.rb +73 -0
  173. data/lib/stripe/resources/webhook_endpoint.rb +119 -11
  174. data/lib/stripe/resources.rb +19 -2
  175. data/lib/stripe/search_result_object.rb +1 -1
  176. data/lib/stripe/services/account_capability_service.rb +71 -0
  177. data/lib/stripe/services/account_external_account_service.rb +318 -0
  178. data/lib/stripe/services/account_link_service.rb +63 -0
  179. data/lib/stripe/services/account_login_link_service.rb +28 -0
  180. data/lib/stripe/services/account_person_service.rb +936 -0
  181. data/lib/stripe/services/account_service.rb +4100 -0
  182. data/lib/stripe/services/account_session_service.rb +501 -0
  183. data/lib/stripe/services/apple_pay_domain_service.rb +101 -0
  184. data/lib/stripe/services/application_fee_refund_service.rb +114 -0
  185. data/lib/stripe/services/application_fee_service.rb +92 -0
  186. data/lib/stripe/services/apps/secret_service.rb +168 -0
  187. data/lib/stripe/services/apps_service.rb +13 -0
  188. data/lib/stripe/services/balance_service.rb +21 -0
  189. data/lib/stripe/services/balance_transaction_service.rb +101 -0
  190. data/lib/stripe/services/billing/alert_service.rb +187 -0
  191. data/lib/stripe/services/billing/credit_balance_summary_service.rb +67 -0
  192. data/lib/stripe/services/billing/credit_balance_transaction_service.rb +70 -0
  193. data/lib/stripe/services/billing/credit_grant_service.rb +240 -0
  194. data/lib/stripe/services/billing/meter_event_adjustment_service.rb +45 -0
  195. data/lib/stripe/services/billing/meter_event_service.rb +40 -0
  196. data/lib/stripe/services/billing/meter_event_summary_service.rb +58 -0
  197. data/lib/stripe/services/billing/meter_service.rb +211 -0
  198. data/lib/stripe/services/billing_portal/configuration_service.rb +496 -0
  199. data/lib/stripe/services/billing_portal/session_service.rb +192 -0
  200. data/lib/stripe/services/billing_portal_service.rb +14 -0
  201. data/lib/stripe/services/billing_service.rb +20 -0
  202. data/lib/stripe/services/charge_service.rb +471 -0
  203. data/lib/stripe/services/checkout/session_line_item_service.rb +37 -0
  204. data/lib/stripe/services/checkout/session_service.rb +2466 -0
  205. data/lib/stripe/services/checkout_service.rb +13 -0
  206. data/lib/stripe/services/climate/order_service.rb +170 -0
  207. data/lib/stripe/services/climate/product_service.rb +57 -0
  208. data/lib/stripe/services/climate/supplier_service.rb +57 -0
  209. data/lib/stripe/services/climate_service.rb +15 -0
  210. data/lib/stripe/services/confirmation_token_service.rb +26 -0
  211. data/lib/stripe/services/country_spec_service.rb +55 -0
  212. data/lib/stripe/services/coupon_service.rb +203 -0
  213. data/lib/stripe/services/credit_note_line_item_service.rb +35 -0
  214. data/lib/stripe/services/credit_note_preview_lines_service.rb +169 -0
  215. data/lib/stripe/services/credit_note_service.rb +458 -0
  216. data/lib/stripe/services/customer_balance_transaction_service.rb +113 -0
  217. data/lib/stripe/services/customer_cash_balance_service.rb +57 -0
  218. data/lib/stripe/services/customer_cash_balance_transaction_service.rb +55 -0
  219. data/lib/stripe/services/customer_funding_instructions_service.rb +61 -0
  220. data/lib/stripe/services/customer_payment_method_service.rb +68 -0
  221. data/lib/stripe/services/customer_payment_source_service.rb +255 -0
  222. data/lib/stripe/services/customer_service.rb +666 -0
  223. data/lib/stripe/services/customer_session_service.rb +113 -0
  224. data/lib/stripe/services/customer_tax_id_service.rb +95 -0
  225. data/lib/stripe/services/dispute_service.rb +422 -0
  226. data/lib/stripe/services/entitlements/active_entitlement_service.rb +66 -0
  227. data/lib/stripe/services/entitlements/feature_service.rb +128 -0
  228. data/lib/stripe/services/entitlements_service.rb +14 -0
  229. data/lib/stripe/services/ephemeral_key_service.rb +64 -0
  230. data/lib/stripe/services/event_service.rb +87 -0
  231. data/lib/stripe/services/exchange_rate_service.rb +55 -0
  232. data/lib/stripe/services/file_link_service.rb +132 -0
  233. data/lib/stripe/services/file_service.rb +124 -0
  234. data/lib/stripe/services/financial_connections/account_owner_service.rb +46 -0
  235. data/lib/stripe/services/financial_connections/account_service.rb +177 -0
  236. data/lib/stripe/services/financial_connections/session_service.rb +98 -0
  237. data/lib/stripe/services/financial_connections/transaction_service.rb +100 -0
  238. data/lib/stripe/services/financial_connections_service.rb +15 -0
  239. data/lib/stripe/services/forwarding/request_service.rb +147 -0
  240. data/lib/stripe/services/forwarding_service.rb +13 -0
  241. data/lib/stripe/services/identity/verification_report_service.rb +95 -0
  242. data/lib/stripe/services/identity/verification_session_service.rb +337 -0
  243. data/lib/stripe/services/identity_service.rb +14 -0
  244. data/lib/stripe/services/invoice_item_service.rb +395 -0
  245. data/lib/stripe/services/invoice_line_item_service.rb +252 -0
  246. data/lib/stripe/services/invoice_payment_service.rb +83 -0
  247. data/lib/stripe/services/invoice_rendering_template_service.rb +101 -0
  248. data/lib/stripe/services/invoice_service.rb +2831 -0
  249. data/lib/stripe/services/issuing/authorization_service.rb +169 -0
  250. data/lib/stripe/services/issuing/card_service.rb +507 -0
  251. data/lib/stripe/services/issuing/cardholder_service.rb +577 -0
  252. data/lib/stripe/services/issuing/dispute_service.rb +696 -0
  253. data/lib/stripe/services/issuing/personalization_design_service.rb +245 -0
  254. data/lib/stripe/services/issuing/physical_bundle_service.rb +70 -0
  255. data/lib/stripe/services/issuing/token_service.rb +114 -0
  256. data/lib/stripe/services/issuing/transaction_service.rb +118 -0
  257. data/lib/stripe/services/issuing_service.rb +20 -0
  258. data/lib/stripe/services/mandate_service.rb +26 -0
  259. data/lib/stripe/services/oauth_service.rb +63 -0
  260. data/lib/stripe/services/payment_intent_service.rb +7258 -0
  261. data/lib/stripe/services/payment_link_line_item_service.rb +35 -0
  262. data/lib/stripe/services/payment_link_service.rb +1333 -0
  263. data/lib/stripe/services/payment_method_configuration_service.rb +2054 -0
  264. data/lib/stripe/services/payment_method_domain_service.rb +142 -0
  265. data/lib/stripe/services/payment_method_service.rb +894 -0
  266. data/lib/stripe/services/payout_service.rb +225 -0
  267. data/lib/stripe/services/plan_service.rb +298 -0
  268. data/lib/stripe/services/price_service.rb +545 -0
  269. data/lib/stripe/services/product_feature_service.rb +92 -0
  270. data/lib/stripe/services/product_service.rb +495 -0
  271. data/lib/stripe/services/promotion_code_service.rb +228 -0
  272. data/lib/stripe/services/quote_computed_upfront_line_items_service.rb +35 -0
  273. data/lib/stripe/services/quote_line_item_service.rb +35 -0
  274. data/lib/stripe/services/quote_service.rb +703 -0
  275. data/lib/stripe/services/radar/early_fraud_warning_service.rb +93 -0
  276. data/lib/stripe/services/radar/value_list_item_service.rb +131 -0
  277. data/lib/stripe/services/radar/value_list_service.rb +166 -0
  278. data/lib/stripe/services/radar_service.rb +15 -0
  279. data/lib/stripe/services/refund_service.rb +200 -0
  280. data/lib/stripe/services/reporting/report_run_service.rb +147 -0
  281. data/lib/stripe/services/reporting/report_type_service.rb +48 -0
  282. data/lib/stripe/services/reporting_service.rb +14 -0
  283. data/lib/stripe/services/review_service.rb +89 -0
  284. data/lib/stripe/services/setup_attempt_service.rb +68 -0
  285. data/lib/stripe/services/setup_intent_service.rb +3268 -0
  286. data/lib/stripe/services/shipping_rate_service.rb +250 -0
  287. data/lib/stripe/services/sigma/scheduled_query_run_service.rb +57 -0
  288. data/lib/stripe/services/sigma_service.rb +13 -0
  289. data/lib/stripe/services/source_service.rb +665 -0
  290. data/lib/stripe/services/source_transaction_service.rb +35 -0
  291. data/lib/stripe/services/subscription_item_service.rb +346 -0
  292. data/lib/stripe/services/subscription_schedule_service.rb +1134 -0
  293. data/lib/stripe/services/subscription_service.rb +1539 -0
  294. data/lib/stripe/services/tax/calculation_line_item_service.rb +37 -0
  295. data/lib/stripe/services/tax/calculation_service.rb +242 -0
  296. data/lib/stripe/services/tax/registration_service.rb +1618 -0
  297. data/lib/stripe/services/tax/settings_service.rb +104 -0
  298. data/lib/stripe/services/tax/transaction_line_item_service.rb +37 -0
  299. data/lib/stripe/services/tax/transaction_service.rb +159 -0
  300. data/lib/stripe/services/tax_code_service.rb +49 -0
  301. data/lib/stripe/services/tax_id_service.rb +117 -0
  302. data/lib/stripe/services/tax_rate_service.rb +193 -0
  303. data/lib/stripe/services/tax_service.rb +16 -0
  304. data/lib/stripe/services/terminal/configuration_service.rb +1060 -0
  305. data/lib/stripe/services/terminal/connection_token_service.rb +31 -0
  306. data/lib/stripe/services/terminal/location_service.rb +208 -0
  307. data/lib/stripe/services/terminal/reader_service.rb +384 -0
  308. data/lib/stripe/services/terminal_service.rb +16 -0
  309. data/lib/stripe/services/test_helpers/confirmation_token_service.rb +661 -0
  310. data/lib/stripe/services/test_helpers/customer_service.rb +37 -0
  311. data/lib/stripe/services/test_helpers/issuing/authorization_service.rb +832 -0
  312. data/lib/stripe/services/test_helpers/issuing/card_service.rb +110 -0
  313. data/lib/stripe/services/test_helpers/issuing/personalization_design_service.rb +84 -0
  314. data/lib/stripe/services/test_helpers/issuing/transaction_service.rb +675 -0
  315. data/lib/stripe/services/test_helpers/issuing_service.rb +19 -0
  316. data/lib/stripe/services/test_helpers/refund_service.rb +28 -0
  317. data/lib/stripe/services/test_helpers/terminal/reader_service.rb +65 -0
  318. data/lib/stripe/services/test_helpers/terminal_service.rb +15 -0
  319. data/lib/stripe/services/test_helpers/test_clock_service.rb +120 -0
  320. data/lib/stripe/services/test_helpers/treasury/inbound_transfer_service.rb +81 -0
  321. data/lib/stripe/services/test_helpers/treasury/outbound_payment_service.rb +141 -0
  322. data/lib/stripe/services/test_helpers/treasury/outbound_transfer_service.rb +141 -0
  323. data/lib/stripe/services/test_helpers/treasury/received_credit_service.rb +81 -0
  324. data/lib/stripe/services/test_helpers/treasury/received_debit_service.rb +81 -0
  325. data/lib/stripe/services/test_helpers/treasury_service.rb +19 -0
  326. data/lib/stripe/services/test_helpers_service.rb +19 -0
  327. data/lib/stripe/services/token_service.rb +1163 -0
  328. data/lib/stripe/services/topup_service.rb +191 -0
  329. data/lib/stripe/services/transfer_reversal_service.rb +122 -0
  330. data/lib/stripe/services/transfer_service.rb +166 -0
  331. data/lib/stripe/services/treasury/credit_reversal_service.rb +100 -0
  332. data/lib/stripe/services/treasury/debit_reversal_service.rb +104 -0
  333. data/lib/stripe/services/treasury/financial_account_features_service.rb +196 -0
  334. data/lib/stripe/services/treasury/financial_account_service.rb +554 -0
  335. data/lib/stripe/services/treasury/inbound_transfer_service.rb +140 -0
  336. data/lib/stripe/services/treasury/outbound_payment_service.rb +310 -0
  337. data/lib/stripe/services/treasury/outbound_transfer_service.rb +176 -0
  338. data/lib/stripe/services/treasury/received_credit_service.rb +82 -0
  339. data/lib/stripe/services/treasury/received_debit_service.rb +70 -0
  340. data/lib/stripe/services/treasury/transaction_entry_service.rb +117 -0
  341. data/lib/stripe/services/treasury/transaction_service.rb +125 -0
  342. data/lib/stripe/services/treasury_service.rb +22 -0
  343. data/lib/stripe/services/v1_services.rb +90 -0
  344. data/lib/stripe/services/v2/billing/meter_event_adjustment_service.rb +44 -0
  345. data/lib/stripe/services/v2/billing/meter_event_service.rb +46 -0
  346. data/lib/stripe/services/v2/billing/meter_event_session_service.rb +24 -0
  347. data/lib/stripe/services/v2/billing/meter_event_stream_service.rb +56 -0
  348. data/lib/stripe/services/v2/billing_service.rb +18 -0
  349. data/lib/stripe/services/v2/core/event_destination_service.rb +241 -0
  350. data/lib/stripe/services/v2/core/event_service.rb +49 -0
  351. data/lib/stripe/services/v2/core_service.rb +16 -0
  352. data/lib/stripe/services/v2_services.rb +14 -0
  353. data/lib/stripe/services/webhook_endpoint_service.rb +157 -0
  354. data/lib/stripe/services.rb +180 -0
  355. data/lib/stripe/singleton_api_resource.rb +1 -18
  356. data/lib/stripe/stripe_client.rb +53 -1031
  357. data/lib/stripe/stripe_configuration.rb +52 -19
  358. data/lib/stripe/stripe_object.rb +54 -20
  359. data/lib/stripe/stripe_service.rb +32 -0
  360. data/lib/stripe/thin_event.rb +37 -0
  361. data/lib/stripe/util.rb +78 -37
  362. data/lib/stripe/v2_list_object.rb +84 -0
  363. data/lib/stripe/version.rb +1 -1
  364. data/lib/stripe/webhook.rb +1 -1
  365. data/lib/stripe.rb +38 -25
  366. data/rbi/stripe/resources/account.rbi +4840 -0
  367. data/rbi/stripe/resources/account_link.rbi +74 -0
  368. data/rbi/stripe/resources/account_session.rbi +894 -0
  369. data/rbi/stripe/resources/apple_pay_domain.rbi +90 -0
  370. data/rbi/stripe/resources/application.rbi +20 -0
  371. data/rbi/stripe/resources/application_fee.rbi +118 -0
  372. data/rbi/stripe/resources/application_fee_refund.rbi +37 -0
  373. data/rbi/stripe/resources/apps/secret.rbi +195 -0
  374. data/rbi/stripe/resources/balance.rbi +180 -0
  375. data/rbi/stripe/resources/balance_transaction.rbi +144 -0
  376. data/rbi/stripe/resources/bank_account.rbi +127 -0
  377. data/rbi/stripe/resources/billing/alert.rbi +201 -0
  378. data/rbi/stripe/resources/billing/alert_triggered.rbi +28 -0
  379. data/rbi/stripe/resources/billing/credit_balance_summary.rbi +63 -0
  380. data/rbi/stripe/resources/billing/credit_balance_transaction.rbi +147 -0
  381. data/rbi/stripe/resources/billing/credit_grant.rbi +291 -0
  382. data/rbi/stripe/resources/billing/meter.rbi +226 -0
  383. data/rbi/stripe/resources/billing/meter_event.rbi +64 -0
  384. data/rbi/stripe/resources/billing/meter_event_adjustment.rbi +64 -0
  385. data/rbi/stripe/resources/billing/meter_event_summary.rbi +35 -0
  386. data/rbi/stripe/resources/billing_portal/configuration.rbi +645 -0
  387. data/rbi/stripe/resources/billing_portal/session.rbi +345 -0
  388. data/rbi/stripe/resources/capability.rbi +125 -0
  389. data/rbi/stripe/resources/card.rbi +125 -0
  390. data/rbi/stripe/resources/cash_balance.rbi +32 -0
  391. data/rbi/stripe/resources/charge.rbi +2054 -0
  392. data/rbi/stripe/resources/checkout/session.rbi +3951 -0
  393. data/rbi/stripe/resources/climate/order.rbi +245 -0
  394. data/rbi/stripe/resources/climate/product.rbi +75 -0
  395. data/rbi/stripe/resources/climate/supplier.rbi +72 -0
  396. data/rbi/stripe/resources/confirmation_token.rbi +1793 -0
  397. data/rbi/stripe/resources/connect_collection_transfer.rbi +26 -0
  398. data/rbi/stripe/resources/country_spec.rbi +85 -0
  399. data/rbi/stripe/resources/coupon.rbi +252 -0
  400. data/rbi/stripe/resources/credit_note.rbi +747 -0
  401. data/rbi/stripe/resources/credit_note_line_item.rbi +101 -0
  402. data/rbi/stripe/resources/customer.rbi +1009 -0
  403. data/rbi/stripe/resources/customer_balance_transaction.rbi +56 -0
  404. data/rbi/stripe/resources/customer_cash_balance_transaction.rbi +151 -0
  405. data/rbi/stripe/resources/customer_session.rbi +200 -0
  406. data/rbi/stripe/resources/discount.rbi +53 -0
  407. data/rbi/stripe/resources/dispute.rbi +761 -0
  408. data/rbi/stripe/resources/entitlements/active_entitlement.rbi +58 -0
  409. data/rbi/stripe/resources/entitlements/active_entitlement_summary.rbi +23 -0
  410. data/rbi/stripe/resources/entitlements/feature.rbi +117 -0
  411. data/rbi/stripe/resources/ephemeral_key.rbi +44 -0
  412. data/rbi/stripe/resources/event.rbi +146 -0
  413. data/rbi/stripe/resources/exchange_rate.rbi +66 -0
  414. data/rbi/stripe/resources/file.rbi +143 -0
  415. data/rbi/stripe/resources/file_link.rbi +141 -0
  416. data/rbi/stripe/resources/financial_connections/account.rbi +339 -0
  417. data/rbi/stripe/resources/financial_connections/account_owner.rbi +35 -0
  418. data/rbi/stripe/resources/financial_connections/account_ownership.rbi +23 -0
  419. data/rbi/stripe/resources/financial_connections/session.rbi +123 -0
  420. data/rbi/stripe/resources/financial_connections/transaction.rbi +124 -0
  421. data/rbi/stripe/resources/forwarding/request.rbi +216 -0
  422. data/rbi/stripe/resources/funding_instructions.rbi +437 -0
  423. data/rbi/stripe/resources/identity/verification_report.rbi +351 -0
  424. data/rbi/stripe/resources/identity/verification_session.rbi +517 -0
  425. data/rbi/stripe/resources/invoice.rbi +3733 -0
  426. data/rbi/stripe/resources/invoice_item.rbi +475 -0
  427. data/rbi/stripe/resources/invoice_line_item.rbi +432 -0
  428. data/rbi/stripe/resources/invoice_payment.rbi +114 -0
  429. data/rbi/stripe/resources/invoice_rendering_template.rbi +104 -0
  430. data/rbi/stripe/resources/issuing/authorization.rbi +1283 -0
  431. data/rbi/stripe/resources/issuing/card.rbi +741 -0
  432. data/rbi/stripe/resources/issuing/cardholder.rbi +744 -0
  433. data/rbi/stripe/resources/issuing/dispute.rbi +913 -0
  434. data/rbi/stripe/resources/issuing/personalization_design.rbi +338 -0
  435. data/rbi/stripe/resources/issuing/physical_bundle.rbi +79 -0
  436. data/rbi/stripe/resources/issuing/token.rbi +226 -0
  437. data/rbi/stripe/resources/issuing/transaction.rbi +1061 -0
  438. data/rbi/stripe/resources/line_item.rbi +72 -0
  439. data/rbi/stripe/resources/login_link.rbi +18 -0
  440. data/rbi/stripe/resources/mandate.rbi +187 -0
  441. data/rbi/stripe/resources/payment_intent.rbi +9731 -0
  442. data/rbi/stripe/resources/payment_link.rbi +1801 -0
  443. data/rbi/stripe/resources/payment_method.rbi +1822 -0
  444. data/rbi/stripe/resources/payment_method_configuration.rbi +3154 -0
  445. data/rbi/stripe/resources/payment_method_domain.rbi +212 -0
  446. data/rbi/stripe/resources/payout.rbi +300 -0
  447. data/rbi/stripe/resources/person.rbi +371 -0
  448. data/rbi/stripe/resources/plan.rbi +373 -0
  449. data/rbi/stripe/resources/price.rbi +694 -0
  450. data/rbi/stripe/resources/product.rbi +557 -0
  451. data/rbi/stripe/resources/product_feature.rbi +26 -0
  452. data/rbi/stripe/resources/promotion_code.rbi +261 -0
  453. data/rbi/stripe/resources/quote.rbi +1123 -0
  454. data/rbi/stripe/resources/radar/early_fraud_warning.rbi +98 -0
  455. data/rbi/stripe/resources/radar/value_list.rbi +170 -0
  456. data/rbi/stripe/resources/radar/value_list_item.rbi +131 -0
  457. data/rbi/stripe/resources/refund.rbi +516 -0
  458. data/rbi/stripe/resources/reporting/report_run.rbi +191 -0
  459. data/rbi/stripe/resources/reporting/report_type.rbi +57 -0
  460. data/rbi/stripe/resources/reserve_transaction.rbi +23 -0
  461. data/rbi/stripe/resources/reversal.rbi +51 -0
  462. data/rbi/stripe/resources/review.rbi +154 -0
  463. data/rbi/stripe/resources/setup_attempt.rbi +477 -0
  464. data/rbi/stripe/resources/setup_intent.rbi +3860 -0
  465. data/rbi/stripe/resources/shipping_rate.rbi +305 -0
  466. data/rbi/stripe/resources/sigma/scheduled_query_run.rbi +75 -0
  467. data/rbi/stripe/resources/source.rbi +1496 -0
  468. data/rbi/stripe/resources/source_mandate_notification.rbi +77 -0
  469. data/rbi/stripe/resources/source_transaction.rbi +127 -0
  470. data/rbi/stripe/resources/subscription.rbi +1964 -0
  471. data/rbi/stripe/resources/subscription_item.rbi +370 -0
  472. data/rbi/stripe/resources/subscription_schedule.rbi +1495 -0
  473. data/rbi/stripe/resources/tax/calculation.rbi +474 -0
  474. data/rbi/stripe/resources/tax/calculation_line_item.rbi +88 -0
  475. data/rbi/stripe/resources/tax/registration.rbi +2485 -0
  476. data/rbi/stripe/resources/tax/settings.rbi +141 -0
  477. data/rbi/stripe/resources/tax/transaction.rbi +351 -0
  478. data/rbi/stripe/resources/tax/transaction_line_item.rbi +54 -0
  479. data/rbi/stripe/resources/tax_code.rbi +44 -0
  480. data/rbi/stripe/resources/tax_deducted_at_source.rbi +23 -0
  481. data/rbi/stripe/resources/tax_id.rbi +167 -0
  482. data/rbi/stripe/resources/tax_rate.rbi +239 -0
  483. data/rbi/stripe/resources/terminal/configuration.rbi +1388 -0
  484. data/rbi/stripe/resources/terminal/connection_token.rbi +37 -0
  485. data/rbi/stripe/resources/terminal/location.rbi +224 -0
  486. data/rbi/stripe/resources/terminal/reader.rbi +587 -0
  487. data/rbi/stripe/resources/test_helpers/test_clock.rbi +134 -0
  488. data/rbi/stripe/resources/token.rbi +1217 -0
  489. data/rbi/stripe/resources/topup.rbi +222 -0
  490. data/rbi/stripe/resources/transfer.rbi +199 -0
  491. data/rbi/stripe/resources/treasury/credit_reversal.rbi +119 -0
  492. data/rbi/stripe/resources/treasury/debit_reversal.rbi +131 -0
  493. data/rbi/stripe/resources/treasury/financial_account.rbi +865 -0
  494. data/rbi/stripe/resources/treasury/financial_account_features.rbi +260 -0
  495. data/rbi/stripe/resources/treasury/inbound_transfer.rbi +295 -0
  496. data/rbi/stripe/resources/treasury/outbound_payment.rbi +592 -0
  497. data/rbi/stripe/resources/treasury/outbound_transfer.rbi +431 -0
  498. data/rbi/stripe/resources/treasury/received_credit.rbi +302 -0
  499. data/rbi/stripe/resources/treasury/received_debit.rbi +256 -0
  500. data/rbi/stripe/resources/treasury/transaction.rbi +215 -0
  501. data/rbi/stripe/resources/treasury/transaction_entry.rbi +192 -0
  502. data/rbi/stripe/resources/v2/amount.rbi +14 -0
  503. data/rbi/stripe/resources/v2/billing/meter_event.rbi +37 -0
  504. data/rbi/stripe/resources/v2/billing/meter_event_adjustment.rbi +41 -0
  505. data/rbi/stripe/resources/v2/billing/meter_event_session.rbi +31 -0
  506. data/rbi/stripe/resources/v2/event.rbi +48 -0
  507. data/rbi/stripe/resources/v2/event_destination.rbi +91 -0
  508. data/rbi/stripe/resources/webhook_endpoint.rbi +170 -0
  509. data/rbi/stripe/services/account_capability_service.rbi +51 -0
  510. data/rbi/stripe/services/account_external_account_service.rbi +306 -0
  511. data/rbi/stripe/services/account_link_service.rbi +58 -0
  512. data/rbi/stripe/services/account_login_link_service.rbi +22 -0
  513. data/rbi/stripe/services/account_person_service.rbi +923 -0
  514. data/rbi/stripe/services/account_service.rbi +4143 -0
  515. data/rbi/stripe/services/account_session_service.rbi +572 -0
  516. data/rbi/stripe/services/apple_pay_domain_service.rbi +78 -0
  517. data/rbi/stripe/services/application_fee_refund_service.rbi +93 -0
  518. data/rbi/stripe/services/application_fee_service.rbi +78 -0
  519. data/rbi/stripe/services/apps/secret_service.rbi +151 -0
  520. data/rbi/stripe/services/apps_service.rbi +9 -0
  521. data/rbi/stripe/services/balance_service.rbi +21 -0
  522. data/rbi/stripe/services/balance_transaction_service.rbi +93 -0
  523. data/rbi/stripe/services/billing/alert_service.rbi +152 -0
  524. data/rbi/stripe/services/billing/credit_balance_summary_service.rbi +68 -0
  525. data/rbi/stripe/services/billing/credit_balance_transaction_service.rbi +59 -0
  526. data/rbi/stripe/services/billing/credit_grant_service.rbi +211 -0
  527. data/rbi/stripe/services/billing/meter_event_adjustment_service.rbi +42 -0
  528. data/rbi/stripe/services/billing/meter_event_service.rbi +42 -0
  529. data/rbi/stripe/services/billing/meter_event_summary_service.rbi +54 -0
  530. data/rbi/stripe/services/billing/meter_service.rbi +163 -0
  531. data/rbi/stripe/services/billing_portal/configuration_service.rbi +511 -0
  532. data/rbi/stripe/services/billing_portal/session_service.rbi +204 -0
  533. data/rbi/stripe/services/billing_portal_service.rbi +10 -0
  534. data/rbi/stripe/services/billing_service.rbi +15 -0
  535. data/rbi/stripe/services/charge_service.rbi +448 -0
  536. data/rbi/stripe/services/checkout/session_line_item_service.rbi +33 -0
  537. data/rbi/stripe/services/checkout/session_service.rbi +2585 -0
  538. data/rbi/stripe/services/checkout_service.rbi +9 -0
  539. data/rbi/stripe/services/climate/order_service.rbi +142 -0
  540. data/rbi/stripe/services/climate/product_service.rbi +46 -0
  541. data/rbi/stripe/services/climate/supplier_service.rbi +46 -0
  542. data/rbi/stripe/services/climate_service.rbi +11 -0
  543. data/rbi/stripe/services/confirmation_token_service.rbi +20 -0
  544. data/rbi/stripe/services/country_spec_service.rbi +44 -0
  545. data/rbi/stripe/services/coupon_service.rbi +196 -0
  546. data/rbi/stripe/services/credit_note_line_item_service.rbi +31 -0
  547. data/rbi/stripe/services/credit_note_preview_lines_service.rbi +167 -0
  548. data/rbi/stripe/services/credit_note_service.rbi +416 -0
  549. data/rbi/stripe/services/customer_balance_transaction_service.rbi +92 -0
  550. data/rbi/stripe/services/customer_cash_balance_service.rbi +45 -0
  551. data/rbi/stripe/services/customer_cash_balance_transaction_service.rbi +44 -0
  552. data/rbi/stripe/services/customer_funding_instructions_service.rbi +59 -0
  553. data/rbi/stripe/services/customer_payment_method_service.rbi +57 -0
  554. data/rbi/stripe/services/customer_payment_source_service.rbi +232 -0
  555. data/rbi/stripe/services/customer_service.rbi +651 -0
  556. data/rbi/stripe/services/customer_session_service.rbi +116 -0
  557. data/rbi/stripe/services/customer_tax_id_service.rbi +72 -0
  558. data/rbi/stripe/services/dispute_service.rbi +424 -0
  559. data/rbi/stripe/services/entitlements/active_entitlement_service.rbi +55 -0
  560. data/rbi/stripe/services/entitlements/feature_service.rbi +107 -0
  561. data/rbi/stripe/services/entitlements_service.rbi +10 -0
  562. data/rbi/stripe/services/ephemeral_key_service.rbi +53 -0
  563. data/rbi/stripe/services/event_service.rbi +83 -0
  564. data/rbi/stripe/services/exchange_rate_service.rbi +44 -0
  565. data/rbi/stripe/services/file_link_service.rbi +124 -0
  566. data/rbi/stripe/services/file_service.rbi +116 -0
  567. data/rbi/stripe/services/financial_connections/account_owner_service.rbi +42 -0
  568. data/rbi/stripe/services/financial_connections/account_service.rbi +133 -0
  569. data/rbi/stripe/services/financial_connections/session_service.rbi +88 -0
  570. data/rbi/stripe/services/financial_connections/transaction_service.rbi +92 -0
  571. data/rbi/stripe/services/financial_connections_service.rbi +11 -0
  572. data/rbi/stripe/services/forwarding/request_service.rbi +134 -0
  573. data/rbi/stripe/services/forwarding_service.rbi +9 -0
  574. data/rbi/stripe/services/identity/verification_report_service.rbi +87 -0
  575. data/rbi/stripe/services/identity/verification_session_service.rbi +323 -0
  576. data/rbi/stripe/services/identity_service.rbi +10 -0
  577. data/rbi/stripe/services/invoice_item_service.rbi +368 -0
  578. data/rbi/stripe/services/invoice_line_item_service.rbi +259 -0
  579. data/rbi/stripe/services/invoice_payment_service.rbi +71 -0
  580. data/rbi/stripe/services/invoice_rendering_template_service.rbi +82 -0
  581. data/rbi/stripe/services/invoice_service.rbi +2920 -0
  582. data/rbi/stripe/services/issuing/authorization_service.rbi +146 -0
  583. data/rbi/stripe/services/issuing/card_service.rbi +495 -0
  584. data/rbi/stripe/services/issuing/cardholder_service.rbi +587 -0
  585. data/rbi/stripe/services/issuing/dispute_service.rbi +707 -0
  586. data/rbi/stripe/services/issuing/personalization_design_service.rbi +243 -0
  587. data/rbi/stripe/services/issuing/physical_bundle_service.rbi +59 -0
  588. data/rbi/stripe/services/issuing/token_service.rbi +99 -0
  589. data/rbi/stripe/services/issuing/transaction_service.rbi +105 -0
  590. data/rbi/stripe/services/issuing_service.rbi +16 -0
  591. data/rbi/stripe/services/mandate_service.rbi +20 -0
  592. data/rbi/stripe/services/payment_intent_service.rbi +7759 -0
  593. data/rbi/stripe/services/payment_link_line_item_service.rbi +31 -0
  594. data/rbi/stripe/services/payment_link_service.rbi +1352 -0
  595. data/rbi/stripe/services/payment_method_configuration_service.rbi +2211 -0
  596. data/rbi/stripe/services/payment_method_domain_service.rbi +112 -0
  597. data/rbi/stripe/services/payment_method_service.rbi +840 -0
  598. data/rbi/stripe/services/payout_service.rbi +205 -0
  599. data/rbi/stripe/services/plan_service.rbi +284 -0
  600. data/rbi/stripe/services/price_service.rbi +546 -0
  601. data/rbi/stripe/services/product_feature_service.rbi +69 -0
  602. data/rbi/stripe/services/product_service.rbi +479 -0
  603. data/rbi/stripe/services/promotion_code_service.rbi +214 -0
  604. data/rbi/stripe/services/quote_computed_upfront_line_items_service.rbi +31 -0
  605. data/rbi/stripe/services/quote_line_item_service.rbi +31 -0
  606. data/rbi/stripe/services/quote_service.rbi +686 -0
  607. data/rbi/stripe/services/radar/early_fraud_warning_service.rbi +85 -0
  608. data/rbi/stripe/services/radar/value_list_item_service.rbi +111 -0
  609. data/rbi/stripe/services/radar/value_list_service.rbi +143 -0
  610. data/rbi/stripe/services/radar_service.rbi +11 -0
  611. data/rbi/stripe/services/refund_service.rbi +185 -0
  612. data/rbi/stripe/services/reporting/report_run_service.rbi +135 -0
  613. data/rbi/stripe/services/reporting/report_type_service.rbi +35 -0
  614. data/rbi/stripe/services/reporting_service.rbi +10 -0
  615. data/rbi/stripe/services/review_service.rbi +84 -0
  616. data/rbi/stripe/services/setup_attempt_service.rbi +65 -0
  617. data/rbi/stripe/services/setup_intent_service.rbi +3596 -0
  618. data/rbi/stripe/services/shipping_rate_service.rbi +241 -0
  619. data/rbi/stripe/services/sigma/scheduled_query_run_service.rbi +46 -0
  620. data/rbi/stripe/services/sigma_service.rbi +9 -0
  621. data/rbi/stripe/services/source_service.rbi +663 -0
  622. data/rbi/stripe/services/source_transaction_service.rbi +31 -0
  623. data/rbi/stripe/services/subscription_item_service.rbi +324 -0
  624. data/rbi/stripe/services/subscription_schedule_service.rbi +1192 -0
  625. data/rbi/stripe/services/subscription_service.rbi +1596 -0
  626. data/rbi/stripe/services/tax/calculation_line_item_service.rbi +33 -0
  627. data/rbi/stripe/services/tax/calculation_service.rbi +230 -0
  628. data/rbi/stripe/services/tax/registration_service.rbi +1689 -0
  629. data/rbi/stripe/services/tax/settings_service.rbi +93 -0
  630. data/rbi/stripe/services/tax/transaction_line_item_service.rbi +33 -0
  631. data/rbi/stripe/services/tax/transaction_service.rbi +146 -0
  632. data/rbi/stripe/services/tax_code_service.rbi +44 -0
  633. data/rbi/stripe/services/tax_id_service.rbi +112 -0
  634. data/rbi/stripe/services/tax_rate_service.rbi +185 -0
  635. data/rbi/stripe/services/tax_service.rbi +12 -0
  636. data/rbi/stripe/services/terminal/configuration_service.rbi +1120 -0
  637. data/rbi/stripe/services/terminal/connection_token_service.rbi +25 -0
  638. data/rbi/stripe/services/terminal/location_service.rbi +184 -0
  639. data/rbi/stripe/services/terminal/reader_service.rbi +344 -0
  640. data/rbi/stripe/services/terminal_service.rbi +12 -0
  641. data/rbi/stripe/services/test_helpers/confirmation_token_service.rbi +746 -0
  642. data/rbi/stripe/services/test_helpers/customer_service.rbi +33 -0
  643. data/rbi/stripe/services/test_helpers/issuing/authorization_service.rbi +848 -0
  644. data/rbi/stripe/services/test_helpers/issuing/card_service.rbi +76 -0
  645. data/rbi/stripe/services/test_helpers/issuing/personalization_design_service.rbi +69 -0
  646. data/rbi/stripe/services/test_helpers/issuing/transaction_service.rbi +711 -0
  647. data/rbi/stripe/services/test_helpers/issuing_service.rbi +14 -0
  648. data/rbi/stripe/services/test_helpers/refund_service.rbi +22 -0
  649. data/rbi/stripe/services/test_helpers/terminal/reader_service.rbi +62 -0
  650. data/rbi/stripe/services/test_helpers/terminal_service.rbi +11 -0
  651. data/rbi/stripe/services/test_helpers/test_clock_service.rbi +92 -0
  652. data/rbi/stripe/services/test_helpers/treasury/inbound_transfer_service.rbi +64 -0
  653. data/rbi/stripe/services/test_helpers/treasury/outbound_payment_service.rbi +125 -0
  654. data/rbi/stripe/services/test_helpers/treasury/outbound_transfer_service.rbi +125 -0
  655. data/rbi/stripe/services/test_helpers/treasury/received_credit_service.rbi +87 -0
  656. data/rbi/stripe/services/test_helpers/treasury/received_debit_service.rbi +87 -0
  657. data/rbi/stripe/services/test_helpers/treasury_service.rbi +15 -0
  658. data/rbi/stripe/services/test_helpers_service.rbi +15 -0
  659. data/rbi/stripe/services/token_service.rbi +1189 -0
  660. data/rbi/stripe/services/topup_service.rbi +176 -0
  661. data/rbi/stripe/services/transfer_reversal_service.rbi +101 -0
  662. data/rbi/stripe/services/transfer_service.rbi +152 -0
  663. data/rbi/stripe/services/treasury/credit_reversal_service.rbi +84 -0
  664. data/rbi/stripe/services/treasury/debit_reversal_service.rbi +88 -0
  665. data/rbi/stripe/services/treasury/financial_account_features_service.rbi +198 -0
  666. data/rbi/stripe/services/treasury/financial_account_service.rbi +562 -0
  667. data/rbi/stripe/services/treasury/inbound_transfer_service.rbi +117 -0
  668. data/rbi/stripe/services/treasury/outbound_payment_service.rbi +304 -0
  669. data/rbi/stripe/services/treasury/outbound_transfer_service.rbi +157 -0
  670. data/rbi/stripe/services/treasury/received_credit_service.rbi +72 -0
  671. data/rbi/stripe/services/treasury/received_debit_service.rbi +59 -0
  672. data/rbi/stripe/services/treasury/transaction_entry_service.rbi +111 -0
  673. data/rbi/stripe/services/treasury/transaction_service.rbi +122 -0
  674. data/rbi/stripe/services/treasury_service.rbi +18 -0
  675. data/rbi/stripe/services/v1_services.rbi +77 -0
  676. data/rbi/stripe/services/v2/billing/meter_event_adjustment_service.rbi +39 -0
  677. data/rbi/stripe/services/v2/billing/meter_event_service.rbi +42 -0
  678. data/rbi/stripe/services/v2/billing/meter_event_session_service.rbi +20 -0
  679. data/rbi/stripe/services/v2/billing/meter_event_stream_service.rbi +55 -0
  680. data/rbi/stripe/services/v2/billing_service.rbi +14 -0
  681. data/rbi/stripe/services/v2/core/event_destination_service.rbi +200 -0
  682. data/rbi/stripe/services/v2/core/event_service.rbi +38 -0
  683. data/rbi/stripe/services/v2/core_service.rbi +12 -0
  684. data/rbi/stripe/services/v2_services.rbi +10 -0
  685. data/rbi/stripe/services/webhook_endpoint_service.rbi +131 -0
  686. metadata +533 -4
  687. data/lib/stripe/resources/usage_record.rb +0 -17
  688. data/lib/stripe/resources/usage_record_summary.rb +0 -11
@@ -1,1066 +1,88 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "stripe/instrumentation"
3
+ require "json"
4
4
 
5
5
  module Stripe
6
- # StripeClient executes requests against the Stripe API and allows a user to
7
- # recover both a resource a call returns as well as a response object that
8
- # contains information on the HTTP call.
9
6
  class StripeClient
10
- # A set of all known thread contexts across all threads and a mutex to
11
- # synchronize global access to them.
12
- @thread_contexts_with_connection_managers = Set.new
13
- @thread_contexts_with_connection_managers_mutex = Mutex.new
14
- @last_connection_manager_gc = Util.monotonic_time
7
+ # attr_readers: The beginning of the section generated from our OpenAPI spec
8
+ attr_reader :v1
9
+ attr_reader :v2
15
10
 
16
- # Initializes a new StripeClient
17
- def initialize(config_arg = {})
18
- @system_profiler = SystemProfiler.new
19
- @last_request_metrics = nil
20
-
21
- # The following attribute is only used to log whether or not
22
- # StripeClient#request has been called. To be removed in a
23
- # future major version.
24
- @usage = []
25
-
26
- @config = case config_arg
27
- when Hash
28
- Stripe.config.reverse_duplicate_merge(config_arg)
29
- when Stripe::ConnectionManager
30
- # Supports accepting a connection manager object for backwards
31
- # compatibility only, and that use is DEPRECATED.
32
- Stripe.config.dup
33
- when Stripe::StripeConfiguration
34
- config_arg
35
- when String
36
- Stripe.config.reverse_duplicate_merge(
37
- { api_key: config_arg }
38
- )
39
- else
40
- raise ArgumentError, "Can't handle argument: #{config_arg}"
41
- end
42
- end
43
-
44
- attr_reader :config, :options
45
-
46
- # Gets a currently active `StripeClient`. Set for the current thread when
47
- # `StripeClient#request` is being run so that API operations being executed
48
- # inside of that block can find the currently active client. It's reset to
49
- # the original value (hopefully `nil`) after the block ends.
50
- #
51
- # For internal use only. Does not provide a stable API and may be broken
52
- # with future non-major changes.
53
- def self.active_client
54
- current_thread_context.active_client || default_client
55
- end
56
-
57
- # Finishes any active connections by closing their TCP connection and
58
- # clears them from internal tracking in all connection managers across all
59
- # threads.
60
- #
61
- # If passed a `config` object, only clear connection managers for that
62
- # particular configuration.
63
- #
64
- # For internal use only. Does not provide a stable API and may be broken
65
- # with future non-major changes.
66
- def self.clear_all_connection_managers(config: nil)
67
- # Just a quick path for when configuration is being set for the first
68
- # time before any connections have been opened. There is technically some
69
- # potential for thread raciness here, but not in a practical sense.
70
- return if @thread_contexts_with_connection_managers.empty?
71
-
72
- @thread_contexts_with_connection_managers_mutex.synchronize do
73
- pruned_contexts = Set.new
74
-
75
- @thread_contexts_with_connection_managers.each do |thread_context|
76
- # Note that the thread context itself is not destroyed, but we clear
77
- # its connection manager and remove our reference to it. If it ever
78
- # makes a new request we'll give it a new connection manager and
79
- # it'll go back into `@thread_contexts_with_connection_managers`.
80
- thread_context.default_connection_managers.reject! do |cm_config, cm|
81
- if config.nil? || config.key == cm_config
82
- cm.clear
83
- true
84
- end
85
- end
86
-
87
- pruned_contexts << thread_context if thread_context.default_connection_managers.empty?
88
- end
89
-
90
- @thread_contexts_with_connection_managers.subtract(pruned_contexts)
91
- end
92
- end
93
-
94
- # A default client for the current thread.
95
- def self.default_client
96
- current_thread_context.default_client ||= StripeClient.new(Stripe.config)
97
- end
98
-
99
- # A default connection manager for the current thread scoped to the
100
- # configuration object that may be provided.
101
- def self.default_connection_manager(config = Stripe.config)
102
- current_thread_context.default_connection_managers[config.key] ||= begin
103
- connection_manager = ConnectionManager.new(config)
104
-
105
- @thread_contexts_with_connection_managers_mutex.synchronize do
106
- maybe_gc_connection_managers
107
- @thread_contexts_with_connection_managers << current_thread_context
108
- end
109
-
110
- connection_manager
111
- end
112
- end
113
-
114
- # Checks if an error is a problem that we should retry on. This includes
115
- # both socket errors that may represent an intermittent problem and some
116
- # special HTTP statuses.
117
- def self.should_retry?(error,
118
- num_retries:, config: Stripe.config)
119
- return false if num_retries >= config.max_network_retries
120
-
121
- case error
122
- when Net::OpenTimeout, Net::ReadTimeout
123
- # Retry on timeout-related problems (either on open or read).
124
- true
125
- when EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, # rubocop:todo Lint/DuplicateBranch
126
- Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
127
- # Destination refused the connection, the connection was reset, or a
128
- # variety of other connection failures. This could occur from a single
129
- # saturated server, so retry in case it's intermittent.
130
- true
131
- when Stripe::StripeError
132
- # The API may ask us not to retry (e.g. if doing so would be a no-op),
133
- # or advise us to retry (e.g. in cases of lock timeouts). Defer to
134
- # those instructions if given.
135
- return false if error.http_headers["stripe-should-retry"] == "false"
136
- return true if error.http_headers["stripe-should-retry"] == "true"
137
-
138
- # 409 Conflict
139
- return true if error.http_status == 409
140
-
141
- # 429 Too Many Requests
142
- #
143
- # There are a few different problems that can lead to a 429. The most
144
- # common is rate limiting, on which we *don't* want to retry because
145
- # that'd likely contribute to more contention problems. However, some
146
- # 429s are lock timeouts, which is when a request conflicted with
147
- # another request or an internal process on some particular object.
148
- # These 429s are safe to retry.
149
- return true if error.http_status == 429 && error.code == "lock_timeout"
150
-
151
- # Retry on 500, 503, and other internal errors.
152
- #
153
- # Note that we expect the stripe-should-retry header to be false
154
- # in most cases when a 500 is returned, since our idempotency framework
155
- # would typically replay it anyway.
156
- true if error.http_status >= 500
157
- else
158
- false
159
- end
160
- end
161
-
162
- def self.sleep_time(num_retries, config: Stripe.config)
163
- # Apply exponential backoff with initial_network_retry_delay on the
164
- # number of num_retries so far as inputs. Do not allow the number to
165
- # exceed max_network_retry_delay.
166
- sleep_seconds = [
167
- config.initial_network_retry_delay * (2**(num_retries - 1)),
168
- config.max_network_retry_delay,
169
- ].min
170
-
171
- # Apply some jitter by randomizing the value in the range of
172
- # (sleep_seconds / 2) to (sleep_seconds).
173
- sleep_seconds *= (0.5 * (1 + rand))
174
-
175
- # But never sleep less than the base sleep seconds.
176
- [config.initial_network_retry_delay, sleep_seconds].max
177
- end
178
-
179
- # Gets the connection manager in use for the current `StripeClient`.
180
- #
181
- # This method is DEPRECATED and for backwards compatibility only.
182
- def connection_manager
183
- self.class.default_connection_manager
184
- end
185
- extend Gem::Deprecate
186
- deprecate :connection_manager, :none, 2020, 9
187
-
188
- # Executes the API call within the given block. Usage looks like:
189
- #
190
- # client = StripeClient.new
191
- # charge, resp = client.request { Charge.create }
192
- #
193
-
194
- def request
195
- @usage = ["stripe_client_request"]
196
- old_stripe_client = self.class.current_thread_context.active_client
197
- self.class.current_thread_context.active_client = self
198
-
199
- if self.class.current_thread_context.last_responses&.key?(object_id)
200
- raise "calls to StripeClient#request cannot be nested within a thread"
201
- end
202
-
203
- self.class.current_thread_context.last_responses ||= {}
204
- self.class.current_thread_context.last_responses[object_id] = nil
205
-
206
- begin
207
- res = yield
208
- [res, self.class.current_thread_context.last_responses[object_id]]
209
- ensure
210
- @usage = []
211
- self.class.current_thread_context.active_client = old_stripe_client
212
- self.class.current_thread_context.last_responses.delete(object_id)
213
- end
214
- end
215
- deprecate :request, "the `last_response` property on the returned resource (see " \
216
- "https://github.com/stripe/stripe-ruby?tab=readme-ov-file#accessing-a-response-object " \
217
- "for usage examples)", 2024, 6
218
-
219
- def execute_request(method, path,
220
- api_base: nil, api_key: nil, headers: {}, params: {}, usage: [])
221
- http_resp, api_key = execute_request_internal(
222
- method, path, api_base, api_key, headers, params, usage
223
- )
224
-
225
- begin
226
- resp = StripeResponse.from_net_http(http_resp)
227
- rescue JSON::ParserError
228
- raise general_api_error(http_resp.code.to_i, http_resp.body)
229
- end
230
-
231
- # If being called from `StripeClient#request`, put the last response in
232
- # thread-local memory so that it can be returned to the user. Don't store
233
- # anything otherwise so that we don't leak memory.
234
- store_last_response(object_id, resp)
235
-
236
- [resp, api_key]
237
- end
238
-
239
- # Executes a request and returns the body as a stream instead of converting
240
- # it to a StripeObject. This should be used for any request where we expect
241
- # an arbitrary binary response.
242
- #
243
- # A `read_body_chunk` block can be passed, which will be called repeatedly
244
- # with the body chunks read from the socket.
245
- #
246
- # If a block is passed, a StripeHeadersOnlyResponse is returned as the
247
- # block is expected to do all the necessary body processing. If no block is
248
- # passed, then a StripeStreamResponse is returned containing an IO stream
249
- # with the response body.
250
- def execute_request_stream(method, path,
251
- api_base: nil, api_key: nil, usage: [],
252
- headers: {}, params: {},
253
- &read_body_chunk_block)
254
- unless block_given?
255
- raise ArgumentError,
256
- "execute_request_stream requires a read_body_chunk_block"
257
- end
11
+ # attr_readers: The end of the section generated from our OpenAPI spec
258
12
 
259
- http_resp, api_key = execute_request_internal(
260
- method, path, api_base, api_key, headers, params, usage, &read_body_chunk_block
261
- )
262
-
263
- # When the read_body_chunk_block is given, we no longer have access to the
264
- # response body at this point and so return a response object containing
265
- # only the headers. This is because the body was consumed by the block.
266
- resp = StripeHeadersOnlyResponse.from_net_http(http_resp)
267
-
268
- [resp, api_key]
269
- end
270
-
271
- def store_last_response(object_id, resp)
272
- return unless last_response_has_key?(object_id)
273
-
274
- self.class.current_thread_context.last_responses[object_id] = resp
275
- end
276
-
277
- def last_response_has_key?(object_id)
278
- self.class.current_thread_context.last_responses&.key?(object_id)
279
- end
280
-
281
- #
282
- # private
283
- #
284
-
285
- # Time (in seconds) that a connection manager has not been used before it's
286
- # eligible for garbage collection.
287
- CONNECTION_MANAGER_GC_LAST_USED_EXPIRY = 120
288
-
289
- # How often to check (in seconds) for connection managers that haven't been
290
- # used in a long time and which should be garbage collected.
291
- CONNECTION_MANAGER_GC_PERIOD = 60
292
-
293
- ERROR_MESSAGE_CONNECTION =
294
- "Unexpected error communicating when trying to connect to " \
295
- "Stripe (%s). You may be seeing this message because your DNS is not " \
296
- "working or you don't have an internet connection. To check, try " \
297
- "running `host stripe.com` from the command line."
298
- ERROR_MESSAGE_SSL =
299
- "Could not establish a secure connection to Stripe (%s), you " \
300
- "may need to upgrade your OpenSSL version. To check, try running " \
301
- "`openssl s_client -connect api.stripe.com:443` from the command " \
302
- "line."
303
-
304
- # Common error suffix sared by both connect and read timeout messages.
305
- ERROR_MESSAGE_TIMEOUT_SUFFIX =
306
- "Please check your internet connection and try again. " \
307
- "If this problem persists, you should check Stripe's service " \
308
- "status at https://status.stripe.com, or let us know at " \
309
- "support@stripe.com."
310
-
311
- ERROR_MESSAGE_TIMEOUT_CONNECT = (
312
- "Timed out connecting to Stripe (%s). " +
313
- ERROR_MESSAGE_TIMEOUT_SUFFIX
314
- ).freeze
315
-
316
- ERROR_MESSAGE_TIMEOUT_READ = (
317
- "Timed out communicating with Stripe (%s). " +
318
- ERROR_MESSAGE_TIMEOUT_SUFFIX
319
- ).freeze
320
-
321
- # Maps types of exceptions that we're likely to see during a network
322
- # request to more user-friendly messages that we put in front of people.
323
- # The original error message is also appended onto the final exception for
324
- # full transparency.
325
- NETWORK_ERROR_MESSAGES_MAP = {
326
- EOFError => ERROR_MESSAGE_CONNECTION,
327
- Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
328
- Errno::ECONNRESET => ERROR_MESSAGE_CONNECTION,
329
- Errno::EHOSTUNREACH => ERROR_MESSAGE_CONNECTION,
330
- Errno::ETIMEDOUT => ERROR_MESSAGE_TIMEOUT_CONNECT,
331
- SocketError => ERROR_MESSAGE_CONNECTION,
332
-
333
- Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT,
334
- Net::ReadTimeout => ERROR_MESSAGE_TIMEOUT_READ,
335
-
336
- OpenSSL::SSL::SSLError => ERROR_MESSAGE_SSL,
337
- }.freeze
338
- private_constant :NETWORK_ERROR_MESSAGES_MAP
339
-
340
- # A record representing any data that `StripeClient` puts into
341
- # `Thread.current`. Making it a class likes this gives us a little extra
342
- # type safety and lets us document what each field does.
343
- #
344
13
  # For internal use only. Does not provide a stable API and may be broken
345
14
  # with future non-major changes.
346
- class ThreadContext
347
- # A `StripeClient` that's been flagged as currently active within a
348
- # thread by `StripeClient#request`. A client stays active until the
349
- # completion of the request block.
350
- attr_accessor :active_client
351
-
352
- # A default `StripeClient` object for the thread. Used in all cases where
353
- # the user hasn't specified their own.
354
- attr_accessor :default_client
355
-
356
- # A temporary map of object IDs to responses from last executed API
357
- # calls. Used to return a responses from calls to `StripeClient#request`.
358
- #
359
- # Stored in the thread data to make the use of a single `StripeClient`
360
- # object safe across multiple threads. Stored as a map so that multiple
361
- # `StripeClient` objects can run concurrently on the same thread.
362
- #
363
- # Responses are only left in as long as they're needed, which means
364
- # they're removed as soon as a call leaves `StripeClient#request`, and
365
- # because that's wrapped in an `ensure` block, they should never leave
366
- # garbage in `Thread.current`.
367
- attr_accessor :last_responses
368
-
369
- # A map of connection managers for the thread. Normally shared between
370
- # all `StripeClient` objects on a particular thread, and created so as to
371
- # minimize the number of open connections that an application needs.
372
- def default_connection_managers
373
- @default_connection_managers ||= {}
374
- end
375
-
376
- def reset_connection_managers
377
- @default_connection_managers = {}
378
- end
379
- end
380
-
381
- # Access data stored for `StripeClient` within the thread's current
382
- # context. Returns `ThreadContext`.
383
- #
384
- # For internal use only. Does not provide a stable API and may be broken
385
- # with future non-major changes.
386
- def self.current_thread_context
387
- Thread.current[:stripe_client__internal_use_only] ||= ThreadContext.new
388
- end
389
-
390
- # Garbage collects connection managers that haven't been used in some time,
391
- # with the idea being that we want to remove old connection managers that
392
- # belong to dead threads and the like.
393
- #
394
- # Prefixed with `maybe_` because garbage collection will only run
395
- # periodically so that we're not constantly engaged in busy work. If
396
- # connection managers live a little passed their useful age it's not
397
- # harmful, so it's not necessary to get them right away.
398
- #
399
- # For testability, returns `nil` if it didn't run and the number of
400
- # connection managers that were garbage collected otherwise.
401
- #
402
- # IMPORTANT: This method is not thread-safe and expects to be called inside
403
- # a lock on `@thread_contexts_with_connection_managers_mutex`.
404
- #
405
- # For internal use only. Does not provide a stable API and may be broken
406
- # with future non-major changes.
407
- def self.maybe_gc_connection_managers
408
- next_gc_time = @last_connection_manager_gc + CONNECTION_MANAGER_GC_PERIOD
409
- return nil if next_gc_time > Util.monotonic_time
410
-
411
- last_used_threshold =
412
- Util.monotonic_time - CONNECTION_MANAGER_GC_LAST_USED_EXPIRY
413
-
414
- pruned_contexts = []
415
- @thread_contexts_with_connection_managers.each do |thread_context|
416
- thread_context
417
- .default_connection_managers
418
- .each do |config_key, connection_manager|
419
- next if connection_manager.last_used > last_used_threshold
420
-
421
- connection_manager.clear
422
- thread_context.default_connection_managers.delete(config_key)
423
- end
424
- end
425
-
426
- @thread_contexts_with_connection_managers.each do |thread_context|
427
- next unless thread_context.default_connection_managers.empty?
428
-
429
- pruned_contexts << thread_context
430
- end
431
-
432
- @thread_contexts_with_connection_managers -= pruned_contexts
433
- @last_connection_manager_gc = Util.monotonic_time
434
-
435
- pruned_contexts.count
436
- end
437
-
438
- private def execute_request_internal(method, path,
439
- api_base, api_key, headers, params, usage,
440
- &read_body_chunk_block)
441
- raise ArgumentError, "method should be a symbol" \
442
- unless method.is_a?(Symbol)
443
- raise ArgumentError, "path should be a string" \
444
- unless path.is_a?(String)
445
-
446
- api_base ||= config.api_base
447
- api_key ||= config.api_key
448
- params = Util.objects_to_ids(params)
449
-
450
- check_api_key!(api_key)
451
-
452
- body_params = nil
453
- query_params = nil
454
- case method
455
- when :get, :head, :delete
456
- query_params = params
457
- else
458
- body_params = params
459
- end
460
-
461
- query_params, path = merge_query_params(query_params, path)
462
-
463
- headers = request_headers(api_key, method)
464
- .update(Util.normalize_headers(headers))
465
-
466
- url = api_url(path, api_base)
467
-
468
- # Merge given query parameters with any already encoded in the path.
469
- query = query_params ? Util.encode_parameters(query_params) : nil
470
-
471
- # Encoding body parameters is a little more complex because we may have
472
- # to send a multipart-encoded body. `body_log` is produced separately as
473
- # a log-friendly variant of the encoded form. File objects are displayed
474
- # as such instead of as their file contents.
475
- body, body_log =
476
- body_params ? encode_body(body_params, headers) : [nil, nil]
477
-
478
- # stores information on the request we're about to make so that we don't
479
- # have to pass as many parameters around for logging.
480
- context = RequestLogContext.new
481
- context.account = headers["Stripe-Account"]
482
- context.api_key = api_key
483
- context.api_version = headers["Stripe-Version"]
484
- context.body = body_log
485
- context.idempotency_key = headers["Idempotency-Key"]
486
- context.method = method
487
- context.path = path
488
- context.query = query
489
-
490
- # A block can be passed in to read the content directly from the response.
491
- # We want to execute this block only when the response was actually
492
- # successful. When it wasn't, we defer to the standard error handling as
493
- # we have to read the body and parse the error JSON.
494
- response_block =
495
- if block_given?
496
- lambda do |response|
497
- response.read_body(&read_body_chunk_block) unless should_handle_as_error(response.code.to_i)
498
- end
499
- end
15
+ CLIENT_OPTIONS = Set.new(%i[api_key stripe_account stripe_context api_version api_base uploads_base connect_base meter_events_base client_id])
500
16
 
501
- http_resp =
502
- execute_request_with_rescues(api_base, headers, usage, context) do
503
- self.class
504
- .default_connection_manager(config)
505
- .execute_request(method, url,
506
- body: body,
507
- headers: headers,
508
- query: query,
509
- &response_block)
510
- end
511
-
512
- [http_resp, api_key]
513
- end
514
-
515
- private def api_url(url = "", api_base = nil)
516
- (api_base || config.api_base) + url
517
- end
518
-
519
- private def check_api_key!(api_key)
17
+ # Initializes a new StripeClient
18
+ def initialize(api_key,
19
+ stripe_account: nil,
20
+ stripe_context: nil,
21
+ stripe_version: nil,
22
+ api_base: nil,
23
+ uploads_base: nil,
24
+ connect_base: nil,
25
+ meter_events_base: nil,
26
+ client_id: nil)
520
27
  unless api_key
521
28
  raise AuthenticationError, "No API key provided. " \
522
- 'Set your API key using "Stripe.api_key = <API-KEY>". ' \
29
+ 'Set your API key using "client = Stripe::StripeClient.new(<API-KEY>)". ' \
523
30
  "You can generate API keys from the Stripe web interface. " \
524
31
  "See https://stripe.com/api for details, or email " \
525
32
  "support@stripe.com if you have any questions."
526
33
  end
527
34
 
528
- return unless api_key =~ /\s/
529
-
530
- raise AuthenticationError, "Your API key is invalid, as it contains " \
531
- "whitespace. (HINT: You can double-check your API key from the " \
532
- "Stripe web interface. See https://stripe.com/api for details, or " \
533
- "email support@stripe.com if you have any questions.)"
534
- end
535
-
536
- # Encodes a set of body parameters using multipart if `Content-Type` is set
537
- # for that, or standard form-encoding otherwise. Returns the encoded body
538
- # and a version of the encoded body that's safe to be logged.
539
- private def encode_body(body_params, headers)
540
- body = nil
541
- flattened_params = Util.flatten_params(body_params)
542
-
543
- if headers["Content-Type"] == MultipartEncoder::MULTIPART_FORM_DATA
544
- body, content_type = MultipartEncoder.encode(flattened_params)
545
-
546
- # Set a new content type that also includes the multipart boundary.
547
- # See `MultipartEncoder` for details.
548
- headers["Content-Type"] = content_type
549
-
550
- # `#to_s` any complex objects like files and the like to build output
551
- # that's more condusive to logging.
552
- flattened_params =
553
- flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
554
-
555
- else
556
- body = Util.encode_parameters(body_params)
557
- end
558
-
559
- # We don't use `Util.encode_parameters` partly as an optimization (to not
560
- # redo work we've already done), and partly because the encoded forms of
561
- # certain characters introduce a lot of visual noise and it's nice to
562
- # have a clearer format for logs.
563
- body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
35
+ config_opts = {
36
+ api_key: api_key,
37
+ stripe_account: stripe_account,
38
+ stripe_context: stripe_context,
39
+ api_version: stripe_version,
40
+ api_base: api_base,
41
+ uploads_base: uploads_base,
42
+ connect_base: connect_base,
43
+ meter_events_base: meter_events_base,
44
+ client_id: client_id,
45
+ }.reject { |_k, v| v.nil? }
564
46
 
565
- [body, body_log]
566
- end
47
+ config = StripeConfiguration.client_init(config_opts)
48
+ @requestor = APIRequestor.new(config)
567
49
 
568
- private def should_handle_as_error(http_status)
569
- http_status >= 400
50
+ # top-level services: The beginning of the section generated from our OpenAPI spec
51
+ @v1 = Stripe::V1Services.new(@requestor)
52
+ @v2 = Stripe::V2Services.new(@requestor)
53
+ # top-level services: The end of the section generated from our OpenAPI spec
570
54
  end
571
55
 
572
- private def execute_request_with_rescues(api_base, headers, usage, context)
573
- num_retries = 0
574
-
575
- begin
576
- request_start = nil
577
- user_data = nil
578
-
579
- log_request(context, num_retries)
580
- user_data = notify_request_begin(context)
581
-
582
- request_start = Util.monotonic_time
583
- resp = yield
584
- request_duration = Util.monotonic_time - request_start
585
-
586
- http_status = resp.code.to_i
587
- context = context.dup_from_response_headers(resp)
588
-
589
- handle_error_response(resp, context) if should_handle_as_error(http_status)
590
-
591
- log_response(context, request_start, http_status, resp.body, resp)
592
- notify_request_end(context, request_duration, http_status,
593
- num_retries, user_data, resp, headers)
594
-
595
- if config.enable_telemetry? && context.request_id
596
- request_duration_ms = (request_duration * 1000).to_i
597
- @last_request_metrics =
598
- StripeRequestMetrics.new(context.request_id, request_duration_ms, usage: usage + @usage)
599
- end
600
-
601
- # We rescue all exceptions from a request so that we have an easy spot to
602
- # implement our retry logic across the board. We'll re-raise if it's a
603
- # type of exception that we didn't expect to handle.
604
- rescue StandardError => e
605
- # If we modify context we copy it into a new variable so as not to
606
- # taint the original on a retry.
607
- error_context = context
608
- http_status = nil
609
- request_duration = Util.monotonic_time - request_start if request_start
610
-
611
- if e.is_a?(Stripe::StripeError)
612
- error_context = context.dup_from_response_headers(e.http_headers)
613
- http_status = resp.code.to_i
614
- log_response(error_context, request_start,
615
- e.http_status, e.http_body, resp)
616
- else
617
- log_response_error(error_context, request_start, e)
618
- end
619
- notify_request_end(context, request_duration, http_status, num_retries,
620
- user_data, resp, headers)
621
-
622
- if self.class.should_retry?(e,
623
- num_retries: num_retries,
624
- config: config)
625
- num_retries += 1
626
- sleep self.class.sleep_time(num_retries, config: config)
627
- retry
628
- end
629
-
630
- case e
631
- when Stripe::StripeError
632
- raise
633
- when *NETWORK_ERROR_MESSAGES_MAP.keys
634
- handle_network_error(e, error_context, num_retries, api_base)
635
-
636
- # Only handle errors when we know we can do so, and re-raise otherwise.
637
- # This should be pretty infrequent.
638
- else # rubocop:todo Lint/DuplicateBranch
639
- raise
640
- end
641
- end
642
-
643
- resp
644
- end
645
-
646
- private def notify_request_begin(context)
647
- return unless Instrumentation.any_subscribers?(:request_begin)
648
-
649
- event = Instrumentation::RequestBeginEvent.new(
650
- method: context.method,
651
- path: context.path,
652
- user_data: {}
653
- )
654
- Stripe::Instrumentation.notify(:request_begin, event)
655
-
656
- # This field may be set in the `request_begin` callback. If so, we'll
657
- # forward it onto `request_end`.
658
- event.user_data
659
- end
660
-
661
- private def notify_request_end(context, duration, http_status, num_retries,
662
- user_data, resp, headers)
663
- return if !Instrumentation.any_subscribers?(:request_end) &&
664
- !Instrumentation.any_subscribers?(:request)
665
-
666
- request_context = Stripe::Instrumentation::RequestContext.new(
667
- duration: duration,
668
- context: context,
669
- header: headers
670
- )
671
- response_context = Stripe::Instrumentation::ResponseContext.new(
672
- http_status: http_status,
673
- response: resp
674
- )
675
-
676
- event = Instrumentation::RequestEndEvent.new(
677
- request_context: request_context,
678
- response_context: response_context,
679
- num_retries: num_retries,
680
- user_data: user_data || {}
681
- )
682
- Stripe::Instrumentation.notify(:request_end, event)
683
-
684
- # The name before `request_begin` was also added. Provided for backwards
685
- # compatibility.
686
- Stripe::Instrumentation.notify(:request, event)
687
- end
688
-
689
- private def general_api_error(status, body)
690
- APIError.new("Invalid response object from API: #{body.inspect} " \
691
- "(HTTP response code was #{status})",
692
- http_status: status, http_body: body)
693
- end
694
-
695
- # Formats a plugin "app info" hash into a string that we can tack onto the
696
- # end of a User-Agent string where it'll be fairly prominent in places like
697
- # the Dashboard. Note that this formatting has been implemented to match
698
- # other libraries, and shouldn't be changed without universal consensus.
699
- private def format_app_info(info)
700
- str = info[:name]
701
- str = "#{str}/#{info[:version]}" unless info[:version].nil?
702
- str = "#{str} (#{info[:url]})" unless info[:url].nil?
703
- str
704
- end
705
-
706
- private def handle_error_response(http_resp, context)
707
- begin
708
- resp = StripeResponse.from_net_http(http_resp)
709
- error_data = resp.data[:error]
710
-
711
- raise StripeError, "Indeterminate error" unless error_data
712
- rescue JSON::ParserError, StripeError
713
- raise general_api_error(http_resp.code.to_i, http_resp.body)
714
- end
715
-
716
- error = if error_data.is_a?(String)
717
- specific_oauth_error(resp, error_data, context)
718
- else
719
- specific_api_error(resp, error_data, context)
720
- end
721
-
722
- error.response = resp
723
- raise(error)
724
- end
725
-
726
- # Works around an edge case where we end up with both query parameters from
727
- # parameteers and query parameters that were appended onto the end of the
728
- # given path.
729
- #
730
- # Decode any parameters that were added onto the end of a path and add them
731
- # to a unified query parameter hash so that all parameters end up in one
732
- # place and all of them are correctly included in the final request.
733
- private def merge_query_params(query_params, path)
734
- u = URI.parse(path)
735
-
736
- # Return original results if there was nothing to be found.
737
- return query_params, path if u.query.nil?
738
-
739
- query_params ||= {}
740
- query_params = Hash[URI.decode_www_form(u.query)].merge(query_params)
741
-
742
- # Reset the path minus any query parameters that were specified.
743
- path = u.path
744
-
745
- [query_params, path]
746
- end
747
-
748
- private def specific_api_error(resp, error_data, context)
749
- Util.log_error("Stripe API error",
750
- status: resp.http_status,
751
- error_code: error_data[:code],
752
- error_message: error_data[:message],
753
- error_param: error_data[:param],
754
- error_type: error_data[:type],
755
- idempotency_key: context.idempotency_key,
756
- request_id: context.request_id,
757
- config: config)
758
-
759
- # The standard set of arguments that can be used to initialize most of
760
- # the exceptions.
761
- opts = {
762
- http_body: resp.http_body,
763
- http_headers: resp.http_headers,
764
- http_status: resp.http_status,
765
- json_body: resp.data,
766
- code: error_data[:code],
767
- }
768
-
769
- case resp.http_status
770
- when 400, 404
771
- case error_data[:type]
772
- when "idempotency_error"
773
- IdempotencyError.new(error_data[:message], **opts)
774
- else
775
- InvalidRequestError.new(
776
- error_data[:message], error_data[:param],
777
- **opts
778
- )
779
- end
780
- when 401
781
- AuthenticationError.new(error_data[:message], **opts)
782
- when 402
783
- CardError.new(
784
- error_data[:message], error_data[:param],
785
- **opts
786
- )
787
- when 403
788
- PermissionError.new(error_data[:message], **opts)
789
- when 429
790
- RateLimitError.new(error_data[:message], **opts)
791
- else
792
- APIError.new(error_data[:message], **opts)
793
- end
794
- end
795
-
796
- # Attempts to look at a response's error code and return an OAuth error if
797
- # one matches. Will return `nil` if the code isn't recognized.
798
- private def specific_oauth_error(resp, error_code, context)
799
- description = resp.data[:error_description] || error_code
800
-
801
- Util.log_error("Stripe OAuth error",
802
- status: resp.http_status,
803
- error_code: error_code,
804
- error_description: description,
805
- idempotency_key: context.idempotency_key,
806
- request_id: context.request_id,
807
- config: config)
808
-
809
- args = {
810
- http_status: resp.http_status, http_body: resp.http_body,
811
- json_body: resp.data, http_headers: resp.http_headers,
812
- }
813
-
814
- case error_code
815
- when "invalid_client"
816
- OAuth::InvalidClientError.new(error_code, description, **args)
817
- when "invalid_grant"
818
- OAuth::InvalidGrantError.new(error_code, description, **args)
819
- when "invalid_request"
820
- OAuth::InvalidRequestError.new(error_code, description, **args)
821
- when "invalid_scope"
822
- OAuth::InvalidScopeError.new(error_code, description, **args)
823
- when "unsupported_grant_type"
824
- OAuth::UnsupportedGrantTypeError.new(error_code, description, **args)
825
- when "unsupported_response_type"
826
- OAuth::UnsupportedResponseTypeError.new(error_code, description, **args)
827
- else
828
- # We'd prefer that all errors are typed, but we create a generic
829
- # OAuthError in case we run into a code that we don't recognize.
830
- OAuth::OAuthError.new(error_code, description, **args)
831
- end
832
- end
833
-
834
- private def handle_network_error(error, context, num_retries,
835
- api_base = nil)
836
- Util.log_error("Stripe network error",
837
- error_message: error.message,
838
- idempotency_key: context.idempotency_key,
839
- request_id: context.request_id,
840
- config: config)
841
-
842
- errors, message = NETWORK_ERROR_MESSAGES_MAP.detect do |(e, _)|
843
- error.is_a?(e)
844
- end
845
-
846
- if errors.nil?
847
- message = "Unexpected error #{error.class.name} communicating " \
848
- "with Stripe. Please let us know at support@stripe.com."
849
- end
850
-
851
- api_base ||= config.api_base
852
- message = message % api_base
853
-
854
- message += " Request was retried #{num_retries} times." if num_retries > 0
855
-
856
- raise APIConnectionError,
857
- message + "\n\n(Network error: #{error.message})"
858
- end
859
-
860
- private def request_headers(api_key, method)
861
- user_agent = "Stripe/v1 RubyBindings/#{Stripe::VERSION}"
862
- user_agent += " " + format_app_info(Stripe.app_info) unless Stripe.app_info.nil?
863
-
864
- headers = {
865
- "User-Agent" => user_agent,
866
- "Authorization" => "Bearer #{api_key}",
867
- "Content-Type" => "application/x-www-form-urlencoded",
868
- }
869
-
870
- if config.enable_telemetry? && !@last_request_metrics.nil?
871
- headers["X-Stripe-Client-Telemetry"] = JSON.generate(
872
- last_request_metrics: @last_request_metrics.payload
873
- )
874
- end
875
-
876
- # It is only safe to retry network failures on post and delete
877
- # requests if we add an Idempotency-Key header
878
- if %i[post delete].include?(method) && config.max_network_retries > 0
879
- headers["Idempotency-Key"] ||= SecureRandom.uuid
880
- end
881
-
882
- headers["Stripe-Version"] = config.api_version if config.api_version
883
-
884
- headers["Stripe-Account"] = config.stripe_account if config.stripe_account
885
-
886
- user_agent = @system_profiler.user_agent
887
- begin
888
- headers.update(
889
- "X-Stripe-Client-User-Agent" => JSON.generate(user_agent)
890
- )
891
- rescue StandardError => e
892
- headers.update(
893
- "X-Stripe-Client-Raw-User-Agent" => user_agent.inspect,
894
- :error => "#{e} (#{e.class})"
895
- )
896
- end
897
-
898
- headers
56
+ def request(&block)
57
+ @requestor.request(&block)
899
58
  end
59
+ extend Gem::Deprecate
60
+ deprecate :request, :raw_request, 2024, 9
900
61
 
901
- private def log_request(context, num_retries)
902
- Util.log_info("Request to Stripe API",
903
- account: context.account,
904
- api_version: context.api_version,
905
- idempotency_key: context.idempotency_key,
906
- method: context.method,
907
- num_retries: num_retries,
908
- path: context.path,
909
- config: config)
910
- Util.log_debug("Request details",
911
- body: context.body,
912
- idempotency_key: context.idempotency_key,
913
- query: context.query,
914
- config: config,
915
- process_id: Process.pid,
916
- thread_object_id: Thread.current.object_id,
917
- log_timestamp: Util.monotonic_time)
918
- end
62
+ def parse_thin_event(payload, sig_header, secret, tolerance: Webhook::DEFAULT_TOLERANCE)
63
+ payload = payload.force_encoding("UTF-8") if payload.respond_to?(:force_encoding)
919
64
 
920
- private def log_response(context, request_start, status, body, resp)
921
- Util.log_info("Response from Stripe API",
922
- account: context.account,
923
- api_version: context.api_version,
924
- elapsed: Util.monotonic_time - request_start,
925
- idempotency_key: context.idempotency_key,
926
- method: context.method,
927
- path: context.path,
928
- request_id: context.request_id,
929
- status: status,
930
- config: config)
931
- Util.log_debug("Response details",
932
- body: body,
933
- idempotency_key: context.idempotency_key,
934
- request_id: context.request_id,
935
- config: config,
936
- process_id: Process.pid,
937
- thread_object_id: Thread.current.object_id,
938
- response_object_id: resp.object_id,
939
- log_timestamp: Util.monotonic_time)
65
+ # v2 events use the same signing mechanism as v1 events
66
+ Webhook::Signature.verify_header(payload, sig_header, secret, tolerance: tolerance)
940
67
 
941
- return unless context.request_id
68
+ parsed = JSON.parse(payload, symbolize_names: true)
942
69
 
943
- Util.log_debug("Dashboard link for request",
944
- idempotency_key: context.idempotency_key,
945
- request_id: context.request_id,
946
- url: Util.request_id_dashboard_url(context.request_id,
947
- context.api_key),
948
- config: config)
70
+ Stripe::ThinEvent.new(parsed)
949
71
  end
950
72
 
951
- private def log_response_error(context, request_start, error)
952
- elapsed = request_start ? Util.monotonic_time - request_start : nil
953
- Util.log_error("Request error",
954
- elapsed: elapsed,
955
- error_message: error.message,
956
- idempotency_key: context.idempotency_key,
957
- method: context.method,
958
- path: context.path,
959
- config: config)
960
- end
73
+ def raw_request(method, url, base_address: :api, params: {}, opts: {})
74
+ opts = Util.normalize_opts(opts)
75
+ req_opts = RequestOptions.extract_opts_from_hash(opts)
961
76
 
962
- # RequestLogContext stores information about a request that's begin made so
963
- # that we can log certain information. It's useful because it means that we
964
- # don't have to pass around as many parameters.
965
- class RequestLogContext
966
- attr_accessor :body, :account, :api_key, :api_version, :idempotency_key, :method, :path, :query, :request_id
77
+ params = params.to_h if params.is_a?(Stripe::RequestParams)
78
+ resp, = @requestor.send(:execute_request_internal, method, url, base_address, params, req_opts, usage: ["raw_request"])
967
79
 
968
- # The idea with this method is that we might want to update some of
969
- # context information because a response that we've received from the API
970
- # contains information that's more authoritative than what we started
971
- # with for a request. For example, we should trust whatever came back in
972
- # a `Stripe-Version` header beyond what configuration information that we
973
- # might have had available.
974
- def dup_from_response_headers(headers)
975
- context = dup
976
- context.account = headers["Stripe-Account"]
977
- context.api_version = headers["Stripe-Version"]
978
- context.idempotency_key = headers["Idempotency-Key"]
979
- context.request_id = headers["Request-Id"]
980
- context
981
- end
80
+ @requestor.interpret_response(resp)
982
81
  end
983
82
 
984
- # SystemProfiler extracts information about the system that we're running
985
- # in so that we can generate a rich user agent header to help debug
986
- # integrations.
987
- class SystemProfiler
988
- def self.uname
989
- if ::File.exist?("/proc/version")
990
- ::File.read("/proc/version").strip
991
- else
992
- case RbConfig::CONFIG["host_os"]
993
- when /linux|darwin|bsd|sunos|solaris|cygwin/i
994
- uname_from_system
995
- when /mswin|mingw/i
996
- uname_from_system_ver
997
- else
998
- "unknown platform"
999
- end
1000
- end
1001
- end
1002
-
1003
- def self.uname_from_system
1004
- (`uname -a 2>/dev/null` || "").strip
1005
- rescue Errno::ENOENT
1006
- "uname executable not found"
1007
- rescue Errno::ENOMEM # couldn't create subprocess
1008
- "uname lookup failed"
1009
- end
1010
-
1011
- def self.uname_from_system_ver
1012
- (`ver` || "").strip
1013
- rescue Errno::ENOENT
1014
- "ver executable not found"
1015
- rescue Errno::ENOMEM # couldn't create subprocess
1016
- "uname lookup failed"
1017
- end
1018
-
1019
- def initialize
1020
- @uname = self.class.uname
1021
- end
1022
-
1023
- def user_agent
1024
- lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} " \
1025
- "(#{RUBY_RELEASE_DATE})"
1026
-
1027
- {
1028
- application: Stripe.app_info,
1029
- bindings_version: Stripe::VERSION,
1030
- lang: "ruby",
1031
- lang_version: lang_version,
1032
- platform: RUBY_PLATFORM,
1033
- engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
1034
- publisher: "stripe",
1035
- uname: @uname,
1036
- hostname: Socket.gethostname,
1037
- }.delete_if { |_k, v| v.nil? }
1038
- end
1039
- end
1040
-
1041
- # StripeRequestMetrics tracks metadata to be reported to stripe for metrics
1042
- # collection
1043
- class StripeRequestMetrics
1044
- # The Stripe request ID of the response.
1045
- attr_accessor :request_id
1046
-
1047
- # Request duration in milliseconds
1048
- attr_accessor :request_duration_ms
1049
-
1050
- # list of names of tracked behaviors associated with this request
1051
- attr_accessor :usage
1052
-
1053
- def initialize(request_id, request_duration_ms, usage: [])
1054
- self.request_id = request_id
1055
- self.request_duration_ms = request_duration_ms
1056
- self.usage = usage
1057
- end
1058
-
1059
- def payload
1060
- ret = { request_id: request_id, request_duration_ms: request_duration_ms }
1061
- ret[:usage] = usage if !usage.nil? && !usage.empty?
1062
- ret
1063
- end
83
+ def deserialize(data, api_mode: :v1)
84
+ data = JSON.parse(data) if data.is_a?(String)
85
+ Util.convert_to_stripe_object(data, {}, api_mode: api_mode, requestor: @requestor)
1064
86
  end
1065
87
  end
1066
88
  end