stripe 4.18.1 → 5.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +232 -1
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/Gemfile +10 -16
  5. data/README.md +168 -63
  6. data/Rakefile +8 -7
  7. data/VERSION +1 -1
  8. data/lib/stripe/api_operations/create.rb +1 -1
  9. data/lib/stripe/api_operations/delete.rb +7 -3
  10. data/lib/stripe/api_operations/list.rb +1 -12
  11. data/lib/stripe/api_operations/nested_resource.rb +29 -26
  12. data/lib/stripe/api_operations/request.rb +82 -6
  13. data/lib/stripe/api_operations/save.rb +7 -4
  14. data/lib/stripe/api_resource.rb +27 -2
  15. data/lib/stripe/connection_manager.rb +200 -0
  16. data/lib/stripe/error_object.rb +93 -0
  17. data/lib/stripe/errors.rb +24 -3
  18. data/lib/stripe/instrumentation.rb +84 -0
  19. data/lib/stripe/list_object.rb +34 -5
  20. data/lib/stripe/multipart_encoder.rb +131 -0
  21. data/lib/stripe/oauth.rb +8 -6
  22. data/lib/stripe/object_types.rb +108 -0
  23. data/lib/stripe/{account.rb → resources/account.rb} +23 -26
  24. data/lib/stripe/{account_link.rb → resources/account_link.rb} +2 -1
  25. data/lib/stripe/{alipay_account.rb → resources/alipay_account.rb} +1 -1
  26. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +2 -1
  27. data/lib/stripe/resources/application_fee.rb +14 -0
  28. data/lib/stripe/{application_fee_refund.rb → resources/application_fee_refund.rb} +3 -2
  29. data/lib/stripe/{balance.rb → resources/balance.rb} +2 -1
  30. data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +2 -5
  31. data/lib/stripe/{bank_account.rb → resources/bank_account.rb} +5 -6
  32. data/lib/stripe/{issuing/dispute.rb → resources/billing_portal/configuration.rb} +4 -3
  33. data/lib/stripe/{checkout → resources/billing_portal}/session.rb +3 -2
  34. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +5 -5
  35. data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
  36. data/lib/stripe/{capability.rb → resources/capability.rb} +3 -2
  37. data/lib/stripe/{card.rb → resources/card.rb} +5 -7
  38. data/lib/stripe/resources/charge.rb +23 -0
  39. data/lib/stripe/resources/checkout/session.rb +27 -0
  40. data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +2 -1
  41. data/lib/stripe/{coupon.rb → resources/coupon.rb} +2 -1
  42. data/lib/stripe/resources/credit_note.rb +33 -0
  43. data/lib/stripe/resources/credit_note_line_item.rb +8 -0
  44. data/lib/stripe/resources/customer.rb +52 -0
  45. data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
  46. data/lib/stripe/{discount.rb → resources/discount.rb} +2 -1
  47. data/lib/stripe/resources/dispute.rb +22 -0
  48. data/lib/stripe/{ephemeral_key.rb → resources/ephemeral_key.rb} +2 -1
  49. data/lib/stripe/{event.rb → resources/event.rb} +2 -1
  50. data/lib/stripe/{exchange_rate.rb → resources/exchange_rate.rb} +2 -1
  51. data/lib/stripe/{file.rb → resources/file.rb} +7 -12
  52. data/lib/stripe/{file_link.rb → resources/file_link.rb} +2 -1
  53. data/lib/stripe/resources/identity/verification_report.rb +12 -0
  54. data/lib/stripe/resources/identity/verification_session.rb +35 -0
  55. data/lib/stripe/resources/invoice.rb +74 -0
  56. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +2 -1
  57. data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +2 -1
  58. data/lib/stripe/{issuing → resources/issuing}/authorization.rb +14 -5
  59. data/lib/stripe/{issuing → resources/issuing}/card.rb +8 -3
  60. data/lib/stripe/resources/issuing/card_details.rb +10 -0
  61. data/lib/stripe/{issuing → resources/issuing}/cardholder.rb +2 -1
  62. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  63. data/lib/stripe/{issuing → resources/issuing}/transaction.rb +2 -1
  64. data/lib/stripe/resources/line_item.rb +8 -0
  65. data/lib/stripe/{login_link.rb → resources/login_link.rb} +2 -1
  66. data/lib/stripe/resources/mandate.rb +8 -0
  67. data/lib/stripe/resources/order.rb +33 -0
  68. data/lib/stripe/{order_return.rb → resources/order_return.rb} +2 -1
  69. data/lib/stripe/resources/payment_intent.rb +43 -0
  70. data/lib/stripe/{payment_method.rb → resources/payment_method.rb} +14 -5
  71. data/lib/stripe/resources/payout.rb +33 -0
  72. data/lib/stripe/{person.rb → resources/person.rb} +2 -1
  73. data/lib/stripe/{plan.rb → resources/plan.rb} +2 -1
  74. data/lib/stripe/resources/price.rb +12 -0
  75. data/lib/stripe/{product.rb → resources/product.rb} +2 -1
  76. data/lib/stripe/resources/promotion_code.rb +12 -0
  77. data/lib/stripe/resources/quote.rb +105 -0
  78. data/lib/stripe/{radar → resources/radar}/early_fraud_warning.rb +2 -1
  79. data/lib/stripe/{radar → resources/radar}/value_list.rb +2 -1
  80. data/lib/stripe/{radar → resources/radar}/value_list_item.rb +2 -1
  81. data/lib/stripe/{recipient.rb → resources/recipient.rb} +2 -5
  82. data/lib/stripe/{recipient_transfer.rb → resources/recipient_transfer.rb} +1 -1
  83. data/lib/stripe/{refund.rb → resources/refund.rb} +2 -1
  84. data/lib/stripe/{reporting → resources/reporting}/report_run.rb +2 -1
  85. data/lib/stripe/{reporting → resources/reporting}/report_type.rb +2 -1
  86. data/lib/stripe/{reversal.rb → resources/reversal.rb} +4 -3
  87. data/lib/stripe/{review.rb → resources/review.rb} +8 -3
  88. data/lib/stripe/resources/setup_attempt.rb +10 -0
  89. data/lib/stripe/resources/setup_intent.rb +33 -0
  90. data/lib/stripe/resources/shipping_rate.rb +12 -0
  91. data/lib/stripe/{sigma → resources/sigma}/scheduled_query_run.rb +2 -1
  92. data/lib/stripe/{sku.rb → resources/sku.rb} +2 -1
  93. data/lib/stripe/{source.rb → resources/source.rb} +20 -15
  94. data/lib/stripe/{source_transaction.rb → resources/source_transaction.rb} +2 -1
  95. data/lib/stripe/{subscription.rb → resources/subscription.rb} +12 -11
  96. data/lib/stripe/resources/subscription_item.rb +26 -0
  97. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  98. data/lib/stripe/resources/tax_code.rb +10 -0
  99. data/lib/stripe/{tax_id.rb → resources/tax_id.rb} +2 -1
  100. data/lib/stripe/{tax_rate.rb → resources/tax_rate.rb} +2 -1
  101. data/lib/stripe/{terminal → resources/terminal}/connection_token.rb +2 -1
  102. data/lib/stripe/{terminal → resources/terminal}/location.rb +2 -1
  103. data/lib/stripe/{terminal → resources/terminal}/reader.rb +2 -1
  104. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +2 -1
  105. data/lib/stripe/{token.rb → resources/token.rb} +2 -1
  106. data/lib/stripe/{topup.rb → resources/topup.rb} +8 -3
  107. data/lib/stripe/{transfer.rb → resources/transfer.rb} +9 -8
  108. data/lib/stripe/resources/usage_record.rb +8 -0
  109. data/lib/stripe/{usage_record_summary.rb → resources/usage_record_summary.rb} +2 -1
  110. data/lib/stripe/{webhook_endpoint.rb → resources/webhook_endpoint.rb} +2 -1
  111. data/lib/stripe/resources.rb +91 -0
  112. data/lib/stripe/stripe_client.rb +617 -243
  113. data/lib/stripe/stripe_configuration.rb +194 -0
  114. data/lib/stripe/stripe_object.rb +30 -25
  115. data/lib/stripe/stripe_response.rb +87 -27
  116. data/lib/stripe/util.rb +43 -103
  117. data/lib/stripe/version.rb +1 -1
  118. data/lib/stripe/webhook.rb +39 -8
  119. data/lib/stripe.rb +41 -205
  120. data/stripe.gemspec +19 -5
  121. metadata +109 -287
  122. data/.editorconfig +0 -10
  123. data/.gitattributes +0 -4
  124. data/.github/ISSUE_TEMPLATE.md +0 -5
  125. data/.gitignore +0 -8
  126. data/.rubocop.yml +0 -42
  127. data/.rubocop_todo.yml +0 -38
  128. data/.travis.yml +0 -43
  129. data/.vscode/extensions.json +0 -7
  130. data/.vscode/settings.json +0 -8
  131. data/lib/stripe/application_fee.rb +0 -24
  132. data/lib/stripe/bitcoin_transaction.rb +0 -15
  133. data/lib/stripe/charge.rb +0 -84
  134. data/lib/stripe/credit_note.rb +0 -18
  135. data/lib/stripe/customer.rb +0 -93
  136. data/lib/stripe/dispute.rb +0 -23
  137. data/lib/stripe/invoice.rb +0 -49
  138. data/lib/stripe/issuer_fraud_record.rb +0 -9
  139. data/lib/stripe/issuing/card_details.rb +0 -9
  140. data/lib/stripe/order.rb +0 -32
  141. data/lib/stripe/payment_intent.rb +0 -30
  142. data/lib/stripe/payout.rb +0 -24
  143. data/lib/stripe/subscription_item.rb +0 -18
  144. data/lib/stripe/subscription_schedule.rb +0 -35
  145. data/lib/stripe/subscription_schedule_revision.rb +0 -34
  146. data/lib/stripe/usage_record.rb +0 -23
  147. data/test/api_stub_helpers.rb +0 -1
  148. data/test/openapi/README.md +0 -9
  149. data/test/stripe/account_link_test.rb +0 -18
  150. data/test/stripe/account_test.rb +0 -428
  151. data/test/stripe/alipay_account_test.rb +0 -37
  152. data/test/stripe/api_operations_test.rb +0 -80
  153. data/test/stripe/api_resource_test.rb +0 -523
  154. data/test/stripe/apple_pay_domain_test.rb +0 -46
  155. data/test/stripe/application_fee_refund_test.rb +0 -37
  156. data/test/stripe/application_fee_test.rb +0 -58
  157. data/test/stripe/balance_test.rb +0 -13
  158. data/test/stripe/bank_account_test.rb +0 -36
  159. data/test/stripe/capability_test.rb +0 -45
  160. data/test/stripe/charge_test.rb +0 -80
  161. data/test/stripe/checkout/session_test.rb +0 -41
  162. data/test/stripe/country_spec_test.rb +0 -20
  163. data/test/stripe/coupon_test.rb +0 -61
  164. data/test/stripe/credit_note_test.rb +0 -61
  165. data/test/stripe/customer_card_test.rb +0 -42
  166. data/test/stripe/customer_test.rb +0 -226
  167. data/test/stripe/dispute_test.rb +0 -51
  168. data/test/stripe/ephemeral_key_test.rb +0 -93
  169. data/test/stripe/errors_test.rb +0 -20
  170. data/test/stripe/exchange_rate_test.rb +0 -20
  171. data/test/stripe/file_link_test.rb +0 -41
  172. data/test/stripe/file_test.rb +0 -97
  173. data/test/stripe/file_upload_test.rb +0 -79
  174. data/test/stripe/invoice_item_test.rb +0 -66
  175. data/test/stripe/invoice_line_item_test.rb +0 -8
  176. data/test/stripe/invoice_test.rb +0 -213
  177. data/test/stripe/issuer_fraud_record_test.rb +0 -20
  178. data/test/stripe/issuing/authorization_test.rb +0 -72
  179. data/test/stripe/issuing/card_test.rb +0 -62
  180. data/test/stripe/issuing/cardholder_test.rb +0 -53
  181. data/test/stripe/issuing/dispute_test.rb +0 -45
  182. data/test/stripe/issuing/transaction_test.rb +0 -48
  183. data/test/stripe/list_object_test.rb +0 -156
  184. data/test/stripe/login_link_test.rb +0 -37
  185. data/test/stripe/oauth_test.rb +0 -88
  186. data/test/stripe/order_return_test.rb +0 -21
  187. data/test/stripe/order_test.rb +0 -82
  188. data/test/stripe/payment_intent_test.rb +0 -107
  189. data/test/stripe/payment_method_test.rb +0 -84
  190. data/test/stripe/payout_test.rb +0 -57
  191. data/test/stripe/person_test.rb +0 -46
  192. data/test/stripe/plan_test.rb +0 -98
  193. data/test/stripe/product_test.rb +0 -59
  194. data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
  195. data/test/stripe/radar/value_list_item_test.rb +0 -48
  196. data/test/stripe/radar/value_list_test.rb +0 -61
  197. data/test/stripe/recipient_test.rb +0 -62
  198. data/test/stripe/refund_test.rb +0 -39
  199. data/test/stripe/reporting/report_run_test.rb +0 -33
  200. data/test/stripe/reporting/report_type_test.rb +0 -22
  201. data/test/stripe/reversal_test.rb +0 -43
  202. data/test/stripe/review_test.rb +0 -27
  203. data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
  204. data/test/stripe/sku_test.rb +0 -60
  205. data/test/stripe/source_test.rb +0 -99
  206. data/test/stripe/source_transaction_test.rb +0 -19
  207. data/test/stripe/stripe_client_test.rb +0 -842
  208. data/test/stripe/stripe_object_test.rb +0 -525
  209. data/test/stripe/stripe_response_test.rb +0 -49
  210. data/test/stripe/subscription_item_test.rb +0 -63
  211. data/test/stripe/subscription_schedule_revision_test.rb +0 -37
  212. data/test/stripe/subscription_schedule_test.rb +0 -116
  213. data/test/stripe/subscription_test.rb +0 -80
  214. data/test/stripe/tax_id_test.rb +0 -31
  215. data/test/stripe/tax_rate_test.rb +0 -43
  216. data/test/stripe/terminal/connection_token_test.rb +0 -16
  217. data/test/stripe/terminal/location_test.rb +0 -68
  218. data/test/stripe/terminal/reader_test.rb +0 -62
  219. data/test/stripe/three_d_secure_test.rb +0 -23
  220. data/test/stripe/topup_test.rb +0 -62
  221. data/test/stripe/transfer_test.rb +0 -88
  222. data/test/stripe/usage_record_summary_test.rb +0 -19
  223. data/test/stripe/usage_record_test.rb +0 -28
  224. data/test/stripe/util_test.rb +0 -402
  225. data/test/stripe/webhook_endpoint_test.rb +0 -59
  226. data/test/stripe/webhook_test.rb +0 -96
  227. data/test/stripe_mock.rb +0 -77
  228. data/test/stripe_test.rb +0 -63
  229. data/test/test_data.rb +0 -61
  230. data/test/test_helper.rb +0 -71
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Stripe Ruby Library
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/stripe.svg)](https://badge.fury.io/rb/stripe)
3
4
  [![Build Status](https://travis-ci.org/stripe/stripe-ruby.svg?branch=master)](https://travis-ci.org/stripe/stripe-ruby)
4
- [![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-ruby/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-ruby?branch=master)
5
5
 
6
6
  The Stripe Ruby library provides convenient access to the Stripe API from
7
7
  applications written in the Ruby language. It includes a pre-defined set of
@@ -11,31 +11,36 @@ API.
11
11
 
12
12
  The library also provides other features. For example:
13
13
 
14
- * Easy configuration path for fast setup and use.
15
- * Helpers for pagination.
16
- * Tracking of "fresh" values in API resources so that partial updates can be
17
- executed.
18
- * Built-in mechanisms for the serialization of parameters according to the
14
+ - Easy configuration path for fast setup and use.
15
+ - Helpers for pagination.
16
+ - Built-in mechanisms for the serialization of parameters according to the
19
17
  expectations of Stripe's API.
20
18
 
21
19
  ## Documentation
22
20
 
23
21
  See the [Ruby API docs](https://stripe.com/docs/api/ruby#intro).
24
22
 
23
+ See [video demonstrations][youtube-playlist] covering how to use the library.
24
+
25
+
25
26
  ## Installation
26
27
 
27
28
  You don't need this source code unless you want to modify the gem. If you just
28
29
  want to use the package, just run:
29
30
 
30
- gem install stripe
31
+ ```sh
32
+ gem install stripe
33
+ ```
31
34
 
32
35
  If you want to build the gem from source:
33
36
 
34
- gem build stripe.gemspec
37
+ ```sh
38
+ gem build stripe.gemspec
39
+ ```
35
40
 
36
41
  ### Requirements
37
42
 
38
- * Ruby 2.1+.
43
+ - Ruby 2.3+.
39
44
 
40
45
  ### Bundler
41
46
 
@@ -43,7 +48,7 @@ If you are installing via bundler, you should be sure to use the https rubygems
43
48
  source in your Gemfile, as any gems fetched over http could potentially be
44
49
  compromised in transit and alter the code of gems fetched securely over https:
45
50
 
46
- ``` ruby
51
+ ```ruby
47
52
  source 'https://rubygems.org'
48
53
 
49
54
  gem 'rails'
@@ -56,17 +61,15 @@ The library needs to be configured with your account's secret key which is
56
61
  available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
57
62
  value:
58
63
 
59
- ``` ruby
60
- require "stripe"
61
- Stripe.api_key = "sk_test_..."
64
+ ```ruby
65
+ require 'stripe'
66
+ Stripe.api_key = 'sk_test_...'
62
67
 
63
- # list charges
64
- Stripe::Charge.list()
68
+ # list customers
69
+ Stripe::Customer.list()
65
70
 
66
- # retrieve single charge
67
- Stripe::Charge.retrieve(
68
- "ch_18atAXCdGbJFKhCuBAa4532Z",
69
- )
71
+ # retrieve single customer
72
+ Stripe::Customer.retrieve('cus_123456789')
70
73
  ```
71
74
 
72
75
  ### Per-request Configuration
@@ -75,52 +78,67 @@ For apps that need to use multiple keys during the lifetime of a process, like
75
78
  one that uses [Stripe Connect][connect], it's also possible to set a
76
79
  per-request key and/or account:
77
80
 
78
- ``` ruby
81
+ ```ruby
79
82
  require "stripe"
80
83
 
81
- Stripe::Charge.list(
84
+ Stripe::Customer.list(
82
85
  {},
83
86
  {
84
- :api_key => "sk_test_...",
85
- :stripe_account => "acct_...",
86
- :stripe_version => "2018-02-28"
87
+ api_key: 'sk_test_...',
88
+ stripe_account: 'acct_...',
89
+ stripe_version: '2018-02-28',
87
90
  }
88
91
  )
89
92
 
90
- Stripe::Charge.retrieve(
91
- "ch_18atAXCdGbJFKhCuBAa4532Z",
93
+ Stripe::Customer.retrieve(
94
+ 'cus_123456789',
92
95
  {
93
- :api_key => "sk_test_...",
94
- :stripe_account => "acct_...",
95
- :stripe_version => "2018-02-28"
96
+ api_key: 'sk_test_...',
97
+ stripe_account: 'acct_...',
98
+ stripe_version: '2018-02-28',
96
99
  }
97
100
  )
98
101
 
99
- Stripe::Charge.retrieve(
102
+ Stripe::Customer.retrieve(
100
103
  {
101
- id: 'ch_18atAXCdGbJFKhCuBAa4532Z',
104
+ id: 'cus_123456789',
102
105
  expand: %w(balance_transaction)
103
106
  },
104
107
  {
105
108
  stripe_version: '2018-02-28',
106
- api_key: 'sk_test_...'
109
+ api_key: 'sk_test_...',
110
+ }
111
+ )
112
+
113
+ Stripe::Customer.capture(
114
+ 'cus_123456789',
115
+ {},
116
+ {
117
+ stripe_version: '2018-02-28',
118
+ api_key: 'sk_test_...',
107
119
  }
108
120
  )
109
121
  ```
110
122
 
111
- ### Configuring a Client
123
+ Keep in mind that there are different method signatures depending on the action:
124
+
125
+ - When operating on a collection (e.g. `.list`, `.create`) the method signature is
126
+ `method(params, opts)`.
127
+ - When operating on resource (e.g. `.capture`, `.update`) the method signature is
128
+ `method(id, params, opts)`.
129
+ - One exception is that `retrieve`, despite being an operation on a resource, has the signature
130
+ `retrieve(id, opts)`. In addition, it will accept a Hash for the `id` param but will extract the
131
+ `id` key out and use the others as options.
132
+
133
+ ### Accessing a response object
112
134
 
113
- While a default HTTP client is used by default, it's also possible to have the
114
- library use any client supported by [Faraday][faraday] by initializing a
115
- `Stripe::StripeClient` object and giving it a connection:
135
+ Get access to response objects by initializing a client and using its `request`
136
+ method:
116
137
 
117
- ``` ruby
118
- conn = Faraday.new
119
- client = Stripe::StripeClient.new(conn)
120
- charge, resp = client.request do
121
- Stripe::Charge.retrieve(
122
- "ch_18atAXCdGbJFKhCuBAa4532Z",
123
- )
138
+ ```ruby
139
+ client = Stripe::StripeClient.new
140
+ customer, resp = client.request do
141
+ Stripe::Customer.retrieve('cus_123456789',)
124
142
  end
125
143
  puts resp.request_id
126
144
  ```
@@ -130,7 +148,7 @@ puts resp.request_id
130
148
  A proxy can be configured with `Stripe.proxy`:
131
149
 
132
150
  ```ruby
133
- Stripe.proxy = "https://user:pass@example.com:1234"
151
+ Stripe.proxy = 'https://user:pass@example.com:1234'
134
152
  ```
135
153
 
136
154
  ### Configuring an API Version
@@ -138,7 +156,9 @@ Stripe.proxy = "https://user:pass@example.com:1234"
138
156
  By default, the library will use the API version pinned to the account making
139
157
  a request. This can be overridden with this global option:
140
158
 
141
- Stripe.api_version = "2018-02-28"
159
+ ```ruby
160
+ Stripe.api_version = '2018-02-28'
161
+ ```
142
162
 
143
163
  See [versioning in the API reference][versioning] for more information.
144
164
 
@@ -147,25 +167,33 @@ See [versioning in the API reference][versioning] for more information.
147
167
  By default, the library will use its own internal bundle of known CA
148
168
  certificates, but it's possible to configure your own:
149
169
 
150
- Stripe.ca_bundle_path = "path/to/ca/bundle"
170
+ ```ruby
171
+ Stripe.ca_bundle_path = 'path/to/ca/bundle'
172
+ ```
151
173
 
152
174
  ### Configuring Automatic Retries
153
175
 
154
- The library can be configured to automatically retry requests that fail due to
155
- an intermittent network problem:
176
+ You can enable automatic retries on requests that fail due to a transient
177
+ problem by configuring the maximum number of retries:
178
+
179
+ ```ruby
180
+ Stripe.max_network_retries = 2
181
+ ```
156
182
 
157
- Stripe.max_network_retries = 2
183
+ Various errors can trigger a retry, like a connection error or a timeout, and
184
+ also certain API responses like HTTP status `409 Conflict`.
158
185
 
159
186
  [Idempotency keys][idempotency-keys] are added to requests to guarantee that
160
187
  retries are safe.
161
188
 
162
189
  ### Configuring Timeouts
163
190
 
164
- Open and read timeouts are configurable:
191
+ Open, read and write timeouts are configurable:
165
192
 
166
- ```java
167
- Stripe.open_timeout = 30 // in seconds
193
+ ```ruby
194
+ Stripe.open_timeout = 30 # in seconds
168
195
  Stripe.read_timeout = 80
196
+ Stripe.write_timeout = 30 # only supported on Ruby 2.6+
169
197
  ```
170
198
 
171
199
  Please take care to set conservative read timeouts. Some API requests can take
@@ -181,53 +209,130 @@ production use, but `debug` is also available for more verbosity.
181
209
  There are a few options for enabling it:
182
210
 
183
211
  1. Set the environment variable `STRIPE_LOG` to the value `debug` or `info`:
184
- ```
212
+
213
+ ```sh
185
214
  $ export STRIPE_LOG=info
186
215
  ```
187
216
 
188
217
  2. Set `Stripe.log_level`:
189
- ``` ruby
218
+
219
+ ```ruby
190
220
  Stripe.log_level = Stripe::LEVEL_INFO
191
221
  ```
192
222
 
223
+ ### Instrumentation
224
+
225
+ The library has various hooks that user code can tie into by passing a block to
226
+ `Stripe::Instrumentation.subscribe` to be notified about specific events.
227
+
228
+ #### `request_begin`
229
+
230
+ Invoked when an HTTP request starts. Receives `RequestBeginEvent` with the
231
+ following properties:
232
+
233
+ - `method`: HTTP method. (`Symbol`)
234
+ - `path`: Request path. (`String`)
235
+ - `user_data`: A hash on which users can set arbitrary data, and which will be
236
+ passed through to `request_end` invocations. This could be used, for example,
237
+ to assign unique IDs to each request, and it'd work even if many requests are
238
+ running in parallel. All subscribers share the same object for any particular
239
+ request, so they must be careful to use unique keys that will not conflict
240
+ with other subscribers. (`Hash`)
241
+
242
+ #### `request_end`
243
+
244
+ Invoked when an HTTP request finishes, regardless of whether it terminated with
245
+ a success or error. Receives `RequestEndEvent` with the following properties:
246
+
247
+ - `duration`: Request duration in seconds. (`Float`)
248
+ - `http_status`: HTTP response code (`Integer`) if available, or `nil` in case
249
+ of a lower level network error.
250
+ - `method`: HTTP method. (`Symbol`)
251
+ - `num_retries`: The number of retries. (`Integer`)
252
+ - `path`: Request path. (`String`)
253
+ - `user_data`: A hash on which users may have set arbitrary data in
254
+ `request_begin`. See above for more information. (`Hash`)
255
+ - `request_id`. HTTP request identifier.
256
+
257
+ #### Example
258
+
259
+ For example:
260
+
261
+ ```ruby
262
+ Stripe::Instrumentation.subscribe(:request_end) do |request_event|
263
+ tags = {
264
+ method: request_event.method,
265
+ resource: request_event.path.split('/')[2],
266
+ code: request_event.http_status,
267
+ retries: request_event.num_retries
268
+ }
269
+ StatsD.distribution('stripe_request', request_event.duration, tags: tags)
270
+ end
271
+ ```
272
+
193
273
  ### Writing a Plugin
194
274
 
195
275
  If you're writing a plugin that uses the library, we'd appreciate it if you
196
276
  identified using `#set_app_info`:
197
277
 
198
- Stripe.set_app_info("MyAwesomePlugin", version: "1.2.34", url: "https://myawesomeplugin.info");
278
+ ```ruby
279
+ Stripe.set_app_info('MyAwesomePlugin', version: '1.2.34', url: 'https://myawesomeplugin.info')
280
+ ```
199
281
 
200
282
  This information is passed along when the library makes calls to the Stripe
201
283
  API.
202
284
 
285
+ ### Request latency telemetry
286
+
287
+ By default, the library sends request latency telemetry to Stripe. These
288
+ numbers help Stripe improve the overall latency of its API for all users.
289
+
290
+ You can disable this behavior if you prefer:
291
+
292
+ ```ruby
293
+ Stripe.enable_telemetry = false
294
+ ```
295
+
203
296
  ## Development
204
297
 
205
298
  The test suite depends on [stripe-mock], so make sure to fetch and run it from a
206
299
  background terminal ([stripe-mock's README][stripe-mock] also contains
207
300
  instructions for installing via Homebrew and other methods):
208
301
 
209
- go get -u github.com/stripe/stripe-mock
210
- stripe-mock
302
+ ```sh
303
+ go get -u github.com/stripe/stripe-mock
304
+ stripe-mock
305
+ ```
211
306
 
212
307
  Run all tests:
213
308
 
214
- bundle exec rake test
309
+ ```sh
310
+ bundle exec rake test
311
+ ```
215
312
 
216
313
  Run a single test suite:
217
314
 
218
- bundle exec ruby -Ilib/ test/stripe/util_test.rb
315
+ ```sh
316
+ bundle exec ruby -Ilib/ test/stripe/util_test.rb
317
+ ```
219
318
 
220
319
  Run a single test:
221
320
 
222
- bundle exec ruby -Ilib/ test/stripe/util_test.rb -n /should.convert.names.to.symbols/
321
+ ```sh
322
+ bundle exec ruby -Ilib/ test/stripe/util_test.rb -n /should.convert.names.to.symbols/
323
+ ```
223
324
 
224
325
  Run the linter:
225
326
 
226
- bundle exec rake rubocop
327
+ ```sh
328
+ bundle exec rake rubocop
329
+ ```
227
330
 
228
331
  Update bundled CA certificates from the [Mozilla cURL release][curl]:
229
332
 
230
- bundle exec rake update_certs
333
+ ```sh
334
+ bundle exec rake update_certs
335
+ ```
231
336
 
232
337
  Update the bundled [stripe-mock] by editing the version number found in
233
338
  `.travis.yml`.
@@ -235,10 +340,10 @@ Update the bundled [stripe-mock] by editing the version number found in
235
340
  [api-keys]: https://dashboard.stripe.com/account/apikeys
236
341
  [connect]: https://stripe.com/connect
237
342
  [curl]: http://curl.haxx.se/docs/caextract.html
238
- [faraday]: https://github.com/lostisland/faraday
239
343
  [idempotency-keys]: https://stripe.com/docs/api/ruby#idempotent_requests
240
344
  [stripe-mock]: https://github.com/stripe/stripe-mock
241
345
  [versioning]: https://stripe.com/docs/api/ruby#versioning
346
+ [youtube-playlist]: https://www.youtube.com/playlist?list=PLy1nL-pvL2M50RmP6ie-gdcSnfOuQCRYk
242
347
 
243
348
  <!--
244
349
  # vim: set tw=79:
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.18.1
1
+ 5.42.0
@@ -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
@@ -15,15 +15,19 @@ module Stripe
15
15
  # * +opts+ - A Hash of additional options (separate from the params /
16
16
  # object values) to be added to the request. E.g. to allow for an
17
17
  # idempotency_key to be passed in the request headers, or for the
18
- # api_key to be overwritten. See {APIOperations::Request.request}.
18
+ # api_key to be overwritten. See
19
+ # {APIOperations::Request.execute_resource_request}.
19
20
  def delete(id, params = {}, opts = {})
20
- resp, opts = request(:delete, "#{resource_url}/#{id}", params, opts)
21
+ resp, opts = execute_resource_request(:delete,
22
+ "#{resource_url}/#{id}",
23
+ params, opts)
21
24
  Util.convert_to_stripe_object(resp.data, opts)
22
25
  end
23
26
  end
24
27
 
25
28
  def delete(params = {}, opts = {})
26
- resp, opts = request(:delete, resource_url, params, opts)
29
+ resp, opts = execute_resource_request(:delete, resource_url,
30
+ params, opts)
27
31
  initialize_from(resp.data, opts)
28
32
  end
29
33
 
@@ -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,7 +6,7 @@ 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
@@ -14,9 +14,11 @@ module Stripe
14
14
  resource_plural: nil)
15
15
  resource_plural ||= "#{resource}s"
16
16
  path ||= resource_plural
17
+
17
18
  raise ArgumentError, "operations array required" if operations.nil?
18
19
 
19
20
  resource_url_method = :"#{resource}s_url"
21
+
20
22
  define_singleton_method(resource_url_method) do |id, nested_id = nil|
21
23
  url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(path)}"
22
24
  url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
@@ -27,39 +29,40 @@ module Stripe
27
29
  case operation
28
30
  when :create
29
31
  define_singleton_method(:"create_#{resource}") \
30
- do |id, params = {}, opts = {}|
31
- url = send(resource_url_method, id)
32
- resp, opts = request(:post, url, params, opts)
33
- Util.convert_to_stripe_object(resp.data, opts)
34
- end
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
35
37
  when :retrieve
36
38
  define_singleton_method(:"retrieve_#{resource}") \
37
- do |id, nested_id, opts = {}|
38
- url = send(resource_url_method, id, nested_id)
39
- resp, opts = request(:get, url, {}, opts)
40
- Util.convert_to_stripe_object(resp.data, opts)
41
- end
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
42
44
  when :update
43
45
  define_singleton_method(:"update_#{resource}") \
44
- do |id, nested_id, params = {}, opts = {}|
45
- url = send(resource_url_method, id, nested_id)
46
- resp, opts = request(:post, url, params, opts)
47
- Util.convert_to_stripe_object(resp.data, opts)
48
- end
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
49
51
  when :delete
50
52
  define_singleton_method(:"delete_#{resource}") \
51
- do |id, nested_id, params = {}, opts = {}|
52
- url = send(resource_url_method, id, nested_id)
53
- resp, opts = request(:delete, url, params, opts)
54
- Util.convert_to_stripe_object(resp.data, opts)
55
- end
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
56
59
  when :list
57
60
  define_singleton_method(:"list_#{resource_plural}") \
58
- do |id, params = {}, opts = {}|
59
- url = send(resource_url_method, id)
60
- resp, opts = request(:get, url, params, opts)
61
- Util.convert_to_stripe_object(resp.data, opts)
62
- end
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
63
66
  else
64
67
  raise ArgumentError, "Unknown operation: #{operation.inspect}"
65
68
  end