knp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +100 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +40 -0
- data/app/assets/images/knp/.gitkeep +0 -0
- data/app/assets/javascripts/knp/application.js +15 -0
- data/app/assets/stylesheets/knp/application.css +13 -0
- data/app/controllers/knp/application_controller.rb +4 -0
- data/app/controllers/knp/notifications_controller.rb +39 -0
- data/app/helpers/knp/application_helper.rb +4 -0
- data/app/models/knp/notification.rb +61 -0
- data/app/views/layouts/knp/application.html.erb +14 -0
- data/config/routes.rb +4 -0
- data/knp.gemspec +23 -0
- data/lib/knp.rb +12 -0
- data/lib/knp/engine.rb +13 -0
- data/lib/knp/version.rb +3 -0
- data/lib/tasks/knp_tasks.rake +4 -0
- data/script/rails +8 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/knp/adyen_notifications_controller_test.rb +34 -0
- data/test/functional/knp/functional_test_helper.rb +9 -0
- data/test/functional/knp/mock_notifications_controller_test.rb +42 -0
- data/test/knp_test.rb +7 -0
- data/test/test_helper.rb +17 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c079e51495b1cd0b1427d622d5473ce85b0c00b
|
4
|
+
data.tar.gz: 3475b42afea5d212cf632f7163cf5f46c1b3ada3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1059bed7fc0cdd0a55578336a66dc34949bb627ed82a199c1b4d364437f728a98783b7ec88bbd7cd080d7b80a219fb77ff32d2f9762820f037ca5edae0e54be
|
7
|
+
data.tar.gz: 5e49acb6f45f13a558466475871aa52b3f8eb001d2b83f8ed311db9d63b90027a55f1e939aee590b53c390d01e46a0d8c520f7bd6a82af2dd6aaef2a89ecd062
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in knp.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# jquery-rails is used by the dummy application
|
9
|
+
gem "jquery-rails"
|
10
|
+
|
11
|
+
# Declare any dependencies that are still in development here instead of in
|
12
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
13
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
14
|
+
# your gem to rubygems.org.
|
15
|
+
|
16
|
+
# To use debugger
|
17
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
knp (0.0.1)
|
5
|
+
killbill-client (~> 0.8.0)
|
6
|
+
rails (~> 3.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.21)
|
12
|
+
actionpack (= 3.2.21)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (3.2.21)
|
15
|
+
activemodel (= 3.2.21)
|
16
|
+
activesupport (= 3.2.21)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
journey (~> 1.0.4)
|
20
|
+
rack (~> 1.4.5)
|
21
|
+
rack-cache (~> 1.2)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.2.1)
|
24
|
+
activemodel (3.2.21)
|
25
|
+
activesupport (= 3.2.21)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.21)
|
28
|
+
activemodel (= 3.2.21)
|
29
|
+
activesupport (= 3.2.21)
|
30
|
+
arel (~> 3.0.2)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.21)
|
33
|
+
activemodel (= 3.2.21)
|
34
|
+
activesupport (= 3.2.21)
|
35
|
+
activesupport (3.2.21)
|
36
|
+
i18n (~> 0.6, >= 0.6.4)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
arel (3.0.3)
|
39
|
+
builder (3.0.4)
|
40
|
+
erubis (2.7.0)
|
41
|
+
hike (1.2.3)
|
42
|
+
i18n (0.7.0)
|
43
|
+
journey (1.0.4)
|
44
|
+
jquery-rails (3.1.2)
|
45
|
+
railties (>= 3.0, < 5.0)
|
46
|
+
thor (>= 0.14, < 2.0)
|
47
|
+
json (1.8.1)
|
48
|
+
killbill-client (0.8.1)
|
49
|
+
json (>= 1.2.0)
|
50
|
+
mail (2.5.4)
|
51
|
+
mime-types (~> 1.16)
|
52
|
+
treetop (~> 1.4.8)
|
53
|
+
mime-types (1.25.1)
|
54
|
+
multi_json (1.10.1)
|
55
|
+
polyglot (0.3.5)
|
56
|
+
rack (1.4.5)
|
57
|
+
rack-cache (1.2)
|
58
|
+
rack (>= 0.4)
|
59
|
+
rack-ssl (1.3.4)
|
60
|
+
rack
|
61
|
+
rack-test (0.6.2)
|
62
|
+
rack (>= 1.0)
|
63
|
+
rails (3.2.21)
|
64
|
+
actionmailer (= 3.2.21)
|
65
|
+
actionpack (= 3.2.21)
|
66
|
+
activerecord (= 3.2.21)
|
67
|
+
activeresource (= 3.2.21)
|
68
|
+
activesupport (= 3.2.21)
|
69
|
+
bundler (~> 1.0)
|
70
|
+
railties (= 3.2.21)
|
71
|
+
railties (3.2.21)
|
72
|
+
actionpack (= 3.2.21)
|
73
|
+
activesupport (= 3.2.21)
|
74
|
+
rack-ssl (~> 1.3.2)
|
75
|
+
rake (>= 0.8.7)
|
76
|
+
rdoc (~> 3.4)
|
77
|
+
thor (>= 0.14.6, < 2.0)
|
78
|
+
rake (10.4.2)
|
79
|
+
rdoc (3.12.2)
|
80
|
+
json (~> 1.4)
|
81
|
+
sprockets (2.2.3)
|
82
|
+
hike (~> 1.2)
|
83
|
+
multi_json (~> 1.0)
|
84
|
+
rack (~> 1.0)
|
85
|
+
tilt (~> 1.1, != 1.3.0)
|
86
|
+
sqlite3 (1.3.10)
|
87
|
+
thor (0.19.1)
|
88
|
+
tilt (1.4.1)
|
89
|
+
treetop (1.4.15)
|
90
|
+
polyglot
|
91
|
+
polyglot (>= 0.3.1)
|
92
|
+
tzinfo (0.3.42)
|
93
|
+
|
94
|
+
PLATFORMS
|
95
|
+
ruby
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
jquery-rails
|
99
|
+
knp!
|
100
|
+
sqlite3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
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,37 @@
|
|
1
|
+
Knp
|
2
|
+
===
|
3
|
+
|
4
|
+
The Kill Bill Notifications Proxy is a Rails mountable engine that can be exposed on a public IP to process notifications from gateways.
|
5
|
+
|
6
|
+
|
7
|
+
Mounting Knp into your own Rails app
|
8
|
+
------------------------------------
|
9
|
+
|
10
|
+
* Add `knp` to your Gemfile
|
11
|
+
* Add `mount Knp::Engine, at: "/killbill"` in your `config/routes.rb`
|
12
|
+
|
13
|
+
|
14
|
+
Configuration
|
15
|
+
-------------
|
16
|
+
|
17
|
+
Specify your Kill Bill server configuration in ```config/initializers/killbill_client.rb```:
|
18
|
+
|
19
|
+
```
|
20
|
+
KillBillClient.url = 'http://127.0.0.1:8080/'
|
21
|
+
KillBillClient.api_key = 'bob'
|
22
|
+
KillBillClient.api_secret = 'lazar'
|
23
|
+
KillBillClient.username = 'admin'
|
24
|
+
KillBillClient.password = 'password'
|
25
|
+
# To log requests
|
26
|
+
KillBillClient.logger = Rails.logger
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
Running tests
|
31
|
+
-------------
|
32
|
+
|
33
|
+
```
|
34
|
+
rake test
|
35
|
+
```
|
36
|
+
|
37
|
+
Note: functional tests require an instance of Kill Bill to test against.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
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 = 'Knp'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Knp
|
2
|
+
class NotificationsController < ApplicationController
|
3
|
+
|
4
|
+
# Catch-all
|
5
|
+
#
|
6
|
+
# Assuming your KNP public address is killbill-public.acme.com, configure the notification
|
7
|
+
# URL in the gateway to be: killbill-public.acme.com/notifications/<plugin-name>.
|
8
|
+
# Examples: killbill-public.acme.com/notifications/killbill-adyen, killbill-public.acme.com/notifications/killbill-bitpay
|
9
|
+
def notify
|
10
|
+
notification = build_notification(params[:plugin_name])
|
11
|
+
kb_response = notification.notify!
|
12
|
+
build_response(kb_response)
|
13
|
+
rescue => e
|
14
|
+
logger.warn "Error processing notification for plugin #{params[:plugin_name]}: #{e}\n\t#{e.backtrace.join("\n\t")}"
|
15
|
+
head :bad_request
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_notification(plugin_name)
|
21
|
+
notification = Notification.new
|
22
|
+
notification.plugin_name = plugin_name
|
23
|
+
notification.body = request.body.read
|
24
|
+
notification.params = request.query_parameters
|
25
|
+
notification.headers = request.headers
|
26
|
+
notification
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_response(kb_response)
|
30
|
+
# This could have security issues (e.g. leak of JSESSIONID). Is there a gateway that actually requires it?
|
31
|
+
#response.headers = kb_response[:headers]
|
32
|
+
|
33
|
+
render :text => kb_response[:body],
|
34
|
+
:content_type => kb_response[:content_type],
|
35
|
+
:location => kb_response[:location],
|
36
|
+
:status => kb_response[:status]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Knp
|
2
|
+
class Notification
|
3
|
+
|
4
|
+
attr_accessor :plugin_name
|
5
|
+
attr_accessor :body
|
6
|
+
attr_accessor :params
|
7
|
+
attr_accessor :headers
|
8
|
+
attr_accessor :user
|
9
|
+
attr_accessor :reason
|
10
|
+
attr_accessor :comment
|
11
|
+
attr_accessor :api_key
|
12
|
+
attr_accessor :api_secret
|
13
|
+
attr_accessor :username
|
14
|
+
attr_accessor :password
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
self.user = Knp.user || 'Knp'
|
18
|
+
self.reason = Knp.reason
|
19
|
+
self.comment = Knp.comment
|
20
|
+
self.api_key = Knp.api_key
|
21
|
+
self.api_secret = Knp.api_secret
|
22
|
+
self.username = Knp.username
|
23
|
+
self.password = Knp.password
|
24
|
+
end
|
25
|
+
|
26
|
+
def notify!
|
27
|
+
# Response is a Net::HTTPResponse
|
28
|
+
response = KillBillClient::API.post(kb_url, body, params, build_options)
|
29
|
+
|
30
|
+
{
|
31
|
+
:body => response.body,
|
32
|
+
:status => response.code,
|
33
|
+
# The header key is case insensitive in Net::HTTPHeader
|
34
|
+
:location => response['location'],
|
35
|
+
:content_type => response.content_type,
|
36
|
+
:headers => response.to_hash,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def kb_url
|
43
|
+
"#{KillBillClient::Model::Resource::KILLBILL_API_PREFIX}/paymentGateways/notification/#{plugin_name}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_options
|
47
|
+
# Merge after to avoid conflicts with headers passed by the gateway
|
48
|
+
headers
|
49
|
+
.deep_dup
|
50
|
+
.merge(
|
51
|
+
:user => user,
|
52
|
+
:reason => reason,
|
53
|
+
:comment => comment,
|
54
|
+
:api_key => api_key,
|
55
|
+
:api_secret => api_secret,
|
56
|
+
:username => username,
|
57
|
+
:password => password
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Knp</title>
|
5
|
+
<%= stylesheet_link_tag "knp/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "knp/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/knp.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "knp/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "knp"
|
9
|
+
s.version = Knp::VERSION
|
10
|
+
s.authors = ['Killbill core team']
|
11
|
+
s.email = ['killbilling-users@googlegroups.com']
|
12
|
+
s.homepage = 'http://killbill.io'
|
13
|
+
s.summary = 'Kill Bill Notifications Proxy'
|
14
|
+
s.description = 'Externally-facing proxy to forward notifications to Kill Bill'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
|
19
|
+
s.add_dependency "rails", "~> 3.2.0"
|
20
|
+
s.add_dependency "killbill-client", "~> 0.8.0"
|
21
|
+
|
22
|
+
s.add_development_dependency "sqlite3"
|
23
|
+
end
|