killbill-payment-test 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +0 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/application.js +24 -0
  6. data/app/assets/javascripts/payment_test/payment_test.js +7 -0
  7. data/app/assets/stylesheets/application.css +20 -0
  8. data/app/assets/stylesheets/bootstrap_and_overrides.css +17 -0
  9. data/app/assets/stylesheets/payment_test/payment_test.css +6 -0
  10. data/app/controllers/payment_test/engine_controller.rb +29 -0
  11. data/app/controllers/payment_test/payments_controller.rb +66 -0
  12. data/app/helpers/payment_test/application_helper.rb +4 -0
  13. data/app/views/payment_test/layouts/payment_test_application.html.erb +31 -0
  14. data/app/views/payment_test/payments/index.html.erb +45 -0
  15. data/config/routes.rb +12 -0
  16. data/lib/payment_test.rb +23 -0
  17. data/lib/payment_test/client.rb +74 -0
  18. data/lib/payment_test/engine.rb +24 -0
  19. data/lib/payment_test/version.rb +3 -0
  20. data/lib/tasks/payment_test_tasks.rake +4 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/controllers/application_controller.rb +5 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/bin/bundle +3 -0
  26. data/test/dummy/bin/rails +4 -0
  27. data/test/dummy/bin/rake +4 -0
  28. data/test/dummy/bin/setup +29 -0
  29. data/test/dummy/config.ru +4 -0
  30. data/test/dummy/config/application.rb +32 -0
  31. data/test/dummy/config/boot.rb +5 -0
  32. data/test/dummy/config/database.yml +23 -0
  33. data/test/dummy/config/environment.rb +5 -0
  34. data/test/dummy/config/environments/development.rb +41 -0
  35. data/test/dummy/config/environments/production.rb +79 -0
  36. data/test/dummy/config/environments/test.rb +42 -0
  37. data/test/dummy/config/initializers/assets.rb +11 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/killbill_client.rb +3 -0
  43. data/test/dummy/config/initializers/mime_types.rb +4 -0
  44. data/test/dummy/config/initializers/session_store.rb +3 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +23 -0
  47. data/test/dummy/config/routes.rb +4 -0
  48. data/test/dummy/config/secrets.yml +22 -0
  49. data/test/integration/navigation_test.rb +8 -0
  50. data/test/payment_test_test.rb +7 -0
  51. data/test/test_helper.rb +21 -0
  52. metadata +432 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b6bdfb40babe27be1ad1355f2a0331e130935d9
4
+ data.tar.gz: a88aac9b8e64dc9362458f8d6c3e19fa7a11c1b3
5
+ SHA512:
6
+ metadata.gz: 382de36e5ba5b60e054de6a3230f7338c3cf223856e6600eff6a54345d7112ef7162a1ff26abb39024bd24bde2b65d450e2719f81ea17f8b4f24f36411aff0a3
7
+ data.tar.gz: 9860a80fb29ea758310d52c090e68a7be88141f1aa7c662c5a21f3f17c859d10f8a20390d03e95ef230fbe9b40106c55e52d4d5712582bedbf868f027b377af1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 stephane brossier
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
File without changes
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'PaymentTest'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,24 @@
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 any plugin's vendor/assets/javascripts directory 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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require js-routes
14
+ //= require moment
15
+ //= require spin
16
+ //= require jquery
17
+ //= require jquery_ujs
18
+ //= require twitter/bootstrap
19
+ //= require dataTables/jquery.dataTables
20
+ //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
21
+ //= require d3
22
+ //= require bootstrap-datepicker
23
+ //= require jquery.spin
24
+ //= require payment_test/payment_test
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_tree .
@@ -0,0 +1,20 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_self
14
+ *= require bootstrap-datepicker3
15
+ *= require dataTables/jquery.dataTables
16
+ *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
17
+ *= require bootstrap_and_overrides
18
+ *= require payment_test/payment_test
19
+ */
20
+
@@ -0,0 +1,17 @@
1
+ /*
2
+ *= require twitter-bootstrap-static/bootstrap
3
+ *
4
+ * Use Font Awesome icons (default)
5
+ * To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
6
+ *= require twitter-bootstrap-static/fontawesome
7
+ */
8
+
9
+ /* Override Bootstrap 3 font locations */
10
+ @font-face {
11
+ font-family: 'Glyphicons Halflings';
12
+ src: url('../assets/glyphicons-halflings-regular.eot');
13
+ src: url('../assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
14
+ url('../assets/glyphicons-halflings-regular.woff') format('woff'),
15
+ url('../assets/glyphicons-halflings-regular.ttf') format('truetype'),
16
+ url('../assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
17
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_tree .
6
+ */
@@ -0,0 +1,29 @@
1
+ module PaymentTest
2
+ class EngineController < ApplicationController
3
+
4
+ layout :get_layout
5
+
6
+ def get_layout
7
+ layout ||= PaymentTest.config[:layout]
8
+ end
9
+
10
+ def current_tenant_user
11
+ # If the rails application on which that engine is mounted defines such method (Devise), we extract the current user,
12
+ # if not we default to nil, and serve our static mock configuration
13
+ user = current_user if respond_to?(:current_user)
14
+ PaymentTest.current_tenant_user.call(session, user)
15
+ end
16
+
17
+ def options_for_klient
18
+ user = current_tenant_user
19
+ {
20
+ :username => user[:username],
21
+ :password => user[:password],
22
+ :session_id => user[:session_id],
23
+ :api_key => user[:api_key],
24
+ :api_secret => user[:api_secret]
25
+ }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ require 'payment_test/client'
2
+
3
+ module PaymentTest
4
+ class PaymentsController < EngineController
5
+
6
+ def index
7
+ begin
8
+ raw_status = ::Killbill::PaymentTest::PaymentTestClient.status(options_for_klient)
9
+ rescue => e
10
+ Rails.logger.warn("Failed to retrieve payment status : #{e}")
11
+ end
12
+
13
+ if raw_status.nil?
14
+ @status = "UNKNOWN"
15
+ elsif raw_status.key? :always_return_plugin_status_error.to_s
16
+ @status = "RETURN ERROR"
17
+ elsif raw_status.key? :always_return_plugin_status_pending.to_s
18
+ @status = "RETURN PENDING"
19
+ elsif raw_status.key? :always_return_plugin_status_canceled.to_s
20
+ @status = "RETURN CANCELED"
21
+ elsif raw_status.key? :always_throw.to_s
22
+ @status = "RETURN THROW"
23
+ elsif raw_status.key? :always_return_nil.to_s
24
+ @status = "RETURN NULL "
25
+ elsif raw_status.key? :sleep_time_sec.to_s
26
+ @status = "SLEEP #{sleep_time_sec}"
27
+ else
28
+ @status = "CLEAR"
29
+ end
30
+
31
+ if raw_status.nil?
32
+ @methods = ['*']
33
+ elsif !raw_status.key?("methods") || raw_status["methods"].empty?
34
+ @methods = ['*']
35
+ else
36
+ @methods = raw_status["methods"]
37
+ end
38
+ end
39
+
40
+ def set_failed_state
41
+
42
+ new_state = params.require(:state)
43
+ target_method = "set_status_#{new_state.to_s.downcase}".to_sym
44
+
45
+ begin
46
+ ::Killbill::PaymentTest::PaymentTestClient.send(target_method, nil, options_for_klient)
47
+ rescue => e
48
+ flash[:error] = "Failed to set state: #{e}"
49
+ end
50
+
51
+
52
+ redirect_to root_path and return
53
+ end
54
+
55
+ def reset
56
+
57
+ begin
58
+ ::Killbill::PaymentTest::PaymentTestClient.reset(nil, options_for_klient)
59
+ rescue => e
60
+ flash[:error] = "Failed to reset state: #{e}"
61
+ end
62
+ redirect_to root_path and return
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,4 @@
1
+ module PaymentTest
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PaymentTest</title>
5
+ <%= yield :scripts %>
6
+ <%= stylesheet_link_tag 'application', :media => 'all' %>
7
+ <%= javascript_include_tag 'application' %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <div class="container-fluid">
11
+ <%- # :alert used by devise -%>
12
+ <% [:error, :alert].each do |key| %>
13
+ <% if flash[key] %>
14
+ <div class="row">
15
+ <div class="col-md-10 col-md-offset-2">
16
+ <div class="alert alert-error"><%= flash[key] %></div>
17
+ </div>
18
+ </div>
19
+ <% end %>
20
+ <% end %>
21
+ <% if flash[:notice] %>
22
+ <div class="row">
23
+ <div class="col-md-10 col-md-offset-2">
24
+ <div class="alert alert-info"><%= flash[:notice] %></div>
25
+ </div>
26
+ </div>
27
+ <% end %>
28
+ <%= yield %>
29
+ </div>
30
+ </body>
31
+ </html>
@@ -0,0 +1,45 @@
1
+ <div class="search">
2
+
3
+ <div class="column-block">
4
+
5
+ <h1>Payment Test Status</h1>
6
+
7
+ <div id="payment-status-table-wrapper">
8
+ <table id="payment-status-table" class="table table-condensed table-striped mobile-data">
9
+ <thead>
10
+ <tr>
11
+ <th>Method</th>
12
+ <th>
13
+ <span>Status</span>
14
+
15
+ <div class="btn-group">
16
+ <a class="btn btn-xs dropdown-toggle" data-toggle="dropdown" href="#">
17
+ Set status
18
+ <span class="caret"></span>
19
+ </a>
20
+ <ul class="dropdown-menu">
21
+ <li><%= link_to 'Clear all status', reset_path, :method => :post %></li>
22
+ <li><%= link_to 'Configure ERROR', set_failed_state_path(:state => :ERROR), :method => :post %></li>
23
+ <li><%= link_to 'Configure PENDING', set_failed_state_path(:state => :PENDING), :method => :post %></li>
24
+ <li><%= link_to 'Configure CANCELED', set_failed_state_path(:state => :CANCELED), :method => :post %></li>
25
+ <li><%= link_to 'Configure THROW', set_failed_state_path(:state => :THROW), :method => :post %></li>
26
+ </ul>
27
+ </div>
28
+ </th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% @methods.each do |m| %>
33
+ <tr>
34
+ <td><%= m %></td>
35
+ <td>
36
+ <span class="label label-<%= @status == 'CLEAR' ? 'success' : (@status.starts_with?('SLEEP') ? 'warning' : 'danger') %>"><%= @status %></span>
37
+ </td>
38
+ </tr>
39
+ <% end %>
40
+ </tbody>
41
+ </table>
42
+ </div>
43
+
44
+ </div>
45
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ PaymentTest::Engine.routes.draw do
2
+
3
+ root to: 'payments#index'
4
+
5
+ resources :payments, :only => [:index]
6
+
7
+ scope '/payments' do
8
+ match '/set_failed_state' => 'payments#set_failed_state', :via => :post, :as => 'set_failed_state'
9
+ match '/reset' => 'payments#reset', :via => :post, :as => 'reset'
10
+ end
11
+
12
+ end
@@ -0,0 +1,23 @@
1
+ require "payment_test/engine"
2
+
3
+ module PaymentTest
4
+
5
+ mattr_accessor :current_tenant_user
6
+ mattr_accessor :layout
7
+
8
+ self.current_tenant_user = lambda { |session, user|
9
+ {
10
+ :username => 'admin',
11
+ :password => 'password',
12
+ :session_id => nil,
13
+ :api_key => KillBillClient.api_key,
14
+ :api_secret => KillBillClient.api_secret
15
+ }
16
+ }
17
+
18
+ def self.config(&block)
19
+ {
20
+ :layout => layout || 'payment_test/layouts/payment_test_application',
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,74 @@
1
+ require 'json'
2
+
3
+ module Killbill
4
+ module PaymentTest
5
+
6
+ class PaymentTestClient < KillBillClient::Model::Resource
7
+
8
+ KILLBILL_PAYMENT_TEST_PREFIX = '/plugins/killbill-payment-test'
9
+ class << self
10
+
11
+ def status(options = {})
12
+ response = KillBillClient::API.get "#{KILLBILL_PAYMENT_TEST_PREFIX}/status",
13
+ {},
14
+ options
15
+ JSON.parse(response.body)
16
+ end
17
+
18
+ def set_status_pending(methods, options = {})
19
+ configure("ACTION_RETURN_PLUGIN_STATUS_PENDING", nil, methods, options)
20
+ end
21
+
22
+ def set_status_error(methods, options = {})
23
+ configure("ACTION_RETURN_PLUGIN_STATUS_ERROR", nil, methods, options)
24
+ end
25
+
26
+ def set_status_canceled(methods, options = {})
27
+ configure("ACTION_RETURN_PLUGIN_STATUS_CANCELED", nil, methods, options)
28
+ end
29
+
30
+
31
+ def set_sleep_time(sleep_time_sec, methods, options = {})
32
+ configure("ACTION_SLEEP", sleep_time_sec, methods, options)
33
+ end
34
+
35
+ def set_status_throw(methods, options = {})
36
+ configure("ACTION_THROW_EXCEPTION", nil, methods, options)
37
+ end
38
+
39
+ def set_status_null(methods, options = {})
40
+ configure("ACTION_RETURN_NIL", nil, methods, options)
41
+ end
42
+
43
+ def reset(methods, options = {})
44
+ configure("ACTION_RESET", nil, methods, options)
45
+ end
46
+
47
+ private
48
+
49
+ def configure(action, arg, methods, options = {})
50
+
51
+ body = {
52
+ "CONFIGURE_ACTION" => action
53
+ }
54
+
55
+ if action == "ACTION_RESET"
56
+ body["SLEEP_TIME_SEC"] = arg
57
+ end
58
+
59
+ body["METHODS"] = methods.nil? ? nil : methods.join(",")
60
+
61
+ KillBillClient::API.post "#{KILLBILL_PAYMENT_TEST_PREFIX}/configure",
62
+ body.to_json,
63
+ {},
64
+ {
65
+ :user => 'anonymous',
66
+ :reason => "TEST",
67
+ :comment => "TEST",
68
+ }.merge(options)
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end