kaui 0.0.1
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 +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/kaui/account_timeline.js +2 -0
- data/app/assets/javascripts/kaui/application.js +15 -0
- data/app/assets/javascripts/kaui/bundles.js +2 -0
- data/app/assets/javascripts/kaui/chargebacks.js +2 -0
- data/app/assets/javascripts/kaui/extpayments.js +2 -0
- data/app/assets/javascripts/kaui/home.js +2 -0
- data/app/assets/javascripts/kaui/invoices.js +2 -0
- data/app/assets/javascripts/kaui/payments.js +2 -0
- data/app/assets/javascripts/kaui/refunds.js +2 -0
- data/app/assets/stylesheets/kaui/account_timeline.css +4 -0
- data/app/assets/stylesheets/kaui/application.css +13 -0
- data/app/assets/stylesheets/kaui/bundles.css +4 -0
- data/app/assets/stylesheets/kaui/chargebacks.css +4 -0
- data/app/assets/stylesheets/kaui/extpayments.css +4 -0
- data/app/assets/stylesheets/kaui/home.css +4 -0
- data/app/assets/stylesheets/kaui/invoices.css +4 -0
- data/app/assets/stylesheets/kaui/payments.css +4 -0
- data/app/assets/stylesheets/kaui/refunds.css +4 -0
- data/app/controllers/kaui/account_tags_controller.rb +33 -0
- data/app/controllers/kaui/account_timelines_controller.rb +58 -0
- data/app/controllers/kaui/accounts_controller.rb +61 -0
- data/app/controllers/kaui/application_controller.rb +2 -0
- data/app/controllers/kaui/bundle_tags_controller.rb +28 -0
- data/app/controllers/kaui/bundles_controller.rb +23 -0
- data/app/controllers/kaui/chargebacks_controller.rb +38 -0
- data/app/controllers/kaui/credits_controller.rb +33 -0
- data/app/controllers/kaui/home_controller.rb +6 -0
- data/app/controllers/kaui/invoices_controller.rb +36 -0
- data/app/controllers/kaui/payment_methods_controller.rb +7 -0
- data/app/controllers/kaui/payments_controller.rb +4 -0
- data/app/controllers/kaui/refunds_controller.rb +38 -0
- data/app/controllers/kaui/subscriptions_controller.rb +73 -0
- data/app/helpers/kaui/application_helper.rb +4 -0
- data/app/helpers/kaui/date_helper.rb +9 -0
- data/app/helpers/kaui/home_helper.rb +4 -0
- data/app/helpers/kaui/killbill_helper.rb +391 -0
- data/app/models/kaui/account.rb +35 -0
- data/app/models/kaui/account_timeline.rb +12 -0
- data/app/models/kaui/base.rb +99 -0
- data/app/models/kaui/bundle.rb +15 -0
- data/app/models/kaui/chargeback.rb +31 -0
- data/app/models/kaui/credit.rb +11 -0
- data/app/models/kaui/event.rb +21 -0
- data/app/models/kaui/invoice.rb +29 -0
- data/app/models/kaui/invoice_item.rb +29 -0
- data/app/models/kaui/payment.rb +35 -0
- data/app/models/kaui/payment_attempt.rb +29 -0
- data/app/models/kaui/product.rb +24 -0
- data/app/models/kaui/refund.rb +14 -0
- data/app/models/kaui/subscription.rb +25 -0
- data/app/models/kaui/tag.rb +7 -0
- data/app/views/kaui/account_tags/_account_tags_table.html.erb +10 -0
- data/app/views/kaui/account_tags/edit.html.erb +38 -0
- data/app/views/kaui/account_timelines/index.html.erb +14 -0
- data/app/views/kaui/account_timelines/show.html.erb +198 -0
- data/app/views/kaui/accounts/index.html.erb +14 -0
- data/app/views/kaui/accounts/show.html.erb +38 -0
- data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +11 -0
- data/app/views/kaui/bundle_tags/edit.html.erb +37 -0
- data/app/views/kaui/bundles/index.html.erb +14 -0
- data/app/views/kaui/bundles/show.html.erb +13 -0
- data/app/views/kaui/chargebacks/index.html.erb +14 -0
- data/app/views/kaui/chargebacks/new.html.erb +81 -0
- data/app/views/kaui/chargebacks/show.html.erb +19 -0
- data/app/views/kaui/credits/index.html.erb +14 -0
- data/app/views/kaui/credits/new.html.erb +73 -0
- data/app/views/kaui/credits/show.html.erb +19 -0
- data/app/views/kaui/home/index.html.erb +0 -0
- data/app/views/kaui/invoices/index.html.erb +14 -0
- data/app/views/kaui/invoices/show.html.erb +58 -0
- data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +37 -0
- data/app/views/kaui/payment_methods/index.html.erb +14 -0
- data/app/views/kaui/payment_methods/show.html.erb +1 -0
- data/app/views/kaui/refunds/index.html.erb +14 -0
- data/app/views/kaui/refunds/new.html.erb +81 -0
- data/app/views/kaui/refunds/show.html.erb +19 -0
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +39 -0
- data/app/views/kaui/subscriptions/edit.html.erb +27 -0
- data/app/views/kaui/subscriptions/index.html.erb +14 -0
- data/app/views/kaui/subscriptions/show.html.erb +22 -0
- data/app/views/kaui/tags/_tags_table.html.erb +10 -0
- data/config/initializers/time_formats.rb +2 -0
- data/config/routes.rb +46 -0
- data/db/schema.rb +15 -0
- data/lib/kaui/engine.rb +11 -0
- data/lib/kaui/version.rb +3 -0
- data/lib/kaui.rb +20 -0
- data/lib/tasks/kaui_tasks.rake +4 -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/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +42 -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/config.ru +4 -0
- data/test/dummy/log/test.log +250 -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/kaui/account_timeline_controller_test.rb +9 -0
- data/test/functional/kaui/bundles_controller_test.rb +9 -0
- data/test/functional/kaui/chargebacks_controller_test.rb +9 -0
- data/test/functional/kaui/extpayments_controller_test.rb +9 -0
- data/test/functional/kaui/home_controller_test.rb +11 -0
- data/test/functional/kaui/invoices_controller_test.rb +9 -0
- data/test/functional/kaui/payments_controller_test.rb +9 -0
- data/test/functional/kaui/refunds_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/kaui_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/helpers/kaui/account_timeline_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/bundles_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/chargebacks_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/extpayments_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/home_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/invoices_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/payments_helper_test.rb +6 -0
- data/test/unit/helpers/kaui/refunds_helper_test.rb +6 -0
- data/test/unit/model_test.rb +151 -0
- metadata +253 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2012 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.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
8
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
9
|
+
load 'rails/tasks/engine.rake'
|
|
10
|
+
|
|
11
|
+
Bundler::GemHelper.install_tasks
|
|
12
|
+
|
|
13
|
+
require 'rake/testtask'
|
|
14
|
+
|
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
|
16
|
+
t.libs << 'lib'
|
|
17
|
+
t.libs << 'test'
|
|
18
|
+
t.pattern = 'test/**/*_test.rb'
|
|
19
|
+
t.verbose = false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
task :default => :test
|
|
@@ -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,33 @@
|
|
|
1
|
+
class Kaui::AccountTagsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
def show
|
|
4
|
+
account_id = params[:id]
|
|
5
|
+
|
|
6
|
+
if account_id.present?
|
|
7
|
+
tags = Kaui::KillbillHelper::get_tags_for_account(account_id)
|
|
8
|
+
else
|
|
9
|
+
flash[:error] = "No account id given"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def edit
|
|
14
|
+
@account_id = params[:account_id]
|
|
15
|
+
@available_tags = Kaui::KillbillHelper::get_tag_definitions.sort {|tag_a, tag_b| tag_a.name.downcase <=> tag_b.name.downcase }
|
|
16
|
+
|
|
17
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
18
|
+
@tags = Kaui::KillbillHelper::get_tags_for_account(@account.account_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update
|
|
22
|
+
account = Kaui::KillbillHelper::get_account(params[:account_id])
|
|
23
|
+
tags = params[:tags]
|
|
24
|
+
|
|
25
|
+
if account.account_id.present?
|
|
26
|
+
Kaui::KillbillHelper::set_tags_for_account(account.account_id, tags)
|
|
27
|
+
redirect_to Kaui.account_home_path.call(account.external_key)
|
|
28
|
+
else
|
|
29
|
+
flash[:error] = "No account id given"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
class Kaui::AccountTimelinesController < ApplicationController
|
|
2
|
+
def index
|
|
3
|
+
if params[:account_id].present?
|
|
4
|
+
redirect_to account_timeline_path(params[:account_id])
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show
|
|
9
|
+
@account_id = params[:id]
|
|
10
|
+
if @account_id.present?
|
|
11
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
12
|
+
@timeline = Kaui::KillbillHelper::get_account_timeline(@account_id)
|
|
13
|
+
# @payment_attempts_by_payment_id = {}
|
|
14
|
+
@invoices_by_id = {}
|
|
15
|
+
@bundle_names = {}
|
|
16
|
+
unless @timeline.nil?
|
|
17
|
+
@timeline.payments.each do |payment|
|
|
18
|
+
if payment.invoice_id.present? &&
|
|
19
|
+
payment.payment_id.present? &&
|
|
20
|
+
# !@payment_attempts_by_payment_id.has_key?(payment.payment_id)
|
|
21
|
+
|
|
22
|
+
@invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id)
|
|
23
|
+
# payment_attempt = Kaui::KillbillHelper::get_payment_attempt(@timeline.account.external_key,
|
|
24
|
+
# payment.invoice_id,
|
|
25
|
+
# payment.payment_id)
|
|
26
|
+
# @payment_attempts_by_payment_id[payment.payment_id] = payment_attempt
|
|
27
|
+
payment.bundle_keys.split(",").each do |bundle_key|
|
|
28
|
+
unless @bundle_names.has_key?(bundle_key)
|
|
29
|
+
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
@timeline.invoices.each do |invoice|
|
|
35
|
+
if invoice.invoice_id.present? && !@invoices_by_id.has_key?(invoice.invoice_id)
|
|
36
|
+
@invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id)
|
|
37
|
+
invoice.bundle_keys.split(",").each do |bundle_key|
|
|
38
|
+
unless @bundle_names.has_key?(bundle_key)
|
|
39
|
+
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
@timeline.bundles.each do |bundle|
|
|
45
|
+
unless @bundle_names.has_key?(bundle.external_key)
|
|
46
|
+
@bundle_names[bundle.external_key] = Kaui.bundle_key_display_string.call(bundle.external_key)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
if params.has_key?(:external_key)
|
|
50
|
+
@selected_bundle = @bundle_names[params[:external_key]]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
flash[:notice] = "No id given"
|
|
55
|
+
redirect_to :back
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'rest_client'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class Kaui::AccountsController < ApplicationController
|
|
5
|
+
def index
|
|
6
|
+
if params[:account_id].present?
|
|
7
|
+
redirect_to account_path(params[:account_id])
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
@account_id = params[:id]
|
|
13
|
+
if @account_id.present?
|
|
14
|
+
@account = Kaui::KillbillHelper.get_account(@account_id)
|
|
15
|
+
if @account.present?
|
|
16
|
+
# TODO: add when payment methods are implemented
|
|
17
|
+
# @payment_methods = Kaui::KillbillHelper.get_payment_methods(@account_id)
|
|
18
|
+
# unless @payment_methods.is_a?(Array)
|
|
19
|
+
# flash[:error] = "No payment methods for account #{@account_id}"
|
|
20
|
+
# redirect_to :action => :index
|
|
21
|
+
# end
|
|
22
|
+
else
|
|
23
|
+
flash[:error] = "Account #{@account_id} not found"
|
|
24
|
+
redirect_to :action => :index
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
flash[:error] = "No id given"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def payment_methods
|
|
32
|
+
@external_key = params[:id]
|
|
33
|
+
if @external_key.present?
|
|
34
|
+
@payment_methods = Kaui::KillbillHelper::get_payment_methods(@external_key)
|
|
35
|
+
unless @payment_methods.is_a?(Array)
|
|
36
|
+
flash[:notice] = "No payment methods for external_key '#{@external_key}'"
|
|
37
|
+
redirect_to :action => :index
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
flash[:notice] = "No id given"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def set_default_payment_method
|
|
46
|
+
@external_key = params[:id]
|
|
47
|
+
# TODO
|
|
48
|
+
redirect_to :back
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def delete_payment_method
|
|
52
|
+
@external_key = params[:id]
|
|
53
|
+
@payment_method_id = params[:payment_method_id]
|
|
54
|
+
if @external_key.present? && @payment_method_id.present?
|
|
55
|
+
Kaui::KillbillHelper::delete_payment_method(@external_key, @payment_method_id)
|
|
56
|
+
else
|
|
57
|
+
flash[:notice] = "No id given"
|
|
58
|
+
end
|
|
59
|
+
redirect_to :back
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Kaui::BundleTagsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
def show
|
|
4
|
+
bundle_id = params[:id]
|
|
5
|
+
if bundle_id.present?
|
|
6
|
+
tags = Kaui::KillbillHelper::get_tags_for_bundle(bundle_id)
|
|
7
|
+
else
|
|
8
|
+
flash[:error] = "No account id given"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def edit
|
|
13
|
+
@bundle_id = params[:bundle_id]
|
|
14
|
+
@available_tags = Kaui::KillbillHelper::get_tag_definitions.sort {|tag_a, tag_b| tag_a.name.downcase <=> tag_b.name.downcase }
|
|
15
|
+
|
|
16
|
+
@bundle = Kaui::KillbillHelper::get_bundle(@bundle_id)
|
|
17
|
+
@tags = Kaui::KillbillHelper::get_tags_for_bundle(@bundle_id)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update
|
|
21
|
+
bundle = Kaui::KillbillHelper::get_bundle(params[:bundle_id])
|
|
22
|
+
tags = params[:tags]
|
|
23
|
+
|
|
24
|
+
Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags)
|
|
25
|
+
redirect_to Kaui.bundle_home_path.call(bundle.external_key)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Kaui::BundlesController < ApplicationController
|
|
2
|
+
|
|
3
|
+
def index
|
|
4
|
+
if params[:bundle_id].present?
|
|
5
|
+
redirect_to bundle_path(params[:bundle_id])
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
@external_key = params[:id]
|
|
11
|
+
if @external_key.present?
|
|
12
|
+
@bundle = Kaui::KillbillHelper.get_bundle_by_external_key(@external_key)
|
|
13
|
+
if @bundle.present?
|
|
14
|
+
@subscriptions = Kaui::KillbillHelper.get_subscriptions_for_bundle(@bundle.bundle_id)
|
|
15
|
+
else
|
|
16
|
+
flash[:error] = "Bundle #{@external_key} not found"
|
|
17
|
+
redirect_to :action => :index
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
flash[:error] = "No id given"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Kaui::ChargebacksController < ApplicationController
|
|
2
|
+
def show
|
|
3
|
+
@payment_id = params[:id]
|
|
4
|
+
if @payment_id.present?
|
|
5
|
+
data = Kaui::KillbillHelper::get_chargebacks_for_payment(@payment_id)
|
|
6
|
+
if data.present?
|
|
7
|
+
@chargeback = Kaui::Chargeback.new(data)
|
|
8
|
+
else
|
|
9
|
+
Rails.logger.warn("Did not get back chargebacks #{response_body}")
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
flash[:notice] = "No id given"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def new
|
|
17
|
+
@payment_id = params[:payment_id]
|
|
18
|
+
@invoice_id = params[:invoice_id]
|
|
19
|
+
@account_id = params[:account_id]
|
|
20
|
+
|
|
21
|
+
@chargeback = Kaui::Chargeback.new(:payment_id => @payment_id,
|
|
22
|
+
:invoice_id => @invoice_id,
|
|
23
|
+
:account_id => @account_id)
|
|
24
|
+
|
|
25
|
+
# @payment_attempt = Kaui::KillbillHelper::get_payment_attempt(@external_key, @invoice_id, @payment_id)
|
|
26
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
27
|
+
# TODO: get payment by payment id (no api at the moment)
|
|
28
|
+
@payment = Kaui::KillbillHelper::get_payment(@invoice_id, @payment_id)
|
|
29
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create
|
|
33
|
+
chargeback = Kaui::Chargeback.new(params[:chargeback])
|
|
34
|
+
# TODO: read chargeback object from post params
|
|
35
|
+
#Kaui::KillbillHelper::create_chargeback(@payment_id)
|
|
36
|
+
redirect_to account_timeline_path(:id => chargeback.account_id)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class Kaui::CreditsController < ApplicationController
|
|
2
|
+
def show
|
|
3
|
+
@payment_id = params[:id]
|
|
4
|
+
if @payment_id.present?
|
|
5
|
+
data = Kaui::KillbillHelper::get_credits_for_payment(@payment_id)
|
|
6
|
+
if data.present?
|
|
7
|
+
@credit = Kaui::Credit.new(data)
|
|
8
|
+
else
|
|
9
|
+
Rails.logger.warn("Did not get back external payments #{response_body}")
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
flash[:notice] = "No id given"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def new
|
|
17
|
+
@account_id = params[:account_id]
|
|
18
|
+
@invoice_id = params[:invoice_id]
|
|
19
|
+
|
|
20
|
+
@credit = Kaui::Credit.new(:invoice_id => @invoice_id,
|
|
21
|
+
:account_id => @account_id)
|
|
22
|
+
|
|
23
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
24
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
credit = Kaui::Credit.new(params[:credit])
|
|
29
|
+
# TODO: read credit object from post params
|
|
30
|
+
#Kaui::KillbillHelper::create_credit(@payment_id)
|
|
31
|
+
redirect_to account_timeline_path(:id => credit.account_id)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class Kaui::InvoicesController < ApplicationController
|
|
2
|
+
def index
|
|
3
|
+
if params[:id].present?
|
|
4
|
+
redirect_to invoice_path(params[:id])
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show
|
|
9
|
+
@invoice_id = params[:id]
|
|
10
|
+
if @invoice_id.present?
|
|
11
|
+
@invoice = Kaui::KillbillHelper.get_invoice(@invoice_id)
|
|
12
|
+
if @invoice.present?
|
|
13
|
+
@account = Kaui::KillbillHelper.get_account(@invoice.account_id)
|
|
14
|
+
@subscriptions = {}
|
|
15
|
+
@bundles = {}
|
|
16
|
+
if @invoice.items.present?
|
|
17
|
+
@invoice.items.each do |item|
|
|
18
|
+
unless item.subscription_id.nil? || @subscriptions.has_key?(item.subscription_id)
|
|
19
|
+
@subscriptions[item.subscription_id] = Kaui::KillbillHelper.get_subscription(item.subscription_id)
|
|
20
|
+
end
|
|
21
|
+
unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
|
|
22
|
+
@bundles[item.bundle_id] = Kaui::KillbillHelper.get_bundle(item.bundle_id)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
else
|
|
26
|
+
flash[:error] = "Invoice items for #{@invoice_id} not found"
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
flash[:error] = "Invoice #{@invoice_id} not found"
|
|
30
|
+
redirect_to :action => :index
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
flash[:error] = "No id given"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Kaui::RefundsController < ApplicationController
|
|
2
|
+
def show
|
|
3
|
+
@payment_id = params[:id]
|
|
4
|
+
if @payment_id.present?
|
|
5
|
+
data = Kaui::KillbillHelper::get_refunds_for_payment(@payment_id)
|
|
6
|
+
if data.present?
|
|
7
|
+
@refund = Kaui::Refund.new(data)
|
|
8
|
+
else
|
|
9
|
+
Rails.logger.warn("Did not get back refunds for the payment id #{response_body}")
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
flash[:notice] = "No payment id given"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def new
|
|
17
|
+
@payment_id = params[:payment_id]
|
|
18
|
+
@invoice_id = params[:invoice_id]
|
|
19
|
+
@account_id = params[:account_id]
|
|
20
|
+
|
|
21
|
+
@refund = Kaui::Refund.new(:payment_id => @payment_id,
|
|
22
|
+
:invoice_id => @invoice_id,
|
|
23
|
+
:account_id => @account_id)
|
|
24
|
+
|
|
25
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
26
|
+
# @payment_attempt = Kaui::KillbillHelper::get_payment_attempt(@external_key, @invoice_id, @payment_id)
|
|
27
|
+
@payment = Kaui::KillbillHelper::get_payment(@invoice_id, @payment_id)
|
|
28
|
+
puts "payment is #{@payment.to_yaml}"
|
|
29
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create
|
|
33
|
+
refund = Kaui::Refund.new(params[:refund])
|
|
34
|
+
# TODO: read refund object from post params
|
|
35
|
+
#Kaui::KillbillHelper::create_refund(refund)
|
|
36
|
+
redirect_to account_timeline_path(:id => refund.account_id)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'kaui/product'
|
|
2
|
+
|
|
3
|
+
class Kaui::SubscriptionsController < ApplicationController
|
|
4
|
+
def index
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
@subscription = Kaui::KillbillHelper.get_subscription(params[:id])
|
|
9
|
+
unless @subscription.present?
|
|
10
|
+
flash[:error] = "No subscription id given or subscription not found"
|
|
11
|
+
redirect_to :back
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new
|
|
16
|
+
@bundle_id = params[:bundle_id]
|
|
17
|
+
@product_name = params[:product_name]
|
|
18
|
+
@product_category = params[:product_category]
|
|
19
|
+
@billing_period = params[:billing_period]
|
|
20
|
+
@price_list = params[:price_list]
|
|
21
|
+
|
|
22
|
+
@subscription = Kaui::Subscription.new(:bundle_id => @bundle_id,
|
|
23
|
+
:product_name => @product_name,
|
|
24
|
+
:product_category => @product_category,
|
|
25
|
+
:billing_period => @billing_period,
|
|
26
|
+
:price_list => @price_list)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create
|
|
30
|
+
subscription = Kaui::Subscription.new(params[:subscription])
|
|
31
|
+
bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
|
|
32
|
+
|
|
33
|
+
Kaui::KillbillHelper::create_subscription(subscription)
|
|
34
|
+
redirect_to account_timeline_path(:id => bundle.account_id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def edit
|
|
38
|
+
@subscription = Kaui::KillbillHelper.get_subscription(params[:id])
|
|
39
|
+
unless @subscription.present?
|
|
40
|
+
flash[:error] = "No subscription id given or subscription not found"
|
|
41
|
+
redirect_to :back
|
|
42
|
+
end
|
|
43
|
+
@products = Kaui::BASE_PRODUCTS
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def update
|
|
47
|
+
if params.has_key?(:subscription) && params[:subscription].has_key?(:subscription_id)
|
|
48
|
+
subscription = Kaui::KillbillHelper.get_subscription(params[:subscription][:subscription_id])
|
|
49
|
+
product_id = params[:subscription][:product_name]
|
|
50
|
+
products = Kaui::BASE_PRODUCTS.select{|p| p.id == product_id}
|
|
51
|
+
unless products.empty?
|
|
52
|
+
subscription.product_name = products[0].product_name
|
|
53
|
+
subscription.billing_period = products[0].billing_period
|
|
54
|
+
subscription.start_date = params[:subscription][:start_date]
|
|
55
|
+
Kaui::KillbillHelper.update_subscription(subscription)
|
|
56
|
+
end
|
|
57
|
+
redirect_to :action => :show, :id => subscription.subscription_id
|
|
58
|
+
else
|
|
59
|
+
flash[:error] = "No subscription given"
|
|
60
|
+
redirect_to :back
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def destroy
|
|
65
|
+
subscription_id = params[:id]
|
|
66
|
+
if subscription_id.present?
|
|
67
|
+
Kaui::KillbillHelper.delete_subscription(subscription_id)
|
|
68
|
+
redirect_to :back
|
|
69
|
+
else
|
|
70
|
+
flash[:error] = "No subscription id given"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module Kaui
|
|
2
|
+
module DateHelper
|
|
3
|
+
def format_date(date)
|
|
4
|
+
# TODO: make timezone configurable
|
|
5
|
+
parsed_date = DateTime.parse(date).in_time_zone("Pacific Time (US & Canada)")
|
|
6
|
+
parsed_date.to_s(:pretty) + " " + (parsed_date.dst? ? "PDT" : "PST")
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|