stripe_tester 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +9 -6
- data/lib/stripe_tester.rb +16 -7
- data/lib/stripe_tester/version.rb +1 -1
- data/spec/spec_helper.rb +7 -1
- data/spec/stripe_tester_spec.rb +48 -18
- data/stripe_tester.gemspec +2 -0
- metadata +35 -4
- data/stripe_webhooks/.DS_Store +0 -0
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -33,10 +33,13 @@ In your test:
|
|
33
33
|
```ruby
|
34
34
|
StripeTester.webhook_url = "http://www.example.com/my_post_url"
|
35
35
|
```
|
36
|
-
|
37
|
-
2. Send the webhook. This will send a POST request to the URL with the event data as JSON:
|
38
36
|
|
39
|
-
|
37
|
+
2. If you want to specify which Stripe webhook API version you would like to use (the default will be the latest [supported version](https://github.com/buttercloud/stripe_tester#supported-stripe-webhook-api-versions)):
|
38
|
+
```ruby
|
39
|
+
StripeTester.stripe_version = "2013-09-08"
|
40
|
+
```
|
41
|
+
|
42
|
+
3. Send the webhook. This will send a POST request to the URL with the event data as JSON:
|
40
43
|
```ruby
|
41
44
|
# as a symbol
|
42
45
|
StripeTester.create_event(:invoice_created)
|
@@ -44,15 +47,15 @@ In your test:
|
|
44
47
|
# or as a string
|
45
48
|
StripeTester.create_event("invoice_created")
|
46
49
|
```
|
47
|
-
|
50
|
+
|
48
51
|
Or if you want to overwrite certain attributes:
|
49
52
|
```ruby
|
50
53
|
StripeTester.create_event(:invoice_created, {"amount" => 100, "currency" => 'gbp'})
|
51
54
|
```
|
52
55
|
|
53
|
-
If you want to
|
56
|
+
If you want to load the JSON only:
|
54
57
|
```ruby
|
55
|
-
StripeTester.
|
58
|
+
json = StripeTester.load_template(:invoice_payment_failed)
|
56
59
|
```
|
57
60
|
|
58
61
|
## Supported Webhooks
|
data/lib/stripe_tester.rb
CHANGED
@@ -7,13 +7,13 @@ module StripeTester
|
|
7
7
|
|
8
8
|
LATEST_STRIPE_VERSION = "2013-07-05"
|
9
9
|
|
10
|
-
#
|
11
|
-
def self.create_event(callback_type,
|
12
|
-
webhook_data = self.load_template(callback_type
|
10
|
+
# send the url the webhook event
|
11
|
+
def self.create_event(callback_type, options={})
|
12
|
+
webhook_data = self.load_template(callback_type)
|
13
|
+
|
13
14
|
if webhook_data
|
14
15
|
webhook_data = overwrite_attributes(webhook_data, options) unless options.empty?
|
15
16
|
post_to_url(webhook_data)
|
16
|
-
true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -57,7 +57,7 @@ module StripeTester
|
|
57
57
|
|
58
58
|
case res
|
59
59
|
when Net::HTTPSuccess, Net::HTTPRedirection
|
60
|
-
|
60
|
+
true
|
61
61
|
else
|
62
62
|
res.value
|
63
63
|
end
|
@@ -67,15 +67,16 @@ module StripeTester
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# load yaml with specified callback type
|
70
|
-
def self.load_template(callback_type
|
70
|
+
def self.load_template(callback_type)
|
71
71
|
spec = Gem::Specification.find_by_name("stripe_tester")
|
72
72
|
gem_root = spec.gem_dir
|
73
|
+
version = StripeTester.stripe_version
|
73
74
|
|
74
75
|
path = gem_root + "/stripe_webhooks/#{version}/#{callback_type}.yml"
|
75
76
|
if File.exists?(path)
|
76
77
|
template = Psych.load_file(path)
|
77
78
|
else
|
78
|
-
raise "Webhook not found. Please use a correct webhook type or correct
|
79
|
+
raise "Webhook not found. Please use a correct webhook type or correct Stripe version"
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -94,4 +95,12 @@ module StripeTester
|
|
94
95
|
def self.remove_url
|
95
96
|
@url = nil
|
96
97
|
end
|
98
|
+
|
99
|
+
def self.stripe_version=(version)
|
100
|
+
@version = version
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.stripe_version
|
104
|
+
@version ? @version : LATEST_STRIPE_VERSION
|
105
|
+
end
|
97
106
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/stripe_tester_spec.rb
CHANGED
@@ -4,12 +4,18 @@ describe StripeTester do
|
|
4
4
|
|
5
5
|
describe "instance methods" do
|
6
6
|
|
7
|
+
LATEST_STRIPE_VERSION = "2013-07-05"
|
8
|
+
|
7
9
|
before(:each) do
|
8
|
-
|
10
|
+
StripeTester.remove_url
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
StripeTester.stripe_version = nil
|
9
15
|
end
|
10
16
|
|
11
17
|
it "#load_template should return hash" do
|
12
|
-
result = StripeTester.load_template(:invoice_created
|
18
|
+
result = StripeTester.load_template(:invoice_created)
|
13
19
|
|
14
20
|
expect(result).to be_a_kind_of(Hash)
|
15
21
|
end
|
@@ -17,7 +23,7 @@ describe StripeTester do
|
|
17
23
|
it "#load_template should return correct callback type" do
|
18
24
|
type = "invoice_created"
|
19
25
|
|
20
|
-
returned_hash = StripeTester.load_template(type
|
26
|
+
returned_hash = StripeTester.load_template(type)
|
21
27
|
returned_type = returned_hash["type"]
|
22
28
|
|
23
29
|
returned_type.sub!('.', '_')
|
@@ -28,12 +34,22 @@ describe StripeTester do
|
|
28
34
|
it "#load_template should raise an exception when invalid event is given" do
|
29
35
|
type = "incorrect_type"
|
30
36
|
|
31
|
-
expect { StripeTester.load_template(type
|
37
|
+
expect { StripeTester.load_template(type) }.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#stripe_version should set the correct stripe version" do
|
41
|
+
version = "2013-02-13"
|
42
|
+
StripeTester.stripe_version = version
|
43
|
+
|
44
|
+
expect(StripeTester.stripe_version).to eq version
|
32
45
|
end
|
33
46
|
|
34
|
-
it "#
|
47
|
+
it "#stripe_version should return the latest version when no version has been specified" do
|
48
|
+
expect(StripeTester.stripe_version).to eq LATEST_STRIPE_VERSION
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#webhook_url should set the correct url" do
|
35
52
|
url = 'http://www.google.com'
|
36
|
-
StripeTester.remove_url
|
37
53
|
StripeTester.webhook_url = url
|
38
54
|
|
39
55
|
result_url = StripeTester.webhook_url
|
@@ -42,7 +58,6 @@ describe StripeTester do
|
|
42
58
|
|
43
59
|
it "#webhook_url should store url as and URI object" do
|
44
60
|
url = 'http://www.hello.com'
|
45
|
-
StripeTester.remove_url
|
46
61
|
StripeTester.webhook_url = url
|
47
62
|
|
48
63
|
result_url = StripeTester.webhook_url
|
@@ -50,17 +65,40 @@ describe StripeTester do
|
|
50
65
|
end
|
51
66
|
|
52
67
|
it "#webhook_url should not store URL when URL is invalid" do
|
53
|
-
StripeTester.remove_url
|
54
68
|
StripeTester.webhook_url = 'datatatat'
|
55
69
|
expect(StripeTester.webhook_url).to eq(nil)
|
56
70
|
end
|
57
71
|
|
58
|
-
it "#post_to_url should
|
72
|
+
it "#post_to_url should return true when request is successful" do
|
73
|
+
data = StripeTester.load_template(:invoice_created)
|
74
|
+
url = "http://localhost:3000/transactions"
|
75
|
+
StripeTester.webhook_url = url
|
59
76
|
|
77
|
+
FakeWeb.register_uri(:post,
|
78
|
+
url,
|
79
|
+
body: data.to_json,
|
80
|
+
content_type: 'application/json')
|
81
|
+
|
82
|
+
response = StripeTester.post_to_url(data)
|
83
|
+
|
84
|
+
expect(response).to be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "#post_to_url should raise an error when request fails" do
|
88
|
+
data = StripeTester.load_template(:invoice_created)
|
89
|
+
url = "http://localhost:3000/"
|
90
|
+
StripeTester.webhook_url = url
|
91
|
+
|
92
|
+
FakeWeb.register_uri(:post,
|
93
|
+
url,
|
94
|
+
body: data.to_json,
|
95
|
+
content_type: 'application/json',
|
96
|
+
status: ["404", "Not Found"])
|
97
|
+
|
98
|
+
expect{ StripeTester.post_to_url(data) }.to raise_error('404 "Not Found"')
|
60
99
|
end
|
61
100
|
|
62
101
|
it "#post_to_url should raise an error if webhook URL is not set" do
|
63
|
-
StripeTester.remove_url
|
64
102
|
expect { StripeTester.post_to_url() }.to raise_error
|
65
103
|
end
|
66
104
|
|
@@ -89,13 +127,5 @@ describe StripeTester do
|
|
89
127
|
|
90
128
|
expect(new_data[:info][:age]).to eq(99)
|
91
129
|
end
|
92
|
-
|
93
|
-
it "#create_event should send the event to the URL with the modified hash if options exist" do
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
it "#create_event should send the event with an unmodified hash to the URL if options don't exist" do
|
98
|
-
|
99
|
-
end
|
100
130
|
end
|
101
131
|
end
|
data/stripe_tester.gemspec
CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "mocha"
|
26
|
+
spec.add_development_dependency "fakeweb", "~> 1.3"
|
25
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe_tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,6 +59,38 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: fakeweb
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
62
94
|
description: Test Stripe webhooks locally
|
63
95
|
email:
|
64
96
|
- info@buttercloud.com
|
@@ -76,7 +108,6 @@ files:
|
|
76
108
|
- spec/spec_helper.rb
|
77
109
|
- spec/stripe_tester_spec.rb
|
78
110
|
- stripe_tester.gemspec
|
79
|
-
- stripe_webhooks/.DS_Store
|
80
111
|
- stripe_webhooks/2013-02-13/charge_failed.yml
|
81
112
|
- stripe_webhooks/2013-02-13/charge_refunded.yml
|
82
113
|
- stripe_webhooks/2013-02-13/charge_succeeded.yml
|
@@ -124,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
155
|
version: '0'
|
125
156
|
segments:
|
126
157
|
- 0
|
127
|
-
hash:
|
158
|
+
hash: -3266622437105311327
|
128
159
|
requirements: []
|
129
160
|
rubyforge_project:
|
130
161
|
rubygems_version: 1.8.25
|
data/stripe_webhooks/.DS_Store
DELETED
Binary file
|