stripe 12.7.0.pre.beta.2 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +720 -1360
  3. data/OPENAPI_VERSION +1 -1
  4. data/README.md +4 -3
  5. data/VERSION +1 -1
  6. data/examples/README.md +11 -0
  7. data/examples/meter_event_stream.rb +47 -0
  8. data/examples/new_example.rb +24 -0
  9. data/examples/stripe_webhook_handler.rb +28 -0
  10. data/lib/stripe/api_operations/nested_resource.rb +1 -21
  11. data/lib/stripe/api_operations/request.rb +19 -70
  12. data/lib/stripe/api_operations/save.rb +4 -3
  13. data/lib/stripe/api_operations/singleton_save.rb +5 -2
  14. data/lib/stripe/api_requestor.rb +1131 -0
  15. data/lib/stripe/api_resource.rb +22 -14
  16. data/lib/stripe/api_version.rb +1 -2
  17. data/lib/stripe/connection_manager.rb +1 -1
  18. data/lib/stripe/errors.rb +8 -2
  19. data/lib/stripe/event_types.rb +14 -0
  20. data/lib/stripe/events/v1_billing_meter_error_report_triggered_event.rb +23 -0
  21. data/lib/stripe/events/v1_billing_meter_no_meter_found_event.rb +13 -0
  22. data/lib/stripe/list_object.rb +2 -3
  23. data/lib/stripe/oauth.rb +8 -15
  24. data/lib/stripe/object_types.rb +16 -20
  25. data/lib/stripe/request_options.rb +128 -0
  26. data/lib/stripe/resources/billing/credit_balance_summary.rb +14 -0
  27. data/lib/stripe/resources/billing/credit_balance_transaction.rb +26 -0
  28. data/lib/stripe/resources/billing/credit_grant.rb +88 -0
  29. data/lib/stripe/resources/customer.rb +2 -3
  30. data/lib/stripe/resources/file.rb +7 -5
  31. data/lib/stripe/resources/financial_connections/account.rb +0 -3
  32. data/lib/stripe/resources/invoice.rb +0 -81
  33. data/lib/stripe/resources/payment_intent.rb +0 -50
  34. data/lib/stripe/resources/quote.rb +4 -108
  35. data/lib/stripe/resources/source.rb +3 -2
  36. data/lib/stripe/resources/subscription.rb +6 -6
  37. data/lib/stripe/resources/subscription_schedule.rb +0 -20
  38. data/lib/stripe/resources/terminal/reader.rb +0 -60
  39. data/lib/stripe/resources/v2/billing/meter_event.rb +16 -0
  40. data/lib/stripe/resources/v2/billing/meter_event_adjustment.rb +15 -0
  41. data/lib/stripe/resources/v2/billing/meter_event_session.rb +15 -0
  42. data/lib/stripe/resources/v2/event.rb +13 -0
  43. data/lib/stripe/resources.rb +9 -18
  44. data/lib/stripe/search_result_object.rb +1 -1
  45. data/lib/stripe/services/account_capability_service.rb +39 -0
  46. data/lib/stripe/services/account_external_account_service.rb +68 -0
  47. data/lib/stripe/services/account_link_service.rb +17 -0
  48. data/lib/stripe/services/account_login_link_service.rb +19 -0
  49. data/lib/stripe/services/account_person_service.rb +61 -0
  50. data/lib/stripe/services/account_service.rb +100 -0
  51. data/lib/stripe/services/account_session_service.rb +17 -0
  52. data/lib/stripe/services/apple_pay_domain_service.rb +50 -0
  53. data/lib/stripe/services/application_fee_refund_service.rb +60 -0
  54. data/lib/stripe/services/application_fee_service.rb +35 -0
  55. data/lib/stripe/services/apps/secret_service.rb +52 -0
  56. data/lib/stripe/services/apps_service.rb +13 -0
  57. data/lib/stripe/services/balance_service.rb +12 -0
  58. data/lib/stripe/services/balance_transaction_service.rb +32 -0
  59. data/lib/stripe/services/billing/alert_service.rb +74 -0
  60. data/lib/stripe/services/billing/credit_balance_summary_service.rb +19 -0
  61. data/lib/stripe/services/billing/credit_balance_transaction_service.rb +30 -0
  62. data/lib/stripe/services/billing/credit_grant_service.rb +74 -0
  63. data/lib/stripe/services/billing/meter_event_adjustment_service.rb +19 -0
  64. data/lib/stripe/services/billing/meter_event_service.rb +19 -0
  65. data/lib/stripe/services/billing/meter_event_summary_service.rb +19 -0
  66. data/lib/stripe/services/billing/meter_service.rb +81 -0
  67. data/lib/stripe/services/billing_portal/configuration_service.rb +52 -0
  68. data/lib/stripe/services/billing_portal/session_service.rb +19 -0
  69. data/lib/stripe/services/billing_portal_service.rb +14 -0
  70. data/lib/stripe/services/billing_service.rb +20 -0
  71. data/lib/stripe/services/charge_service.rb +69 -0
  72. data/lib/stripe/services/checkout/session_line_item_service.rb +19 -0
  73. data/lib/stripe/services/checkout/session_service.rb +72 -0
  74. data/lib/stripe/services/checkout_service.rb +13 -0
  75. data/lib/stripe/services/climate/order_service.rb +68 -0
  76. data/lib/stripe/services/climate/product_service.rb +30 -0
  77. data/lib/stripe/services/climate/supplier_service.rb +30 -0
  78. data/lib/stripe/services/climate_service.rb +15 -0
  79. data/lib/stripe/services/confirmation_token_service.rb +17 -0
  80. data/lib/stripe/services/country_spec_service.rb +28 -0
  81. data/lib/stripe/services/coupon_service.rb +51 -0
  82. data/lib/stripe/services/credit_note_line_item_service.rb +17 -0
  83. data/lib/stripe/services/credit_note_preview_lines_service.rb +17 -0
  84. data/lib/stripe/services/credit_note_service.rb +93 -0
  85. data/lib/stripe/services/customer_balance_transaction_service.rb +50 -0
  86. data/lib/stripe/services/customer_cash_balance_service.rb +28 -0
  87. data/lib/stripe/services/customer_cash_balance_transaction_service.rb +28 -0
  88. data/lib/stripe/services/customer_funding_instructions_service.rb +19 -0
  89. data/lib/stripe/services/customer_payment_method_service.rb +28 -0
  90. data/lib/stripe/services/customer_payment_source_service.rb +76 -0
  91. data/lib/stripe/services/customer_service.rb +89 -0
  92. data/lib/stripe/services/customer_session_service.rb +17 -0
  93. data/lib/stripe/services/customer_tax_id_service.rb +50 -0
  94. data/lib/stripe/services/dispute_service.rb +48 -0
  95. data/lib/stripe/services/entitlements/active_entitlement_service.rb +30 -0
  96. data/lib/stripe/services/entitlements/feature_service.rb +52 -0
  97. data/lib/stripe/services/entitlements_service.rb +14 -0
  98. data/lib/stripe/services/ephemeral_key_service.rb +28 -0
  99. data/lib/stripe/services/event_service.rb +22 -0
  100. data/lib/stripe/services/exchange_rate_service.rb +28 -0
  101. data/lib/stripe/services/file_link_service.rb +38 -0
  102. data/lib/stripe/services/file_service.rb +35 -0
  103. data/lib/stripe/services/financial_connections/account_owner_service.rb +19 -0
  104. data/lib/stripe/services/financial_connections/account_service.rb +81 -0
  105. data/lib/stripe/services/financial_connections/session_service.rb +30 -0
  106. data/lib/stripe/services/financial_connections/transaction_service.rb +30 -0
  107. data/lib/stripe/services/financial_connections_service.rb +15 -0
  108. data/lib/stripe/services/forwarding/request_service.rb +41 -0
  109. data/lib/stripe/services/forwarding_service.rb +13 -0
  110. data/lib/stripe/services/identity/verification_report_service.rb +30 -0
  111. data/lib/stripe/services/identity/verification_session_service.rb +106 -0
  112. data/lib/stripe/services/identity_service.rb +14 -0
  113. data/lib/stripe/services/invoice_item_service.rb +61 -0
  114. data/lib/stripe/services/invoice_line_item_service.rb +31 -0
  115. data/lib/stripe/services/invoice_rendering_template_service.rb +50 -0
  116. data/lib/stripe/services/invoice_service.rb +202 -0
  117. data/lib/stripe/services/invoice_upcoming_lines_service.rb +17 -0
  118. data/lib/stripe/services/issuing/authorization_service.rb +65 -0
  119. data/lib/stripe/services/issuing/card_service.rb +52 -0
  120. data/lib/stripe/services/issuing/cardholder_service.rb +52 -0
  121. data/lib/stripe/services/issuing/dispute_service.rb +63 -0
  122. data/lib/stripe/services/issuing/personalization_design_service.rb +52 -0
  123. data/lib/stripe/services/issuing/physical_bundle_service.rb +30 -0
  124. data/lib/stripe/services/issuing/token_service.rb +41 -0
  125. data/lib/stripe/services/issuing/transaction_service.rb +41 -0
  126. data/lib/stripe/services/issuing_service.rb +20 -0
  127. data/lib/stripe/services/mandate_service.rb +17 -0
  128. data/lib/stripe/services/oauth_service.rb +63 -0
  129. data/lib/stripe/services/payment_intent_service.rb +204 -0
  130. data/lib/stripe/services/payment_link_line_item_service.rb +17 -0
  131. data/lib/stripe/services/payment_link_service.rb +57 -0
  132. data/lib/stripe/services/payment_method_configuration_service.rb +50 -0
  133. data/lib/stripe/services/payment_method_domain_service.rb +66 -0
  134. data/lib/stripe/services/payment_method_service.rb +86 -0
  135. data/lib/stripe/services/payout_service.rb +66 -0
  136. data/lib/stripe/services/plan_service.rb +49 -0
  137. data/lib/stripe/services/price_service.rb +52 -0
  138. data/lib/stripe/services/product_feature_service.rb +50 -0
  139. data/lib/stripe/services/product_service.rb +70 -0
  140. data/lib/stripe/services/promotion_code_service.rb +50 -0
  141. data/lib/stripe/services/quote_computed_upfront_line_items_service.rb +17 -0
  142. data/lib/stripe/services/quote_line_item_service.rb +17 -0
  143. data/lib/stripe/services/quote_service.rb +92 -0
  144. data/lib/stripe/services/radar/early_fraud_warning_service.rb +32 -0
  145. data/lib/stripe/services/radar/value_list_item_service.rb +52 -0
  146. data/lib/stripe/services/radar/value_list_service.rb +63 -0
  147. data/lib/stripe/services/radar_service.rb +15 -0
  148. data/lib/stripe/services/refund_service.rb +63 -0
  149. data/lib/stripe/services/reporting/report_run_service.rb +41 -0
  150. data/lib/stripe/services/reporting/report_type_service.rb +30 -0
  151. data/lib/stripe/services/reporting_service.rb +14 -0
  152. data/lib/stripe/services/review_service.rb +33 -0
  153. data/lib/stripe/services/setup_attempt_service.rb +17 -0
  154. data/lib/stripe/services/setup_intent_service.rb +105 -0
  155. data/lib/stripe/services/shipping_rate_service.rb +50 -0
  156. data/lib/stripe/services/sigma/scheduled_query_run_service.rb +30 -0
  157. data/lib/stripe/services/sigma_service.rb +13 -0
  158. data/lib/stripe/services/source_service.rb +64 -0
  159. data/lib/stripe/services/source_transaction_service.rb +17 -0
  160. data/lib/stripe/services/subscription_item_service.rb +69 -0
  161. data/lib/stripe/services/subscription_item_usage_record_service.rb +23 -0
  162. data/lib/stripe/services/subscription_item_usage_record_summary_service.rb +19 -0
  163. data/lib/stripe/services/subscription_schedule_service.rb +72 -0
  164. data/lib/stripe/services/subscription_service.rb +127 -0
  165. data/lib/stripe/services/tax/calculation_line_item_service.rb +19 -0
  166. data/lib/stripe/services/tax/calculation_service.rb +37 -0
  167. data/lib/stripe/services/tax/registration_service.rb +54 -0
  168. data/lib/stripe/services/tax/settings_service.rb +30 -0
  169. data/lib/stripe/services/tax/transaction_line_item_service.rb +19 -0
  170. data/lib/stripe/services/tax/transaction_service.rb +48 -0
  171. data/lib/stripe/services/tax_code_service.rb +22 -0
  172. data/lib/stripe/services/tax_id_service.rb +38 -0
  173. data/lib/stripe/services/tax_rate_service.rb +38 -0
  174. data/lib/stripe/services/tax_service.rb +16 -0
  175. data/lib/stripe/services/terminal/configuration_service.rb +63 -0
  176. data/lib/stripe/services/terminal/connection_token_service.rb +19 -0
  177. data/lib/stripe/services/terminal/location_service.rb +64 -0
  178. data/lib/stripe/services/terminal/reader_service.rb +118 -0
  179. data/lib/stripe/services/terminal_service.rb +16 -0
  180. data/lib/stripe/services/test_helpers/confirmation_token_service.rb +19 -0
  181. data/lib/stripe/services/test_helpers/customer_service.rb +19 -0
  182. data/lib/stripe/services/test_helpers/issuing/authorization_service.rb +76 -0
  183. data/lib/stripe/services/test_helpers/issuing/card_service.rb +54 -0
  184. data/lib/stripe/services/test_helpers/issuing/personalization_design_service.rb +43 -0
  185. data/lib/stripe/services/test_helpers/issuing/transaction_service.rb +43 -0
  186. data/lib/stripe/services/test_helpers/issuing_service.rb +19 -0
  187. data/lib/stripe/services/test_helpers/refund_service.rb +19 -0
  188. data/lib/stripe/services/test_helpers/terminal/reader_service.rb +21 -0
  189. data/lib/stripe/services/test_helpers/terminal_service.rb +15 -0
  190. data/lib/stripe/services/test_helpers/test_clock_service.rb +63 -0
  191. data/lib/stripe/services/test_helpers/treasury/inbound_transfer_service.rb +43 -0
  192. data/lib/stripe/services/test_helpers/treasury/outbound_payment_service.rb +54 -0
  193. data/lib/stripe/services/test_helpers/treasury/outbound_transfer_service.rb +54 -0
  194. data/lib/stripe/services/test_helpers/treasury/received_credit_service.rb +21 -0
  195. data/lib/stripe/services/test_helpers/treasury/received_debit_service.rb +21 -0
  196. data/lib/stripe/services/test_helpers/treasury_service.rb +19 -0
  197. data/lib/stripe/services/test_helpers_service.rb +19 -0
  198. data/lib/stripe/services/token_service.rb +23 -0
  199. data/lib/stripe/services/topup_service.rb +49 -0
  200. data/lib/stripe/services/transfer_reversal_service.rb +56 -0
  201. data/lib/stripe/services/transfer_service.rb +47 -0
  202. data/lib/stripe/services/treasury/credit_reversal_service.rb +41 -0
  203. data/lib/stripe/services/treasury/debit_reversal_service.rb +41 -0
  204. data/lib/stripe/services/treasury/financial_account_features_service.rb +30 -0
  205. data/lib/stripe/services/treasury/financial_account_service.rb +59 -0
  206. data/lib/stripe/services/treasury/inbound_transfer_service.rb +52 -0
  207. data/lib/stripe/services/treasury/outbound_payment_service.rb +52 -0
  208. data/lib/stripe/services/treasury/outbound_transfer_service.rb +52 -0
  209. data/lib/stripe/services/treasury/received_credit_service.rb +30 -0
  210. data/lib/stripe/services/treasury/received_debit_service.rb +30 -0
  211. data/lib/stripe/services/treasury/transaction_entry_service.rb +30 -0
  212. data/lib/stripe/services/treasury/transaction_service.rb +30 -0
  213. data/lib/stripe/services/treasury_service.rb +22 -0
  214. data/lib/stripe/services/v1_services.rb +89 -0
  215. data/lib/stripe/services/v2/billing/meter_event_adjustment_service.rb +21 -0
  216. data/lib/stripe/services/v2/billing/meter_event_service.rb +21 -0
  217. data/lib/stripe/services/v2/billing/meter_event_session_service.rb +21 -0
  218. data/lib/stripe/services/v2/billing/meter_event_stream_service.rb +23 -0
  219. data/lib/stripe/services/v2/billing_service.rb +18 -0
  220. data/lib/stripe/services/v2/core/event_service.rb +32 -0
  221. data/lib/stripe/services/v2/core_service.rb +15 -0
  222. data/lib/stripe/services/v2_services.rb +14 -0
  223. data/lib/stripe/services/webhook_endpoint_service.rb +61 -0
  224. data/lib/stripe/services.rb +181 -0
  225. data/lib/stripe/singleton_api_resource.rb +1 -18
  226. data/lib/stripe/stripe_client.rb +51 -1067
  227. data/lib/stripe/stripe_configuration.rb +32 -20
  228. data/lib/stripe/stripe_object.rb +37 -18
  229. data/lib/stripe/stripe_service.rb +32 -0
  230. data/lib/stripe/thin_event.rb +17 -0
  231. data/lib/stripe/util.rb +69 -46
  232. data/lib/stripe/v2_list_object.rb +84 -0
  233. data/lib/stripe/version.rb +1 -1
  234. data/lib/stripe/webhook.rb +1 -1
  235. data/lib/stripe.rb +15 -54
  236. metadata +203 -23
  237. data/lib/stripe/request_signing_authenticator.rb +0 -79
  238. data/lib/stripe/resources/account_notice.rb +0 -32
  239. data/lib/stripe/resources/capital/financing_offer.rb +0 -49
  240. data/lib/stripe/resources/capital/financing_summary.rb +0 -15
  241. data/lib/stripe/resources/capital/financing_transaction.rb +0 -27
  242. data/lib/stripe/resources/financial_connections/account_inferred_balance.rb +0 -14
  243. data/lib/stripe/resources/financial_connections/institution.rb +0 -26
  244. data/lib/stripe/resources/gift_cards/card.rb +0 -59
  245. data/lib/stripe/resources/gift_cards/transaction.rb +0 -93
  246. data/lib/stripe/resources/invoice_payment.rb +0 -12
  247. data/lib/stripe/resources/issuing/credit_underwriting_record.rb +0 -88
  248. data/lib/stripe/resources/issuing/dispute_settlement_detail.rb +0 -26
  249. data/lib/stripe/resources/margin.rb +0 -37
  250. data/lib/stripe/resources/order.rb +0 -120
  251. data/lib/stripe/resources/quote_preview_invoice.rb +0 -43
  252. data/lib/stripe/resources/quote_preview_subscription_schedule.rb +0 -11
  253. data/lib/stripe/resources/tax/association.rb +0 -24
  254. data/lib/stripe/resources/tax/form.rb +0 -49
  255. data/lib/stripe/resources/terminal/reader_collected_data.rb +0 -14
@@ -25,12 +25,11 @@ module Stripe
25
25
  # If `.logger` is set, the value of `.log_level` is ignored. The decision on
26
26
  # what levels to print is entirely deferred to the logger.
27
27
  class StripeConfiguration
28
- attr_accessor :api_key, :api_version, :authenticator, :client_id, :enable_telemetry, :logger, :stripe_account
28
+ attr_accessor :api_key, :api_version, :client_id, :enable_telemetry, :logger, :stripe_account, :stripe_context
29
29
 
30
- attr_reader :api_base, :uploads_base, :connect_base, :ca_bundle_path, :log_level, :initial_network_retry_delay,
31
- # rubocop:todo Layout/LineLength
32
- :max_network_retries, :max_network_retry_delay, :open_timeout, :read_timeout, :write_timeout, :proxy, :verify_ssl_certs
33
- # rubocop:enable Layout/LineLength
30
+ attr_reader :api_base, :uploads_base, :connect_base, :meter_events_base, :base_addresses, :ca_bundle_path,
31
+ :log_level, :initial_network_retry_delay, :max_network_retries, :max_network_retry_delay,
32
+ :open_timeout, :read_timeout, :write_timeout, :proxy, :verify_ssl_certs
34
33
 
35
34
  def self.setup
36
35
  new.tap do |instance|
@@ -45,27 +44,31 @@ module Stripe
45
44
  hash.each do |option, value|
46
45
  instance.public_send("#{option}=", value)
47
46
  end
47
+ instance.send("instance_variable_set", "@base_addresses",
48
+ { api: instance.api_base, connect: instance.connect_base,
49
+ files: instance.uploads_base, meter_events: instance.meter_events_base, })
48
50
  end
49
51
  end
50
52
 
51
53
  def initialize
52
54
  @api_version = ApiVersion::CURRENT
53
-
54
55
  @ca_bundle_path = Stripe::DEFAULT_CA_BUNDLE_PATH
55
56
  @enable_telemetry = true
56
57
  @verify_ssl_certs = true
57
58
 
58
- @max_network_retries = 0
59
+ @max_network_retries = 2
59
60
  @initial_network_retry_delay = 0.5
60
- @max_network_retry_delay = 2
61
+ @max_network_retry_delay = 5
61
62
 
62
63
  @open_timeout = 30
63
64
  @read_timeout = 80
64
65
  @write_timeout = 30
65
66
 
66
- @api_base = "https://api.stripe.com"
67
- @connect_base = "https://connect.stripe.com"
68
- @uploads_base = "https://files.stripe.com"
67
+ @api_base = DEFAULT_API_BASE
68
+ @connect_base = DEFAULT_CONNECT_BASE
69
+ @uploads_base = DEFAULT_UPLOAD_BASE
70
+ @meter_events_base = DEFAULT_METER_EVENTS_BASE
71
+ @base_addresses = { api: @api_base, connect: @connect_base, files: @uploads_base, events: @meter_events_base }
69
72
  end
70
73
 
71
74
  def log_level=(val)
@@ -102,44 +105,53 @@ module Stripe
102
105
 
103
106
  def open_timeout=(open_timeout)
104
107
  @open_timeout = open_timeout
105
- StripeClient.clear_all_connection_managers(config: self)
108
+ APIRequestor.clear_all_connection_managers(config: self)
106
109
  end
107
110
 
108
111
  def read_timeout=(read_timeout)
109
112
  @read_timeout = read_timeout
110
- StripeClient.clear_all_connection_managers(config: self)
113
+ APIRequestor.clear_all_connection_managers(config: self)
111
114
  end
112
115
 
113
116
  def write_timeout=(write_timeout)
114
117
  raise NotImplementedError unless Net::HTTP.instance_methods.include?(:write_timeout=)
115
118
 
116
119
  @write_timeout = write_timeout
117
- StripeClient.clear_all_connection_managers(config: self)
120
+ APIRequestor.clear_all_connection_managers(config: self)
118
121
  end
119
122
 
120
123
  def proxy=(proxy)
121
124
  @proxy = proxy
122
- StripeClient.clear_all_connection_managers(config: self)
125
+ APIRequestor.clear_all_connection_managers(config: self)
123
126
  end
124
127
 
125
128
  def verify_ssl_certs=(verify_ssl_certs)
126
129
  @verify_ssl_certs = verify_ssl_certs
127
- StripeClient.clear_all_connection_managers(config: self)
130
+ APIRequestor.clear_all_connection_managers(config: self)
131
+ end
132
+
133
+ def meter_events_base=(meter_events_base)
134
+ @meter_events_base = meter_events_base
135
+ @base_addresses[:meter_events] = meter_events_base
136
+ APIRequestor.clear_all_connection_managers(config: self)
128
137
  end
129
138
 
130
139
  def uploads_base=(uploads_base)
131
140
  @uploads_base = uploads_base
132
- StripeClient.clear_all_connection_managers(config: self)
141
+ @base_addresses[:files] = uploads_base
142
+ APIRequestor.clear_all_connection_managers(config: self)
133
143
  end
134
144
 
135
145
  def connect_base=(connect_base)
136
146
  @connect_base = connect_base
137
- StripeClient.clear_all_connection_managers(config: self)
147
+ @base_addresses[:connect] = connect_base
148
+ APIRequestor.clear_all_connection_managers(config: self)
138
149
  end
139
150
 
140
151
  def api_base=(api_base)
141
152
  @api_base = api_base
142
- StripeClient.clear_all_connection_managers(config: self)
153
+ @base_addresses[:api] = api_base
154
+ APIRequestor.clear_all_connection_managers(config: self)
143
155
  end
144
156
 
145
157
  def ca_bundle_path=(path)
@@ -148,7 +160,7 @@ module Stripe
148
160
  # empty this field so a new store is initialized
149
161
  @ca_store = nil
150
162
 
151
- StripeClient.clear_all_connection_managers(config: self)
163
+ APIRequestor.clear_all_connection_managers(config: self)
152
164
  end
153
165
 
154
166
  # A certificate store initialized from the the bundle in #ca_bundle_path and
@@ -72,7 +72,8 @@ module Stripe
72
72
  @additive_params.include?(name)
73
73
  end
74
74
 
75
- def initialize(id = nil, opts = {})
75
+ def initialize(id = nil, opts = {}, api_mode = :v1, requestor = nil)
76
+ @api_mode = api_mode
76
77
  id, @retrieve_params = Util.normalize_id(id)
77
78
  @opts = Util.normalize_opts(opts)
78
79
  @original_values = {}
@@ -83,13 +84,14 @@ module Stripe
83
84
  @transient_values = Set.new
84
85
  @values[:id] = id if id
85
86
  @last_response = nil
87
+ @requestor = requestor || APIRequestor.active_requestor
86
88
  end
87
89
 
88
- def self.construct_from(values, opts = {}, last_response = nil)
90
+ def self.construct_from(values, opts = {}, last_response = nil, api_mode = :v1, requestor = nil)
89
91
  values = Stripe::Util.symbolize_names(values)
90
92
 
91
93
  # work around protected #initialize_from for now
92
- new(values[:id]).send(:initialize_from, values, opts, last_response)
94
+ new(values[:id]).send(:initialize_from, values, opts, last_response, api_mode: api_mode, requestor: requestor)
93
95
  end
94
96
 
95
97
  # Determines the equality of two Stripe objects. Stripe objects are
@@ -151,7 +153,7 @@ module Stripe
151
153
  def update_attributes(values, opts = {}, dirty: true)
152
154
  values.each do |k, v|
153
155
  add_accessors([k], values) unless metaclass.method_defined?(k.to_sym)
154
- @values[k] = Util.convert_to_stripe_object(v, opts)
156
+ @values[k] = Util.convert_to_stripe_object(v, opts, api_mode: @api_mode)
155
157
  dirty_value!(@values[k]) if dirty
156
158
  @unsaved_values.add(k)
157
159
  end
@@ -220,20 +222,22 @@ module Stripe
220
222
  # This allows us to remove certain features that cannot or should not be
221
223
  # serialized.
222
224
  def marshal_dump
223
- # The StripeClient instance in @opts is not serializable and is not
225
+ # The APIRequestor instance in @opts is not serializable and is not
224
226
  # really a property of the StripeObject, so we exclude it when
225
227
  # dumping
226
228
  opts = @opts.clone
229
+
230
+ # TODO: (major) Remove the :client option. This is not explicitly supported as a user-specified option.
227
231
  opts.delete(:client)
228
232
  [@values, opts]
229
233
  end
230
234
 
231
235
  # Implements custom decoding for Ruby's Marshal. Consumes data that's
232
236
  # produced by #marshal_dump.
233
- def marshal_load(data)
237
+ def marshal_load(data, api_mode: :v1)
234
238
  values, opts = data
235
- initialize(values[:id])
236
- initialize_from(values, opts)
239
+ initialize(values[:id], api_mode: api_mode)
240
+ initialize_from(values, opts, api_mode: api_mode, requestor: @requestor)
237
241
  end
238
242
 
239
243
  def serialize_params(options = {})
@@ -357,7 +361,7 @@ module Stripe
357
361
  "We interpret empty strings as nil in requests. " \
358
362
  "You may set (object).#{k} = nil to delete the property."
359
363
  end
360
- @values[k] = Util.convert_to_stripe_object(v, @opts)
364
+ @values[k] = Util.convert_to_stripe_object(v, @opts, api_mode: @api_mode)
361
365
  dirty_value!(@values[k])
362
366
  @unsaved_values.add(k)
363
367
  end
@@ -427,13 +431,15 @@ module Stripe
427
431
  # * +:opts:+ Options for StripeObject like an API key.
428
432
  # * +:partial:+ Indicates that the re-initialization should not attempt to
429
433
  # remove accessors.
430
- protected def initialize_from(values, opts, last_response = nil)
434
+ protected def initialize_from(values, opts, last_response = nil, api_mode:, requestor: nil)
435
+ @api_mode = api_mode
431
436
  @last_response = last_response
437
+ @requestor = requestor
432
438
 
433
439
  @opts = Util.normalize_opts(opts)
434
440
 
435
441
  # the `#send` is here so that we can keep this method private
436
- @original_values = self.class.send(:deep_copy, values)
442
+ @original_values = self.class.send(:deep_copy, values, api_mode: api_mode)
437
443
 
438
444
  removed = Set.new(@values.keys - values.keys)
439
445
  added = Set.new(values.keys - @values.keys)
@@ -460,6 +466,18 @@ module Stripe
460
466
  self
461
467
  end
462
468
 
469
+ # Should only be for v2 events and lists, for now.
470
+ protected def _request(method:, path:, base_address:, params: {}, opts: {})
471
+ req_opts = RequestOptions.combine_opts(@opts, opts)
472
+ @requestor.execute_request(
473
+ method,
474
+ path,
475
+ base_address,
476
+ params: params,
477
+ opts: RequestOptions.extract_opts_from_hash(req_opts)
478
+ )
479
+ end
480
+
463
481
  # rubocop:todo Metrics/PerceivedComplexity
464
482
  protected def serialize_params_value(value, original, unsaved, force, # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
465
483
  key: nil)
@@ -540,21 +558,22 @@ module Stripe
540
558
 
541
559
  # Produces a deep copy of the given object including support for arrays,
542
560
  # hashes, and StripeObjects.
543
- private_class_method def self.deep_copy(obj)
561
+ private_class_method def self.deep_copy(obj, api_mode:)
544
562
  case obj
545
563
  when Array
546
- obj.map { |e| deep_copy(e) }
564
+ obj.map { |e| deep_copy(e, api_mode: api_mode) }
547
565
  when Hash
548
566
  obj.each_with_object({}) do |(k, v), copy|
549
- copy[k] = deep_copy(v)
567
+ copy[k] = deep_copy(v, api_mode: api_mode)
550
568
  copy
551
569
  end
552
570
  when StripeObject
553
571
  obj.class.construct_from(
554
- deep_copy(obj.instance_variable_get(:@values)),
555
- obj.instance_variable_get(:@opts).select do |k, _v|
556
- Util::OPTS_COPYABLE.include?(k)
557
- end
572
+ deep_copy(obj.instance_variable_get(:@values), api_mode: api_mode),
573
+ RequestOptions.copyable(obj.instance_variable_get(:@opts)),
574
+ nil,
575
+ api_mode,
576
+ obj.instance_variable_get(:@requestor)
558
577
  )
559
578
  else
560
579
  obj
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module Stripe
5
+ class StripeService
6
+ # Initializes a new StripeService
7
+ def initialize(requestor)
8
+ @requestor = requestor
9
+ end
10
+
11
+ def request(method:, path:, base_address:, params: {}, opts: {})
12
+ @requestor.execute_request(
13
+ method,
14
+ path,
15
+ base_address,
16
+ params: params,
17
+ opts: RequestOptions.extract_opts_from_hash(opts)
18
+ )
19
+ end
20
+
21
+ def request_stream(method:, path:, base_address:, params: {}, opts: {}, &read_body_chunk_block)
22
+ @requestor.execute_request_stream(
23
+ method,
24
+ path,
25
+ base_address,
26
+ params: params,
27
+ opts: RequestOptions.extract_opts_from_hash(opts),
28
+ &read_body_chunk_block
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class ThinEvent
5
+ attr_reader :id, :type, :created, :context, :related_object
6
+
7
+ def initialize(event_payload = {})
8
+ @id = event_payload[:id]
9
+ @type = event_payload[:type]
10
+ @created = event_payload[:created]
11
+ @context = event_payload[:context]
12
+ @livemode = event_payload[:livemode]
13
+ @related_object = event_payload[:related_object]
14
+ @reason = event_payload[:reason]
15
+ end
16
+ end
17
+ end
data/lib/stripe/util.rb CHANGED
@@ -4,27 +4,6 @@ require "cgi"
4
4
 
5
5
  module Stripe
6
6
  module Util
7
- # Options that a user is allowed to specify.
8
- OPTS_USER_SPECIFIED = Set[
9
- :api_key,
10
- :authenticator,
11
- :idempotency_key,
12
- :stripe_account,
13
- :stripe_version
14
- ].freeze
15
-
16
- # Options that should be copyable from one StripeObject to another
17
- # including options that may be internal.
18
- OPTS_COPYABLE = (
19
- OPTS_USER_SPECIFIED + Set[:api_base]
20
- ).freeze
21
-
22
- # Options that should be persisted between API requests. This includes
23
- # client, which is an object containing an HTTP client to reuse.
24
- OPTS_PERSISTABLE = (
25
- OPTS_USER_SPECIFIED + Set[:client] - Set[:idempotency_key]
26
- ).freeze
27
-
28
7
  def self.objects_to_ids(obj)
29
8
  case obj
30
9
  when APIResource
@@ -44,6 +23,14 @@ module Stripe
44
23
  @object_classes ||= Stripe::ObjectTypes.object_names_to_classes
45
24
  end
46
25
 
26
+ def self.v2_object_classes
27
+ @v2_object_classes ||= Stripe::ObjectTypes.v2_object_names_to_classes
28
+ end
29
+
30
+ def self.thin_event_classes
31
+ @thin_event_classes ||= Stripe::EventTypes.thin_event_names_to_classes
32
+ end
33
+
47
34
  def self.object_name_matches_class?(object_name, klass)
48
35
  Util.object_classes[object_name] == klass
49
36
  end
@@ -62,6 +49,7 @@ module Stripe
62
49
  # custom_method :capture, http_verb: post
63
50
  # adds a `capture` class method to the resource class that, when called,
64
51
  # will send a POST request to `/v1/<object_name>/capture`.
52
+ # TODO: are we comfortable with deleting this?
65
53
  def self.custom_method(resource, target, name, http_verb, http_path)
66
54
  unless %i[get post delete].include?(http_verb)
67
55
  raise ArgumentError,
@@ -84,14 +72,13 @@ module Stripe
84
72
  "#{CGI.escape(id)}/" \
85
73
  "#{CGI.escape(http_path)}"
86
74
 
87
- resp, opts = resource.execute_resource_request(
75
+ resource.execute_resource_request(
88
76
  http_verb,
89
77
  url,
78
+ :api,
90
79
  params,
91
80
  opts
92
81
  )
93
-
94
- Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp)
95
82
  end
96
83
  end
97
84
 
@@ -109,8 +96,8 @@ module Stripe
109
96
  # will be reused on subsequent API calls.
110
97
  # * +opts+ - Options for +StripeObject+ like an API key that will be reused
111
98
  # on subsequent API calls.
112
- def self.convert_to_stripe_object(data, opts = {})
113
- convert_to_stripe_object_with_params(data, {}, opts)
99
+ def self.convert_to_stripe_object(data, opts = {}, api_mode: :v1, requestor: nil)
100
+ convert_to_stripe_object_with_params(data, {}, opts, api_mode: api_mode, requestor: requestor)
114
101
  end
115
102
 
116
103
  # Converts a hash of fields or an array of hashes into a +StripeObject+ or
@@ -125,18 +112,47 @@ module Stripe
125
112
  # * +data+ - Hash of fields and values to be converted into a StripeObject.
126
113
  # * +opts+ - Options for +StripeObject+ like an API key that will be reused
127
114
  # on subsequent API calls.
128
- def self.convert_to_stripe_object_with_params(data, params, opts = {}, last_response = nil)
115
+ # * +last_response+ - The raw response associated with the object.
116
+ # * +api_mode+ - The API mode to use when converting the object, either :v1 or :v2.
117
+ # * +requestor+ - The requestor to use when constructing the object.
118
+ def self.convert_to_stripe_object_with_params(
119
+ data,
120
+ params,
121
+ opts = {},
122
+ last_response = nil,
123
+ api_mode: :v1,
124
+ requestor: nil
125
+ )
129
126
  opts = normalize_opts(opts)
130
127
 
131
128
  case data
132
129
  when Array
133
- data.map { |i| convert_to_stripe_object(i, opts) }
130
+ data.map { |i| convert_to_stripe_object(i, opts, api_mode: api_mode) }
134
131
  when Hash
132
+ # TODO: This is a terrible hack.
133
+ # Waiting on https://jira.corp.stripe.com/browse/API_SERVICES-3167 to add
134
+ # an object in v2 lists
135
+ if api_mode == :v2 && data.include?(:data) && data.include?(:next_page_url)
136
+ return V2::ListObject.construct_from(data, opts, last_response, api_mode, requestor)
137
+ end
138
+
135
139
  # Try converting to a known object class. If none available, fall back
136
140
  # to generic StripeObject
141
+ object_type = data[:type] || data["type"]
137
142
  object_name = data[:object] || data["object"]
138
- obj = object_classes.fetch(object_name, StripeObject)
139
- .construct_from(data, opts, last_response)
143
+ object_class = if api_mode == :v2
144
+ if object_name == "v2.core.event" && thin_event_classes.key?(object_type)
145
+ thin_event_classes.fetch(object_type)
146
+ else
147
+ v2_object_classes.fetch(
148
+ object_name, StripeObject
149
+ )
150
+ end
151
+ else
152
+ object_classes.fetch(object_name, StripeObject)
153
+ end
154
+
155
+ obj = object_class.construct_from(data, opts, last_response, api_mode, requestor)
140
156
 
141
157
  # set filters so that we can fetch the same limit, expansions, and
142
158
  # predicates when accessing the next and previous pages
@@ -202,8 +218,8 @@ module Stripe
202
218
  # parameters in a URI or as form parameters in a request body. This mainly
203
219
  # involves escaping special characters from parameter keys and values (e.g.
204
220
  # `&`).
205
- def self.encode_parameters(params)
206
- Util.flatten_params(params)
221
+ def self.encode_parameters(params, api_mode)
222
+ Util.flatten_params(params, api_mode)
207
223
  .map { |k, v| "#{url_encode(k)}=#{url_encode(v)}" }.join("&")
208
224
  end
209
225
 
@@ -218,7 +234,7 @@ module Stripe
218
234
  gsub("%5B", "[").gsub("%5D", "]")
219
235
  end
220
236
 
221
- def self.flatten_params(params, parent_key = nil)
237
+ def self.flatten_params(params, api_mode, parent_key = nil)
222
238
  result = []
223
239
 
224
240
  # do not sort the final output because arrays (and arrays of hashes
@@ -226,9 +242,9 @@ module Stripe
226
242
  params.each do |key, value|
227
243
  calculated_key = parent_key ? "#{parent_key}[#{key}]" : key.to_s
228
244
  if value.is_a?(Hash)
229
- result += flatten_params(value, calculated_key)
245
+ result += flatten_params(value, api_mode, calculated_key)
230
246
  elsif value.is_a?(Array)
231
- result += flatten_params_array(value, calculated_key)
247
+ result += flatten_params_array(value, api_mode, calculated_key)
232
248
  else
233
249
  result << [calculated_key, value]
234
250
  end
@@ -237,15 +253,19 @@ module Stripe
237
253
  result
238
254
  end
239
255
 
240
- def self.flatten_params_array(value, calculated_key)
256
+ def self.flatten_params_array(value, api_mode, calculated_key)
241
257
  result = []
242
258
  value.each_with_index do |elem, i|
243
259
  if elem.is_a?(Hash)
244
- result += flatten_params(elem, "#{calculated_key}[#{i}]")
260
+ result += flatten_params(elem, api_mode, "#{calculated_key}[#{i}]")
245
261
  elsif elem.is_a?(Array)
246
- result += flatten_params_array(elem, calculated_key)
262
+ result += flatten_params_array(elem, calculated_key, api_mode)
247
263
  else
248
- result << ["#{calculated_key}[#{i}]", elem]
264
+ result << if api_mode == :v2
265
+ [calculated_key, elem]
266
+ else
267
+ ["#{calculated_key}[#{i}]", elem]
268
+ end
249
269
  end
250
270
  end
251
271
  result
@@ -280,13 +300,7 @@ module Stripe
280
300
  when String
281
301
  { api_key: opts }
282
302
  when Hash
283
- # If the user is using request signing for authentication,
284
- # no need to check the api_key per request.
285
- if !(opts.key?(:client) &&
286
- opts.fetch(:client).config.authenticator) &&
287
- opts.key?(:api_key)
288
- check_api_key!(opts.fetch(:api_key))
289
- end
303
+ check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key)
290
304
  # Explicitly use dup here instead of clone to avoid preserving freeze
291
305
  # state on input params.
292
306
  opts.dup
@@ -341,6 +355,15 @@ module Stripe
341
355
  res.zero?
342
356
  end
343
357
 
358
+ # Returns either v1 or v2 as api_mode based on the given path
359
+ def self.get_api_mode(path)
360
+ if path.start_with?("/v2/")
361
+ :v2
362
+ else
363
+ :v1
364
+ end
365
+ end
366
+
344
367
  #
345
368
  # private
346
369
  #
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ module V2
5
+ class ListObject < StripeObject
6
+ OBJECT_NAME = "list"
7
+ def self.object_name
8
+ "list"
9
+ end
10
+
11
+ # An empty list object. This is returned from +fetch_next_page+ when we know that
12
+ # there isn't a next page.
13
+ def self.empty_list(opts = {})
14
+ ListObject.construct_from({ data: [] }, opts, nil, :v2)
15
+ end
16
+
17
+ def [](key)
18
+ case key
19
+ when String, Symbol
20
+ super
21
+ else
22
+ raise ArgumentError,
23
+ "You tried to access the #{key.inspect} index, but ListObject " \
24
+ "types only support String keys. (HINT: List calls return an " \
25
+ "object with a 'data' (which is the data array). You likely " \
26
+ "want to call #data[#{key.inspect}])"
27
+ end
28
+ end
29
+
30
+ # Iterates through each resource in the page represented by the current
31
+ # `ListObject`.
32
+ #
33
+ # Note that this method makes no effort to fetch a new page when it gets to
34
+ # the end of the current page's resources. See also +auto_paging_each+.
35
+ def each(&blk)
36
+ data.each(&blk)
37
+ end
38
+
39
+ # Iterates through each resource in the page represented by the current
40
+ # `ListObject` in reverse.
41
+ def reverse_each(&blk)
42
+ data.reverse_each(&blk)
43
+ end
44
+
45
+ # Iterates through each resource in all pages, making additional fetches to
46
+ # the API as necessary.
47
+ #
48
+ # Note that this method will make as many API calls as necessary to fetch
49
+ # all resources. For more granular control, please see +each+ and
50
+ # +fetch_next_page+.
51
+ def auto_paging_each(&blk)
52
+ return enum_for(:auto_paging_each) unless block_given?
53
+
54
+ page = self
55
+ loop do
56
+ page.each(&blk)
57
+
58
+ break if page.next_page_url.nil?
59
+
60
+ page = page.fetch_next_page
61
+ end
62
+ end
63
+
64
+ # Returns true if the page object contains no elements.
65
+ def empty?
66
+ data.empty?
67
+ end
68
+
69
+ # Fetches the next page in the resource list (if there is one).
70
+ #
71
+ # This method will try to respect the limit of the current page. If none
72
+ # was given, the default limit will be fetched again.
73
+ def fetch_next_page(opts = {})
74
+ return self.class.empty_list(opts) if next_page_url.nil?
75
+
76
+ _request(
77
+ method: :get,
78
+ path: next_page_url,
79
+ base_address: :api
80
+ )
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "12.7.0-beta.2"
4
+ VERSION = "13.0.0"
5
5
  end
@@ -18,7 +18,7 @@ module Stripe
18
18
  # doesn't GC symbols. It also decreases the likelihood that we receive a
19
19
  # bad payload that fails to parse and throws an exception.
20
20
  data = JSON.parse(payload, symbolize_names: true)
21
- Event.construct_from(data)
21
+ Event.construct_from(data, {}, nil, :v1)
22
22
  end
23
23
 
24
24
  module Signature