stripe 4.21.3 → 5.52.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +254 -1
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +10 -16
- data/Makefile +7 -0
- data/README.md +115 -47
- data/Rakefile +8 -7
- data/VERSION +1 -1
- data/lib/stripe/api_operations/create.rb +1 -1
- data/lib/stripe/api_operations/delete.rb +7 -3
- data/lib/stripe/api_operations/list.rb +1 -12
- data/lib/stripe/api_operations/nested_resource.rb +29 -26
- data/lib/stripe/api_operations/request.rb +82 -6
- data/lib/stripe/api_operations/save.rb +7 -4
- data/lib/stripe/api_operations/search.rb +19 -0
- data/lib/stripe/api_resource.rb +22 -17
- data/lib/stripe/api_resource_test_helpers.rb +47 -0
- data/lib/stripe/connection_manager.rb +200 -0
- data/lib/stripe/error_object.rb +93 -0
- data/lib/stripe/errors.rb +24 -3
- data/lib/stripe/instrumentation.rb +84 -0
- data/lib/stripe/list_object.rb +34 -5
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +8 -6
- data/lib/stripe/object_types.rb +20 -5
- data/lib/stripe/resources/account.rb +12 -16
- data/lib/stripe/resources/account_link.rb +2 -1
- data/lib/stripe/resources/alipay_account.rb +1 -1
- data/lib/stripe/resources/apple_pay_domain.rb +2 -1
- data/lib/stripe/resources/application_fee.rb +2 -12
- data/lib/stripe/resources/application_fee_refund.rb +3 -2
- data/lib/stripe/resources/balance.rb +2 -1
- data/lib/stripe/resources/balance_transaction.rb +2 -5
- data/lib/stripe/resources/bank_account.rb +3 -2
- data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
- data/lib/stripe/resources/billing_portal/session.rb +12 -0
- data/lib/stripe/resources/bitcoin_receiver.rb +2 -1
- data/lib/stripe/resources/bitcoin_transaction.rb +4 -3
- data/lib/stripe/resources/capability.rb +3 -2
- data/lib/stripe/resources/card.rb +2 -1
- data/lib/stripe/resources/charge.rb +13 -65
- data/lib/stripe/resources/checkout/session.rb +17 -1
- data/lib/stripe/resources/country_spec.rb +2 -1
- data/lib/stripe/resources/coupon.rb +2 -1
- data/lib/stripe/resources/credit_note.rb +18 -3
- data/lib/stripe/resources/credit_note_line_item.rb +8 -0
- data/lib/stripe/resources/customer.rb +35 -59
- data/lib/stripe/resources/customer_balance_transaction.rb +4 -3
- data/lib/stripe/resources/discount.rb +2 -1
- data/lib/stripe/resources/dispute.rb +8 -9
- data/lib/stripe/resources/ephemeral_key.rb +2 -1
- data/lib/stripe/resources/event.rb +2 -1
- data/lib/stripe/resources/exchange_rate.rb +2 -1
- data/lib/stripe/resources/file.rb +6 -14
- data/lib/stripe/resources/file_link.rb +2 -1
- data/lib/stripe/resources/funding_instructions.rb +16 -0
- data/lib/stripe/resources/identity/verification_report.rb +12 -0
- data/lib/stripe/resources/identity/verification_session.rb +35 -0
- data/lib/stripe/resources/invoice.rb +47 -12
- data/lib/stripe/resources/invoice_item.rb +2 -1
- data/lib/stripe/resources/invoice_line_item.rb +2 -1
- data/lib/stripe/resources/issuing/authorization.rb +14 -5
- data/lib/stripe/resources/issuing/card.rb +8 -3
- data/lib/stripe/resources/issuing/card_details.rb +3 -2
- data/lib/stripe/resources/issuing/cardholder.rb +2 -1
- data/lib/stripe/resources/issuing/dispute.rb +13 -1
- data/lib/stripe/resources/issuing/transaction.rb +2 -1
- data/lib/stripe/resources/line_item.rb +8 -0
- data/lib/stripe/resources/login_link.rb +2 -1
- data/lib/stripe/resources/mandate.rb +8 -0
- data/lib/stripe/resources/order.rb +14 -13
- data/lib/stripe/resources/order_return.rb +2 -1
- data/lib/stripe/resources/payment_intent.rb +59 -7
- data/lib/stripe/resources/payment_link.rb +23 -0
- data/lib/stripe/resources/payment_method.rb +14 -5
- data/lib/stripe/resources/payout.rb +16 -7
- data/lib/stripe/resources/person.rb +2 -1
- data/lib/stripe/resources/plan.rb +2 -1
- data/lib/stripe/resources/price.rb +21 -0
- data/lib/stripe/resources/product.rb +11 -1
- data/lib/stripe/resources/promotion_code.rb +12 -0
- data/lib/stripe/resources/quote.rb +105 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +2 -1
- data/lib/stripe/resources/radar/value_list.rb +2 -1
- data/lib/stripe/resources/radar/value_list_item.rb +2 -1
- data/lib/stripe/resources/recipient.rb +2 -5
- data/lib/stripe/resources/recipient_transfer.rb +1 -1
- data/lib/stripe/resources/refund.rb +13 -1
- data/lib/stripe/resources/reporting/report_run.rb +2 -1
- data/lib/stripe/resources/reporting/report_type.rb +2 -1
- data/lib/stripe/resources/reversal.rb +4 -3
- data/lib/stripe/resources/review.rb +8 -3
- data/lib/stripe/resources/setup_attempt.rb +10 -0
- data/lib/stripe/resources/setup_intent.rb +24 -5
- data/lib/stripe/resources/shipping_rate.rb +12 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +2 -1
- data/lib/stripe/resources/sku.rb +2 -1
- data/lib/stripe/resources/source.rb +17 -12
- data/lib/stripe/resources/source_transaction.rb +2 -1
- data/lib/stripe/resources/subscription.rb +16 -6
- data/lib/stripe/resources/subscription_item.rb +11 -2
- data/lib/stripe/resources/subscription_schedule.rb +14 -13
- data/lib/stripe/resources/tax_code.rb +10 -0
- data/lib/stripe/resources/tax_id.rb +2 -1
- data/lib/stripe/resources/tax_rate.rb +2 -1
- data/lib/stripe/resources/terminal/configuration.rb +15 -0
- data/lib/stripe/resources/terminal/connection_token.rb +2 -1
- data/lib/stripe/resources/terminal/location.rb +2 -1
- data/lib/stripe/resources/terminal/reader.rb +62 -1
- data/lib/stripe/resources/test_helpers/test_clock.rb +25 -0
- data/lib/stripe/resources/three_d_secure.rb +2 -1
- data/lib/stripe/resources/token.rb +2 -1
- data/lib/stripe/resources/topup.rb +8 -3
- data/lib/stripe/resources/transfer.rb +8 -8
- data/lib/stripe/resources/usage_record.rb +2 -17
- data/lib/stripe/resources/usage_record_summary.rb +2 -1
- data/lib/stripe/resources/webhook_endpoint.rb +2 -1
- data/lib/stripe/resources.rb +18 -2
- data/lib/stripe/search_result_object.rb +86 -0
- data/lib/stripe/stripe_client.rb +617 -243
- data/lib/stripe/stripe_configuration.rb +194 -0
- data/lib/stripe/stripe_object.rb +30 -25
- data/lib/stripe/stripe_response.rb +87 -27
- data/lib/stripe/util.rb +88 -18
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe/webhook.rb +39 -8
- data/lib/stripe.rb +43 -131
- data/stripe.gemspec +17 -13
- metadata +36 -220
- data/.editorconfig +0 -10
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -43
- data/.rubocop_todo.yml +0 -38
- data/.travis.yml +0 -43
- data/.vscode/extensions.json +0 -7
- data/.vscode/settings.json +0 -8
- data/lib/stripe/resources/issuer_fraud_record.rb +0 -9
- data/lib/stripe/resources/subscription_schedule_revision.rb +0 -34
- data/test/api_stub_helpers.rb +0 -1
- data/test/openapi/README.md +0 -9
- data/test/stripe/account_link_test.rb +0 -18
- data/test/stripe/account_test.rb +0 -428
- data/test/stripe/alipay_account_test.rb +0 -37
- data/test/stripe/api_operations_test.rb +0 -80
- data/test/stripe/api_resource_test.rb +0 -544
- data/test/stripe/apple_pay_domain_test.rb +0 -46
- data/test/stripe/application_fee_refund_test.rb +0 -37
- data/test/stripe/application_fee_test.rb +0 -58
- data/test/stripe/balance_test.rb +0 -13
- data/test/stripe/bank_account_test.rb +0 -36
- data/test/stripe/capability_test.rb +0 -45
- data/test/stripe/charge_test.rb +0 -80
- data/test/stripe/checkout/session_test.rb +0 -41
- data/test/stripe/country_spec_test.rb +0 -20
- data/test/stripe/coupon_test.rb +0 -61
- data/test/stripe/credit_note_test.rb +0 -61
- data/test/stripe/customer_balance_transaction_test.rb +0 -37
- data/test/stripe/customer_card_test.rb +0 -42
- data/test/stripe/customer_test.rb +0 -269
- data/test/stripe/dispute_test.rb +0 -51
- data/test/stripe/ephemeral_key_test.rb +0 -93
- data/test/stripe/errors_test.rb +0 -20
- data/test/stripe/exchange_rate_test.rb +0 -20
- data/test/stripe/file_link_test.rb +0 -41
- data/test/stripe/file_test.rb +0 -97
- data/test/stripe/file_upload_test.rb +0 -79
- data/test/stripe/invoice_item_test.rb +0 -66
- data/test/stripe/invoice_line_item_test.rb +0 -8
- data/test/stripe/invoice_test.rb +0 -213
- data/test/stripe/issuer_fraud_record_test.rb +0 -20
- data/test/stripe/issuing/authorization_test.rb +0 -72
- data/test/stripe/issuing/card_test.rb +0 -62
- data/test/stripe/issuing/cardholder_test.rb +0 -53
- data/test/stripe/issuing/dispute_test.rb +0 -45
- data/test/stripe/issuing/transaction_test.rb +0 -48
- data/test/stripe/list_object_test.rb +0 -156
- data/test/stripe/login_link_test.rb +0 -37
- data/test/stripe/oauth_test.rb +0 -88
- data/test/stripe/order_return_test.rb +0 -21
- data/test/stripe/order_test.rb +0 -82
- data/test/stripe/payment_intent_test.rb +0 -107
- data/test/stripe/payment_method_test.rb +0 -84
- data/test/stripe/payout_test.rb +0 -57
- data/test/stripe/person_test.rb +0 -46
- data/test/stripe/plan_test.rb +0 -98
- data/test/stripe/product_test.rb +0 -59
- data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
- data/test/stripe/radar/value_list_item_test.rb +0 -48
- data/test/stripe/radar/value_list_test.rb +0 -61
- data/test/stripe/recipient_test.rb +0 -62
- data/test/stripe/refund_test.rb +0 -39
- data/test/stripe/reporting/report_run_test.rb +0 -33
- data/test/stripe/reporting/report_type_test.rb +0 -22
- data/test/stripe/reversal_test.rb +0 -43
- data/test/stripe/review_test.rb +0 -27
- data/test/stripe/setup_intent_test.rb +0 -84
- data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
- data/test/stripe/sku_test.rb +0 -60
- data/test/stripe/source_test.rb +0 -99
- data/test/stripe/source_transaction_test.rb +0 -19
- data/test/stripe/stripe_client_test.rb +0 -842
- data/test/stripe/stripe_object_test.rb +0 -525
- data/test/stripe/stripe_response_test.rb +0 -49
- data/test/stripe/subscription_item_test.rb +0 -63
- data/test/stripe/subscription_schedule_revision_test.rb +0 -37
- data/test/stripe/subscription_schedule_test.rb +0 -116
- data/test/stripe/subscription_test.rb +0 -80
- data/test/stripe/tax_id_test.rb +0 -31
- data/test/stripe/tax_rate_test.rb +0 -43
- data/test/stripe/terminal/connection_token_test.rb +0 -16
- data/test/stripe/terminal/location_test.rb +0 -68
- data/test/stripe/terminal/reader_test.rb +0 -62
- data/test/stripe/three_d_secure_test.rb +0 -23
- data/test/stripe/topup_test.rb +0 -62
- data/test/stripe/transfer_test.rb +0 -88
- data/test/stripe/usage_record_summary_test.rb +0 -19
- data/test/stripe/usage_record_test.rb +0 -28
- data/test/stripe/util_test.rb +0 -402
- data/test/stripe/webhook_endpoint_test.rb +0 -59
- data/test/stripe/webhook_test.rb +0 -96
- data/test/stripe_mock.rb +0 -77
- data/test/stripe_test.rb +0 -63
- data/test/test_data.rb +0 -61
- 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
|
@@ -13,14 +13,15 @@ The library also provides other features. For example:
|
|
13
13
|
|
14
14
|
- Easy configuration path for fast setup and use.
|
15
15
|
- Helpers for pagination.
|
16
|
-
- Tracking of "fresh" values in API resources so that partial updates can be
|
17
|
-
executed.
|
18
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
|
-
See the [Ruby API docs](https://stripe.com/docs/api
|
21
|
+
See the [Ruby API docs](https://stripe.com/docs/api?lang=ruby).
|
22
|
+
|
23
|
+
See [video demonstrations][youtube-playlist] covering how to use the library.
|
24
|
+
|
24
25
|
|
25
26
|
## Installation
|
26
27
|
|
@@ -39,7 +40,7 @@ gem build stripe.gemspec
|
|
39
40
|
|
40
41
|
### Requirements
|
41
42
|
|
42
|
-
- Ruby 2.
|
43
|
+
- Ruby 2.3+.
|
43
44
|
|
44
45
|
### Bundler
|
45
46
|
|
@@ -61,16 +62,14 @@ available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
|
|
61
62
|
value:
|
62
63
|
|
63
64
|
```ruby
|
64
|
-
require
|
65
|
-
Stripe.api_key =
|
65
|
+
require 'stripe'
|
66
|
+
Stripe.api_key = 'sk_test_...'
|
66
67
|
|
67
|
-
# list
|
68
|
-
Stripe::
|
68
|
+
# list customers
|
69
|
+
Stripe::Customer.list()
|
69
70
|
|
70
|
-
# retrieve single
|
71
|
-
Stripe::
|
72
|
-
"ch_18atAXCdGbJFKhCuBAa4532Z",
|
73
|
-
)
|
71
|
+
# retrieve single customer
|
72
|
+
Stripe::Customer.retrieve('cus_123456789')
|
74
73
|
```
|
75
74
|
|
76
75
|
### Per-request Configuration
|
@@ -82,49 +81,64 @@ per-request key and/or account:
|
|
82
81
|
```ruby
|
83
82
|
require "stripe"
|
84
83
|
|
85
|
-
Stripe::
|
84
|
+
Stripe::Customer.list(
|
86
85
|
{},
|
87
86
|
{
|
88
|
-
api_key:
|
89
|
-
stripe_account:
|
90
|
-
stripe_version:
|
87
|
+
api_key: 'sk_test_...',
|
88
|
+
stripe_account: 'acct_...',
|
89
|
+
stripe_version: '2018-02-28',
|
91
90
|
}
|
92
91
|
)
|
93
92
|
|
94
|
-
Stripe::
|
95
|
-
|
93
|
+
Stripe::Customer.retrieve(
|
94
|
+
'cus_123456789',
|
96
95
|
{
|
97
|
-
api_key:
|
98
|
-
stripe_account:
|
99
|
-
stripe_version:
|
96
|
+
api_key: 'sk_test_...',
|
97
|
+
stripe_account: 'acct_...',
|
98
|
+
stripe_version: '2018-02-28',
|
100
99
|
}
|
101
100
|
)
|
102
101
|
|
103
|
-
Stripe::
|
102
|
+
Stripe::Customer.retrieve(
|
104
103
|
{
|
105
|
-
id:
|
104
|
+
id: 'cus_123456789',
|
106
105
|
expand: %w(balance_transaction)
|
107
106
|
},
|
108
107
|
{
|
109
|
-
stripe_version:
|
110
|
-
api_key:
|
108
|
+
stripe_version: '2018-02-28',
|
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_...',
|
111
119
|
}
|
112
120
|
)
|
113
121
|
```
|
114
122
|
|
115
|
-
|
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
|
116
134
|
|
117
|
-
|
118
|
-
|
119
|
-
`Stripe::StripeClient` object and giving it a connection:
|
135
|
+
Get access to response objects by initializing a client and using its `request`
|
136
|
+
method:
|
120
137
|
|
121
138
|
```ruby
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
Stripe::Charge.retrieve(
|
126
|
-
"ch_18atAXCdGbJFKhCuBAa4532Z",
|
127
|
-
)
|
139
|
+
client = Stripe::StripeClient.new
|
140
|
+
customer, resp = client.request do
|
141
|
+
Stripe::Customer.retrieve('cus_123456789',)
|
128
142
|
end
|
129
143
|
puts resp.request_id
|
130
144
|
```
|
@@ -134,7 +148,7 @@ puts resp.request_id
|
|
134
148
|
A proxy can be configured with `Stripe.proxy`:
|
135
149
|
|
136
150
|
```ruby
|
137
|
-
Stripe.proxy =
|
151
|
+
Stripe.proxy = 'https://user:pass@example.com:1234'
|
138
152
|
```
|
139
153
|
|
140
154
|
### Configuring an API Version
|
@@ -143,7 +157,7 @@ By default, the library will use the API version pinned to the account making
|
|
143
157
|
a request. This can be overridden with this global option:
|
144
158
|
|
145
159
|
```ruby
|
146
|
-
Stripe.api_version =
|
160
|
+
Stripe.api_version = '2018-02-28'
|
147
161
|
```
|
148
162
|
|
149
163
|
See [versioning in the API reference][versioning] for more information.
|
@@ -154,28 +168,32 @@ By default, the library will use its own internal bundle of known CA
|
|
154
168
|
certificates, but it's possible to configure your own:
|
155
169
|
|
156
170
|
```ruby
|
157
|
-
Stripe.ca_bundle_path =
|
171
|
+
Stripe.ca_bundle_path = 'path/to/ca/bundle'
|
158
172
|
```
|
159
173
|
|
160
174
|
### Configuring Automatic Retries
|
161
175
|
|
162
|
-
|
163
|
-
|
176
|
+
You can enable automatic retries on requests that fail due to a transient
|
177
|
+
problem by configuring the maximum number of retries:
|
164
178
|
|
165
179
|
```ruby
|
166
180
|
Stripe.max_network_retries = 2
|
167
181
|
```
|
168
182
|
|
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`.
|
185
|
+
|
169
186
|
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
|
170
187
|
retries are safe.
|
171
188
|
|
172
189
|
### Configuring Timeouts
|
173
190
|
|
174
|
-
Open and
|
191
|
+
Open, read and write timeouts are configurable:
|
175
192
|
|
176
193
|
```ruby
|
177
|
-
Stripe.open_timeout = 30
|
194
|
+
Stripe.open_timeout = 30 # in seconds
|
178
195
|
Stripe.read_timeout = 80
|
196
|
+
Stripe.write_timeout = 30 # only supported on Ruby 2.6+
|
179
197
|
```
|
180
198
|
|
181
199
|
Please take care to set conservative read timeouts. Some API requests can take
|
@@ -202,13 +220,63 @@ There are a few options for enabling it:
|
|
202
220
|
Stripe.log_level = Stripe::LEVEL_INFO
|
203
221
|
```
|
204
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
|
+
|
205
273
|
### Writing a Plugin
|
206
274
|
|
207
275
|
If you're writing a plugin that uses the library, we'd appreciate it if you
|
208
276
|
identified using `#set_app_info`:
|
209
277
|
|
210
278
|
```ruby
|
211
|
-
Stripe.set_app_info(
|
279
|
+
Stripe.set_app_info('MyAwesomePlugin', version: '1.2.34', url: 'https://myawesomeplugin.info')
|
212
280
|
```
|
213
281
|
|
214
282
|
This information is passed along when the library makes calls to the Stripe
|
@@ -272,10 +340,10 @@ Update the bundled [stripe-mock] by editing the version number found in
|
|
272
340
|
[api-keys]: https://dashboard.stripe.com/account/apikeys
|
273
341
|
[connect]: https://stripe.com/connect
|
274
342
|
[curl]: http://curl.haxx.se/docs/caextract.html
|
275
|
-
[
|
276
|
-
[idempotency-keys]: https://stripe.com/docs/api/ruby#idempotent_requests
|
343
|
+
[idempotency-keys]: https://stripe.com/docs/api/idempotent_requests?lang=ruby
|
277
344
|
[stripe-mock]: https://github.com/stripe/stripe-mock
|
278
|
-
[versioning]: https://stripe.com/docs/api/ruby
|
345
|
+
[versioning]: https://stripe.com/docs/api/versioning?lang=ruby
|
346
|
+
[youtube-playlist]: https://www.youtube.com/playlist?list=PLy1nL-pvL2M50RmP6ie-gdcSnfOuQCRYk
|
279
347
|
|
280
348
|
<!--
|
281
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 "
|
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(
|
27
|
+
def fetch_file(uri, dest)
|
27
28
|
::File.open(dest, "w") do |file|
|
28
|
-
resp =
|
29
|
-
unless resp.
|
30
|
-
abort("bad response when fetching: #{
|
31
|
-
"Status #{resp.
|
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: #{
|
35
|
+
puts "Successfully fetched: #{uri}"
|
35
36
|
end
|
36
37
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
5.52.0
|
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
module APIOperations
|
5
5
|
module Create
|
6
6
|
def create(params = {}, opts = {})
|
7
|
-
resp, 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
|
18
|
+
# api_key to be overwritten. See
|
19
|
+
# {APIOperations::Request.execute_resource_request}.
|
19
20
|
def delete(id, params = {}, opts = {})
|
20
|
-
resp, 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 =
|
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 =
|
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
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
@@ -4,10 +4,38 @@ module Stripe
|
|
4
4
|
module APIOperations
|
5
5
|
module Request
|
6
6
|
module ClassMethods
|
7
|
-
def
|
7
|
+
def execute_resource_request(method, url,
|
8
|
+
params = {}, opts = {})
|
9
|
+
execute_resource_request_internal(
|
10
|
+
:execute_request, method, url, params, opts
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute_resource_request_stream(method, url,
|
15
|
+
params = {}, opts = {},
|
16
|
+
&read_body_chunk_block)
|
17
|
+
execute_resource_request_internal(
|
18
|
+
:execute_request_stream,
|
19
|
+
method,
|
20
|
+
url,
|
21
|
+
params,
|
22
|
+
opts,
|
23
|
+
&read_body_chunk_block
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private def execute_resource_request_internal(client_request_method_sym,
|
28
|
+
method, url,
|
29
|
+
params, opts,
|
30
|
+
&read_body_chunk_block)
|
31
|
+
params ||= {}
|
32
|
+
|
33
|
+
error_on_invalid_params(params)
|
8
34
|
warn_on_opts_in_params(params)
|
9
35
|
|
10
36
|
opts = Util.normalize_opts(opts)
|
37
|
+
error_on_non_string_user_opts(opts)
|
38
|
+
|
11
39
|
opts[:client] ||= StripeClient.active_client
|
12
40
|
|
13
41
|
headers = opts.clone
|
@@ -16,10 +44,12 @@ module Stripe
|
|
16
44
|
client = headers.delete(:client)
|
17
45
|
# Assume all remaining opts must be headers
|
18
46
|
|
19
|
-
resp, opts[:api_key] = client.
|
47
|
+
resp, opts[:api_key] = client.send(
|
48
|
+
client_request_method_sym,
|
20
49
|
method, url,
|
21
50
|
api_base: api_base, api_key: api_key,
|
22
|
-
headers: headers, params: params
|
51
|
+
headers: headers, params: params,
|
52
|
+
&read_body_chunk_block
|
23
53
|
)
|
24
54
|
|
25
55
|
# Hash#select returns an array before 1.9
|
@@ -31,10 +61,43 @@ module Stripe
|
|
31
61
|
[resp, opts_to_persist]
|
32
62
|
end
|
33
63
|
|
64
|
+
# This method used to be called `request`, but it's such a short name
|
65
|
+
# that it eventually conflicted with the name of a field on an API
|
66
|
+
# resource (specifically, `Event#request`), so it was renamed to
|
67
|
+
# something more unique.
|
68
|
+
#
|
69
|
+
# The former name had been around for just about forever though, and
|
70
|
+
# although all internal uses have been renamed, I've left this alias in
|
71
|
+
# place for backwards compatibility. Consider removing it on the next
|
72
|
+
# major.
|
73
|
+
alias request execute_resource_request
|
74
|
+
|
75
|
+
private def error_on_non_string_user_opts(opts)
|
76
|
+
Util::OPTS_USER_SPECIFIED.each do |opt|
|
77
|
+
next unless opts.key?(opt)
|
78
|
+
|
79
|
+
val = opts[opt]
|
80
|
+
next if val.nil?
|
81
|
+
next if val.is_a?(String)
|
82
|
+
|
83
|
+
raise ArgumentError,
|
84
|
+
"request option '#{opt}' should be a string value " \
|
85
|
+
"(was a #{val.class})"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private def error_on_invalid_params(params)
|
90
|
+
return if params.nil? || params.is_a?(Hash)
|
91
|
+
|
92
|
+
raise ArgumentError,
|
93
|
+
"request params should be either a Hash or nil " \
|
94
|
+
"(was a #{params.class})"
|
95
|
+
end
|
96
|
+
|
34
97
|
private def warn_on_opts_in_params(params)
|
35
98
|
Util::OPTS_USER_SPECIFIED.each do |opt|
|
36
99
|
if params.key?(opt)
|
37
|
-
warn("WARNING: #{opt} should be in opts instead of params.")
|
100
|
+
warn("WARNING: '#{opt}' should be in opts instead of params.")
|
38
101
|
end
|
39
102
|
end
|
40
103
|
end
|
@@ -44,10 +107,23 @@ module Stripe
|
|
44
107
|
base.extend(ClassMethods)
|
45
108
|
end
|
46
109
|
|
47
|
-
protected def
|
110
|
+
protected def execute_resource_request(method, url,
|
111
|
+
params = {}, opts = {})
|
48
112
|
opts = @opts.merge(Util.normalize_opts(opts))
|
49
|
-
self.class.
|
113
|
+
self.class.execute_resource_request(method, url, params, opts)
|
50
114
|
end
|
115
|
+
|
116
|
+
protected def execute_resource_request_stream(method, url,
|
117
|
+
params = {}, opts = {},
|
118
|
+
&read_body_chunk_block)
|
119
|
+
opts = @opts.merge(Util.normalize_opts(opts))
|
120
|
+
self.class.execute_resource_request_stream(
|
121
|
+
method, url, params, opts, &read_body_chunk_block
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
# See notes on `alias` above.
|
126
|
+
alias request execute_resource_request
|
51
127
|
end
|
52
128
|
end
|
53
129
|
end
|
@@ -15,7 +15,8 @@ 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
|
18
|
+
# api_key to be overwritten. See
|
19
|
+
# {APIOperations::Request.execute_resource_request}.
|
19
20
|
def update(id, params = {}, opts = {})
|
20
21
|
params.each_key do |k|
|
21
22
|
if protected_fields.include?(k)
|
@@ -23,7 +24,8 @@ module Stripe
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
resp, opts =
|
27
|
+
resp, opts = execute_resource_request(:post, "#{resource_url}/#{id}",
|
28
|
+
params, opts)
|
27
29
|
Util.convert_to_stripe_object(resp.data, opts)
|
28
30
|
end
|
29
31
|
end
|
@@ -43,7 +45,8 @@ module Stripe
|
|
43
45
|
# * +opts+ - A Hash of additional options (separate from the params /
|
44
46
|
# object values) to be added to the request. E.g. to allow for an
|
45
47
|
# idempotency_key to be passed in the request headers, or for the
|
46
|
-
# api_key to be overwritten. See
|
48
|
+
# api_key to be overwritten. See
|
49
|
+
# {APIOperations::Request.execute_resource_request}.
|
47
50
|
def save(params = {}, opts = {})
|
48
51
|
# We started unintentionally (sort of) allowing attributes sent to
|
49
52
|
# +save+ to override values used during the update. So as not to break
|
@@ -59,7 +62,7 @@ module Stripe
|
|
59
62
|
# generated a uri for this object with an identifier baked in
|
60
63
|
values.delete(:id)
|
61
64
|
|
62
|
-
resp, opts =
|
65
|
+
resp, opts = execute_resource_request(:post, save_url, values, opts)
|
63
66
|
initialize_from(resp.data, opts)
|
64
67
|
end
|
65
68
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
module APIOperations
|
5
|
+
module Search
|
6
|
+
def _search(search_url, filters = {}, opts = {})
|
7
|
+
opts = Util.normalize_opts(opts)
|
8
|
+
|
9
|
+
resp, opts = execute_resource_request(:get, search_url, filters, opts)
|
10
|
+
obj = SearchResultObject.construct_from(resp.data, opts)
|
11
|
+
|
12
|
+
# set filters so that we can fetch the same limit and query
|
13
|
+
# when accessing the next page
|
14
|
+
obj.filters = filters.dup
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|