stripe 2.0.3 → 5.55.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1036 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +24 -23
- data/History.txt +1 -593
- data/Makefile +7 -0
- data/README.md +252 -53
- data/Rakefile +18 -24
- data/VERSION +1 -1
- data/bin/stripe-console +5 -3
- data/lib/stripe/api_operations/create.rb +4 -2
- data/lib/stripe/api_operations/delete.rb +31 -3
- data/lib/stripe/api_operations/list.rb +4 -13
- data/lib/stripe/api_operations/nested_resource.rb +73 -0
- data/lib/stripe/api_operations/request.rb +92 -10
- data/lib/stripe/api_operations/save.rb +25 -13
- data/lib/stripe/api_operations/search.rb +19 -0
- data/lib/stripe/api_resource.rb +55 -11
- 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 +98 -13
- data/lib/stripe/instrumentation.rb +84 -0
- data/lib/stripe/list_object.rb +55 -21
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +65 -0
- data/lib/stripe/object_types.rb +119 -0
- data/lib/stripe/{account.rb → resources/account.rb} +75 -38
- data/lib/stripe/resources/account_link.rb +10 -0
- data/lib/stripe/resources/alipay_account.rb +34 -0
- data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +6 -1
- data/lib/stripe/resources/application_fee.rb +14 -0
- data/lib/stripe/resources/application_fee_refund.rb +31 -0
- data/lib/stripe/resources/balance.rb +8 -0
- data/lib/stripe/resources/balance_transaction.rb +10 -0
- data/lib/stripe/resources/bank_account.rb +43 -0
- data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
- data/lib/stripe/resources/billing_portal/session.rb +12 -0
- data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +8 -4
- data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
- data/lib/stripe/resources/capability.rb +34 -0
- data/lib/stripe/resources/card.rb +38 -0
- data/lib/stripe/resources/cash_balance.rb +22 -0
- data/lib/stripe/resources/charge.rb +32 -0
- data/lib/stripe/resources/checkout/session.rb +27 -0
- data/lib/stripe/resources/country_spec.rb +10 -0
- data/lib/stripe/{coupon.rb → resources/coupon.rb} +6 -1
- data/lib/stripe/resources/credit_note.rb +33 -0
- data/lib/stripe/resources/credit_note_line_item.rb +8 -0
- data/lib/stripe/resources/customer.rb +74 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
- data/lib/stripe/resources/discount.rb +8 -0
- data/lib/stripe/resources/dispute.rb +22 -0
- data/lib/stripe/resources/ephemeral_key.rb +20 -0
- data/lib/stripe/resources/event.rb +10 -0
- data/lib/stripe/resources/exchange_rate.rb +10 -0
- data/lib/stripe/resources/file.rb +36 -0
- data/lib/stripe/resources/file_link.rb +12 -0
- data/lib/stripe/resources/financial_connections/account.rb +31 -0
- data/lib/stripe/resources/financial_connections/account_owner.rb +10 -0
- data/lib/stripe/resources/financial_connections/account_ownership.rb +10 -0
- data/lib/stripe/resources/financial_connections/session.rb +12 -0
- 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 +83 -0
- data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +6 -1
- data/lib/stripe/resources/invoice_line_item.rb +8 -0
- data/lib/stripe/resources/issuing/authorization.rb +34 -0
- data/lib/stripe/resources/issuing/card.rb +25 -0
- data/lib/stripe/resources/issuing/card_details.rb +10 -0
- data/lib/stripe/resources/issuing/cardholder.rb +14 -0
- data/lib/stripe/resources/issuing/dispute.rb +25 -0
- data/lib/stripe/resources/issuing/transaction.rb +13 -0
- data/lib/stripe/resources/line_item.rb +8 -0
- data/lib/stripe/resources/login_link.rb +15 -0
- data/lib/stripe/resources/mandate.rb +8 -0
- data/lib/stripe/resources/order.rb +33 -0
- data/lib/stripe/resources/order_return.rb +10 -0
- data/lib/stripe/resources/payment_intent.rb +82 -0
- data/lib/stripe/resources/payment_link.rb +23 -0
- data/lib/stripe/resources/payment_method.rb +33 -0
- data/lib/stripe/resources/payout.rb +33 -0
- data/lib/stripe/resources/person.rb +32 -0
- data/lib/stripe/{plan.rb → resources/plan.rb} +5 -0
- data/lib/stripe/resources/price.rb +21 -0
- data/lib/stripe/resources/product.rb +22 -0
- 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 +12 -0
- data/lib/stripe/resources/radar/value_list.rb +15 -0
- data/lib/stripe/resources/radar/value_list_item.rb +14 -0
- data/lib/stripe/resources/recipient.rb +14 -0
- data/lib/stripe/resources/recipient_transfer.rb +7 -0
- data/lib/stripe/resources/refund.rb +42 -0
- data/lib/stripe/resources/reporting/report_run.rb +13 -0
- data/lib/stripe/resources/reporting/report_type.rb +13 -0
- data/lib/stripe/resources/reversal.rb +30 -0
- data/lib/stripe/resources/review.rb +21 -0
- data/lib/stripe/resources/setup_attempt.rb +10 -0
- data/lib/stripe/resources/setup_intent.rb +43 -0
- data/lib/stripe/resources/shipping_rate.rb +12 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
- data/lib/stripe/{sku.rb → resources/sku.rb} +7 -2
- data/lib/stripe/resources/source.rb +47 -0
- data/lib/stripe/resources/source_transaction.rb +8 -0
- data/lib/stripe/resources/subscription.rb +35 -0
- data/lib/stripe/resources/subscription_item.rb +26 -0
- data/lib/stripe/resources/subscription_schedule.rb +33 -0
- data/lib/stripe/resources/tax_code.rb +10 -0
- data/lib/stripe/resources/tax_id.rb +27 -0
- data/lib/stripe/{product.rb → resources/tax_rate.rb} +7 -3
- data/lib/stripe/resources/terminal/configuration.rb +15 -0
- data/lib/stripe/resources/terminal/connection_token.rb +12 -0
- data/lib/stripe/resources/terminal/location.rb +15 -0
- data/lib/stripe/resources/terminal/reader.rb +75 -0
- data/lib/stripe/resources/test_helpers/test_clock.rb +25 -0
- data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +5 -0
- data/lib/stripe/resources/token.rb +10 -0
- data/lib/stripe/resources/topup.rb +23 -0
- data/lib/stripe/resources/transfer.rb +27 -0
- data/lib/stripe/resources/usage_record.rb +8 -0
- data/lib/stripe/resources/usage_record_summary.rb +8 -0
- data/lib/stripe/{recipient.rb → resources/webhook_endpoint.rb} +6 -5
- data/lib/stripe/resources.rb +100 -0
- data/lib/stripe/search_result_object.rb +86 -0
- data/lib/stripe/singleton_api_resource.rb +10 -4
- data/lib/stripe/stripe_client.rb +886 -223
- data/lib/stripe/stripe_configuration.rb +194 -0
- data/lib/stripe/stripe_object.rb +301 -132
- data/lib/stripe/stripe_response.rb +89 -27
- data/lib/stripe/util.rb +272 -122
- data/lib/stripe/version.rb +3 -1
- data/lib/stripe/webhook.rb +121 -0
- data/lib/stripe.rb +94 -116
- data/stripe.gemspec +35 -16
- metadata +127 -156
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -5
- data/.travis.yml +0 -15
- data/lib/stripe/alipay_account.rb +0 -20
- data/lib/stripe/application_fee.rb +0 -20
- data/lib/stripe/application_fee_refund.rb +0 -18
- data/lib/stripe/balance.rb +0 -4
- data/lib/stripe/balance_transaction.rb +0 -9
- data/lib/stripe/bank_account.rb +0 -28
- data/lib/stripe/bitcoin_transaction.rb +0 -9
- data/lib/stripe/card.rb +0 -25
- data/lib/stripe/charge.rb +0 -80
- data/lib/stripe/country_spec.rb +0 -9
- data/lib/stripe/customer.rb +0 -77
- data/lib/stripe/dispute.rb +0 -15
- data/lib/stripe/event.rb +0 -5
- data/lib/stripe/file_upload.rb +0 -31
- data/lib/stripe/invoice.rb +0 -27
- data/lib/stripe/order.rb +0 -27
- data/lib/stripe/order_return.rb +0 -9
- data/lib/stripe/refund.rb +0 -7
- data/lib/stripe/reversal.rb +0 -18
- data/lib/stripe/source.rb +0 -11
- data/lib/stripe/subscription.rb +0 -31
- data/lib/stripe/subscription_item.rb +0 -12
- data/lib/stripe/token.rb +0 -5
- data/lib/stripe/transfer.rb +0 -16
- data/openapi/fixtures.json +0 -1383
- data/openapi/fixtures.yaml +0 -1130
- data/openapi/spec.json +0 -19749
- data/openapi/spec.yaml +0 -15359
- data/test/api_fixtures.rb +0 -29
- data/test/api_stub_helpers.rb +0 -125
- data/test/stripe/account_test.rb +0 -204
- data/test/stripe/alipay_account_test.rb +0 -19
- data/test/stripe/api_operations_test.rb +0 -31
- data/test/stripe/api_resource_test.rb +0 -496
- data/test/stripe/apple_pay_domain_test.rb +0 -33
- data/test/stripe/application_fee_refund_test.rb +0 -38
- data/test/stripe/application_fee_test.rb +0 -14
- data/test/stripe/balance_test.rb +0 -11
- data/test/stripe/bank_account_test.rb +0 -41
- data/test/stripe/bitcoin_receiver_test.rb +0 -70
- data/test/stripe/bitcoin_transaction_test.rb +0 -21
- data/test/stripe/charge_test.rb +0 -59
- data/test/stripe/country_spec_test.rb +0 -20
- data/test/stripe/coupon_test.rb +0 -44
- data/test/stripe/customer_card_test.rb +0 -42
- data/test/stripe/customer_test.rb +0 -116
- data/test/stripe/dispute_test.rb +0 -42
- data/test/stripe/errors_test.rb +0 -18
- data/test/stripe/file_upload_test.rb +0 -66
- data/test/stripe/invoice_item_test.rb +0 -55
- data/test/stripe/invoice_test.rb +0 -66
- data/test/stripe/list_object_test.rb +0 -170
- data/test/stripe/order_return_test.rb +0 -21
- data/test/stripe/order_test.rb +0 -59
- data/test/stripe/plan_test.rb +0 -52
- data/test/stripe/product_test.rb +0 -47
- data/test/stripe/recipient_card_test.rb +0 -40
- data/test/stripe/recipient_test.rb +0 -50
- data/test/stripe/refund_test.rb +0 -39
- data/test/stripe/reversal_test.rb +0 -43
- data/test/stripe/sku_test.rb +0 -50
- data/test/stripe/source_test.rb +0 -43
- data/test/stripe/stripe_client_test.rb +0 -440
- data/test/stripe/stripe_object_test.rb +0 -361
- data/test/stripe/stripe_response_test.rb +0 -46
- data/test/stripe/subscription_item_test.rb +0 -54
- data/test/stripe/subscription_test.rb +0 -60
- data/test/stripe/three_d_secure_test.rb +0 -23
- data/test/stripe/transfer_test.rb +0 -50
- data/test/stripe/util_test.rb +0 -149
- data/test/stripe_test.rb +0 -41
- data/test/test_data.rb +0 -59
- data/test/test_helper.rb +0 -41
data/README.md
CHANGED
@@ -1,38 +1,46 @@
|
|
1
|
-
# Stripe Ruby Library
|
1
|
+
# Stripe Ruby Library
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/stripe.svg)](https://badge.fury.io/rb/stripe)
|
4
|
+
[![Build Status](https://travis-ci.org/stripe/stripe-ruby.svg?branch=master)](https://travis-ci.org/stripe/stripe-ruby)
|
2
5
|
|
3
6
|
The Stripe Ruby library provides convenient access to the Stripe API from
|
4
7
|
applications written in the Ruby language. It includes a pre-defined set of
|
5
8
|
classes for API resources that initialize themselves dynamically from API
|
6
|
-
responses
|
9
|
+
responses which makes it compatible with a wide range of versions of the Stripe
|
7
10
|
API.
|
8
11
|
|
9
12
|
The library also provides other features. For example:
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
executed.
|
15
|
-
* 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
|
16
17
|
expectations of Stripe's API.
|
17
18
|
|
18
19
|
## Documentation
|
19
20
|
|
20
|
-
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
|
+
|
21
25
|
|
22
26
|
## Installation
|
23
27
|
|
24
28
|
You don't need this source code unless you want to modify the gem. If you just
|
25
29
|
want to use the package, just run:
|
26
30
|
|
27
|
-
|
31
|
+
```sh
|
32
|
+
gem install stripe
|
33
|
+
```
|
28
34
|
|
29
35
|
If you want to build the gem from source:
|
30
36
|
|
31
|
-
|
37
|
+
```sh
|
38
|
+
gem build stripe.gemspec
|
39
|
+
```
|
32
40
|
|
33
41
|
### Requirements
|
34
42
|
|
35
|
-
|
43
|
+
- Ruby 2.3+.
|
36
44
|
|
37
45
|
### Bundler
|
38
46
|
|
@@ -40,7 +48,7 @@ If you are installing via bundler, you should be sure to use the https rubygems
|
|
40
48
|
source in your Gemfile, as any gems fetched over http could potentially be
|
41
49
|
compromised in transit and alter the code of gems fetched securely over https:
|
42
50
|
|
43
|
-
```
|
51
|
+
```ruby
|
44
52
|
source 'https://rubygems.org'
|
45
53
|
|
46
54
|
gem 'rails'
|
@@ -53,17 +61,15 @@ The library needs to be configured with your account's secret key which is
|
|
53
61
|
available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
|
54
62
|
value:
|
55
63
|
|
56
|
-
```
|
57
|
-
require
|
58
|
-
Stripe.api_key =
|
64
|
+
```ruby
|
65
|
+
require 'stripe'
|
66
|
+
Stripe.api_key = 'sk_test_...'
|
59
67
|
|
60
|
-
# list
|
61
|
-
Stripe::
|
68
|
+
# list customers
|
69
|
+
Stripe::Customer.list()
|
62
70
|
|
63
|
-
# retrieve single
|
64
|
-
Stripe::
|
65
|
-
"ch_18atAXCdGbJFKhCuBAa4532Z",
|
66
|
-
)
|
71
|
+
# retrieve single customer
|
72
|
+
Stripe::Customer.retrieve('cus_123456789')
|
67
73
|
```
|
68
74
|
|
69
75
|
### Per-request Configuration
|
@@ -72,80 +78,273 @@ For apps that need to use multiple keys during the lifetime of a process, like
|
|
72
78
|
one that uses [Stripe Connect][connect], it's also possible to set a
|
73
79
|
per-request key and/or account:
|
74
80
|
|
75
|
-
```
|
81
|
+
```ruby
|
76
82
|
require "stripe"
|
77
83
|
|
78
|
-
Stripe::
|
84
|
+
Stripe::Customer.list(
|
79
85
|
{},
|
80
|
-
|
81
|
-
|
86
|
+
{
|
87
|
+
api_key: 'sk_test_...',
|
88
|
+
stripe_account: 'acct_...',
|
89
|
+
stripe_version: '2018-02-28',
|
90
|
+
}
|
82
91
|
)
|
83
92
|
|
84
|
-
Stripe::
|
85
|
-
|
86
|
-
|
87
|
-
|
93
|
+
Stripe::Customer.retrieve(
|
94
|
+
'cus_123456789',
|
95
|
+
{
|
96
|
+
api_key: 'sk_test_...',
|
97
|
+
stripe_account: 'acct_...',
|
98
|
+
stripe_version: '2018-02-28',
|
99
|
+
}
|
100
|
+
)
|
101
|
+
|
102
|
+
Stripe::Customer.retrieve(
|
103
|
+
{
|
104
|
+
id: 'cus_123456789',
|
105
|
+
expand: %w(balance_transaction)
|
106
|
+
},
|
107
|
+
{
|
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_...',
|
119
|
+
}
|
88
120
|
)
|
89
121
|
```
|
90
122
|
|
91
|
-
|
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.
|
92
132
|
|
93
|
-
|
94
|
-
library use any client supported by [Faraday][faraday] by initializing a
|
95
|
-
`Stripe::StripeClient` object and giving it a connection:
|
133
|
+
### Accessing a response object
|
96
134
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
)
|
135
|
+
Get access to response objects by initializing a client and using its `request`
|
136
|
+
method:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
client = Stripe::StripeClient.new
|
140
|
+
customer, resp = client.request do
|
141
|
+
Stripe::Customer.retrieve('cus_123456789',)
|
104
142
|
end
|
105
143
|
puts resp.request_id
|
106
144
|
```
|
107
145
|
|
146
|
+
### Configuring a proxy
|
147
|
+
|
148
|
+
A proxy can be configured with `Stripe.proxy`:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
Stripe.proxy = 'https://user:pass@example.com:1234'
|
152
|
+
```
|
153
|
+
|
154
|
+
### Configuring an API Version
|
155
|
+
|
156
|
+
By default, the library will use the API version pinned to the account making
|
157
|
+
a request. This can be overridden with this global option:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
Stripe.api_version = '2018-02-28'
|
161
|
+
```
|
162
|
+
|
163
|
+
See [versioning in the API reference][versioning] for more information.
|
164
|
+
|
108
165
|
### Configuring CA Bundles
|
109
166
|
|
110
167
|
By default, the library will use its own internal bundle of known CA
|
111
168
|
certificates, but it's possible to configure your own:
|
112
169
|
|
113
|
-
|
170
|
+
```ruby
|
171
|
+
Stripe.ca_bundle_path = 'path/to/ca/bundle'
|
172
|
+
```
|
114
173
|
|
115
174
|
### Configuring Automatic Retries
|
116
175
|
|
117
|
-
|
118
|
-
|
176
|
+
You can enable automatic retries on requests that fail due to a transient
|
177
|
+
problem by configuring the maximum number of retries:
|
119
178
|
|
120
|
-
|
179
|
+
```ruby
|
180
|
+
Stripe.max_network_retries = 2
|
181
|
+
```
|
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`.
|
121
185
|
|
122
186
|
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
|
123
187
|
retries are safe.
|
124
188
|
|
189
|
+
### Configuring Timeouts
|
190
|
+
|
191
|
+
Open, read and write timeouts are configurable:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
Stripe.open_timeout = 30 # in seconds
|
195
|
+
Stripe.read_timeout = 80
|
196
|
+
Stripe.write_timeout = 30 # only supported on Ruby 2.6+
|
197
|
+
```
|
198
|
+
|
199
|
+
Please take care to set conservative read timeouts. Some API requests can take
|
200
|
+
some time, and a short timeout increases the likelihood of a problem within our
|
201
|
+
servers.
|
202
|
+
|
203
|
+
### Logging
|
204
|
+
|
205
|
+
The library can be configured to emit logging that will give you better insight
|
206
|
+
into what it's doing. The `info` logging level is usually most appropriate for
|
207
|
+
production use, but `debug` is also available for more verbosity.
|
208
|
+
|
209
|
+
There are a few options for enabling it:
|
210
|
+
|
211
|
+
1. Set the environment variable `STRIPE_LOG` to the value `debug` or `info`:
|
212
|
+
|
213
|
+
```sh
|
214
|
+
$ export STRIPE_LOG=info
|
215
|
+
```
|
216
|
+
|
217
|
+
2. Set `Stripe.log_level`:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
Stripe.log_level = Stripe::LEVEL_INFO
|
221
|
+
```
|
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
|
+
|
273
|
+
### Writing a Plugin
|
274
|
+
|
275
|
+
If you're writing a plugin that uses the library, we'd appreciate it if you
|
276
|
+
identified using `#set_app_info`:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
Stripe.set_app_info('MyAwesomePlugin', version: '1.2.34', url: 'https://myawesomeplugin.info')
|
280
|
+
```
|
281
|
+
|
282
|
+
This information is passed along when the library makes calls to the Stripe
|
283
|
+
API.
|
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
|
+
|
125
296
|
## Development
|
126
297
|
|
298
|
+
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
|
299
|
+
background terminal ([stripe-mock's README][stripe-mock] also contains
|
300
|
+
instructions for installing via Homebrew and other methods):
|
301
|
+
|
302
|
+
```sh
|
303
|
+
go get -u github.com/stripe/stripe-mock
|
304
|
+
stripe-mock
|
305
|
+
```
|
306
|
+
|
127
307
|
Run all tests:
|
128
308
|
|
129
|
-
|
309
|
+
```sh
|
310
|
+
bundle exec rake test
|
311
|
+
```
|
130
312
|
|
131
313
|
Run a single test suite:
|
132
314
|
|
133
|
-
|
315
|
+
```sh
|
316
|
+
bundle exec ruby -Ilib/ test/stripe/util_test.rb
|
317
|
+
```
|
134
318
|
|
135
319
|
Run a single test:
|
136
320
|
|
137
|
-
|
321
|
+
```sh
|
322
|
+
bundle exec ruby -Ilib/ test/stripe/util_test.rb -n /should.convert.names.to.symbols/
|
323
|
+
```
|
138
324
|
|
139
|
-
|
325
|
+
Run the linter:
|
140
326
|
|
141
|
-
|
327
|
+
```sh
|
328
|
+
bundle exec rake rubocop
|
329
|
+
```
|
330
|
+
|
331
|
+
Update bundled CA certificates from the [Mozilla cURL release][curl]:
|
142
332
|
|
143
|
-
|
333
|
+
```sh
|
334
|
+
bundle exec rake update_certs
|
335
|
+
```
|
144
336
|
|
145
|
-
|
337
|
+
Update the bundled [stripe-mock] by editing the version number found in
|
338
|
+
`.travis.yml`.
|
146
339
|
|
147
340
|
[api-keys]: https://dashboard.stripe.com/account/apikeys
|
148
341
|
[connect]: https://stripe.com/connect
|
149
342
|
[curl]: http://curl.haxx.se/docs/caextract.html
|
150
|
-
[
|
151
|
-
[
|
343
|
+
[idempotency-keys]: https://stripe.com/docs/api/idempotent_requests?lang=ruby
|
344
|
+
[stripe-mock]: https://github.com/stripe/stripe-mock
|
345
|
+
[versioning]: https://stripe.com/docs/api/versioning?lang=ruby
|
346
|
+
[youtube-playlist]: https://www.youtube.com/playlist?list=PLy1nL-pvL2M50RmP6ie-gdcSnfOuQCRYk
|
347
|
+
|
348
|
+
<!--
|
349
|
+
# vim: set tw=79:
|
350
|
+
-->
|
data/Rakefile
CHANGED
@@ -1,43 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "rake/testtask"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
|
6
|
+
task default: %i[test rubocop]
|
4
7
|
|
5
8
|
Rake::TestTask.new do |t|
|
6
|
-
t.pattern =
|
9
|
+
t.pattern = "./test/**/*_test.rb"
|
7
10
|
end
|
8
11
|
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
9
14
|
desc "Update bundled certs"
|
10
15
|
task :update_certs do
|
11
|
-
require "
|
16
|
+
require "net/http"
|
17
|
+
require "uri"
|
12
18
|
|
13
19
|
fetch_file "https://curl.haxx.se/ca/cacert.pem",
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Update OpenAPI specification"
|
18
|
-
task :update_openapi do
|
19
|
-
require "faraday"
|
20
|
-
|
21
|
-
["fixtures.json", "fixtures.yaml", "spec.json", "spec.yaml"].map { |file|
|
22
|
-
Thread.new do
|
23
|
-
fetch_file "https://raw.githubusercontent.com/stripe/openapi/master/spec/#{file}",
|
24
|
-
File.expand_path("../openapi/#{file}", __FILE__)
|
25
|
-
end
|
26
|
-
}.map { |t| t.join }
|
20
|
+
::File.expand_path("../lib/data/ca-certificates.crt", __FILE__)
|
27
21
|
end
|
28
22
|
|
29
23
|
#
|
30
24
|
# helpers
|
31
25
|
#
|
32
26
|
|
33
|
-
def fetch_file(
|
34
|
-
File.open(dest,
|
35
|
-
resp =
|
36
|
-
unless resp.
|
37
|
-
abort("bad response when fetching: #{
|
38
|
-
"Status #{resp.
|
27
|
+
def fetch_file(uri, dest)
|
28
|
+
::File.open(dest, "w") do |file|
|
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}")
|
39
33
|
end
|
40
34
|
file.write(resp.body)
|
41
|
-
puts "Successfully fetched: #{
|
35
|
+
puts "Successfully fetched: #{uri}"
|
42
36
|
end
|
43
37
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
5.55.0
|
data/bin/stripe-console
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'irb/completion'
|
3
|
+
# frozen_string_literal: true
|
5
4
|
|
6
|
-
require "
|
5
|
+
require "irb"
|
6
|
+
require "irb/completion"
|
7
|
+
|
8
|
+
require "#{::File.dirname(__FILE__)}/../lib/stripe"
|
7
9
|
|
8
10
|
# Config IRB to enable --simple-prompt and auto indent
|
9
11
|
IRB.conf[:PROMPT_MODE] = :SIMPLE
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
module APIOperations
|
3
5
|
module Create
|
4
|
-
def create(params={}, opts={})
|
5
|
-
resp, opts =
|
6
|
+
def create(params = {}, opts = {})
|
7
|
+
resp, opts = execute_resource_request(:post, resource_url, params, opts)
|
6
8
|
Util.convert_to_stripe_object(resp.data, opts)
|
7
9
|
end
|
8
10
|
end
|
@@ -1,11 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
module APIOperations
|
3
5
|
module Delete
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
+
|
28
|
+
def delete(params = {}, opts = {})
|
29
|
+
resp, opts = execute_resource_request(:delete, resource_url,
|
30
|
+
params, opts)
|
7
31
|
initialize_from(resp.data, opts)
|
8
32
|
end
|
33
|
+
|
34
|
+
def self.included(base)
|
35
|
+
base.extend(ClassMethods)
|
36
|
+
end
|
9
37
|
end
|
10
38
|
end
|
11
39
|
end
|
@@ -1,28 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
module APIOperations
|
3
5
|
module List
|
4
|
-
def list(filters={}, opts={})
|
6
|
+
def list(filters = {}, opts = {})
|
5
7
|
opts = Util.normalize_opts(opts)
|
6
8
|
|
7
|
-
resp, opts =
|
9
|
+
resp, opts = execute_resource_request(:get, resource_url, filters, opts)
|
8
10
|
obj = ListObject.construct_from(resp.data, opts)
|
9
11
|
|
10
12
|
# set filters so that we can fetch the same limit, expansions, and
|
11
13
|
# predicates when accessing the next and previous pages
|
12
|
-
#
|
13
|
-
# just for general cleanliness, remove any paging options
|
14
14
|
obj.filters = filters.dup
|
15
|
-
obj.filters.delete(:ending_before)
|
16
|
-
obj.filters.delete(:starting_after)
|
17
|
-
|
18
15
|
obj
|
19
16
|
end
|
20
|
-
|
21
|
-
# The original version of #list was given the somewhat unfortunate name of
|
22
|
-
# #all, and this alias allows us to maintain backward compatibility (the
|
23
|
-
# choice was somewhat misleading in the way that it only returned a single
|
24
|
-
# page rather than all objects).
|
25
|
-
alias :all :list
|
26
17
|
end
|
27
18
|
end
|
28
19
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
module APIOperations
|
5
|
+
# Adds methods to help manipulate a subresource from its parent resource so
|
6
|
+
# that it's possible to do so from a static context (i.e. without a
|
7
|
+
# pre-existing collection of subresources on the parent).
|
8
|
+
#
|
9
|
+
# For example, a transfer gains the static methods for reversals so that the
|
10
|
+
# methods `.create_reversal`, `.retrieve_reversal`, `.update_reversal`,
|
11
|
+
# etc. all become available.
|
12
|
+
module NestedResource
|
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
|
+
|
18
|
+
raise ArgumentError, "operations array required" if operations.nil?
|
19
|
+
|
20
|
+
resource_url_method = :"#{resource}s_url"
|
21
|
+
|
22
|
+
define_singleton_method(resource_url_method) do |id, nested_id = nil|
|
23
|
+
url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(path)}"
|
24
|
+
url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
|
25
|
+
url
|
26
|
+
end
|
27
|
+
|
28
|
+
operations.each do |operation|
|
29
|
+
case operation
|
30
|
+
when :create
|
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
|
37
|
+
when :retrieve
|
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
|
44
|
+
when :update
|
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
|
51
|
+
when :delete
|
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
|
59
|
+
when :list
|
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
|
66
|
+
else
|
67
|
+
raise ArgumentError, "Unknown operation: #{operation.inspect}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|