stripe 5.55.0 → 13.5.1

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 (380) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +567 -4
  3. data/Gemfile +12 -4
  4. data/Makefile +18 -3
  5. data/OPENAPI_VERSION +1 -0
  6. data/README.md +93 -21
  7. data/Rakefile +3 -6
  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/{bin → exe}/stripe-console +1 -1
  14. data/justfile +43 -0
  15. data/lib/data/ca-certificates.crt +1241 -1937
  16. data/lib/stripe/api_operations/create.rb +6 -2
  17. data/lib/stripe/api_operations/delete.rb +12 -7
  18. data/lib/stripe/api_operations/list.rb +6 -9
  19. data/lib/stripe/api_operations/nested_resource.rb +63 -35
  20. data/lib/stripe/api_operations/request.rb +29 -65
  21. data/lib/stripe/api_operations/save.rb +20 -10
  22. data/lib/stripe/api_operations/search.rb +11 -9
  23. data/lib/stripe/api_operations/singleton_save.rb +90 -0
  24. data/lib/stripe/api_requestor.rb +1131 -0
  25. data/lib/stripe/api_resource.rb +48 -18
  26. data/lib/stripe/api_resource_test_helpers.rb +9 -3
  27. data/lib/stripe/api_version.rb +8 -0
  28. data/lib/stripe/connection_manager.rb +5 -7
  29. data/lib/stripe/errors.rb +11 -13
  30. data/lib/stripe/event_types.rb +14 -0
  31. data/lib/stripe/events/v1_billing_meter_error_report_triggered_event.rb +23 -0
  32. data/lib/stripe/events/v1_billing_meter_no_meter_found_event.rb +13 -0
  33. data/lib/stripe/instrumentation.rb +37 -15
  34. data/lib/stripe/list_object.rb +5 -3
  35. data/lib/stripe/multipart_encoder.rb +7 -7
  36. data/lib/stripe/oauth.rb +14 -21
  37. data/lib/stripe/object_types.rb +151 -103
  38. data/lib/stripe/request_options.rb +129 -0
  39. data/lib/stripe/resources/account.rb +129 -25
  40. data/lib/stripe/resources/account_link.rb +12 -0
  41. data/lib/stripe/resources/account_session.rb +25 -0
  42. data/lib/stripe/resources/alipay_account.rb +1 -1
  43. data/lib/stripe/resources/apple_pay_domain.rb +38 -0
  44. data/lib/stripe/resources/application_fee.rb +9 -2
  45. data/lib/stripe/resources/application_fee_refund.rb +9 -2
  46. data/lib/stripe/resources/apps/secret.rb +55 -0
  47. data/lib/stripe/resources/balance.rb +14 -0
  48. data/lib/stripe/resources/balance_transaction.rb +19 -0
  49. data/lib/stripe/resources/bank_account.rb +53 -4
  50. data/lib/stripe/resources/billing/alert.rb +87 -0
  51. data/lib/stripe/resources/billing/credit_balance_summary.rb +14 -0
  52. data/lib/stripe/resources/billing/credit_balance_transaction.rb +26 -0
  53. data/lib/stripe/resources/billing/credit_grant.rb +90 -0
  54. data/lib/stripe/resources/billing/meter.rb +85 -0
  55. data/lib/stripe/resources/billing/meter_event.rb +26 -0
  56. data/lib/stripe/resources/billing/meter_event_adjustment.rb +26 -0
  57. data/lib/stripe/resources/billing/meter_event_summary.rb +17 -0
  58. data/lib/stripe/resources/billing_portal/configuration.rb +34 -0
  59. data/lib/stripe/resources/billing_portal/session.rb +27 -0
  60. data/lib/stripe/resources/capability.rb +7 -2
  61. data/lib/stripe/resources/card.rb +34 -3
  62. data/lib/stripe/resources/cash_balance.rb +4 -0
  63. data/lib/stripe/resources/charge.rb +52 -3
  64. data/lib/stripe/resources/checkout/session.rb +83 -5
  65. data/lib/stripe/resources/climate/order.rb +67 -0
  66. data/lib/stripe/resources/climate/product.rb +27 -0
  67. data/lib/stripe/resources/climate/supplier.rb +26 -0
  68. data/lib/stripe/resources/confirmation_token.rb +39 -0
  69. data/lib/stripe/resources/country_spec.rb +14 -0
  70. data/lib/stripe/resources/coupon.rb +48 -0
  71. data/lib/stripe/resources/credit_note.rb +67 -9
  72. data/lib/stripe/resources/credit_note_line_item.rb +4 -0
  73. data/lib/stripe/resources/customer.rb +172 -28
  74. data/lib/stripe/resources/customer_balance_transaction.rb +9 -1
  75. data/lib/stripe/resources/customer_cash_balance_transaction.rb +15 -0
  76. data/lib/stripe/resources/customer_session.rb +29 -0
  77. data/lib/stripe/resources/discount.rb +7 -0
  78. data/lib/stripe/resources/dispute.rb +41 -3
  79. data/lib/stripe/resources/entitlements/active_entitlement.rb +26 -0
  80. data/lib/stripe/resources/entitlements/feature.rb +49 -0
  81. data/lib/stripe/resources/ephemeral_key.rb +23 -0
  82. data/lib/stripe/resources/event.rb +38 -0
  83. data/lib/stripe/resources/exchange_rate.rb +34 -0
  84. data/lib/stripe/resources/file.rb +37 -15
  85. data/lib/stripe/resources/file_link.rb +26 -0
  86. data/lib/stripe/resources/financial_connections/account.rb +101 -6
  87. data/lib/stripe/resources/financial_connections/account_owner.rb +4 -0
  88. data/lib/stripe/resources/financial_connections/account_ownership.rb +4 -0
  89. data/lib/stripe/resources/financial_connections/session.rb +14 -0
  90. data/lib/stripe/resources/financial_connections/transaction.rb +26 -0
  91. data/lib/stripe/resources/forwarding/request.rb +52 -0
  92. data/lib/stripe/resources/funding_instructions.rb +8 -0
  93. data/lib/stripe/resources/identity/verification_report.rb +24 -0
  94. data/lib/stripe/resources/identity/verification_session.rb +117 -5
  95. data/lib/stripe/resources/invoice.rb +247 -20
  96. data/lib/stripe/resources/invoice_item.rb +54 -0
  97. data/lib/stripe/resources/invoice_line_item.rb +22 -1
  98. data/lib/stripe/resources/invoice_rendering_template.rb +65 -0
  99. data/lib/stripe/resources/issuing/authorization.rb +210 -5
  100. data/lib/stripe/resources/issuing/card.rb +128 -4
  101. data/lib/stripe/resources/issuing/cardholder.rb +36 -0
  102. data/lib/stripe/resources/issuing/dispute.rb +47 -2
  103. data/lib/stripe/resources/issuing/personalization_design.rb +119 -0
  104. data/lib/stripe/resources/issuing/physical_bundle.rb +26 -0
  105. data/lib/stripe/resources/issuing/token.rb +32 -0
  106. data/lib/stripe/resources/issuing/transaction.rb +79 -0
  107. data/lib/stripe/resources/line_item.rb +4 -0
  108. data/lib/stripe/resources/login_link.rb +4 -0
  109. data/lib/stripe/resources/mandate.rb +4 -0
  110. data/lib/stripe/resources/payment_intent.rb +238 -15
  111. data/lib/stripe/resources/payment_link.rb +39 -2
  112. data/lib/stripe/resources/payment_method.rb +78 -5
  113. data/lib/stripe/resources/payment_method_configuration.rb +59 -0
  114. data/lib/stripe/resources/payment_method_domain.rb +79 -0
  115. data/lib/stripe/resources/payout.rb +63 -5
  116. data/lib/stripe/resources/person.rb +8 -1
  117. data/lib/stripe/resources/plan.rb +51 -0
  118. data/lib/stripe/resources/price.rb +30 -1
  119. data/lib/stripe/resources/product.rb +55 -1
  120. data/lib/stripe/resources/product_feature.rb +13 -0
  121. data/lib/stripe/resources/promotion_code.rb +25 -0
  122. data/lib/stripe/resources/quote.rb +97 -39
  123. data/lib/stripe/resources/radar/early_fraud_warning.rb +17 -0
  124. data/lib/stripe/resources/radar/value_list.rb +56 -0
  125. data/lib/stripe/resources/radar/value_list_item.rb +46 -0
  126. data/lib/stripe/resources/refund.rb +70 -5
  127. data/lib/stripe/resources/reporting/report_run.rb +31 -0
  128. data/lib/stripe/resources/reporting/report_type.rb +21 -1
  129. data/lib/stripe/resources/reversal.rb +17 -2
  130. data/lib/stripe/resources/review.rb +24 -3
  131. data/lib/stripe/resources/setup_attempt.rb +12 -0
  132. data/lib/stripe/resources/setup_intent.rb +113 -7
  133. data/lib/stripe/resources/shipping_rate.rb +25 -0
  134. data/lib/stripe/resources/sigma/scheduled_query_run.rb +17 -0
  135. data/lib/stripe/resources/source.rb +52 -10
  136. data/lib/stripe/resources/source_transaction.rb +7 -0
  137. data/lib/stripe/resources/subscription.rb +118 -5
  138. data/lib/stripe/resources/subscription_item.rb +54 -6
  139. data/lib/stripe/resources/subscription_schedule.rb +60 -5
  140. data/lib/stripe/resources/tax/calculation.rb +48 -0
  141. data/lib/stripe/resources/tax/calculation_line_item.rb +13 -0
  142. data/lib/stripe/resources/tax/registration.rb +54 -0
  143. data/lib/stripe/resources/tax/settings.rb +17 -0
  144. data/lib/stripe/resources/tax/transaction.rb +56 -0
  145. data/lib/stripe/resources/tax/transaction_line_item.rb +13 -0
  146. data/lib/stripe/resources/tax_code.rb +9 -0
  147. data/lib/stripe/resources/tax_id.rb +34 -12
  148. data/lib/stripe/resources/tax_rate.rb +26 -0
  149. data/lib/stripe/resources/terminal/configuration.rb +54 -0
  150. data/lib/stripe/resources/terminal/connection_token.rb +16 -0
  151. data/lib/stripe/resources/terminal/location.rb +57 -0
  152. data/lib/stripe/resources/terminal/reader.rb +138 -11
  153. data/lib/stripe/resources/test_helpers/test_clock.rb +58 -3
  154. data/lib/stripe/resources/token.rb +29 -0
  155. data/lib/stripe/resources/topup.rb +40 -3
  156. data/lib/stripe/resources/transfer.rb +29 -6
  157. data/lib/stripe/resources/treasury/credit_reversal.rb +37 -0
  158. data/lib/stripe/resources/treasury/debit_reversal.rb +37 -0
  159. data/lib/stripe/resources/treasury/financial_account.rb +109 -0
  160. data/lib/stripe/resources/treasury/financial_account_features.rb +15 -0
  161. data/lib/stripe/resources/treasury/inbound_transfer.rb +130 -0
  162. data/lib/stripe/resources/treasury/outbound_payment.rb +152 -0
  163. data/lib/stripe/resources/treasury/outbound_transfer.rb +152 -0
  164. data/lib/stripe/resources/treasury/received_credit.rb +47 -0
  165. data/lib/stripe/resources/treasury/received_debit.rb +47 -0
  166. data/lib/stripe/resources/treasury/transaction.rb +26 -0
  167. data/lib/stripe/resources/treasury/transaction_entry.rb +30 -0
  168. data/lib/stripe/resources/usage_record.rb +9 -0
  169. data/lib/stripe/resources/usage_record_summary.rb +4 -0
  170. data/lib/stripe/resources/v2/billing/meter_event.rb +16 -0
  171. data/lib/stripe/resources/v2/billing/meter_event_adjustment.rb +15 -0
  172. data/lib/stripe/resources/v2/billing/meter_event_session.rb +15 -0
  173. data/lib/stripe/resources/v2/event.rb +13 -0
  174. data/lib/stripe/resources/v2/event_destination.rb +13 -0
  175. data/lib/stripe/resources/webhook_endpoint.rb +55 -0
  176. data/lib/stripe/resources.rb +51 -10
  177. data/lib/stripe/search_result_object.rb +5 -2
  178. data/lib/stripe/services/account_capability_service.rb +39 -0
  179. data/lib/stripe/services/account_external_account_service.rb +68 -0
  180. data/lib/stripe/services/account_link_service.rb +17 -0
  181. data/lib/stripe/services/account_login_link_service.rb +19 -0
  182. data/lib/stripe/services/account_person_service.rb +61 -0
  183. data/lib/stripe/services/account_service.rb +100 -0
  184. data/lib/stripe/services/account_session_service.rb +17 -0
  185. data/lib/stripe/services/apple_pay_domain_service.rb +50 -0
  186. data/lib/stripe/services/application_fee_refund_service.rb +60 -0
  187. data/lib/stripe/services/application_fee_service.rb +35 -0
  188. data/lib/stripe/services/apps/secret_service.rb +52 -0
  189. data/lib/stripe/services/apps_service.rb +13 -0
  190. data/lib/stripe/services/balance_service.rb +12 -0
  191. data/lib/stripe/services/balance_transaction_service.rb +32 -0
  192. data/lib/stripe/services/billing/alert_service.rb +74 -0
  193. data/lib/stripe/services/billing/credit_balance_summary_service.rb +19 -0
  194. data/lib/stripe/services/billing/credit_balance_transaction_service.rb +30 -0
  195. data/lib/stripe/services/billing/credit_grant_service.rb +74 -0
  196. data/lib/stripe/services/billing/meter_event_adjustment_service.rb +19 -0
  197. data/lib/stripe/services/billing/meter_event_service.rb +19 -0
  198. data/lib/stripe/services/billing/meter_event_summary_service.rb +19 -0
  199. data/lib/stripe/services/billing/meter_service.rb +81 -0
  200. data/lib/stripe/services/billing_portal/configuration_service.rb +52 -0
  201. data/lib/stripe/services/billing_portal/session_service.rb +19 -0
  202. data/lib/stripe/services/billing_portal_service.rb +14 -0
  203. data/lib/stripe/services/billing_service.rb +20 -0
  204. data/lib/stripe/services/charge_service.rb +69 -0
  205. data/lib/stripe/services/checkout/session_line_item_service.rb +19 -0
  206. data/lib/stripe/services/checkout/session_service.rb +72 -0
  207. data/lib/stripe/services/checkout_service.rb +13 -0
  208. data/lib/stripe/services/climate/order_service.rb +68 -0
  209. data/lib/stripe/services/climate/product_service.rb +30 -0
  210. data/lib/stripe/services/climate/supplier_service.rb +30 -0
  211. data/lib/stripe/services/climate_service.rb +15 -0
  212. data/lib/stripe/services/confirmation_token_service.rb +17 -0
  213. data/lib/stripe/services/country_spec_service.rb +28 -0
  214. data/lib/stripe/services/coupon_service.rb +51 -0
  215. data/lib/stripe/services/credit_note_line_item_service.rb +17 -0
  216. data/lib/stripe/services/credit_note_preview_lines_service.rb +17 -0
  217. data/lib/stripe/services/credit_note_service.rb +93 -0
  218. data/lib/stripe/services/customer_balance_transaction_service.rb +50 -0
  219. data/lib/stripe/services/customer_cash_balance_service.rb +28 -0
  220. data/lib/stripe/services/customer_cash_balance_transaction_service.rb +28 -0
  221. data/lib/stripe/services/customer_funding_instructions_service.rb +19 -0
  222. data/lib/stripe/services/customer_payment_method_service.rb +28 -0
  223. data/lib/stripe/services/customer_payment_source_service.rb +76 -0
  224. data/lib/stripe/services/customer_service.rb +89 -0
  225. data/lib/stripe/services/customer_session_service.rb +17 -0
  226. data/lib/stripe/services/customer_tax_id_service.rb +50 -0
  227. data/lib/stripe/services/dispute_service.rb +48 -0
  228. data/lib/stripe/services/entitlements/active_entitlement_service.rb +30 -0
  229. data/lib/stripe/services/entitlements/feature_service.rb +52 -0
  230. data/lib/stripe/services/entitlements_service.rb +14 -0
  231. data/lib/stripe/services/ephemeral_key_service.rb +28 -0
  232. data/lib/stripe/services/event_service.rb +22 -0
  233. data/lib/stripe/services/exchange_rate_service.rb +28 -0
  234. data/lib/stripe/services/file_link_service.rb +38 -0
  235. data/lib/stripe/services/file_service.rb +35 -0
  236. data/lib/stripe/services/financial_connections/account_owner_service.rb +19 -0
  237. data/lib/stripe/services/financial_connections/account_service.rb +81 -0
  238. data/lib/stripe/services/financial_connections/session_service.rb +30 -0
  239. data/lib/stripe/services/financial_connections/transaction_service.rb +30 -0
  240. data/lib/stripe/services/financial_connections_service.rb +15 -0
  241. data/lib/stripe/services/forwarding/request_service.rb +41 -0
  242. data/lib/stripe/services/forwarding_service.rb +13 -0
  243. data/lib/stripe/services/identity/verification_report_service.rb +30 -0
  244. data/lib/stripe/services/identity/verification_session_service.rb +106 -0
  245. data/lib/stripe/services/identity_service.rb +14 -0
  246. data/lib/stripe/services/invoice_item_service.rb +61 -0
  247. data/lib/stripe/services/invoice_line_item_service.rb +31 -0
  248. data/lib/stripe/services/invoice_rendering_template_service.rb +50 -0
  249. data/lib/stripe/services/invoice_service.rb +202 -0
  250. data/lib/stripe/services/invoice_upcoming_lines_service.rb +17 -0
  251. data/lib/stripe/services/issuing/authorization_service.rb +65 -0
  252. data/lib/stripe/services/issuing/card_service.rb +52 -0
  253. data/lib/stripe/services/issuing/cardholder_service.rb +52 -0
  254. data/lib/stripe/services/issuing/dispute_service.rb +63 -0
  255. data/lib/stripe/services/issuing/personalization_design_service.rb +52 -0
  256. data/lib/stripe/services/issuing/physical_bundle_service.rb +30 -0
  257. data/lib/stripe/services/issuing/token_service.rb +41 -0
  258. data/lib/stripe/services/issuing/transaction_service.rb +41 -0
  259. data/lib/stripe/services/issuing_service.rb +20 -0
  260. data/lib/stripe/services/mandate_service.rb +17 -0
  261. data/lib/stripe/services/oauth_service.rb +63 -0
  262. data/lib/stripe/services/payment_intent_service.rb +204 -0
  263. data/lib/stripe/services/payment_link_line_item_service.rb +17 -0
  264. data/lib/stripe/services/payment_link_service.rb +57 -0
  265. data/lib/stripe/services/payment_method_configuration_service.rb +50 -0
  266. data/lib/stripe/services/payment_method_domain_service.rb +66 -0
  267. data/lib/stripe/services/payment_method_service.rb +86 -0
  268. data/lib/stripe/services/payout_service.rb +66 -0
  269. data/lib/stripe/services/plan_service.rb +49 -0
  270. data/lib/stripe/services/price_service.rb +52 -0
  271. data/lib/stripe/services/product_feature_service.rb +50 -0
  272. data/lib/stripe/services/product_service.rb +70 -0
  273. data/lib/stripe/services/promotion_code_service.rb +50 -0
  274. data/lib/stripe/services/quote_computed_upfront_line_items_service.rb +17 -0
  275. data/lib/stripe/services/quote_line_item_service.rb +17 -0
  276. data/lib/stripe/services/quote_service.rb +92 -0
  277. data/lib/stripe/services/radar/early_fraud_warning_service.rb +32 -0
  278. data/lib/stripe/services/radar/value_list_item_service.rb +52 -0
  279. data/lib/stripe/services/radar/value_list_service.rb +63 -0
  280. data/lib/stripe/services/radar_service.rb +15 -0
  281. data/lib/stripe/services/refund_service.rb +63 -0
  282. data/lib/stripe/services/reporting/report_run_service.rb +41 -0
  283. data/lib/stripe/services/reporting/report_type_service.rb +30 -0
  284. data/lib/stripe/services/reporting_service.rb +14 -0
  285. data/lib/stripe/services/review_service.rb +33 -0
  286. data/lib/stripe/services/setup_attempt_service.rb +17 -0
  287. data/lib/stripe/services/setup_intent_service.rb +105 -0
  288. data/lib/stripe/services/shipping_rate_service.rb +50 -0
  289. data/lib/stripe/services/sigma/scheduled_query_run_service.rb +30 -0
  290. data/lib/stripe/services/sigma_service.rb +13 -0
  291. data/lib/stripe/services/source_service.rb +64 -0
  292. data/lib/stripe/services/source_transaction_service.rb +17 -0
  293. data/lib/stripe/services/subscription_item_service.rb +69 -0
  294. data/lib/stripe/services/subscription_item_usage_record_service.rb +23 -0
  295. data/lib/stripe/services/subscription_item_usage_record_summary_service.rb +19 -0
  296. data/lib/stripe/services/subscription_schedule_service.rb +72 -0
  297. data/lib/stripe/services/subscription_service.rb +127 -0
  298. data/lib/stripe/services/tax/calculation_line_item_service.rb +19 -0
  299. data/lib/stripe/services/tax/calculation_service.rb +37 -0
  300. data/lib/stripe/services/tax/registration_service.rb +54 -0
  301. data/lib/stripe/services/tax/settings_service.rb +30 -0
  302. data/lib/stripe/services/tax/transaction_line_item_service.rb +19 -0
  303. data/lib/stripe/services/tax/transaction_service.rb +48 -0
  304. data/lib/stripe/services/tax_code_service.rb +22 -0
  305. data/lib/stripe/services/tax_id_service.rb +38 -0
  306. data/lib/stripe/services/tax_rate_service.rb +38 -0
  307. data/lib/stripe/services/tax_service.rb +16 -0
  308. data/lib/stripe/services/terminal/configuration_service.rb +63 -0
  309. data/lib/stripe/services/terminal/connection_token_service.rb +19 -0
  310. data/lib/stripe/services/terminal/location_service.rb +64 -0
  311. data/lib/stripe/services/terminal/reader_service.rb +118 -0
  312. data/lib/stripe/services/terminal_service.rb +16 -0
  313. data/lib/stripe/services/test_helpers/confirmation_token_service.rb +19 -0
  314. data/lib/stripe/services/test_helpers/customer_service.rb +19 -0
  315. data/lib/stripe/services/test_helpers/issuing/authorization_service.rb +87 -0
  316. data/lib/stripe/services/test_helpers/issuing/card_service.rb +65 -0
  317. data/lib/stripe/services/test_helpers/issuing/personalization_design_service.rb +43 -0
  318. data/lib/stripe/services/test_helpers/issuing/transaction_service.rb +43 -0
  319. data/lib/stripe/services/test_helpers/issuing_service.rb +19 -0
  320. data/lib/stripe/services/test_helpers/refund_service.rb +19 -0
  321. data/lib/stripe/services/test_helpers/terminal/reader_service.rb +21 -0
  322. data/lib/stripe/services/test_helpers/terminal_service.rb +15 -0
  323. data/lib/stripe/services/test_helpers/test_clock_service.rb +63 -0
  324. data/lib/stripe/services/test_helpers/treasury/inbound_transfer_service.rb +43 -0
  325. data/lib/stripe/services/test_helpers/treasury/outbound_payment_service.rb +54 -0
  326. data/lib/stripe/services/test_helpers/treasury/outbound_transfer_service.rb +54 -0
  327. data/lib/stripe/services/test_helpers/treasury/received_credit_service.rb +21 -0
  328. data/lib/stripe/services/test_helpers/treasury/received_debit_service.rb +21 -0
  329. data/lib/stripe/services/test_helpers/treasury_service.rb +19 -0
  330. data/lib/stripe/services/test_helpers_service.rb +19 -0
  331. data/lib/stripe/services/token_service.rb +23 -0
  332. data/lib/stripe/services/topup_service.rb +49 -0
  333. data/lib/stripe/services/transfer_reversal_service.rb +56 -0
  334. data/lib/stripe/services/transfer_service.rb +47 -0
  335. data/lib/stripe/services/treasury/credit_reversal_service.rb +41 -0
  336. data/lib/stripe/services/treasury/debit_reversal_service.rb +41 -0
  337. data/lib/stripe/services/treasury/financial_account_features_service.rb +30 -0
  338. data/lib/stripe/services/treasury/financial_account_service.rb +70 -0
  339. data/lib/stripe/services/treasury/inbound_transfer_service.rb +52 -0
  340. data/lib/stripe/services/treasury/outbound_payment_service.rb +52 -0
  341. data/lib/stripe/services/treasury/outbound_transfer_service.rb +52 -0
  342. data/lib/stripe/services/treasury/received_credit_service.rb +30 -0
  343. data/lib/stripe/services/treasury/received_debit_service.rb +30 -0
  344. data/lib/stripe/services/treasury/transaction_entry_service.rb +30 -0
  345. data/lib/stripe/services/treasury/transaction_service.rb +30 -0
  346. data/lib/stripe/services/treasury_service.rb +22 -0
  347. data/lib/stripe/services/v1_services.rb +89 -0
  348. data/lib/stripe/services/v2/billing/meter_event_adjustment_service.rb +21 -0
  349. data/lib/stripe/services/v2/billing/meter_event_service.rb +21 -0
  350. data/lib/stripe/services/v2/billing/meter_event_session_service.rb +21 -0
  351. data/lib/stripe/services/v2/billing/meter_event_stream_service.rb +23 -0
  352. data/lib/stripe/services/v2/billing_service.rb +18 -0
  353. data/lib/stripe/services/v2/core/event_destination_service.rb +98 -0
  354. data/lib/stripe/services/v2/core/event_service.rb +32 -0
  355. data/lib/stripe/services/v2/core_service.rb +16 -0
  356. data/lib/stripe/services/v2_services.rb +14 -0
  357. data/lib/stripe/services/webhook_endpoint_service.rb +61 -0
  358. data/lib/stripe/services.rb +182 -0
  359. data/lib/stripe/singleton_api_resource.rb +3 -3
  360. data/lib/stripe/stripe_client.rb +55 -1028
  361. data/lib/stripe/stripe_configuration.rb +63 -42
  362. data/lib/stripe/stripe_object.rb +60 -38
  363. data/lib/stripe/stripe_response.rb +1 -3
  364. data/lib/stripe/stripe_service.rb +32 -0
  365. data/lib/stripe/thin_event.rb +37 -0
  366. data/lib/stripe/util.rb +109 -45
  367. data/lib/stripe/v2_list_object.rb +84 -0
  368. data/lib/stripe/version.rb +1 -1
  369. data/lib/stripe/webhook.rb +3 -2
  370. data/lib/stripe.rb +39 -0
  371. data/stripe.gemspec +7 -4
  372. metadata +252 -13
  373. data/lib/stripe/resources/bitcoin_receiver.rb +0 -24
  374. data/lib/stripe/resources/bitcoin_transaction.rb +0 -16
  375. data/lib/stripe/resources/issuing/card_details.rb +0 -10
  376. data/lib/stripe/resources/order.rb +0 -33
  377. data/lib/stripe/resources/order_return.rb +0 -10
  378. data/lib/stripe/resources/recipient.rb +0 -14
  379. data/lib/stripe/resources/sku.rb +0 -13
  380. data/lib/stripe/resources/three_d_secure.rb +0 -14
@@ -2,39 +2,145 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # A SetupIntent guides you through the process of setting up and saving a customer's payment credentials for future payments.
6
+ # For example, you can use a SetupIntent to set up and save your customer's card without immediately collecting a payment.
7
+ # Later, you can use [PaymentIntents](https://stripe.com/docs/api#payment_intents) to drive the payment flow.
8
+ #
9
+ # Create a SetupIntent when you're ready to collect your customer's payment credentials.
10
+ # Don't maintain long-lived, unconfirmed SetupIntents because they might not be valid.
11
+ # The SetupIntent transitions through multiple [statuses](https://docs.stripe.com/payments/intents#intent-statuses) as it guides
12
+ # you through the setup process.
13
+ #
14
+ # Successful SetupIntents result in payment credentials that are optimized for future payments.
15
+ # For example, cardholders in [certain regions](https://stripe.com/guides/strong-customer-authentication) might need to be run through
16
+ # [Strong Customer Authentication](https://docs.stripe.com/strong-customer-authentication) during payment method collection
17
+ # to streamline later [off-session payments](https://docs.stripe.com/payments/setup-intents).
18
+ # If you use the SetupIntent with a [Customer](https://stripe.com/docs/api#setup_intent_object-customer),
19
+ # it automatically attaches the resulting payment method to that Customer after successful setup.
20
+ # We recommend using SetupIntents or [setup_future_usage](https://stripe.com/docs/api#payment_intent_object-setup_future_usage) on
21
+ # PaymentIntents to save payment methods to prevent saving invalid or unoptimized payment methods.
22
+ #
23
+ # By using SetupIntents, you can reduce friction for your customers, even as regulations change over time.
24
+ #
25
+ # Related guide: [Setup Intents API](https://docs.stripe.com/payments/setup-intents)
5
26
  class SetupIntent < APIResource
6
27
  extend Stripe::APIOperations::Create
7
28
  extend Stripe::APIOperations::List
8
29
  include Stripe::APIOperations::Save
9
30
 
10
31
  OBJECT_NAME = "setup_intent"
32
+ def self.object_name
33
+ "setup_intent"
34
+ end
11
35
 
12
- custom_method :cancel, http_verb: :post
13
- custom_method :confirm, http_verb: :post
14
- custom_method :verify_microdeposits, http_verb: :post
15
-
36
+ # You can cancel a SetupIntent object when it's in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.
37
+ #
38
+ # After you cancel it, setup is abandoned and any operations on the SetupIntent fail with an error. You can't cancel the SetupIntent for a Checkout Session. [Expire the Checkout Session](https://stripe.com/docs/api/checkout/sessions/expire) instead.
16
39
  def cancel(params = {}, opts = {})
17
40
  request_stripe_object(
18
41
  method: :post,
19
- path: resource_url + "/cancel",
42
+ path: format("/v1/setup_intents/%<intent>s/cancel", { intent: CGI.escape(self["id"]) }),
43
+ params: params,
44
+ opts: opts
45
+ )
46
+ end
47
+
48
+ # You can cancel a SetupIntent object when it's in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.
49
+ #
50
+ # After you cancel it, setup is abandoned and any operations on the SetupIntent fail with an error. You can't cancel the SetupIntent for a Checkout Session. [Expire the Checkout Session](https://stripe.com/docs/api/checkout/sessions/expire) instead.
51
+ def self.cancel(intent, params = {}, opts = {})
52
+ request_stripe_object(
53
+ method: :post,
54
+ path: format("/v1/setup_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
20
55
  params: params,
21
56
  opts: opts
22
57
  )
23
58
  end
24
59
 
60
+ # Confirm that your customer intends to set up the current or
61
+ # provided payment method. For example, you would confirm a SetupIntent
62
+ # when a customer hits the “Save” button on a payment method management
63
+ # page on your website.
64
+ #
65
+ # If the selected payment method does not require any additional
66
+ # steps from the customer, the SetupIntent will transition to the
67
+ # succeeded status.
68
+ #
69
+ # Otherwise, it will transition to the requires_action status and
70
+ # suggest additional actions via next_action. If setup fails,
71
+ # the SetupIntent will transition to the
72
+ # requires_payment_method status or the canceled status if the
73
+ # confirmation limit is reached.
25
74
  def confirm(params = {}, opts = {})
26
75
  request_stripe_object(
27
76
  method: :post,
28
- path: resource_url + "/confirm",
77
+ path: format("/v1/setup_intents/%<intent>s/confirm", { intent: CGI.escape(self["id"]) }),
78
+ params: params,
79
+ opts: opts
80
+ )
81
+ end
82
+
83
+ # Confirm that your customer intends to set up the current or
84
+ # provided payment method. For example, you would confirm a SetupIntent
85
+ # when a customer hits the “Save” button on a payment method management
86
+ # page on your website.
87
+ #
88
+ # If the selected payment method does not require any additional
89
+ # steps from the customer, the SetupIntent will transition to the
90
+ # succeeded status.
91
+ #
92
+ # Otherwise, it will transition to the requires_action status and
93
+ # suggest additional actions via next_action. If setup fails,
94
+ # the SetupIntent will transition to the
95
+ # requires_payment_method status or the canceled status if the
96
+ # confirmation limit is reached.
97
+ def self.confirm(intent, params = {}, opts = {})
98
+ request_stripe_object(
99
+ method: :post,
100
+ path: format("/v1/setup_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
101
+ params: params,
102
+ opts: opts
103
+ )
104
+ end
105
+
106
+ # Creates a SetupIntent object.
107
+ #
108
+ # After you create the SetupIntent, attach a payment method and [confirm](https://stripe.com/docs/api/setup_intents/confirm)
109
+ # it to collect any required permissions to charge the payment method later.
110
+ def self.create(params = {}, opts = {})
111
+ request_stripe_object(method: :post, path: "/v1/setup_intents", params: params, opts: opts)
112
+ end
113
+
114
+ # Returns a list of SetupIntents.
115
+ def self.list(params = {}, opts = {})
116
+ request_stripe_object(method: :get, path: "/v1/setup_intents", params: params, opts: opts)
117
+ end
118
+
119
+ # Updates a SetupIntent object.
120
+ def self.update(intent, params = {}, opts = {})
121
+ request_stripe_object(
122
+ method: :post,
123
+ path: format("/v1/setup_intents/%<intent>s", { intent: CGI.escape(intent) }),
29
124
  params: params,
30
125
  opts: opts
31
126
  )
32
127
  end
33
128
 
129
+ # Verifies microdeposits on a SetupIntent object.
34
130
  def verify_microdeposits(params = {}, opts = {})
35
131
  request_stripe_object(
36
132
  method: :post,
37
- path: resource_url + "/verify_microdeposits",
133
+ path: format("/v1/setup_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(self["id"]) }),
134
+ params: params,
135
+ opts: opts
136
+ )
137
+ end
138
+
139
+ # Verifies microdeposits on a SetupIntent object.
140
+ def self.verify_microdeposits(intent, params = {}, opts = {})
141
+ request_stripe_object(
142
+ method: :post,
143
+ path: format("/v1/setup_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
38
144
  params: params,
39
145
  opts: opts
40
146
  )
@@ -2,11 +2,36 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # Shipping rates describe the price of shipping presented to your customers and
6
+ # applied to a purchase. For more information, see [Charge for shipping](https://stripe.com/docs/payments/during-payment/charge-shipping).
5
7
  class ShippingRate < APIResource
6
8
  extend Stripe::APIOperations::Create
7
9
  extend Stripe::APIOperations::List
8
10
  include Stripe::APIOperations::Save
9
11
 
10
12
  OBJECT_NAME = "shipping_rate"
13
+ def self.object_name
14
+ "shipping_rate"
15
+ end
16
+
17
+ # Creates a new shipping rate object.
18
+ def self.create(params = {}, opts = {})
19
+ request_stripe_object(method: :post, path: "/v1/shipping_rates", params: params, opts: opts)
20
+ end
21
+
22
+ # Returns a list of your shipping rates.
23
+ def self.list(params = {}, opts = {})
24
+ request_stripe_object(method: :get, path: "/v1/shipping_rates", params: params, opts: opts)
25
+ end
26
+
27
+ # Updates an existing shipping rate object.
28
+ def self.update(shipping_rate_token, params = {}, opts = {})
29
+ request_stripe_object(
30
+ method: :post,
31
+ path: format("/v1/shipping_rates/%<shipping_rate_token>s", { shipping_rate_token: CGI.escape(shipping_rate_token) }),
32
+ params: params,
33
+ opts: opts
34
+ )
35
+ end
11
36
  end
12
37
  end
@@ -3,10 +3,27 @@
3
3
 
4
4
  module Stripe
5
5
  module Sigma
6
+ # If you have [scheduled a Sigma query](https://stripe.com/docs/sigma/scheduled-queries), you'll
7
+ # receive a `sigma.scheduled_query_run.created` webhook each time the query
8
+ # runs. The webhook contains a `ScheduledQueryRun` object, which you can use to
9
+ # retrieve the query results.
6
10
  class ScheduledQueryRun < APIResource
7
11
  extend Stripe::APIOperations::List
8
12
 
9
13
  OBJECT_NAME = "scheduled_query_run"
14
+ def self.object_name
15
+ "scheduled_query_run"
16
+ end
17
+
18
+ # Returns a list of scheduled query runs.
19
+ def self.list(params = {}, opts = {})
20
+ request_stripe_object(
21
+ method: :get,
22
+ path: "/v1/sigma/scheduled_query_runs",
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
10
27
 
11
28
  def self.resource_url
12
29
  "/v1/sigma/scheduled_query_runs"
@@ -2,22 +2,60 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # `Source` objects allow you to accept a variety of payment methods. They
6
+ # represent a customer's payment instrument, and can be used with the Stripe API
7
+ # just like a `Card` object: once chargeable, they can be charged, or can be
8
+ # attached to customers.
9
+ #
10
+ # Stripe doesn't recommend using the deprecated [Sources API](https://stripe.com/docs/api/sources).
11
+ # We recommend that you adopt the [PaymentMethods API](https://stripe.com/docs/api/payment_methods).
12
+ # This newer API provides access to our latest features and payment method types.
13
+ #
14
+ # Related guides: [Sources API](https://stripe.com/docs/sources) and [Sources & Customers](https://stripe.com/docs/sources/customers).
5
15
  class Source < APIResource
6
16
  extend Stripe::APIOperations::Create
7
- include Stripe::APIOperations::Save
8
17
  extend Stripe::APIOperations::NestedResource
18
+ include Stripe::APIOperations::Save
9
19
 
10
20
  OBJECT_NAME = "source"
21
+ def self.object_name
22
+ "source"
23
+ end
11
24
 
12
- custom_method :verify, http_verb: :post
25
+ nested_resource_class_methods :source_transaction, operations: %i[retrieve list]
13
26
 
14
- nested_resource_class_methods :source_transaction,
15
- operations: %i[retrieve list]
27
+ # Creates a new source object.
28
+ def self.create(params = {}, opts = {})
29
+ request_stripe_object(method: :post, path: "/v1/sources", params: params, opts: opts)
30
+ end
31
+
32
+ # Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
33
+ #
34
+ # This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our [payment method guides](https://stripe.com/docs/sources) for more detail.
35
+ def self.update(source, params = {}, opts = {})
36
+ request_stripe_object(
37
+ method: :post,
38
+ path: format("/v1/sources/%<source>s", { source: CGI.escape(source) }),
39
+ params: params,
40
+ opts: opts
41
+ )
42
+ end
16
43
 
44
+ # Verify a given source.
17
45
  def verify(params = {}, opts = {})
18
46
  request_stripe_object(
19
47
  method: :post,
20
- path: resource_url + "/verify",
48
+ path: format("/v1/sources/%<source>s/verify", { source: CGI.escape(self["id"]) }),
49
+ params: params,
50
+ opts: opts
51
+ )
52
+ end
53
+
54
+ # Verify a given source.
55
+ def self.verify(source, params = {}, opts = {})
56
+ request_stripe_object(
57
+ method: :post,
58
+ path: format("/v1/sources/%<source>s/verify", { source: CGI.escape(source) }),
21
59
  params: params,
22
60
  opts: opts
23
61
  )
@@ -32,14 +70,18 @@ module Stripe
32
70
 
33
71
  url = "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
34
72
  "/#{CGI.escape(id)}"
35
- resp, opts = execute_resource_request(:delete, url, params, opts)
36
- initialize_from(resp.data, opts)
73
+ opts = Util.normalize_opts(opts)
74
+ APIRequestor.active_requestor.execute_request_initialize_from(:delete, url, :api, self,
75
+ params: params, opts: RequestOptions.extract_opts_from_hash(opts))
37
76
  end
38
77
 
39
78
  def source_transactions(params = {}, opts = {})
40
- resp, opts = execute_resource_request(:get, resource_url + "/source_transactions", params,
41
- opts)
42
- Util.convert_to_stripe_object(resp.data, opts)
79
+ request_stripe_object(
80
+ method: :get,
81
+ path: resource_url + "/source_transactions",
82
+ params: params,
83
+ opts: opts
84
+ )
43
85
  end
44
86
  extend Gem::Deprecate
45
87
  deprecate :source_transactions, :"Source.list_source_transactions", 2020, 1
@@ -2,7 +2,14 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # Some payment methods have no required amount that a customer must send.
6
+ # Customers can be instructed to send any amount, and it can be made up of
7
+ # multiple transactions. As such, sources can have multiple associated
8
+ # transactions.
5
9
  class SourceTransaction < StripeObject
6
10
  OBJECT_NAME = "source_transaction"
11
+ def self.object_name
12
+ "source_transaction"
13
+ end
7
14
  end
8
15
  end
@@ -2,34 +2,147 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # Subscriptions allow you to charge a customer on a recurring basis.
6
+ #
7
+ # Related guide: [Creating subscriptions](https://stripe.com/docs/billing/subscriptions/creating)
5
8
  class Subscription < APIResource
6
9
  extend Stripe::APIOperations::Create
7
- include Stripe::APIOperations::Delete
8
10
  extend Stripe::APIOperations::List
9
11
  extend Stripe::APIOperations::Search
10
12
  include Stripe::APIOperations::Save
11
13
 
12
14
  OBJECT_NAME = "subscription"
15
+ def self.object_name
16
+ "subscription"
17
+ end
13
18
 
14
- custom_method :delete_discount, http_verb: :delete, http_path: "discount"
19
+ # Cancels a customer's subscription immediately. The customer won't be charged again for the subscription. After it's canceled, you can no longer update the subscription or its [metadata](https://stripe.com/metadata).
20
+ #
21
+ # Any pending invoice items that you've created are still charged at the end of the period, unless manually [deleted](https://stripe.com/docs/api#delete_invoiceitem). If you've set the subscription to cancel at the end of the period, any pending prorations are also left in place and collected at the end of the period. But if the subscription is set to cancel immediately, pending prorations are removed.
22
+ #
23
+ # By default, upon subscription cancellation, Stripe stops automatic collection of all finalized invoices for the customer. This is intended to prevent unexpected payment attempts after the customer has canceled a subscription. However, you can resume automatic collection of the invoices manually after subscription cancellation to have us proceed. Or, you could check for unpaid invoices before allowing the customer to cancel the subscription at all.
24
+ def cancel(params = {}, opts = {})
25
+ request_stripe_object(
26
+ method: :delete,
27
+ path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(self["id"]) }),
28
+ params: params,
29
+ opts: opts
30
+ )
31
+ end
15
32
 
33
+ # Cancels a customer's subscription immediately. The customer won't be charged again for the subscription. After it's canceled, you can no longer update the subscription or its [metadata](https://stripe.com/metadata).
34
+ #
35
+ # Any pending invoice items that you've created are still charged at the end of the period, unless manually [deleted](https://stripe.com/docs/api#delete_invoiceitem). If you've set the subscription to cancel at the end of the period, any pending prorations are also left in place and collected at the end of the period. But if the subscription is set to cancel immediately, pending prorations are removed.
36
+ #
37
+ # By default, upon subscription cancellation, Stripe stops automatic collection of all finalized invoices for the customer. This is intended to prevent unexpected payment attempts after the customer has canceled a subscription. However, you can resume automatic collection of the invoices manually after subscription cancellation to have us proceed. Or, you could check for unpaid invoices before allowing the customer to cancel the subscription at all.
38
+ def self.cancel(subscription_exposed_id, params = {}, opts = {})
39
+ request_stripe_object(
40
+ method: :delete,
41
+ path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }),
42
+ params: params,
43
+ opts: opts
44
+ )
45
+ end
46
+
47
+ # Creates a new subscription on an existing customer. Each customer can have up to 500 active or scheduled subscriptions.
48
+ #
49
+ # When you create a subscription with collection_method=charge_automatically, the first invoice is finalized as part of the request.
50
+ # The payment_behavior parameter determines the exact behavior of the initial payment.
51
+ #
52
+ # To start subscriptions where the first invoice always begins in a draft status, use [subscription schedules](https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing) instead.
53
+ # Schedules provide the flexibility to model more complex billing configurations that change over time.
54
+ def self.create(params = {}, opts = {})
55
+ request_stripe_object(method: :post, path: "/v1/subscriptions", params: params, opts: opts)
56
+ end
57
+
58
+ # Removes the currently applied discount on a subscription.
16
59
  def delete_discount(params = {}, opts = {})
17
60
  request_stripe_object(
18
61
  method: :delete,
19
- path: resource_url + "/discount",
62
+ path: format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(self["id"]) }),
20
63
  params: params,
21
64
  opts: opts
22
65
  )
23
66
  end
24
67
 
25
- save_nested_resource :source
68
+ # Removes the currently applied discount on a subscription.
69
+ def self.delete_discount(subscription_exposed_id, params = {}, opts = {})
70
+ request_stripe_object(
71
+ method: :delete,
72
+ path: format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }),
73
+ params: params,
74
+ opts: opts
75
+ )
76
+ end
77
+
78
+ # By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify status=canceled.
79
+ def self.list(params = {}, opts = {})
80
+ request_stripe_object(method: :get, path: "/v1/subscriptions", params: params, opts: opts)
81
+ end
82
+
83
+ # Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations. If a resumption invoice is generated, it must be paid or marked uncollectible before the subscription will be unpaused. If payment succeeds the subscription will become active, and if payment fails the subscription will be past_due. The resumption invoice will void automatically if not paid by the expiration date.
84
+ def resume(params = {}, opts = {})
85
+ request_stripe_object(
86
+ method: :post,
87
+ path: format("/v1/subscriptions/%<subscription>s/resume", { subscription: CGI.escape(self["id"]) }),
88
+ params: params,
89
+ opts: opts
90
+ )
91
+ end
92
+
93
+ # Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations. If a resumption invoice is generated, it must be paid or marked uncollectible before the subscription will be unpaused. If payment succeeds the subscription will become active, and if payment fails the subscription will be past_due. The resumption invoice will void automatically if not paid by the expiration date.
94
+ def self.resume(subscription, params = {}, opts = {})
95
+ request_stripe_object(
96
+ method: :post,
97
+ path: format("/v1/subscriptions/%<subscription>s/resume", { subscription: CGI.escape(subscription) }),
98
+ params: params,
99
+ opts: opts
100
+ )
101
+ end
26
102
 
27
103
  def self.search(params = {}, opts = {})
28
- _search("/v1/subscriptions/search", params, opts)
104
+ request_stripe_object(
105
+ method: :get,
106
+ path: "/v1/subscriptions/search",
107
+ params: params,
108
+ opts: opts
109
+ )
29
110
  end
30
111
 
31
112
  def self.search_auto_paging_each(params = {}, opts = {}, &blk)
32
113
  search(params, opts).auto_paging_each(&blk)
33
114
  end
115
+
116
+ # Updates an existing subscription to match the specified parameters.
117
+ # When changing prices or quantities, we optionally prorate the price we charge next month to make up for any price changes.
118
+ # To preview how the proration is calculated, use the [create preview](https://stripe.com/docs/api/invoices/create_preview) endpoint.
119
+ #
120
+ # By default, we prorate subscription changes. For example, if a customer signs up on May 1 for a 100 price, they'll be billed 100 immediately. If on May 15 they switch to a 200 price, then on June 1 they'll be billed 250 (200 for a renewal of her subscription, plus a 50 prorating adjustment for half of the previous month's 100 difference). Similarly, a downgrade generates a credit that is applied to the next invoice. We also prorate when you make quantity changes.
121
+ #
122
+ # Switching prices does not normally change the billing date or generate an immediate charge unless:
123
+ #
124
+ #
125
+ # The billing interval is changed (for example, from monthly to yearly).
126
+ # The subscription moves from free to paid.
127
+ # A trial starts or ends.
128
+ #
129
+ #
130
+ # In these cases, we apply a credit for the unused time on the previous price, immediately charge the customer using the new price, and reset the billing date. Learn about how [Stripe immediately attempts payment for subscription changes](https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment).
131
+ #
132
+ # If you want to charge for an upgrade immediately, pass proration_behavior as always_invoice to create prorations, automatically invoice the customer for those proration adjustments, and attempt to collect payment. If you pass create_prorations, the prorations are created but not automatically invoiced. If you want to bill the customer for the prorations before the subscription's renewal date, you need to manually [invoice the customer](https://stripe.com/docs/api/invoices/create).
133
+ #
134
+ # If you don't want to prorate, set the proration_behavior option to none. With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set proration_behavior to none when switching between different billing intervals (for example, from monthly to yearly), we don't generate any credits for the old subscription's unused time. We still reset the billing date and bill immediately for the new subscription.
135
+ #
136
+ # Updating the quantity on a subscription many times in an hour may result in [rate limiting. If you need to bill for a frequently changing quantity, consider integrating <a href="/docs/billing/subscriptions/usage-based">usage-based billing](https://stripe.com/docs/rate-limits) instead.
137
+ def self.update(subscription_exposed_id, params = {}, opts = {})
138
+ request_stripe_object(
139
+ method: :post,
140
+ path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }),
141
+ params: params,
142
+ opts: opts
143
+ )
144
+ end
145
+
146
+ save_nested_resource :source
34
147
  end
35
148
  end
@@ -2,25 +2,73 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # Subscription items allow you to create customer subscriptions with more than
6
+ # one plan, making it easy to represent complex billing relationships.
5
7
  class SubscriptionItem < APIResource
6
8
  extend Stripe::APIOperations::Create
7
9
  include Stripe::APIOperations::Delete
8
10
  extend Stripe::APIOperations::List
9
- include Stripe::APIOperations::Save
10
11
  extend Stripe::APIOperations::NestedResource
12
+ include Stripe::APIOperations::Save
11
13
 
12
14
  OBJECT_NAME = "subscription_item"
15
+ def self.object_name
16
+ "subscription_item"
17
+ end
13
18
 
14
19
  nested_resource_class_methods :usage_record, operations: %i[create]
15
20
  nested_resource_class_methods :usage_record_summary,
16
21
  operations: %i[list],
17
22
  resource_plural: "usage_record_summaries"
18
23
 
19
- def usage_record_summaries(params = {}, opts = {})
20
- resp, opts = execute_resource_request(:get, resource_url + "/usage_record_summaries", params, opts)
21
- Util.convert_to_stripe_object(resp.data, opts)
24
+ # Adds a new item to an existing subscription. No existing items will be changed or replaced.
25
+ def self.create(params = {}, opts = {})
26
+ request_stripe_object(
27
+ method: :post,
28
+ path: "/v1/subscription_items",
29
+ params: params,
30
+ opts: opts
31
+ )
32
+ end
33
+
34
+ # Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription.
35
+ def self.delete(item, params = {}, opts = {})
36
+ request_stripe_object(
37
+ method: :delete,
38
+ path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(item) }),
39
+ params: params,
40
+ opts: opts
41
+ )
42
+ end
43
+
44
+ # Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription.
45
+ def delete(params = {}, opts = {})
46
+ request_stripe_object(
47
+ method: :delete,
48
+ path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(self["id"]) }),
49
+ params: params,
50
+ opts: opts
51
+ )
52
+ end
53
+
54
+ # Returns a list of your subscription items for a given subscription.
55
+ def self.list(params = {}, opts = {})
56
+ request_stripe_object(
57
+ method: :get,
58
+ path: "/v1/subscription_items",
59
+ params: params,
60
+ opts: opts
61
+ )
62
+ end
63
+
64
+ # Updates the plan or quantity of an item on a current subscription.
65
+ def self.update(item, params = {}, opts = {})
66
+ request_stripe_object(
67
+ method: :post,
68
+ path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(item) }),
69
+ params: params,
70
+ opts: opts
71
+ )
22
72
  end
23
- extend Gem::Deprecate
24
- deprecate :usage_record_summaries, :"SubscriptionItem.list_usage_record_summaries", 2020, 1
25
73
  end
26
74
  end
@@ -2,29 +2,84 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # A subscription schedule allows you to create and manage the lifecycle of a subscription by predefining expected changes.
6
+ #
7
+ # Related guide: [Subscription schedules](https://stripe.com/docs/billing/subscriptions/subscription-schedules)
5
8
  class SubscriptionSchedule < APIResource
6
9
  extend Stripe::APIOperations::Create
7
10
  extend Stripe::APIOperations::List
8
11
  include Stripe::APIOperations::Save
9
12
 
10
13
  OBJECT_NAME = "subscription_schedule"
14
+ def self.object_name
15
+ "subscription_schedule"
16
+ end
11
17
 
12
- custom_method :cancel, http_verb: :post
13
- custom_method :release, http_verb: :post
14
-
18
+ # Cancels a subscription schedule and its associated subscription immediately (if the subscription schedule has an active subscription). A subscription schedule can only be canceled if its status is not_started or active.
15
19
  def cancel(params = {}, opts = {})
16
20
  request_stripe_object(
17
21
  method: :post,
18
- path: resource_url + "/cancel",
22
+ path: format("/v1/subscription_schedules/%<schedule>s/cancel", { schedule: CGI.escape(self["id"]) }),
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
27
+
28
+ # Cancels a subscription schedule and its associated subscription immediately (if the subscription schedule has an active subscription). A subscription schedule can only be canceled if its status is not_started or active.
29
+ def self.cancel(schedule, params = {}, opts = {})
30
+ request_stripe_object(
31
+ method: :post,
32
+ path: format("/v1/subscription_schedules/%<schedule>s/cancel", { schedule: CGI.escape(schedule) }),
33
+ params: params,
34
+ opts: opts
35
+ )
36
+ end
37
+
38
+ # Creates a new subscription schedule object. Each customer can have up to 500 active or scheduled subscriptions.
39
+ def self.create(params = {}, opts = {})
40
+ request_stripe_object(
41
+ method: :post,
42
+ path: "/v1/subscription_schedules",
43
+ params: params,
44
+ opts: opts
45
+ )
46
+ end
47
+
48
+ # Retrieves the list of your subscription schedules.
49
+ def self.list(params = {}, opts = {})
50
+ request_stripe_object(
51
+ method: :get,
52
+ path: "/v1/subscription_schedules",
19
53
  params: params,
20
54
  opts: opts
21
55
  )
22
56
  end
23
57
 
58
+ # Releases the subscription schedule immediately, which will stop scheduling of its phases, but leave any existing subscription in place. A schedule can only be released if its status is not_started or active. If the subscription schedule is currently associated with a subscription, releasing it will remove its subscription property and set the subscription's ID to the released_subscription property.
24
59
  def release(params = {}, opts = {})
25
60
  request_stripe_object(
26
61
  method: :post,
27
- path: resource_url + "/release",
62
+ path: format("/v1/subscription_schedules/%<schedule>s/release", { schedule: CGI.escape(self["id"]) }),
63
+ params: params,
64
+ opts: opts
65
+ )
66
+ end
67
+
68
+ # Releases the subscription schedule immediately, which will stop scheduling of its phases, but leave any existing subscription in place. A schedule can only be released if its status is not_started or active. If the subscription schedule is currently associated with a subscription, releasing it will remove its subscription property and set the subscription's ID to the released_subscription property.
69
+ def self.release(schedule, params = {}, opts = {})
70
+ request_stripe_object(
71
+ method: :post,
72
+ path: format("/v1/subscription_schedules/%<schedule>s/release", { schedule: CGI.escape(schedule) }),
73
+ params: params,
74
+ opts: opts
75
+ )
76
+ end
77
+
78
+ # Updates an existing subscription schedule.
79
+ def self.update(schedule, params = {}, opts = {})
80
+ request_stripe_object(
81
+ method: :post,
82
+ path: format("/v1/subscription_schedules/%<schedule>s", { schedule: CGI.escape(schedule) }),
28
83
  params: params,
29
84
  opts: opts
30
85
  )