paypal_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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +178 -0
- data/LICENSE.md +22 -0
- data/README.md +96 -0
- data/Rakefile +6 -0
- data/app/controllers/paypal_event/webhook_controller.rb +46 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/paypal_event.rb +68 -0
- data/lib/paypal_event/engine.rb +7 -0
- data/lib/paypal_event/util.rb +25 -0
- data/lib/paypal_event/version.rb +5 -0
- data/paypal_event.gemspec +35 -0
- metadata +171 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 03452d51f8f94fae97cd252d37056076aed29eb49ea9a6ee2ac9e8f07f78c6bb
|
|
4
|
+
data.tar.gz: 552c97ace4fdb77ce8f814b9bd8108bf20f5ecc0a687f6e80d437fd9db09e5ee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '092d6ed840d0c4b5397aaeca2d5f9972369acea3a4a2b7a8092ed6d42e09c503ee8ba89cf1087aec4aa52979a6c918385d4cf79045cd3382f7d7ec6cc995f9db'
|
|
7
|
+
data.tar.gz: 62c63d2e661bf727fab9706821ed65fa015adf5d4298409bf0ccf74f75f6c59657ac4fe62acdcace43fcb927b8aafb4dbaf051f7db4f1ca5fa324d6c92472b4f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
paypal_event (0.1.0)
|
|
5
|
+
activesupport (>= 3.1)
|
|
6
|
+
paypal-sdk-rest
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actioncable (5.2.2)
|
|
12
|
+
actionpack (= 5.2.2)
|
|
13
|
+
nio4r (~> 2.0)
|
|
14
|
+
websocket-driver (>= 0.6.1)
|
|
15
|
+
actionmailer (5.2.2)
|
|
16
|
+
actionpack (= 5.2.2)
|
|
17
|
+
actionview (= 5.2.2)
|
|
18
|
+
activejob (= 5.2.2)
|
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
|
20
|
+
rails-dom-testing (~> 2.0)
|
|
21
|
+
actionpack (5.2.2)
|
|
22
|
+
actionview (= 5.2.2)
|
|
23
|
+
activesupport (= 5.2.2)
|
|
24
|
+
rack (~> 2.0)
|
|
25
|
+
rack-test (>= 0.6.3)
|
|
26
|
+
rails-dom-testing (~> 2.0)
|
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
28
|
+
actionview (5.2.2)
|
|
29
|
+
activesupport (= 5.2.2)
|
|
30
|
+
builder (~> 3.1)
|
|
31
|
+
erubi (~> 1.4)
|
|
32
|
+
rails-dom-testing (~> 2.0)
|
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
34
|
+
activejob (5.2.2)
|
|
35
|
+
activesupport (= 5.2.2)
|
|
36
|
+
globalid (>= 0.3.6)
|
|
37
|
+
activemodel (5.2.2)
|
|
38
|
+
activesupport (= 5.2.2)
|
|
39
|
+
activerecord (5.2.2)
|
|
40
|
+
activemodel (= 5.2.2)
|
|
41
|
+
activesupport (= 5.2.2)
|
|
42
|
+
arel (>= 9.0)
|
|
43
|
+
activestorage (5.2.2)
|
|
44
|
+
actionpack (= 5.2.2)
|
|
45
|
+
activerecord (= 5.2.2)
|
|
46
|
+
marcel (~> 0.3.1)
|
|
47
|
+
activesupport (5.2.2)
|
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
49
|
+
i18n (>= 0.7, < 2)
|
|
50
|
+
minitest (~> 5.1)
|
|
51
|
+
tzinfo (~> 1.1)
|
|
52
|
+
addressable (2.6.0)
|
|
53
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
54
|
+
arel (9.0.0)
|
|
55
|
+
builder (3.2.3)
|
|
56
|
+
concurrent-ruby (1.1.4)
|
|
57
|
+
coveralls (0.8.22)
|
|
58
|
+
json (>= 1.8, < 3)
|
|
59
|
+
simplecov (~> 0.16.1)
|
|
60
|
+
term-ansicolor (~> 1.3)
|
|
61
|
+
thor (~> 0.19.4)
|
|
62
|
+
tins (~> 1.6)
|
|
63
|
+
crack (0.4.3)
|
|
64
|
+
safe_yaml (~> 1.0.0)
|
|
65
|
+
crass (1.0.4)
|
|
66
|
+
diff-lcs (1.3)
|
|
67
|
+
docile (1.3.1)
|
|
68
|
+
erubi (1.8.0)
|
|
69
|
+
globalid (0.4.2)
|
|
70
|
+
activesupport (>= 4.2.0)
|
|
71
|
+
hashdiff (0.3.8)
|
|
72
|
+
i18n (1.5.3)
|
|
73
|
+
concurrent-ruby (~> 1.0)
|
|
74
|
+
json (2.1.0)
|
|
75
|
+
loofah (2.2.3)
|
|
76
|
+
crass (~> 1.0.2)
|
|
77
|
+
nokogiri (>= 1.5.9)
|
|
78
|
+
mail (2.7.1)
|
|
79
|
+
mini_mime (>= 0.1.1)
|
|
80
|
+
marcel (0.3.3)
|
|
81
|
+
mimemagic (~> 0.3.2)
|
|
82
|
+
method_source (0.9.2)
|
|
83
|
+
mimemagic (0.3.3)
|
|
84
|
+
mini_mime (1.0.1)
|
|
85
|
+
mini_portile2 (2.4.0)
|
|
86
|
+
minitest (5.11.3)
|
|
87
|
+
multi_json (1.13.1)
|
|
88
|
+
nio4r (2.3.1)
|
|
89
|
+
nokogiri (1.10.1)
|
|
90
|
+
mini_portile2 (~> 2.4.0)
|
|
91
|
+
paypal-sdk-rest (1.7.3)
|
|
92
|
+
multi_json (~> 1.0)
|
|
93
|
+
xml-simple
|
|
94
|
+
public_suffix (3.0.3)
|
|
95
|
+
rack (2.0.6)
|
|
96
|
+
rack-test (1.1.0)
|
|
97
|
+
rack (>= 1.0, < 3)
|
|
98
|
+
rails (5.2.2)
|
|
99
|
+
actioncable (= 5.2.2)
|
|
100
|
+
actionmailer (= 5.2.2)
|
|
101
|
+
actionpack (= 5.2.2)
|
|
102
|
+
actionview (= 5.2.2)
|
|
103
|
+
activejob (= 5.2.2)
|
|
104
|
+
activemodel (= 5.2.2)
|
|
105
|
+
activerecord (= 5.2.2)
|
|
106
|
+
activestorage (= 5.2.2)
|
|
107
|
+
activesupport (= 5.2.2)
|
|
108
|
+
bundler (>= 1.3.0)
|
|
109
|
+
railties (= 5.2.2)
|
|
110
|
+
sprockets-rails (>= 2.0.0)
|
|
111
|
+
rails-dom-testing (2.0.3)
|
|
112
|
+
activesupport (>= 4.2.0)
|
|
113
|
+
nokogiri (>= 1.6)
|
|
114
|
+
rails-html-sanitizer (1.0.4)
|
|
115
|
+
loofah (~> 2.2, >= 2.2.2)
|
|
116
|
+
railties (5.2.2)
|
|
117
|
+
actionpack (= 5.2.2)
|
|
118
|
+
activesupport (= 5.2.2)
|
|
119
|
+
method_source
|
|
120
|
+
rake (>= 0.8.7)
|
|
121
|
+
thor (>= 0.19.0, < 2.0)
|
|
122
|
+
rake (10.5.0)
|
|
123
|
+
rspec (3.8.0)
|
|
124
|
+
rspec-core (~> 3.8.0)
|
|
125
|
+
rspec-expectations (~> 3.8.0)
|
|
126
|
+
rspec-mocks (~> 3.8.0)
|
|
127
|
+
rspec-core (3.8.0)
|
|
128
|
+
rspec-support (~> 3.8.0)
|
|
129
|
+
rspec-expectations (3.8.2)
|
|
130
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
131
|
+
rspec-support (~> 3.8.0)
|
|
132
|
+
rspec-mocks (3.8.0)
|
|
133
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
134
|
+
rspec-support (~> 3.8.0)
|
|
135
|
+
rspec-support (3.8.0)
|
|
136
|
+
safe_yaml (1.0.4)
|
|
137
|
+
simplecov (0.16.1)
|
|
138
|
+
docile (~> 1.1)
|
|
139
|
+
json (>= 1.8, < 3)
|
|
140
|
+
simplecov-html (~> 0.10.0)
|
|
141
|
+
simplecov-html (0.10.2)
|
|
142
|
+
sprockets (3.7.2)
|
|
143
|
+
concurrent-ruby (~> 1.0)
|
|
144
|
+
rack (> 1, < 3)
|
|
145
|
+
sprockets-rails (3.2.1)
|
|
146
|
+
actionpack (>= 4.0)
|
|
147
|
+
activesupport (>= 4.0)
|
|
148
|
+
sprockets (>= 3.0.0)
|
|
149
|
+
term-ansicolor (1.7.1)
|
|
150
|
+
tins (~> 1.0)
|
|
151
|
+
thor (0.19.4)
|
|
152
|
+
thread_safe (0.3.6)
|
|
153
|
+
tins (1.20.2)
|
|
154
|
+
tzinfo (1.2.5)
|
|
155
|
+
thread_safe (~> 0.1)
|
|
156
|
+
webmock (1.24.6)
|
|
157
|
+
addressable (>= 2.3.6)
|
|
158
|
+
crack (>= 0.3.2)
|
|
159
|
+
hashdiff
|
|
160
|
+
websocket-driver (0.7.0)
|
|
161
|
+
websocket-extensions (>= 0.1.0)
|
|
162
|
+
websocket-extensions (0.1.3)
|
|
163
|
+
xml-simple (1.1.5)
|
|
164
|
+
|
|
165
|
+
PLATFORMS
|
|
166
|
+
ruby
|
|
167
|
+
|
|
168
|
+
DEPENDENCIES
|
|
169
|
+
bundler (~> 2.0)
|
|
170
|
+
coveralls
|
|
171
|
+
paypal_event!
|
|
172
|
+
rails (>= 3.1)
|
|
173
|
+
rake (~> 10.0)
|
|
174
|
+
rspec (~> 3.0)
|
|
175
|
+
webmock (~> 1.9)
|
|
176
|
+
|
|
177
|
+
BUNDLED WITH
|
|
178
|
+
2.0.1
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2019-2020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# PaypalEvent
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/paypal_event)
|
|
4
|
+
[](https://travis-ci.org/iscreen/paypal_event)
|
|
5
|
+
[](https://coveralls.io/github/iscreen/paypal_event?branch=master)
|
|
6
|
+
[](http://www.rubydoc.info/gems/paypal_event)
|
|
7
|
+
|
|
8
|
+
PaypalEvent is built on the [ActiveSupport::Notifications API](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html). Incoming webhook requests are [authenticated with the webhook signature](#authenticating-webhooks-with-signatures). Define subscribers to handle specific event types. Subscribers can be a block or an object that responds to `#call`.
|
|
9
|
+
|
|
10
|
+
This project is refer to [StripeEvent](https://github.com/integrallis/stripe_event)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'paypal_event'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
And then execute:
|
|
21
|
+
|
|
22
|
+
$ bundle
|
|
23
|
+
|
|
24
|
+
Or install it yourself as:
|
|
25
|
+
|
|
26
|
+
$ gem install paypal_event
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
# config/initializers/paypal.rb
|
|
32
|
+
|
|
33
|
+
PaypalEvent.configure do |events|
|
|
34
|
+
events.subscribe 'PAYMENT.SALE.COMPLETED' do |event|
|
|
35
|
+
# Define subscriber behavior based on the event object
|
|
36
|
+
event[:event_type] #=> 'PAYMENT.SALE.COMPLETED'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
events.all do |event|
|
|
40
|
+
# Handle all event types - logging, etc.
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Subscriber objects that respond to #call
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
class PaymentSaleCompleted
|
|
49
|
+
def call(event)
|
|
50
|
+
# Event handling
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class BillingEventLogger
|
|
55
|
+
def initialize(logger)
|
|
56
|
+
@logger = logger
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def call(event)
|
|
60
|
+
@logger.info "BILLING:#{event[:event_type]}:#{event[:id]}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
PaypalEvent.configure do |events|
|
|
67
|
+
events.all BillingEventLogger.new(Rails.logger)
|
|
68
|
+
events.subscribe 'PAYMENT.SALE.COMPLETED', PaymentSaleCompleted.new
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Subscribing to a namespace of event types
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
PaymentEvent.subscribe 'PAYMENT.SALE.' do |event|
|
|
76
|
+
# Will be triggered for any PAYMENT.SALE.* events
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
83
|
+
|
|
84
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
85
|
+
|
|
86
|
+
### [Paypal Webhook Event Names](https://developer.paypal.com/docs/integration/direct/webhooks/event-names/)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paypal_event.
|
|
93
|
+
|
|
94
|
+
### License
|
|
95
|
+
|
|
96
|
+
[MIT License](https://github.com/iscreen/paypal_event/blob/master/LICENSE.md). Copyright 2019-2020 Integrallis Software.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaypalEvent
|
|
4
|
+
class WebhookController < ActionController::Base
|
|
5
|
+
include PayPal::SDK::REST
|
|
6
|
+
include PayPal::SDK::Core::Logging
|
|
7
|
+
|
|
8
|
+
if Rails.application.config.action_controller.default_protect_from_forgery
|
|
9
|
+
skip_before_action :verify_authenticity_token
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def event
|
|
13
|
+
PaypalEvent.instrument(PaypalEvent::Util.symbolize_names(verified_event))
|
|
14
|
+
head :ok
|
|
15
|
+
rescue StandardError => e
|
|
16
|
+
log_error(e)
|
|
17
|
+
head :bad_request
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def verified_event
|
|
23
|
+
actual_signature = request.headers['Paypal-Transmission-Sig']
|
|
24
|
+
auth_algo = request.headers['Paypal-Auth-Algo']
|
|
25
|
+
auth_algo.sub!(/withRSA/i, '')
|
|
26
|
+
cert_url = request.headers['Paypal-Cert-Url']
|
|
27
|
+
transmission_id = request.headers['Paypal-Transmission-Id']
|
|
28
|
+
timestamp = request.headers['Paypal-Transmission-Time']
|
|
29
|
+
webhook_id = ENV['PAYPAL_WEBHOOK_ID'] #The webhook_id provided by PayPal when webhook is created on the PayPal developer site
|
|
30
|
+
event_body = params[:paypal].to_json
|
|
31
|
+
|
|
32
|
+
valid = WebhookEvent.verify(transmission_id, timestamp, webhook_id, event_body, cert_url, actual_signature, auth_algo)
|
|
33
|
+
unless valid
|
|
34
|
+
message = "webhook event #{webhook_id} validation failed"
|
|
35
|
+
logger.error message
|
|
36
|
+
raise PaypalEvent::SignatureVerificationError.new(message, http_body: event_body)
|
|
37
|
+
end
|
|
38
|
+
event_body
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def log_error(e)
|
|
42
|
+
logger.error e.message
|
|
43
|
+
e.backtrace.each { |line| logger.error " #{line}" }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "paypal_event"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/paypal_event.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'paypal_event/version'
|
|
4
|
+
require 'active_support/notifications'
|
|
5
|
+
require 'paypal-sdk-rest'
|
|
6
|
+
require 'paypal_event/engine' if defined?(Rails)
|
|
7
|
+
require 'paypal_event/util'
|
|
8
|
+
|
|
9
|
+
module PaypalEvent
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :adapter, :backend, :namespace, :event_filter
|
|
12
|
+
attr_reader :signing_secrets
|
|
13
|
+
|
|
14
|
+
def configure(&block)
|
|
15
|
+
raise ArgumentError, 'must provide a block' unless block_given?
|
|
16
|
+
block.arity.zero? ? instance_eval(&block) : yield(self)
|
|
17
|
+
end
|
|
18
|
+
alias :setup :configure
|
|
19
|
+
|
|
20
|
+
def instrument(event)
|
|
21
|
+
event = event_filter.call(event)
|
|
22
|
+
backend.instrument namespace.call(event[:event_type]), event if event
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def subscribe(name, callable = Proc.new)
|
|
26
|
+
backend.subscribe namespace.to_regexp(name), adapter.call(callable)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def all(callable = Proc.new)
|
|
30
|
+
subscribe nil, callable
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def listening?(name)
|
|
34
|
+
namespaced_name = namespace.call(name)
|
|
35
|
+
backend.notifier.listening?(namespaced_name)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class Namespace < Struct.new(:value, :delimiter)
|
|
40
|
+
def call(name = nil)
|
|
41
|
+
"#{value}#{delimiter}#{name}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_regexp(name = nil)
|
|
45
|
+
%r{^#{Regexp.escape call(name)}}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class NotificationAdapter < Struct.new(:subscriber)
|
|
50
|
+
def self.call(callable)
|
|
51
|
+
new(callable)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def call(*args)
|
|
55
|
+
payload = args.last
|
|
56
|
+
subscriber.call(payload)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class Error < StandardError; end
|
|
61
|
+
class UnauthorizedError < Error; end
|
|
62
|
+
class SignatureVerificationError < Error; end
|
|
63
|
+
|
|
64
|
+
self.adapter = NotificationAdapter
|
|
65
|
+
self.backend = ActiveSupport::Notifications
|
|
66
|
+
self.namespace = Namespace.new('paypal_event', '.')
|
|
67
|
+
self.event_filter = lambda { |event| event }
|
|
68
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaypalEvent
|
|
4
|
+
module Util
|
|
5
|
+
def self.symbolize_names(object)
|
|
6
|
+
case object
|
|
7
|
+
when Hash
|
|
8
|
+
new_hash = {}
|
|
9
|
+
object.each do |key, value|
|
|
10
|
+
key = (begin
|
|
11
|
+
key.to_sym
|
|
12
|
+
rescue StandardError
|
|
13
|
+
key
|
|
14
|
+
end) || key
|
|
15
|
+
new_hash[key] = symbolize_names(value)
|
|
16
|
+
end
|
|
17
|
+
new_hash
|
|
18
|
+
when Array
|
|
19
|
+
object.map { |value| symbolize_names(value) }
|
|
20
|
+
else
|
|
21
|
+
object
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'paypal_event/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'paypal_event'
|
|
8
|
+
spec.version = PaypalEvent::VERSION
|
|
9
|
+
spec.authors = ['Dean Lin']
|
|
10
|
+
spec.email = ['dean.lin@iscreen.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Paypal webhook integration for Rails applications.}
|
|
13
|
+
spec.description = %q{Paypal webhook integration for Rails applications.}
|
|
14
|
+
spec.homepage = 'https://github.com/iscreen/paypal_event'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = 'exe'
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ['lib']
|
|
25
|
+
|
|
26
|
+
spec.add_dependency 'activesupport', '>= 3.1'
|
|
27
|
+
spec.add_dependency 'paypal-sdk-rest'
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency 'rails', '>= 3.1'
|
|
30
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
33
|
+
spec.add_development_dependency 'webmock', '~> 1.9'
|
|
34
|
+
spec.add_development_dependency 'coveralls'
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: paypal_event
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dean Lin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: paypal-sdk-rest
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rails
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.1'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.1'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '2.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: webmock
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '1.9'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '1.9'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: coveralls
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
description: Paypal webhook integration for Rails applications.
|
|
126
|
+
email:
|
|
127
|
+
- dean.lin@iscreen.com
|
|
128
|
+
executables: []
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".travis.yml"
|
|
135
|
+
- Gemfile
|
|
136
|
+
- Gemfile.lock
|
|
137
|
+
- LICENSE.md
|
|
138
|
+
- README.md
|
|
139
|
+
- Rakefile
|
|
140
|
+
- app/controllers/paypal_event/webhook_controller.rb
|
|
141
|
+
- bin/console
|
|
142
|
+
- bin/setup
|
|
143
|
+
- lib/paypal_event.rb
|
|
144
|
+
- lib/paypal_event/engine.rb
|
|
145
|
+
- lib/paypal_event/util.rb
|
|
146
|
+
- lib/paypal_event/version.rb
|
|
147
|
+
- paypal_event.gemspec
|
|
148
|
+
homepage: https://github.com/iscreen/paypal_event
|
|
149
|
+
licenses: []
|
|
150
|
+
metadata: {}
|
|
151
|
+
post_install_message:
|
|
152
|
+
rdoc_options: []
|
|
153
|
+
require_paths:
|
|
154
|
+
- lib
|
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - ">="
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '0'
|
|
165
|
+
requirements: []
|
|
166
|
+
rubyforge_project:
|
|
167
|
+
rubygems_version: 2.7.8
|
|
168
|
+
signing_key:
|
|
169
|
+
specification_version: 4
|
|
170
|
+
summary: Paypal webhook integration for Rails applications.
|
|
171
|
+
test_files: []
|