stripe 4.9.0 → 5.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +10 -0
  3. data/.rubocop.yml +56 -8
  4. data/.rubocop_todo.yml +8 -25
  5. data/.travis.yml +4 -8
  6. data/.vscode/extensions.json +7 -0
  7. data/.vscode/settings.json +8 -0
  8. data/CHANGELOG.md +206 -2
  9. data/CODE_OF_CONDUCT.md +77 -0
  10. data/Gemfile +10 -13
  11. data/README.md +178 -58
  12. data/Rakefile +8 -7
  13. data/VERSION +1 -1
  14. data/lib/stripe.rb +41 -195
  15. data/lib/stripe/api_operations/create.rb +1 -1
  16. data/lib/stripe/api_operations/delete.rb +28 -2
  17. data/lib/stripe/api_operations/list.rb +1 -12
  18. data/lib/stripe/api_operations/nested_resource.rb +38 -28
  19. data/lib/stripe/api_operations/request.rb +47 -8
  20. data/lib/stripe/api_operations/save.rb +8 -7
  21. data/lib/stripe/api_resource.rb +52 -3
  22. data/lib/stripe/connection_manager.rb +162 -0
  23. data/lib/stripe/error_object.rb +94 -0
  24. data/lib/stripe/errors.rb +31 -10
  25. data/lib/stripe/instrumentation.rb +82 -0
  26. data/lib/stripe/list_object.rb +41 -7
  27. data/lib/stripe/multipart_encoder.rb +131 -0
  28. data/lib/stripe/oauth.rb +4 -3
  29. data/lib/stripe/object_types.rb +101 -0
  30. data/lib/stripe/resources.rb +84 -0
  31. data/lib/stripe/{account.rb → resources/account.rb} +50 -27
  32. data/lib/stripe/{account_link.rb → resources/account_link.rb} +2 -1
  33. data/lib/stripe/resources/alipay_account.rb +34 -0
  34. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +2 -1
  35. data/lib/stripe/resources/application_fee.rb +14 -0
  36. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  37. data/lib/stripe/{balance.rb → resources/balance.rb} +2 -1
  38. data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +2 -5
  39. data/lib/stripe/resources/bank_account.rb +43 -0
  40. data/lib/stripe/resources/billing_portal/session.rb +12 -0
  41. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +4 -3
  42. data/lib/stripe/{bitcoin_transaction.rb → resources/bitcoin_transaction.rb} +1 -1
  43. data/lib/stripe/resources/capability.rb +33 -0
  44. data/lib/stripe/{card.rb → resources/card.rb} +13 -4
  45. data/lib/stripe/resources/charge.rb +23 -0
  46. data/lib/stripe/resources/checkout/session.rb +16 -0
  47. data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +2 -1
  48. data/lib/stripe/{coupon.rb → resources/coupon.rb} +3 -2
  49. data/lib/stripe/resources/credit_note.rb +33 -0
  50. data/lib/stripe/resources/credit_note_line_item.rb +7 -0
  51. data/lib/stripe/resources/customer.rb +36 -0
  52. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  53. data/lib/stripe/resources/discount.rb +7 -0
  54. data/lib/stripe/resources/dispute.rb +22 -0
  55. data/lib/stripe/{ephemeral_key.rb → resources/ephemeral_key.rb} +6 -2
  56. data/lib/stripe/{event.rb → resources/event.rb} +2 -1
  57. data/lib/stripe/{exchange_rate.rb → resources/exchange_rate.rb} +2 -1
  58. data/lib/stripe/{file.rb → resources/file.rb} +9 -11
  59. data/lib/stripe/{file_link.rb → resources/file_link.rb} +3 -2
  60. data/lib/stripe/resources/invoice.rb +74 -0
  61. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +3 -2
  62. data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +1 -1
  63. data/lib/stripe/resources/issuing/authorization.rb +34 -0
  64. data/lib/stripe/resources/issuing/card.rb +25 -0
  65. data/lib/stripe/{issuing → resources/issuing}/card_details.rb +1 -1
  66. data/lib/stripe/{issuing → resources/issuing}/cardholder.rb +3 -2
  67. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  68. data/lib/stripe/{issuing → resources/issuing}/transaction.rb +3 -2
  69. data/lib/stripe/resources/line_item.rb +7 -0
  70. data/lib/stripe/resources/login_link.rb +14 -0
  71. data/lib/stripe/resources/mandate.rb +8 -0
  72. data/lib/stripe/resources/order.rb +33 -0
  73. data/lib/stripe/{order_return.rb → resources/order_return.rb} +2 -1
  74. data/lib/stripe/resources/payment_intent.rb +43 -0
  75. data/lib/stripe/resources/payment_method.rb +33 -0
  76. data/lib/stripe/resources/payout.rb +33 -0
  77. data/lib/stripe/{person.rb → resources/person.rb} +8 -3
  78. data/lib/stripe/{plan.rb → resources/plan.rb} +2 -1
  79. data/lib/stripe/resources/price.rb +12 -0
  80. data/lib/stripe/{product.rb → resources/product.rb} +4 -3
  81. data/lib/stripe/resources/promotion_code.rb +12 -0
  82. data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
  83. data/lib/stripe/{radar → resources/radar}/value_list.rb +3 -2
  84. data/lib/stripe/{radar → resources/radar}/value_list_item.rb +3 -2
  85. data/lib/stripe/{recipient.rb → resources/recipient.rb} +3 -6
  86. data/lib/stripe/{recipient_transfer.rb → resources/recipient_transfer.rb} +1 -1
  87. data/lib/stripe/{refund.rb → resources/refund.rb} +2 -1
  88. data/lib/stripe/{reporting → resources/reporting}/report_run.rb +3 -2
  89. data/lib/stripe/{reporting → resources/reporting}/report_type.rb +3 -2
  90. data/lib/stripe/resources/reversal.rb +29 -0
  91. data/lib/stripe/resources/review.rb +21 -0
  92. data/lib/stripe/resources/setup_attempt.rb +10 -0
  93. data/lib/stripe/resources/setup_intent.rb +33 -0
  94. data/lib/stripe/{sigma → resources/sigma}/scheduled_query_run.rb +3 -2
  95. data/lib/stripe/{sku.rb → resources/sku.rb} +4 -3
  96. data/lib/stripe/resources/source.rb +47 -0
  97. data/lib/stripe/{source_transaction.rb → resources/source_transaction.rb} +1 -1
  98. data/lib/stripe/resources/subscription.rb +26 -0
  99. data/lib/stripe/resources/subscription_item.rb +26 -0
  100. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  101. data/lib/stripe/resources/tax_id.rb +26 -0
  102. data/lib/stripe/resources/tax_rate.rb +12 -0
  103. data/lib/stripe/resources/terminal/connection_token.rb +12 -0
  104. data/lib/stripe/{terminal → resources/terminal}/location.rb +4 -2
  105. data/lib/stripe/{terminal → resources/terminal}/reader.rb +4 -2
  106. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +2 -1
  107. data/lib/stripe/{token.rb → resources/token.rb} +2 -1
  108. data/lib/stripe/resources/topup.rb +23 -0
  109. data/lib/stripe/resources/transfer.rb +27 -0
  110. data/lib/stripe/resources/usage_record.rb +7 -0
  111. data/lib/stripe/{usage_record_summary.rb → resources/usage_record_summary.rb} +1 -1
  112. data/lib/stripe/{webhook_endpoint.rb → resources/webhook_endpoint.rb} +3 -2
  113. data/lib/stripe/singleton_api_resource.rb +3 -1
  114. data/lib/stripe/stripe_client.rb +493 -236
  115. data/lib/stripe/stripe_configuration.rb +178 -0
  116. data/lib/stripe/stripe_object.rb +75 -61
  117. data/lib/stripe/stripe_response.rb +53 -21
  118. data/lib/stripe/util.rb +66 -109
  119. data/lib/stripe/version.rb +1 -1
  120. data/lib/stripe/webhook.rb +43 -10
  121. data/stripe.gemspec +14 -5
  122. data/test/stripe/account_link_test.rb +4 -4
  123. data/test/stripe/account_test.rb +193 -32
  124. data/test/stripe/alipay_account_test.rb +1 -1
  125. data/test/stripe/api_operations_test.rb +3 -4
  126. data/test/stripe/api_resource_test.rb +159 -37
  127. data/test/stripe/apple_pay_domain_test.rb +18 -5
  128. data/test/stripe/application_fee_refund_test.rb +1 -1
  129. data/test/stripe/application_fee_test.rb +45 -1
  130. data/test/stripe/balance_test.rb +1 -1
  131. data/test/stripe/balance_transaction_test.rb +20 -0
  132. data/test/stripe/bank_account_test.rb +1 -1
  133. data/test/stripe/billing_portal/session_test.rb +18 -0
  134. data/test/stripe/capability_test.rb +45 -0
  135. data/test/stripe/charge_test.rb +13 -8
  136. data/test/stripe/checkout/session_test.rb +19 -1
  137. data/test/stripe/connection_manager_test.rb +167 -0
  138. data/test/stripe/country_spec_test.rb +1 -1
  139. data/test/stripe/coupon_test.rb +16 -6
  140. data/test/stripe/credit_note_test.rb +90 -0
  141. data/test/stripe/customer_balance_transaction_test.rb +37 -0
  142. data/test/stripe/customer_card_test.rb +7 -1
  143. data/test/stripe/customer_test.rb +151 -40
  144. data/test/stripe/dispute_test.rb +10 -1
  145. data/test/stripe/ephemeral_key_test.rb +8 -1
  146. data/test/stripe/errors_test.rb +42 -9
  147. data/test/stripe/exchange_rate_test.rb +1 -1
  148. data/test/stripe/file_link_test.rb +1 -1
  149. data/test/stripe/file_test.rb +19 -5
  150. data/test/stripe/instrumentation_test.rb +74 -0
  151. data/test/stripe/invoice_item_test.rb +18 -7
  152. data/test/stripe/invoice_line_item_test.rb +1 -1
  153. data/test/stripe/invoice_test.rb +77 -9
  154. data/test/stripe/issuing/authorization_test.rb +33 -11
  155. data/test/stripe/issuing/card_test.rb +27 -6
  156. data/test/stripe/issuing/cardholder_test.rb +1 -1
  157. data/test/stripe/issuing/dispute_test.rb +23 -14
  158. data/test/stripe/issuing/transaction_test.rb +1 -1
  159. data/test/stripe/list_object_test.rb +70 -24
  160. data/test/stripe/login_link_test.rb +2 -2
  161. data/test/stripe/mandate_test.rb +14 -0
  162. data/test/stripe/multipart_encoder_test.rb +130 -0
  163. data/test/stripe/oauth_test.rb +17 -1
  164. data/test/stripe/order_return_test.rb +1 -1
  165. data/test/stripe/order_test.rb +28 -3
  166. data/test/stripe/payment_intent_test.rb +31 -4
  167. data/test/stripe/payment_method_test.rb +84 -0
  168. data/test/stripe/payout_test.rb +23 -1
  169. data/test/stripe/person_test.rb +1 -1
  170. data/test/stripe/plan_test.rb +26 -20
  171. data/test/stripe/price_test.rb +48 -0
  172. data/test/stripe/product_test.rb +17 -8
  173. data/test/stripe/promotion_code_test.rb +42 -0
  174. data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
  175. data/test/stripe/radar/value_list_item_test.rb +16 -6
  176. data/test/stripe/radar/value_list_test.rb +16 -6
  177. data/test/stripe/recipient_test.rb +18 -5
  178. data/test/stripe/refund_test.rb +1 -1
  179. data/test/stripe/reporting/report_run_test.rb +1 -1
  180. data/test/stripe/reporting/report_type_test.rb +1 -1
  181. data/test/stripe/reversal_test.rb +1 -1
  182. data/test/stripe/review_test.rb +1 -1
  183. data/test/stripe/setup_attempt_test.rb +16 -0
  184. data/test/stripe/setup_intent_test.rb +84 -0
  185. data/test/stripe/sigma/scheduled_query_run_test.rb +1 -1
  186. data/test/stripe/sku_test.rb +16 -6
  187. data/test/stripe/source_test.rb +52 -19
  188. data/test/stripe/stripe_client_test.rb +546 -78
  189. data/test/stripe/stripe_configuration_test.rb +131 -0
  190. data/test/stripe/stripe_object_test.rb +16 -41
  191. data/test/stripe/stripe_response_test.rb +71 -25
  192. data/test/stripe/subscription_item_test.rb +38 -7
  193. data/test/stripe/subscription_schedule_test.rb +19 -1
  194. data/test/stripe/subscription_test.rb +29 -9
  195. data/test/stripe/tax_id_test.rb +31 -0
  196. data/test/stripe/tax_rate_test.rb +43 -0
  197. data/test/stripe/terminal/connection_token_test.rb +1 -1
  198. data/test/stripe/terminal/location_test.rb +18 -1
  199. data/test/stripe/terminal/reader_test.rb +18 -1
  200. data/test/stripe/three_d_secure_test.rb +1 -1
  201. data/test/stripe/topup_test.rb +9 -1
  202. data/test/stripe/transfer_test.rb +46 -1
  203. data/test/stripe/usage_record_summary_test.rb +15 -5
  204. data/test/stripe/util_test.rb +1 -1
  205. data/test/stripe/webhook_endpoint_test.rb +18 -1
  206. data/test/stripe/webhook_test.rb +48 -9
  207. data/test/stripe_mock.rb +4 -3
  208. data/test/stripe_test.rb +102 -33
  209. data/test/test_helper.rb +16 -12
  210. metadata +141 -129
  211. data/lib/stripe/alipay_account.rb +0 -27
  212. data/lib/stripe/application_fee.rb +0 -23
  213. data/lib/stripe/application_fee_refund.rb +0 -22
  214. data/lib/stripe/bank_account.rb +0 -32
  215. data/lib/stripe/charge.rb +0 -84
  216. data/lib/stripe/checkout/session.rb +0 -11
  217. data/lib/stripe/customer.rb +0 -90
  218. data/lib/stripe/dispute.rb +0 -19
  219. data/lib/stripe/invoice.rb +0 -48
  220. data/lib/stripe/issuer_fraud_record.rb +0 -9
  221. data/lib/stripe/issuing/authorization.rb +0 -22
  222. data/lib/stripe/issuing/card.rb +0 -18
  223. data/lib/stripe/issuing/dispute.rb +0 -13
  224. data/lib/stripe/login_link.rb +0 -11
  225. data/lib/stripe/order.rb +0 -31
  226. data/lib/stripe/payment_intent.rb +0 -26
  227. data/lib/stripe/payout.rb +0 -20
  228. data/lib/stripe/reversal.rb +0 -22
  229. data/lib/stripe/review.rb +0 -14
  230. data/lib/stripe/source.rb +0 -38
  231. data/lib/stripe/subscription.rb +0 -25
  232. data/lib/stripe/subscription_item.rb +0 -17
  233. data/lib/stripe/subscription_schedule.rb +0 -32
  234. data/lib/stripe/subscription_schedule_revision.rb +0 -25
  235. data/lib/stripe/terminal/connection_token.rb +0 -11
  236. data/lib/stripe/topup.rb +0 -16
  237. data/lib/stripe/transfer.rb +0 -23
  238. data/lib/stripe/usage_record.rb +0 -14
  239. data/test/api_stub_helpers.rb +0 -1
  240. data/test/stripe/account_external_accounts_operations_test.rb +0 -69
  241. data/test/stripe/account_login_links_operations_test.rb +0 -21
  242. data/test/stripe/account_persons_operations_test.rb +0 -70
  243. data/test/stripe/application_fee_refunds_operations_test.rb +0 -56
  244. data/test/stripe/customer_sources_operations_test.rb +0 -64
  245. data/test/stripe/file_upload_test.rb +0 -76
  246. data/test/stripe/issuer_fraud_record_test.rb +0 -20
  247. data/test/stripe/source_transaction_test.rb +0 -19
  248. data/test/stripe/subscription_schedule_revision_test.rb +0 -37
  249. data/test/stripe/subscription_schedule_revisions_operations_test.rb +0 -35
  250. data/test/stripe/transfer_reversals_operations_test.rb +0 -57
  251. data/test/stripe/usage_record_test.rb +0 -28
data/Rakefile CHANGED
@@ -13,7 +13,8 @@ RuboCop::RakeTask.new
13
13
 
14
14
  desc "Update bundled certs"
15
15
  task :update_certs do
16
- require "faraday"
16
+ require "net/http"
17
+ require "uri"
17
18
 
18
19
  fetch_file "https://curl.haxx.se/ca/cacert.pem",
19
20
  ::File.expand_path("../lib/data/ca-certificates.crt", __FILE__)
@@ -23,14 +24,14 @@ end
23
24
  # helpers
24
25
  #
25
26
 
26
- def fetch_file(url, dest)
27
+ def fetch_file(uri, dest)
27
28
  ::File.open(dest, "w") do |file|
28
- resp = Faraday.get(url)
29
- unless resp.status == 200
30
- abort("bad response when fetching: #{url}\n" \
31
- "Status #{resp.status}: #{resp.body}")
29
+ resp = Net::HTTP.get_response(URI.parse(uri))
30
+ unless resp.code.to_i == 200
31
+ abort("bad response when fetching: #{uri}\n" \
32
+ "Status #{resp.code}: #{resp.body}")
32
33
  end
33
34
  file.write(resp.body)
34
- puts "Successfully fetched: #{url}"
35
+ puts "Successfully fetched: #{uri}"
35
36
  end
36
37
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.9.0
1
+ 5.28.0
@@ -3,15 +3,16 @@
3
3
  # Stripe Ruby bindings
4
4
  # API spec at https://stripe.com/docs/api
5
5
  require "cgi"
6
- require "faraday"
7
6
  require "json"
8
7
  require "logger"
8
+ require "net/http"
9
9
  require "openssl"
10
10
  require "rbconfig"
11
11
  require "securerandom"
12
12
  require "set"
13
13
  require "socket"
14
14
  require "uri"
15
+ require "forwardable"
15
16
 
16
17
  # Version
17
18
  require "stripe/version"
@@ -26,118 +27,65 @@ require "stripe/api_operations/save"
26
27
 
27
28
  # API resource support classes
28
29
  require "stripe/errors"
30
+ require "stripe/object_types"
29
31
  require "stripe/util"
32
+ require "stripe/connection_manager"
33
+ require "stripe/multipart_encoder"
30
34
  require "stripe/stripe_client"
31
35
  require "stripe/stripe_object"
32
36
  require "stripe/stripe_response"
33
37
  require "stripe/list_object"
38
+ require "stripe/error_object"
34
39
  require "stripe/api_resource"
35
40
  require "stripe/singleton_api_resource"
36
41
  require "stripe/webhook"
42
+ require "stripe/stripe_configuration"
37
43
 
38
44
  # Named API resources
39
- require "stripe/account"
40
- require "stripe/account_link"
41
- require "stripe/alipay_account"
42
- require "stripe/apple_pay_domain"
43
- require "stripe/application_fee"
44
- require "stripe/application_fee_refund"
45
- require "stripe/balance"
46
- require "stripe/balance_transaction"
47
- require "stripe/bank_account"
48
- require "stripe/bitcoin_receiver"
49
- require "stripe/bitcoin_transaction"
50
- require "stripe/card"
51
- require "stripe/charge"
52
- require "stripe/checkout/session"
53
- require "stripe/country_spec"
54
- require "stripe/coupon"
55
- require "stripe/customer"
56
- require "stripe/dispute"
57
- require "stripe/ephemeral_key"
58
- require "stripe/event"
59
- require "stripe/exchange_rate"
60
- require "stripe/file"
61
- require "stripe/file_link"
62
- require "stripe/invoice"
63
- require "stripe/invoice_item"
64
- require "stripe/invoice_line_item"
65
- require "stripe/issuer_fraud_record"
66
- require "stripe/issuing/authorization"
67
- require "stripe/issuing/card"
68
- require "stripe/issuing/card_details"
69
- require "stripe/issuing/cardholder"
70
- require "stripe/issuing/dispute"
71
- require "stripe/issuing/transaction"
72
- require "stripe/login_link"
73
- require "stripe/order"
74
- require "stripe/order_return"
75
- require "stripe/payment_intent"
76
- require "stripe/payout"
77
- require "stripe/person"
78
- require "stripe/plan"
79
- require "stripe/product"
80
- require "stripe/radar/value_list"
81
- require "stripe/radar/value_list_item"
82
- require "stripe/recipient"
83
- require "stripe/recipient_transfer"
84
- require "stripe/refund"
85
- require "stripe/reporting/report_run"
86
- require "stripe/reporting/report_type"
87
- require "stripe/reversal"
88
- require "stripe/review"
89
- require "stripe/sigma/scheduled_query_run"
90
- require "stripe/sku"
91
- require "stripe/source"
92
- require "stripe/source_transaction"
93
- require "stripe/subscription"
94
- require "stripe/subscription_item"
95
- require "stripe/subscription_schedule"
96
- require "stripe/subscription_schedule_revision"
97
- require "stripe/terminal/connection_token"
98
- require "stripe/terminal/location"
99
- require "stripe/terminal/reader"
100
- require "stripe/three_d_secure"
101
- require "stripe/token"
102
- require "stripe/topup"
103
- require "stripe/transfer"
104
- require "stripe/usage_record"
105
- require "stripe/usage_record_summary"
106
- require "stripe/webhook_endpoint"
45
+ require "stripe/resources"
107
46
 
108
47
  # OAuth
109
48
  require "stripe/oauth"
110
49
 
111
50
  module Stripe
112
- DEFAULT_CA_BUNDLE_PATH = ::File.dirname(__FILE__) + "/data/ca-certificates.crt"
51
+ DEFAULT_CA_BUNDLE_PATH = __dir__ + "/data/ca-certificates.crt"
113
52
 
114
- @app_info = nil
115
-
116
- @api_base = "https://api.stripe.com"
117
- @connect_base = "https://connect.stripe.com"
118
- @uploads_base = "https://files.stripe.com"
119
-
120
- @log_level = nil
121
- @logger = nil
122
-
123
- @max_network_retries = 0
124
- @max_network_retry_delay = 2
125
- @initial_network_retry_delay = 0.5
126
-
127
- @ca_bundle_path = DEFAULT_CA_BUNDLE_PATH
128
- @ca_store = nil
129
- @verify_ssl_certs = true
53
+ # map to the same values as the standard library's logger
54
+ LEVEL_DEBUG = Logger::DEBUG
55
+ LEVEL_ERROR = Logger::ERROR
56
+ LEVEL_INFO = Logger::INFO
130
57
 
131
- @open_timeout = 30
132
- @read_timeout = 80
58
+ @app_info = nil
133
59
 
134
- @enable_telemetry = false
60
+ @configuration = Stripe::StripeConfiguration.setup
135
61
 
136
62
  class << self
137
- attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :client_id, :connect_base, :uploads_base,
138
- :open_timeout, :read_timeout
139
-
140
- attr_reader :max_network_retry_delay, :initial_network_retry_delay
63
+ extend Forwardable
64
+
65
+ # User configurable options
66
+ def_delegators :@configuration, :api_key, :api_key=
67
+ def_delegators :@configuration, :api_version, :api_version=
68
+ def_delegators :@configuration, :stripe_account, :stripe_account=
69
+ def_delegators :@configuration, :api_base, :api_base=
70
+ def_delegators :@configuration, :uploads_base, :uploads_base=
71
+ def_delegators :@configuration, :connect_base, :connect_base=
72
+ def_delegators :@configuration, :open_timeout, :open_timeout=
73
+ def_delegators :@configuration, :read_timeout, :read_timeout=
74
+ def_delegators :@configuration, :write_timeout, :write_timeout=
75
+ def_delegators :@configuration, :proxy, :proxy=
76
+ def_delegators :@configuration, :verify_ssl_certs, :verify_ssl_certs=
77
+ def_delegators :@configuration, :ca_bundle_path, :ca_bundle_path=
78
+ def_delegators :@configuration, :log_level, :log_level=
79
+ def_delegators :@configuration, :logger, :logger=
80
+ def_delegators :@configuration, :max_network_retries, :max_network_retries=
81
+ def_delegators :@configuration, :enable_telemetry=, :enable_telemetry?
82
+
83
+ # Internal configurations
84
+ def_delegators :@configuration, :max_network_retry_delay
85
+ def_delegators :@configuration, :initial_network_retry_delay
86
+ def_delegators :@configuration, :ca_store
87
+
88
+ attr_accessor :client_id
141
89
  end
142
90
 
143
91
  # Gets the application for a plugin that's identified some. See
@@ -150,98 +98,6 @@ module Stripe
150
98
  @app_info = info
151
99
  end
152
100
 
153
- # The location of a file containing a bundle of CA certificates. By default
154
- # the library will use an included bundle that can successfully validate
155
- # Stripe certificates.
156
- def self.ca_bundle_path
157
- @ca_bundle_path
158
- end
159
-
160
- def self.ca_bundle_path=(path)
161
- @ca_bundle_path = path
162
-
163
- # empty this field so a new store is initialized
164
- @ca_store = nil
165
- end
166
-
167
- # A certificate store initialized from the the bundle in #ca_bundle_path and
168
- # which is used to validate TLS on every request.
169
- #
170
- # This was added to the give the gem "pseudo thread safety" in that it seems
171
- # when initiating many parallel requests marshaling the certificate store is
172
- # the most likely point of failure (see issue #382). Any program attempting
173
- # to leverage this pseudo safety should make a call to this method (i.e.
174
- # `Stripe.ca_store`) in their initialization code because it marshals lazily
175
- # and is itself not thread safe.
176
- def self.ca_store
177
- @ca_store ||= begin
178
- store = OpenSSL::X509::Store.new
179
- store.add_file(ca_bundle_path)
180
- store
181
- end
182
- end
183
-
184
- # map to the same values as the standard library's logger
185
- LEVEL_DEBUG = Logger::DEBUG
186
- LEVEL_ERROR = Logger::ERROR
187
- LEVEL_INFO = Logger::INFO
188
-
189
- # When set prompts the library to log some extra information to $stdout and
190
- # $stderr about what it's doing. For example, it'll produce information about
191
- # requests, responses, and errors that are received. Valid log levels are
192
- # `debug` and `info`, with `debug` being a little more verbose in places.
193
- #
194
- # Use of this configuration is only useful when `.logger` is _not_ set. When
195
- # it is, the decision what levels to print is entirely deferred to the logger.
196
- def self.log_level
197
- @log_level
198
- end
199
-
200
- def self.log_level=(val)
201
- # Backwards compatibility for values that we briefly allowed
202
- if val == "debug"
203
- val = LEVEL_DEBUG
204
- elsif val == "info"
205
- val = LEVEL_INFO
206
- end
207
-
208
- if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
209
- raise ArgumentError, "log_level should only be set to `nil`, `debug` or `info`"
210
- end
211
- @log_level = val
212
- end
213
-
214
- # Sets a logger to which logging output will be sent. The logger should
215
- # support the same interface as the `Logger` class that's part of Ruby's
216
- # standard library (hint, anything in `Rails.logger` will likely be
217
- # suitable).
218
- #
219
- # If `.logger` is set, the value of `.log_level` is ignored. The decision on
220
- # what levels to print is entirely deferred to the logger.
221
- def self.logger
222
- @logger
223
- end
224
-
225
- def self.logger=(val)
226
- @logger = val
227
- end
228
-
229
- def self.max_network_retries
230
- @max_network_retries
231
- end
232
-
233
- def self.max_network_retries=(val)
234
- @max_network_retries = val.to_i
235
- end
236
-
237
- def self.enable_telemetry?
238
- @enable_telemetry
239
- end
240
-
241
- def self.enable_telemetry=(val)
242
- @enable_telemetry = val
243
- end
244
-
245
101
  # Sets some basic information about the running application that's sent along
246
102
  # with API requests. Useful for plugin authors to identify their plugin when
247
103
  # communicating with Stripe.
@@ -255,16 +111,6 @@ module Stripe
255
111
  version: version,
256
112
  }
257
113
  end
258
-
259
- # DEPRECATED. Use `Util#encode_parameters` instead.
260
- def self.uri_encode(params)
261
- Util.encode_parameters(params)
262
- end
263
- private_class_method :uri_encode
264
- class << self
265
- extend Gem::Deprecate
266
- deprecate :uri_encode, "Stripe::Util#encode_parameters", 2016, 1
267
- end
268
114
  end
269
115
 
270
116
  Stripe.log_level = ENV["STRIPE_LOG"] unless ENV["STRIPE_LOG"].nil?
@@ -4,7 +4,7 @@ module Stripe
4
4
  module APIOperations
5
5
  module Create
6
6
  def create(params = {}, opts = {})
7
- resp, opts = request(:post, resource_url, params, opts)
7
+ resp, opts = execute_resource_request(:post, resource_url, params, opts)
8
8
  Util.convert_to_stripe_object(resp.data, opts)
9
9
  end
10
10
  end
@@ -3,11 +3,37 @@
3
3
  module Stripe
4
4
  module APIOperations
5
5
  module Delete
6
+ module ClassMethods
7
+ # Deletes an API resource
8
+ #
9
+ # Deletes the identified resource with the passed in parameters.
10
+ #
11
+ # ==== Attributes
12
+ #
13
+ # * +id+ - ID of the resource to delete.
14
+ # * +params+ - A hash of parameters to pass to the API
15
+ # * +opts+ - A Hash of additional options (separate from the params /
16
+ # object values) to be added to the request. E.g. to allow for an
17
+ # idempotency_key to be passed in the request headers, or for the
18
+ # api_key to be overwritten. See
19
+ # {APIOperations::Request.execute_resource_request}.
20
+ def delete(id, params = {}, opts = {})
21
+ resp, opts = execute_resource_request(:delete,
22
+ "#{resource_url}/#{id}",
23
+ params, opts)
24
+ Util.convert_to_stripe_object(resp.data, opts)
25
+ end
26
+ end
27
+
6
28
  def delete(params = {}, opts = {})
7
- opts = Util.normalize_opts(opts)
8
- resp, opts = request(:delete, resource_url, params, opts)
29
+ resp, opts = execute_resource_request(:delete, resource_url,
30
+ params, opts)
9
31
  initialize_from(resp.data, opts)
10
32
  end
33
+
34
+ def self.included(base)
35
+ base.extend(ClassMethods)
36
+ end
11
37
  end
12
38
  end
13
39
  end
@@ -6,25 +6,14 @@ module Stripe
6
6
  def list(filters = {}, opts = {})
7
7
  opts = Util.normalize_opts(opts)
8
8
 
9
- resp, opts = request(:get, resource_url, filters, opts)
9
+ resp, opts = execute_resource_request(:get, resource_url, filters, opts)
10
10
  obj = ListObject.construct_from(resp.data, opts)
11
11
 
12
12
  # set filters so that we can fetch the same limit, expansions, and
13
13
  # predicates when accessing the next and previous pages
14
- #
15
- # just for general cleanliness, remove any paging options
16
14
  obj.filters = filters.dup
17
- obj.filters.delete(:ending_before)
18
- obj.filters.delete(:starting_after)
19
-
20
15
  obj
21
16
  end
22
-
23
- # The original version of #list was given the somewhat unfortunate name of
24
- # #all, and this alias allows us to maintain backward compatibility (the
25
- # choice was somewhat misleading in the way that it only returned a single
26
- # page rather than all objects).
27
- alias all list
28
17
  end
29
18
  end
30
19
  end
@@ -6,15 +6,19 @@ module Stripe
6
6
  # that it's possible to do so from a static context (i.e. without a
7
7
  # pre-existing collection of subresources on the parent).
8
8
  #
9
- # For examle, a transfer gains the static methods for reversals so that the
9
+ # For example, a transfer gains the static methods for reversals so that the
10
10
  # methods `.create_reversal`, `.retrieve_reversal`, `.update_reversal`,
11
11
  # etc. all become available.
12
12
  module NestedResource
13
- def nested_resource_class_methods(resource, path: nil, operations: nil)
14
- path ||= "#{resource}s"
13
+ def nested_resource_class_methods(resource, path: nil, operations: nil,
14
+ resource_plural: nil)
15
+ resource_plural ||= "#{resource}s"
16
+ path ||= resource_plural
17
+
15
18
  raise ArgumentError, "operations array required" if operations.nil?
16
19
 
17
20
  resource_url_method = :"#{resource}s_url"
21
+
18
22
  define_singleton_method(resource_url_method) do |id, nested_id = nil|
19
23
  url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(path)}"
20
24
  url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
@@ -24,35 +28,41 @@ module Stripe
24
28
  operations.each do |operation|
25
29
  case operation
26
30
  when :create
27
- define_singleton_method(:"create_#{resource}") do |id, params = {}, opts = {}|
28
- url = send(resource_url_method, id)
29
- resp, opts = request(:post, url, params, opts)
30
- Util.convert_to_stripe_object(resp.data, opts)
31
- end
31
+ define_singleton_method(:"create_#{resource}") \
32
+ do |id, params = {}, opts = {}|
33
+ url = send(resource_url_method, id)
34
+ resp, opts = execute_resource_request(:post, url, params, opts)
35
+ Util.convert_to_stripe_object(resp.data, opts)
36
+ end
32
37
  when :retrieve
33
- define_singleton_method(:"retrieve_#{resource}") do |id, nested_id, opts = {}|
34
- url = send(resource_url_method, id, nested_id)
35
- resp, opts = request(:get, url, {}, opts)
36
- Util.convert_to_stripe_object(resp.data, opts)
37
- end
38
+ define_singleton_method(:"retrieve_#{resource}") \
39
+ do |id, nested_id, opts = {}|
40
+ url = send(resource_url_method, id, nested_id)
41
+ resp, opts = execute_resource_request(:get, url, {}, opts)
42
+ Util.convert_to_stripe_object(resp.data, opts)
43
+ end
38
44
  when :update
39
- define_singleton_method(:"update_#{resource}") do |id, nested_id, params = {}, opts = {}|
40
- url = send(resource_url_method, id, nested_id)
41
- resp, opts = request(:post, url, params, opts)
42
- Util.convert_to_stripe_object(resp.data, opts)
43
- end
45
+ define_singleton_method(:"update_#{resource}") \
46
+ do |id, nested_id, params = {}, opts = {}|
47
+ url = send(resource_url_method, id, nested_id)
48
+ resp, opts = execute_resource_request(:post, url, params, opts)
49
+ Util.convert_to_stripe_object(resp.data, opts)
50
+ end
44
51
  when :delete
45
- define_singleton_method(:"delete_#{resource}") do |id, nested_id, params = {}, opts = {}|
46
- url = send(resource_url_method, id, nested_id)
47
- resp, opts = request(:delete, url, params, opts)
48
- Util.convert_to_stripe_object(resp.data, opts)
49
- end
52
+ define_singleton_method(:"delete_#{resource}") \
53
+ do |id, nested_id, params = {}, opts = {}|
54
+ url = send(resource_url_method, id, nested_id)
55
+ resp, opts = execute_resource_request(:delete, url, params,
56
+ opts)
57
+ Util.convert_to_stripe_object(resp.data, opts)
58
+ end
50
59
  when :list
51
- define_singleton_method(:"list_#{resource}s") do |id, params = {}, opts = {}|
52
- url = send(resource_url_method, id)
53
- resp, opts = request(:get, url, params, opts)
54
- Util.convert_to_stripe_object(resp.data, opts)
55
- end
60
+ define_singleton_method(:"list_#{resource_plural}") \
61
+ do |id, params = {}, opts = {}|
62
+ url = send(resource_url_method, id)
63
+ resp, opts = execute_resource_request(:get, url, params, opts)
64
+ Util.convert_to_stripe_object(resp.data, opts)
65
+ end
56
66
  else
57
67
  raise ArgumentError, "Unknown operation: #{operation.inspect}"
58
68
  end