stripe_event 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ea02ffe131e7f8b5fe2ffa94ba2c889a7b4eb00
4
- data.tar.gz: 4c6c8d779fbedd63815d37a62f2cc23310fe5aa4
3
+ metadata.gz: b0d6619841f7069b8c12f167ffec6895a0d08fac
4
+ data.tar.gz: ee91d70a34cffef31c804be916a55287789b0f66
5
5
  SHA512:
6
- metadata.gz: 77221858fe9843e705b89859f6a6d4c38c6e0106c0f01c7ce9ad2a83dd11927f275629feda73fb0cef500d60020e5ad888246f9df1c43441bafad958813585d3
7
- data.tar.gz: 669c28fb841f16fb81b3421ca8f2cc9af14325407bb1db9d88cacaac2053c142027ff824d66ea873301aec773424329928c12117a61aa4e6bee1ad870213f615
6
+ metadata.gz: 746742414aab41ff384d07e1aaf4f9e548bf59f607b1a40adcfcbd4c09387810692bc3ff5f6df2b8a99d46083026ca3681c58054a5bed8ac63ac382326a38803
7
+ data.tar.gz: b5691cb85b28b407594a058461886ac01d8db96b4413f651cc8c3491e9488910722d57d47d485a57f43282b7642e18424614fc57420e4db0068e6494acf9e6fb
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
6
7
  - jruby-19mode
7
8
  - jruby-head
8
9
  gemfile:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### 1.2.0 (June 17, 2014)
2
+ * Gracefully authenticate `account.application.deauthorized` events. Thank you to [Ryan McGeary](https://github.com/rmm5t) for the pull request and for taking the time to test the change in a live environment.
3
+
1
4
  ### 1.1.0 (January 8, 2014)
2
5
  * Deprecate `StripeEvent.setup` in favor of `StripeEvent.configure`. Remove `setup` at next major release.
3
6
  * `StripeEvent.configure` yields the module to the block for configuration.
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright 2012-2013 Integrallis Software
3
+ Copyright 2012-2014 Integrallis Software
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # StripeEvent
2
2
  [![Build Status](https://secure.travis-ci.org/integrallis/stripe_event.png?branch=master)](http://travis-ci.org/integrallis/stripe_event) [![Dependency Status](https://gemnasium.com/integrallis/stripe_event.png)](https://gemnasium.com/integrallis/stripe_event) [![Gem Version](https://badge.fury.io/rb/stripe_event.png)](http://badge.fury.io/rb/stripe_event) [![Code Climate](https://codeclimate.com/github/integrallis/stripe_event.png)](https://codeclimate.com/github/integrallis/stripe_event) [![Coverage Status](https://coveralls.io/repos/integrallis/stripe_event/badge.png)](https://coveralls.io/r/integrallis/stripe_event)
3
3
 
4
- StripeEvent is built on the [ActiveSupport::Notifications API](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html). Incoming webhook requests are authenticated by [retrieving the event object](https://stripe.com/docs/api?lang=ruby#retrieve_event) from Stripe. Define subscribers to handle a single event type or all event types. Subscribers can be a block or any object that responds to `#call`.
4
+ StripeEvent is built on the [ActiveSupport::Notifications API](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html). Incoming webhook requests are authenticated by [retrieving the event object](https://stripe.com/docs/api?lang=ruby#retrieve_event) from Stripe. Define subscribers to handle specific event types. Subscribers can be a block or an object that responds to `#call`.
5
5
 
6
6
  ## Install
7
7
 
@@ -33,9 +33,11 @@ StripeEvent.configure do |events|
33
33
  # Handle all event types - logging, etc.
34
34
  end
35
35
  end
36
+ ```
36
37
 
37
- # Subscriber objects that respond to #call
38
+ ### Subscriber objects that respond to #call
38
39
 
40
+ ```ruby
39
41
  class CustomerCreated
40
42
  def call(event)
41
43
  # Event handling
@@ -43,25 +45,26 @@ class CustomerCreated
43
45
  end
44
46
 
45
47
  class BillingEventLogger
46
- def initialize(logger = nil)
47
- @logger = logger || begin
48
- require 'logger'
49
- Logger.new($stdout)
50
- end
48
+ def initialize(logger)
49
+ @logger = logger
51
50
  end
52
51
 
53
52
  def call(event)
54
- @logger.info "BILLING-EVENT: #{event.type} #{event.id}"
53
+ @logger.info "BILLING:#{event.type}:#{event.id}"
55
54
  end
56
55
  end
56
+ ```
57
57
 
58
+ ```ruby
58
59
  StripeEvent.configure do |events|
59
60
  events.all BillingEventLogger.new(Rails.logger)
60
61
  events.subscribe 'customer.created', CustomerCreated.new
61
62
  end
63
+ ```
62
64
 
63
- # Subscribing to a namespace of event types
65
+ ### Subscribing to a namespace of event types
64
66
 
67
+ ```ruby
65
68
  StripeEvent.subscribe 'customer.card.' do |event|
66
69
  # Will be triggered for any customer.card.* events
67
70
  end
@@ -76,9 +79,9 @@ StripeEvent.event_retriever = lambda do |params|
76
79
  api_key = Account.find_by!(stripe_user_id: params[:user_id]).api_key
77
80
  Stripe::Event.retrieve(params[:id], api_key)
78
81
  end
82
+ ```
79
83
 
80
- # Or use any object that responds to #call
81
-
84
+ ```ruby
82
85
  class EventRetriever
83
86
  def call(params)
84
87
  api_key = retrieve_api_key(params[:user_id])
@@ -119,7 +122,7 @@ end
119
122
 
120
123
  ## Testing
121
124
 
122
- Handling webhooks is a critical piece of modern billing systems. Verifying the behavior of StripeEvent subscribers can be done fairly easily by stubbing out the HTTP request used to authenticate the webhook request. Tools like [Webmock](https://github.com/bblimke/webmock) and [VCR](https://github.com/vcr/vcr) work well. [RequestBin](http://requestb.in/) is great for collecting the payloads. For exploratory phases of development, [UltraHook](http://www.ultrahook.com/) and other tools can forward webhook requests directly to localhost. You can check out [test-hooks](https://github.com/invisiblefunnel/test-hooks), and example Rails application to see how to test StripeEvent subscribers with RSpec request specs and Webmock. A quick look:
125
+ Handling webhooks is a critical piece of modern billing systems. Verifying the behavior of StripeEvent subscribers can be done fairly easily by stubbing out the HTTP request used to authenticate the webhook request. Tools like [Webmock](https://github.com/bblimke/webmock) and [VCR](https://github.com/vcr/vcr) work well. [RequestBin](http://requestb.in/) is great for collecting the payloads. For exploratory phases of development, [UltraHook](http://www.ultrahook.com/) and other tools can forward webhook requests directly to localhost. You can check out [test-hooks](https://github.com/invisiblefunnel/test-hooks), an example Rails application to see how to test StripeEvent subscribers with RSpec request specs and Webmock. A quick look:
123
126
 
124
127
  ```ruby
125
128
  # spec/requests/billing_events_spec.rb
@@ -151,4 +154,4 @@ This button sends an example event to your webhook urls, including an `id` of `e
151
154
 
152
155
  ### License
153
156
 
154
- [MIT License](https://github.com/integrallis/stripe_event/blob/master/LICENSE.md). Copyright 2012-2013 Integrallis Software.
157
+ [MIT License](https://github.com/integrallis/stripe_event/blob/master/LICENSE.md). Copyright 2012-2014 Integrallis Software.
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 3.1.0"
6
6
 
7
- gemspec :path=>"../"
7
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.1.0)
4
+ stripe_event (1.2.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -113,9 +113,9 @@ GEM
113
113
  hike (~> 1.2)
114
114
  rack (~> 1.0)
115
115
  tilt (~> 1.1, != 1.3.0)
116
- stripe (1.9.9)
116
+ stripe (1.11.0)
117
+ json (~> 1.8.1)
117
118
  mime-types (~> 1.25)
118
- multi_json (>= 1.0.4, < 2)
119
119
  rest-client (~> 1.4)
120
120
  term-ansicolor (1.2.2)
121
121
  tins (~> 0.8)
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 3.2.0"
6
6
 
7
- gemspec :path=>"../"
7
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.1.0)
4
+ stripe_event (1.2.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -111,9 +111,9 @@ GEM
111
111
  multi_json (~> 1.0)
112
112
  rack (~> 1.0)
113
113
  tilt (~> 1.1, != 1.3.0)
114
- stripe (1.9.9)
114
+ stripe (1.11.0)
115
+ json (~> 1.8.1)
115
116
  mime-types (~> 1.25)
116
- multi_json (>= 1.0.4, < 2)
117
117
  rest-client (~> 1.4)
118
118
  term-ansicolor (1.2.2)
119
119
  tins (~> 0.8)
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.0.0"
6
6
 
7
- gemspec :path=>"../"
7
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.1.0)
4
+ stripe_event (1.2.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -52,6 +52,7 @@ GEM
52
52
  erubis (2.7.0)
53
53
  hike (1.2.3)
54
54
  i18n (0.6.9)
55
+ json (1.8.1)
55
56
  mail (2.5.4)
56
57
  mime-types (~> 1.16)
57
58
  treetop (~> 1.4.8)
@@ -104,9 +105,9 @@ GEM
104
105
  actionpack (>= 3.0)
105
106
  activesupport (>= 3.0)
106
107
  sprockets (~> 2.8)
107
- stripe (1.9.9)
108
+ stripe (1.11.0)
109
+ json (~> 1.8.1)
108
110
  mime-types (~> 1.25)
109
- multi_json (>= 1.0.4, < 2)
110
111
  rest-client (~> 1.4)
111
112
  term-ansicolor (1.2.2)
112
113
  tins (~> 0.8)
data/lib/stripe_event.rb CHANGED
@@ -15,6 +15,12 @@ module StripeEvent
15
15
  def instrument(params)
16
16
  begin
17
17
  event = event_retriever.call(params)
18
+ rescue Stripe::AuthenticationError => e
19
+ if params[:type] == "account.application.deauthorized"
20
+ event = Stripe::Event.construct_from(params.deep_symbolize_keys)
21
+ else
22
+ raise UnauthorizedError.new(e)
23
+ end
18
24
  rescue Stripe::StripeError => e
19
25
  raise UnauthorizedError.new(e)
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module StripeEvent
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -53,6 +53,38 @@ describe StripeEvent do
53
53
  end
54
54
  end
55
55
 
56
+ describe "subscribing to the 'account.application.deauthorized' event type" do
57
+ before do
58
+ expect(Stripe::Event).to receive(:retrieve).with('evt_account_application_deauthorized').and_raise(Stripe::AuthenticationError)
59
+ end
60
+
61
+ context "with a subscriber params with symbolized keys" do
62
+ it "calls the subscriber with the retrieved event" do
63
+ StripeEvent.subscribe('account.application.deauthorized', subscriber)
64
+
65
+ StripeEvent.instrument(id: 'evt_account_application_deauthorized', type: 'account.application.deauthorized')
66
+
67
+ expect(events.first.type).to eq 'account.application.deauthorized'
68
+ expect(events.first[:type]).to eq 'account.application.deauthorized'
69
+ end
70
+ end
71
+
72
+ # The Stripe api expects params to be passed into their StripeObject's
73
+ # with symbolized keys, but the params that we pass through from a
74
+ # accont.application.deauthorized webhook are a HashWithIndifferentAccess
75
+ # (keys stored as strings always.
76
+ context "with a subscriber params with indifferent access (stringified keys)" do
77
+ it "calls the subscriber with the retrieved event" do
78
+ StripeEvent.subscribe('account.application.deauthorized', subscriber)
79
+
80
+ StripeEvent.instrument({ id: 'evt_account_application_deauthorized', type: 'account.application.deauthorized' }.with_indifferent_access)
81
+
82
+ expect(events.first.type).to eq 'account.application.deauthorized'
83
+ expect(events.first[:type]).to eq 'account.application.deauthorized'
84
+ end
85
+ end
86
+ end
87
+
56
88
  describe "subscribing to a namespace of event types" do
57
89
  let(:card_created) { double('card created') }
58
90
  let(:card_updated) { double('card updated') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe_event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Whalen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  requirements: []
194
194
  rubyforge_project:
195
- rubygems_version: 2.2.0
195
+ rubygems_version: 2.2.2
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: Stripe webhook integration for Rails applications.
@@ -241,4 +241,3 @@ test_files:
241
241
  - spec/spec_helper.rb
242
242
  - spec/support/fixtures/evt_charge_succeeded.json
243
243
  - spec/support/fixtures/evt_invalid_id.json
244
- has_rdoc: