stripe 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/README.md +10 -0
- data/VERSION +1 -1
- data/lib/stripe.rb +25 -0
- data/lib/stripe/stripe_client.rb +18 -2
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_client_test.rb +48 -6
- data/test/stripe_test.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5a5d77a37b6f87fe0e40d1eb03072b82d0b4cf
|
4
|
+
data.tar.gz: aacdfe4bb67bdc6671e300a899a0e9cf037332ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79d65a44f1a015f5d052396ae54a7a103ff35821ea9b7e290e52f0aa35b5ed0e70f0e9c2230a0ee8cbc2e03508517a4d8bcad79e3248ce2d08a869febfa08207
|
7
|
+
data.tar.gz: c57103af7cdbf0026211c11a121764bb02f859d00ad822cb29ec49f5a45181274a06c6cb54f86fb9cb9a28e27231490e836b2b29dc4d62273387f66b79653b93
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -122,6 +122,16 @@ an intermittent network problem:
|
|
122
122
|
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
|
123
123
|
retries are safe.
|
124
124
|
|
125
|
+
### Writing a Plugin
|
126
|
+
|
127
|
+
If you're writing a plugin that uses the library, we'd appreciate it if you
|
128
|
+
identified using `#set_app_info`:
|
129
|
+
|
130
|
+
Stripe.set_app_info("MyAwesomePlugin", version: "1.2.34", url: "https://myawesomeplugin.info");
|
131
|
+
|
132
|
+
This information is passed along when the library makes calls to the Stripe
|
133
|
+
API.
|
134
|
+
|
125
135
|
## Development
|
126
136
|
|
127
137
|
Run all tests:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.0
|
data/lib/stripe.rb
CHANGED
@@ -70,6 +70,8 @@ require 'stripe/transfer'
|
|
70
70
|
module Stripe
|
71
71
|
DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt'
|
72
72
|
|
73
|
+
@app_info = nil
|
74
|
+
|
73
75
|
@api_base = 'https://api.stripe.com'
|
74
76
|
@connect_base = 'https://connect.stripe.com'
|
75
77
|
@uploads_base = 'https://uploads.stripe.com'
|
@@ -92,6 +94,16 @@ module Stripe
|
|
92
94
|
attr_reader :max_network_retry_delay, :initial_network_retry_delay
|
93
95
|
end
|
94
96
|
|
97
|
+
# Gets the application for a plugin that's identified some. See
|
98
|
+
# #set_app_info.
|
99
|
+
def self.app_info
|
100
|
+
@app_info
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.app_info=(info)
|
104
|
+
@app_info = info
|
105
|
+
end
|
106
|
+
|
95
107
|
# The location of a file containing a bundle of CA certificates. By default
|
96
108
|
# the library will use an included bundle that can successfully validate
|
97
109
|
# Stripe certificates.
|
@@ -131,6 +143,19 @@ module Stripe
|
|
131
143
|
@max_network_retries = val.to_i
|
132
144
|
end
|
133
145
|
|
146
|
+
# Sets some basic information about the running application that's sent along
|
147
|
+
# with API requests. Useful for plugin authors to identify their plugin when
|
148
|
+
# communicating with Stripe.
|
149
|
+
#
|
150
|
+
# Takes a name and optional version and plugin URL.
|
151
|
+
def self.set_app_info(name, version: nil, url: nil)
|
152
|
+
@app_info = {
|
153
|
+
name: name,
|
154
|
+
url: url,
|
155
|
+
version: version,
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
134
159
|
private
|
135
160
|
|
136
161
|
# DEPRECATED. Use `Util#encode_parameters` instead.
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -218,6 +218,16 @@ module Stripe
|
|
218
218
|
http_status: status, http_body: body)
|
219
219
|
end
|
220
220
|
|
221
|
+
# Formats a plugin "app info" hash into a string that we can tack onto the
|
222
|
+
# end of a User-Agent string where it'll be fairly prominant in places like
|
223
|
+
# the Dashboard. Note that this formatting has been implemented to match
|
224
|
+
# other libraries, and shouldn't be changed without universal consensus.
|
225
|
+
def format_app_info(info)
|
226
|
+
str = info[:name]
|
227
|
+
str = "#{str}/#{info[:version]}" unless info[:version].nil?
|
228
|
+
str = "#{str} (#{info[:url]})" unless info[:url].nil?
|
229
|
+
str
|
230
|
+
end
|
221
231
|
|
222
232
|
def handle_api_error(http_resp)
|
223
233
|
begin
|
@@ -309,8 +319,13 @@ module Stripe
|
|
309
319
|
end
|
310
320
|
|
311
321
|
def request_headers(api_key, method)
|
322
|
+
user_agent = "Stripe/v1 RubyBindings/#{Stripe::VERSION}"
|
323
|
+
unless Stripe.app_info.nil?
|
324
|
+
user_agent += " " + format_app_info(Stripe.app_info)
|
325
|
+
end
|
326
|
+
|
312
327
|
headers = {
|
313
|
-
'User-Agent' =>
|
328
|
+
'User-Agent' => user_agent,
|
314
329
|
'Authorization' => "Bearer #{api_key}",
|
315
330
|
'Content-Type' => 'application/x-www-form-urlencoded'
|
316
331
|
}
|
@@ -382,6 +397,7 @@ module Stripe
|
|
382
397
|
lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
|
383
398
|
|
384
399
|
{
|
400
|
+
:application => Stripe.app_info,
|
385
401
|
:bindings_version => Stripe::VERSION,
|
386
402
|
:lang => 'ruby',
|
387
403
|
:lang_version => lang_version,
|
@@ -390,7 +406,7 @@ module Stripe
|
|
390
406
|
:publisher => 'stripe',
|
391
407
|
:uname => @uname,
|
392
408
|
:hostname => Socket.gethostname,
|
393
|
-
}
|
409
|
+
}.delete_if { |k, v| v.nil? }
|
394
410
|
end
|
395
411
|
end
|
396
412
|
end
|
data/lib/stripe/version.rb
CHANGED
@@ -143,14 +143,19 @@ module Stripe
|
|
143
143
|
|
144
144
|
context "Stripe-Account header" do
|
145
145
|
should "use a globally set header" do
|
146
|
-
|
146
|
+
begin
|
147
|
+
old = Stripe.stripe_account
|
148
|
+
Stripe.stripe_account = 'acct_1234'
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
151
|
+
with(headers: {"Stripe-Account" => Stripe.stripe_account}).
|
152
|
+
to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
+
client = StripeClient.new
|
155
|
+
client.execute_request(:post, '/v1/account')
|
156
|
+
ensure
|
157
|
+
Stripe.stripe_account = old
|
158
|
+
end
|
154
159
|
end
|
155
160
|
|
156
161
|
should "use a locally set header" do
|
@@ -176,6 +181,43 @@ module Stripe
|
|
176
181
|
end
|
177
182
|
end
|
178
183
|
|
184
|
+
context "app_info" do
|
185
|
+
should "send app_info if set" do
|
186
|
+
begin
|
187
|
+
old = Stripe.app_info
|
188
|
+
Stripe.set_app_info(
|
189
|
+
"MyAwesomePlugin",
|
190
|
+
url: "https://myawesomeplugin.info",
|
191
|
+
version: "1.2.34"
|
192
|
+
)
|
193
|
+
|
194
|
+
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
195
|
+
with { |req|
|
196
|
+
assert_equal \
|
197
|
+
"Stripe/v1 RubyBindings/#{Stripe::VERSION} " \
|
198
|
+
"MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)",
|
199
|
+
req.headers["User-Agent"]
|
200
|
+
|
201
|
+
data = JSON.parse(req.headers["X-Stripe-Client-User-Agent"],
|
202
|
+
symbolize_names: true)
|
203
|
+
|
204
|
+
assert_equal({
|
205
|
+
name: "MyAwesomePlugin",
|
206
|
+
url: "https://myawesomeplugin.info",
|
207
|
+
version: "1.2.34"
|
208
|
+
}, data[:application])
|
209
|
+
|
210
|
+
true
|
211
|
+
}.to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
212
|
+
|
213
|
+
client = StripeClient.new
|
214
|
+
client.execute_request(:post, '/v1/account')
|
215
|
+
ensure
|
216
|
+
Stripe.app_info = old
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
179
221
|
context "error handling" do
|
180
222
|
should "handle error response with empty body" do
|
181
223
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
data/test/stripe_test.rb
CHANGED
@@ -14,6 +14,24 @@ class StripeTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
should "allow app_info to be configured" do
|
18
|
+
begin
|
19
|
+
old = Stripe.app_info
|
20
|
+
Stripe.set_app_info(
|
21
|
+
"MyAwesomePlugin",
|
22
|
+
url: "https://myawesomeplugin.info",
|
23
|
+
version: "1.2.34"
|
24
|
+
)
|
25
|
+
assert_equal({
|
26
|
+
name: "MyAwesomePlugin",
|
27
|
+
url: "https://myawesomeplugin.info",
|
28
|
+
version: "1.2.34"
|
29
|
+
}, Stripe.app_info)
|
30
|
+
ensure
|
31
|
+
Stripe.app_info = old
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
17
35
|
should "allow ca_bundle_path to be configured" do
|
18
36
|
begin
|
19
37
|
old = Stripe.ca_bundle_path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|