stripe_event 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Integrallis Software
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ stripe_event
2
+ ============
3
+
4
+ stripe_event is built on the ActiveSupport::Notifications API. Incoming webhook requests are authenticated by retrieving the event from Stripe. The retrieved event is yielded to subscribers when published.
5
+
6
+ ```ruby
7
+ # Gemfile
8
+ gem 'stripe_event'
9
+ ```
10
+
11
+ ```ruby
12
+ # config/routes.rb
13
+ mount StripeEvent::Engine => "/stripe_event"
14
+ ```
15
+
16
+ ```ruby
17
+ # config/initializers/stripe.rb
18
+ Stripe.api_key = ENV['STRIPE_API_KEY'] # Set your api key
19
+
20
+ StripeEvent.configure do |config|
21
+ # Define subscriber behavior
22
+ config.subscribe 'charge.failed' do |event|
23
+ MyClass.handle_failed_charge(event)
24
+ end
25
+ end
26
+ ```
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'StripeEvent'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('lib/**/*.rb')
20
+ end
21
+
22
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,14 @@
1
+ module StripeEvent
2
+ class ApplicationController < ActionController::Base
3
+
4
+ # Authentication
5
+ before_filter do
6
+ begin
7
+ @event = Stripe::Event.retrieve(params[:id])
8
+ rescue Stripe::StripeError
9
+ head :unauthorized
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module StripeEvent
2
+ class WebhookController < ApplicationController
3
+ def event
4
+ StripeEvent.publish(@event)
5
+ head :ok
6
+ end
7
+ end
8
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ StripeEvent::Engine.routes.draw do
2
+ root :to => 'webhook#event'
3
+ end
@@ -0,0 +1,5 @@
1
+ module StripeEvent
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace StripeEvent
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ module StripeEvent
2
+ TYPES = [
3
+ 'charge.succeeded',
4
+ 'charge.failed',
5
+ 'charge.refunded',
6
+ 'charge.disputed',
7
+ 'customer.created',
8
+ 'customer.updated',
9
+ 'customer.deleted',
10
+ 'customer.subscription.created',
11
+ 'customer.subscription.updated',
12
+ 'customer.subscription.deleted',
13
+ 'customer.subscription.trial_will_end',
14
+ 'customer.discount.created',
15
+ 'customer.discount.updated',
16
+ 'customer.discount.deleted',
17
+ 'invoice.created',
18
+ 'invoice.updated',
19
+ 'invoice.payment_succeeded',
20
+ 'invoice.payment_failed',
21
+ 'invoiceitem.created',
22
+ 'invoiceitem.updated',
23
+ 'invoiceitem.deleted',
24
+ 'plan.created',
25
+ 'plan.updated',
26
+ 'plan.deleted',
27
+ 'coupon.created',
28
+ 'coupon.updated',
29
+ 'coupon.deleted',
30
+ 'transfer.created',
31
+ 'transfer.failed',
32
+ 'ping'
33
+ ]
34
+ end
@@ -0,0 +1,3 @@
1
+ module StripeEvent
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "stripe"
2
+ require "stripe_event/engine"
3
+ require "stripe_event/types"
4
+
5
+ module StripeEvent
6
+ InvalidEventType = Class.new(StandardError)
7
+
8
+ def self.configure
9
+ yield self
10
+ self
11
+ end
12
+
13
+ def self.publish(event_obj)
14
+ ActiveSupport::Notifications.instrument(event_obj.type, :event => event_obj)
15
+ end
16
+
17
+ def self.subscribe(name, &block)
18
+ raise InvalidEventType.new(name) if !TYPES.include?(name)
19
+ ActiveSupport::Notifications.subscribe(name, proxy(&block))
20
+ end
21
+
22
+ def self.subscribers(name)
23
+ ActiveSupport::Notifications.notifier.listeners_for(name)
24
+ end
25
+
26
+ def self.clear_subscribers!
27
+ TYPES.each do |type|
28
+ subscribers(type).each { |s| unsubscribe(s) }
29
+ end
30
+ end
31
+
32
+ def self.unsubscribe(subscriber)
33
+ ActiveSupport::Notifications.notifier.unsubscribe(subscriber)
34
+ end
35
+
36
+ def self.proxy(&block)
37
+ lambda do |name, started, finished, id, payload|
38
+ block.call(payload[:event])
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stripe_event
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Danny Whalen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70267703430460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70267703430460
25
+ - !ruby/object:Gem::Dependency
26
+ name: stripe
27
+ requirement: &70267703429960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.6'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70267703429960
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ requirement: &70267703429580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70267703429580
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: &70267703428980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.10'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70267703428980
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ requirement: &70267703428540 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70267703428540
69
+ description: Easily handle webhook events from Stripe.
70
+ email:
71
+ - dwhalen@integrallis.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - app/controllers/stripe_event/application_controller.rb
77
+ - app/controllers/stripe_event/webhook_controller.rb
78
+ - config/routes.rb
79
+ - lib/stripe_event/engine.rb
80
+ - lib/stripe_event/types.rb
81
+ - lib/stripe_event/version.rb
82
+ - lib/stripe_event.rb
83
+ - MIT-LICENSE
84
+ - Rakefile
85
+ - README.md
86
+ homepage: https://github.com/integrallis/stripe_event
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.15
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Stripe webhook integration for Rails applications
110
+ test_files: []
111
+ has_rdoc: