fake_stripe 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +9 -2
- data/lib/fake_stripe/assets/v3.js +34 -0
- data/lib/fake_stripe/fixtures/invalid_positive_integer.json +8 -0
- data/lib/fake_stripe/stub_app.rb +6 -2
- data/lib/fake_stripe/stub_stripe_js.rb +21 -13
- data/lib/fake_stripe/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 413ab3d5a27b5f4ae2a6be8cb3bfa8b16630bd06e6e2d34a5b96ce206cf06e1b
|
4
|
+
data.tar.gz: 4c110b55b4c1677b7070d76fd99eee063bbd186dc463a1e50249996341e7fd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9a000e2733d4a823c2de60d55f9b53f75261799c05cdae3546603040bc1ad1561c69ee28b713e78c75fd7498bd0a68d0aa395102253120936a918eb2b49a65b
|
7
|
+
data.tar.gz: 45ed28b5046d62eb4001cec3581578dd62b912c130d31eeaa57c2ab081d25beabb3bc725d7992240838736a52ba72eede1aa2409031e88cf6fa418018f4815e5
|
data/README.md
CHANGED
@@ -36,20 +36,27 @@ end
|
|
36
36
|
|
37
37
|
Include the Stripe JavaScript in your application template.
|
38
38
|
|
39
|
-
|
39
|
+
For Stripe.js v1:
|
40
40
|
|
41
41
|
```rhtml
|
42
42
|
# app/views/layouts/application.html.erb
|
43
43
|
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v1/" %>
|
44
44
|
```
|
45
45
|
|
46
|
-
|
46
|
+
For Stripe.js v2:
|
47
47
|
|
48
48
|
```rhtml
|
49
49
|
# app/views/layouts/application.html.erb
|
50
50
|
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v2/" %>
|
51
51
|
```
|
52
52
|
|
53
|
+
For Stripe.js v3:
|
54
|
+
|
55
|
+
```rhtml
|
56
|
+
# app/views/layouts/application.html.erb
|
57
|
+
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v3/" %>
|
58
|
+
```
|
59
|
+
|
53
60
|
When the test suite runs `fake_stripe` will override the address for
|
54
61
|
`STRIPE_JS_HOST` and serve up a local version of [Stripe.js](https://stripe.com/docs/stripe.js).
|
55
62
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Element {
|
2
|
+
mount(el) {
|
3
|
+
if (typeof el === "string") {
|
4
|
+
el = document.querySelector(el)[0];
|
5
|
+
}
|
6
|
+
|
7
|
+
el.innerHTML = `
|
8
|
+
<input id="stripe-cardnumber" placeholder="cardnumber" size="16" type="text">
|
9
|
+
<input placeholder="exp-date" size="6" type="text">
|
10
|
+
<input placeholder="cvc" size="3" type="text">
|
11
|
+
<input placeholder="postal" size="6" type="text">
|
12
|
+
`;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
window.Stripe = () => {
|
17
|
+
const fetchLastFour = () => {
|
18
|
+
return document.getElementById("stripe-cardnumber").value.substr(-4, 4);
|
19
|
+
};
|
20
|
+
|
21
|
+
return {
|
22
|
+
elements: () => {
|
23
|
+
return {
|
24
|
+
create: (type, options) => new Element()
|
25
|
+
};
|
26
|
+
},
|
27
|
+
|
28
|
+
createToken: card => {
|
29
|
+
return new Promise(resolve => {
|
30
|
+
resolve({ token: { id: "tok_123", card: { last4: fetchLastFour() } } });
|
31
|
+
});
|
32
|
+
}
|
33
|
+
};
|
34
|
+
};
|
data/lib/fake_stripe/stub_app.rb
CHANGED
@@ -5,8 +5,12 @@ module FakeStripe
|
|
5
5
|
|
6
6
|
# Charges
|
7
7
|
post '/v1/charges' do
|
8
|
-
|
9
|
-
|
8
|
+
if params['amount'] && params['amount'].to_i <= 0
|
9
|
+
json_response 400, fixture('invalid_positive_integer')
|
10
|
+
else
|
11
|
+
FakeStripe.charge_count += 1
|
12
|
+
json_response 201, fixture('create_charge')
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
get '/v1/charges/:charge_id' do
|
@@ -1,34 +1,42 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "capybara"
|
2
|
+
require "capybara/server"
|
3
|
+
require "fake_stripe/utils"
|
4
|
+
require "sinatra/base"
|
5
5
|
|
6
6
|
module FakeStripe
|
7
7
|
class StubStripeJS < Sinatra::Base
|
8
|
-
get
|
9
|
-
file_path = File.join(File.dirname(__FILE__),
|
8
|
+
get "/v1/" do
|
9
|
+
file_path = File.join(File.dirname(__FILE__), "/assets/v1.js")
|
10
10
|
|
11
|
-
content_type
|
11
|
+
content_type "text/javascript"
|
12
12
|
status 200
|
13
13
|
IO.read(file_path)
|
14
14
|
end
|
15
15
|
|
16
|
-
get
|
17
|
-
file_path = File.join(File.dirname(__FILE__),
|
18
|
-
mock_file_path = File.join(File.dirname(__FILE__),
|
16
|
+
get "/v2/" do
|
17
|
+
file_path = File.join(File.dirname(__FILE__), "/assets/v2.js")
|
18
|
+
mock_file_path = File.join(File.dirname(__FILE__), "/assets/v2-mock.js")
|
19
19
|
|
20
|
-
content_type
|
20
|
+
content_type "text/javascript"
|
21
21
|
status 200
|
22
22
|
IO.read(file_path) + IO.read(mock_file_path)
|
23
23
|
end
|
24
24
|
|
25
|
+
get "/v3/" do
|
26
|
+
file_path = File.join(File.dirname(__FILE__), "/assets/v3.js")
|
27
|
+
|
28
|
+
content_type "text/javascript"
|
29
|
+
status 200
|
30
|
+
IO.read(file_path)
|
31
|
+
end
|
32
|
+
|
25
33
|
def self.boot(port = FakeStripe::Utils.find_available_port)
|
26
34
|
instance = new
|
27
|
-
Capybara::Server.new(instance, port).tap
|
35
|
+
Capybara::Server.new(instance, port: port).tap(&:boot)
|
28
36
|
end
|
29
37
|
|
30
38
|
def self.boot_once
|
31
|
-
@@stripe_js_server ||= FakeStripe::StubStripeJS.boot(
|
39
|
+
@@stripe_js_server ||= FakeStripe::StubStripeJS.boot(server_port)
|
32
40
|
end
|
33
41
|
|
34
42
|
def self.server_port
|
data/lib/fake_stripe/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harlow Ward
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: puma
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- lib/fake_stripe/assets/v1.js
|
114
128
|
- lib/fake_stripe/assets/v2-mock.js
|
115
129
|
- lib/fake_stripe/assets/v2.js
|
130
|
+
- lib/fake_stripe/assets/v3.js
|
116
131
|
- lib/fake_stripe/configuration.rb
|
117
132
|
- lib/fake_stripe/fixtures/cancel_subscription.json
|
118
133
|
- lib/fake_stripe/fixtures/cancel_transfer.json
|
@@ -139,6 +154,7 @@ files:
|
|
139
154
|
- lib/fake_stripe/fixtures/delete_plan.json
|
140
155
|
- lib/fake_stripe/fixtures/delete_recipient.json
|
141
156
|
- lib/fake_stripe/fixtures/delete_subscription_discount.json
|
157
|
+
- lib/fake_stripe/fixtures/invalid_positive_integer.json
|
142
158
|
- lib/fake_stripe/fixtures/list_application_fees.json
|
143
159
|
- lib/fake_stripe/fixtures/list_balance_history.json
|
144
160
|
- lib/fake_stripe/fixtures/list_cards.json
|
@@ -208,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
224
|
version: '0'
|
209
225
|
requirements: []
|
210
226
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.7.7
|
212
228
|
signing_key:
|
213
229
|
specification_version: 4
|
214
230
|
summary: A fake Stripe server.
|