kaui 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +51 -37
- data/README.md +5 -0
- data/Rakefile +1 -1
- data/app/controllers/kaui/account_emails_controller.rb +26 -44
- data/app/controllers/kaui/account_tags_controller.rb +26 -38
- data/app/controllers/kaui/account_timelines_controller.rb +47 -50
- data/app/controllers/kaui/accounts_controller.rb +68 -148
- data/app/controllers/kaui/bundle_tags_controller.rb +32 -21
- data/app/controllers/kaui/bundles_controller.rb +44 -69
- data/app/controllers/kaui/chargebacks_controller.rb +31 -61
- data/app/controllers/kaui/charges_controller.rb +19 -21
- data/app/controllers/kaui/credits_controller.rb +22 -36
- data/app/controllers/kaui/custom_fields_controller.rb +15 -13
- data/app/controllers/kaui/engine_controller.rb +8 -10
- data/app/controllers/kaui/invoice_items_controller.rb +24 -41
- data/app/controllers/kaui/invoices_controller.rb +36 -46
- data/app/controllers/kaui/payment_methods_controller.rb +84 -28
- data/app/controllers/kaui/payments_controller.rb +64 -26
- data/app/controllers/kaui/refunds_controller.rb +27 -107
- data/app/controllers/kaui/subscriptions_controller.rb +88 -132
- data/app/controllers/kaui/tag_definitions_controller.rb +32 -79
- data/app/controllers/kaui/tags_controller.rb +16 -14
- data/app/controllers/kaui/transactions_controller.rb +25 -0
- data/app/helpers/kaui/money_helper.rb +8 -0
- data/app/helpers/kaui/subscription_helper.rb +115 -0
- data/app/helpers/kaui/uuid_helper.rb +9 -0
- data/app/models/kaui/ability.rb +2 -2
- data/app/models/kaui/account.rb +25 -42
- data/app/models/kaui/account_email.rb +11 -48
- data/app/models/kaui/account_timeline.rb +1 -5
- data/app/models/kaui/audit_log.rb +1 -15
- data/app/models/kaui/base.rb +1 -126
- data/app/models/kaui/bundle.rb +47 -14
- data/app/models/kaui/catalog.rb +2 -0
- data/app/models/kaui/chargeback.rb +24 -36
- data/app/models/kaui/credit.rb +5 -20
- data/app/models/kaui/custom_field.rb +9 -5
- data/app/models/kaui/invoice.rb +9 -53
- data/app/models/kaui/invoice_item.rb +8 -18
- data/app/models/kaui/invoice_payment.rb +24 -0
- data/app/models/kaui/payment.rb +14 -32
- data/app/models/kaui/payment_method.rb +36 -0
- data/app/models/kaui/rails_methods.rb +7 -9
- data/app/models/kaui/refund.rb +5 -20
- data/app/models/kaui/subscription.rb +7 -27
- data/app/models/kaui/tag.rb +10 -6
- data/app/models/kaui/tag_definition.rb +26 -34
- data/app/models/kaui/transaction.rb +30 -0
- data/app/models/kaui/user.rb +2 -0
- data/app/views/kaui/account_emails/_form.html.erb +8 -28
- data/app/views/kaui/account_emails/show.html.erb +10 -10
- data/app/views/kaui/account_tags/_account_tags_table.html.erb +20 -18
- data/app/views/kaui/account_tags/_form.html.erb +42 -0
- data/app/views/kaui/account_tags/edit.html.erb +1 -41
- data/app/views/kaui/account_tags/show.html.erb +6 -3
- data/app/views/kaui/account_timelines/show.html.erb +273 -302
- data/app/views/kaui/accounts/_form.html.erb +116 -0
- data/app/views/kaui/accounts/index.html.erb +13 -11
- data/app/views/kaui/accounts/new.html.erb +5 -0
- data/app/views/kaui/accounts/show.html.erb +101 -99
- data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +29 -9
- data/app/views/kaui/bundle_tags/_form.html.erb +41 -0
- data/app/views/kaui/bundle_tags/edit.html.erb +2 -34
- data/app/views/kaui/bundle_tags/show.html.erb +6 -0
- data/app/views/kaui/bundles/index.html.erb +9 -9
- data/app/views/kaui/bundles/show.html.erb +17 -15
- data/app/views/kaui/bundles/transfer.html.erb +25 -24
- data/app/views/kaui/chargebacks/_form.html.erb +44 -0
- data/app/views/kaui/chargebacks/new.html.erb +3 -115
- data/app/views/kaui/charges/_form.html.erb +73 -0
- data/app/views/kaui/charges/new.html.erb +2 -91
- data/app/views/kaui/credits/_form.html.erb +73 -0
- data/app/views/kaui/credits/new.html.erb +2 -85
- data/app/views/kaui/invoice_items/edit.html.erb +77 -78
- data/app/views/kaui/invoices/show.html.erb +3 -10
- data/app/views/kaui/layouts/kaui_application.html.erb +0 -2
- data/app/views/kaui/payment_methods/_form.html.erb +30 -0
- data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +19 -18
- data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +8 -5
- data/app/views/kaui/payment_methods/index.html.erb +10 -10
- data/app/views/kaui/payment_methods/new.html.erb +2 -20
- data/app/views/kaui/payment_methods/show.html.erb +2 -1
- data/app/views/kaui/payments/_payments_table.html.erb +30 -22
- data/app/views/kaui/payments/index.html.erb +1 -1
- data/app/views/kaui/payments/new.html.erb +5 -5
- data/app/views/kaui/payments/show.html.erb +3 -0
- data/app/views/kaui/refunds/new.html.erb +96 -104
- data/app/views/kaui/subscriptions/_form.html.erb +36 -0
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +39 -44
- data/app/views/kaui/subscriptions/edit.html.erb +24 -35
- data/app/views/kaui/subscriptions/index.html.erb +13 -12
- data/app/views/kaui/subscriptions/new.html.erb +6 -43
- data/app/views/kaui/subscriptions/show.html.erb +32 -25
- data/app/views/kaui/tag_definitions/_form.html.erb +10 -37
- data/app/views/kaui/tag_definitions/index.html.erb +3 -5
- data/app/views/kaui/tag_definitions/show.html.erb +1 -2
- data/app/views/kaui/transactions/_form.html.erb +77 -0
- data/app/views/kaui/transactions/new.html.erb +3 -0
- data/config/initializers/kilbill-client-init.rb +1 -1
- data/config/routes.rb +4 -15
- data/kaui.gemspec +8 -6
- data/lib/kaui/engine.rb +4 -1
- data/lib/kaui/version.rb +1 -1
- data/lib/kaui.rb +2 -2
- data/test/functional/kaui/account_emails_controller_test.rb +28 -0
- data/test/functional/kaui/account_tags_controller_test.rb +29 -0
- data/test/functional/kaui/account_timelines_controller_test.rb +21 -0
- data/test/functional/kaui/accounts_controller_test.rb +56 -50
- data/test/functional/kaui/bundle_tags_controller_test.rb +29 -0
- data/test/functional/kaui/bundles_controller_test.rb +58 -13
- data/test/functional/kaui/chargebacks_controller_test.rb +16 -5
- data/test/functional/kaui/charges_controller_test.rb +39 -0
- data/test/functional/kaui/credits_controller_test.rb +35 -0
- data/test/functional/kaui/custom_fields_controller_test.rb +21 -0
- data/test/functional/kaui/functional_test_helper.rb +61 -0
- data/test/functional/kaui/invoice_items_controller_test.rb +24 -10
- data/test/functional/kaui/invoices_controller_test.rb +41 -13
- data/test/functional/kaui/payment_methods_controller_test.rb +49 -0
- data/test/functional/kaui/payments_controller_test.rb +32 -5
- data/test/functional/kaui/refunds_controller_test.rb +40 -5
- data/test/functional/kaui/subscriptions_controller_test.rb +82 -0
- data/test/functional/kaui/tag_definitions_controller_test.rb +27 -53
- data/test/functional/kaui/tags_controller_test.rb +21 -0
- data/test/functional/kaui/transactions_controller_test.rb +32 -0
- data/test/integration/kaui/integration_test_helper.rb +31 -0
- data/test/integration/kaui/navigation_test.rb +43 -0
- data/test/killbill_test_helper.rb +143 -0
- data/test/test_helper.rb +10 -227
- data/test/unit/kaui/account_email_test.rb +19 -0
- data/test/unit/kaui/account_test.rb +7 -35
- data/test/unit/kaui/base_test.rb +5 -46
- data/test/unit/kaui/date_helper_test.rb +6 -5
- data/test/unit/kaui/invoice_item_test.rb +5 -17
- data/test/unit/kaui/invoice_payment_test.rb +42 -0
- data/test/unit/kaui/invoice_test.rb +15 -15
- data/test/unit/kaui/money_helper_test.rb +10 -0
- data/test/unit/kaui/payment_test.rb +42 -0
- data/test/unit/kaui/tag_definition_test.rb +5 -28
- data/test/unit/kaui/uuid_helper_test.rb +10 -0
- metadata +134 -159
- data/app/controllers/kaui/analytics_controller.rb +0 -28
- data/app/helpers/kaui/killbill_helper.rb +0 -611
- data/app/models/kaui/analytics.rb +0 -19
- data/app/models/kaui/analytics_sanity.rb +0 -7
- data/app/models/kaui/business_account.rb +0 -12
- data/app/models/kaui/business_field.rb +0 -6
- data/app/models/kaui/business_invoice.rb +0 -31
- data/app/models/kaui/business_invoice_item.rb +0 -17
- data/app/models/kaui/business_invoice_payment.rb +0 -25
- data/app/models/kaui/business_overdue_status.rb +0 -8
- data/app/models/kaui/business_snapshot.rb +0 -9
- data/app/models/kaui/business_subscription_transition.rb +0 -53
- data/app/models/kaui/business_tag.rb +0 -5
- data/app/models/kaui/charge.rb +0 -14
- data/app/models/kaui/entitlement.rb +0 -2
- data/app/models/kaui/event.rb +0 -13
- data/app/models/kaui/external_payment.rb +0 -15
- data/app/models/kaui/overdue_state.rb +0 -10
- data/app/models/kaui/payment_attempt.rb +0 -27
- data/app/models/kaui/product.rb +0 -24
- data/app/models/kaui/time_series_data.rb +0 -8
- data/app/views/kaui/analytics/account_snapshot.html.erb +0 -211
- data/app/views/kaui/analytics/index.html.erb +0 -17
- data/app/views/kaui/chargebacks/index.html.erb +0 -14
- data/app/views/kaui/chargebacks/show.html.erb +0 -19
- data/app/views/kaui/credits/index.html.erb +0 -14
- data/app/views/kaui/credits/show.html.erb +0 -19
- data/app/views/kaui/invoice_items/index.html.erb +0 -20
- data/app/views/kaui/invoice_items/show.html.erb +0 -31
- data/app/views/kaui/refunds/_refunds_table.html.erb +0 -31
- data/app/views/kaui/refunds/index.html.erb +0 -43
- data/app/views/kaui/refunds/show.html.erb +0 -33
- data/app/views/kaui/tag_definitions/edit.html.erb +0 -3
- data/test/dummy/test/fixtures/accounts.yml +0 -32
- data/test/dummy/test/fixtures/bill_cycle_days.yml +0 -3
- data/test/dummy/test/fixtures/bundles.yml +0 -4
- data/test/dummy/test/fixtures/invoice_items.yml +0 -13
- data/test/dummy/test/fixtures/invoices.yml +0 -11
- data/test/dummy/test/fixtures/overdue_states.yml +0 -8
- data/test/dummy/test/fixtures/payment_methods.yml +0 -5
- data/test/dummy/test/fixtures/plugin_info_properties.yml +0 -59
- data/test/dummy/test/fixtures/plugin_infos.yml +0 -2
- data/test/dummy/test/fixtures/refunds.yml +0 -9
- data/test/dummy/test/fixtures/tag_definitions.yml +0 -20
- data/test/functional/kaui/account_timeline_controller_test.rb +0 -9
- data/test/functional/kaui/extpayments_controller_test.rb +0 -9
- data/test/functional/kaui/home_controller_test.rb +0 -11
- data/test/integration/navigation_test.rb +0 -10
- data/test/kaui_test.rb +0 -7
- data/test/unit/helpers/kaui/account_timeline_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/bundles_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/chargebacks_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/extpayments_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/home_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/invoices_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/payments_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/refunds_helper_test.rb +0 -6
- data/test/unit/kaui/overdue_state_test.rb +0 -18
- data/test/unit/kaui/refund_test.rb +0 -20
- data/test/unit/model_test.rb +0 -151
@@ -1,127 +1,47 @@
|
|
1
1
|
class Kaui::RefundsController < Kaui::EngineController
|
2
2
|
|
3
|
-
def index
|
4
|
-
if params[:refund_id].present?
|
5
|
-
redirect_to kaui_engine.refund_path(params[:refund_id])
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def pagination
|
10
|
-
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
11
|
-
|
12
|
-
search_key = params[:sSearch]
|
13
|
-
if search_key.present?
|
14
|
-
refunds = Kaui::KillbillHelper::search_refunds(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
15
|
-
else
|
16
|
-
refunds = Kaui::KillbillHelper::get_refunds(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
17
|
-
end
|
18
|
-
json[:iTotalDisplayRecords] = refunds.pagination_total_nb_records
|
19
|
-
json[:iTotalRecords] = refunds.pagination_max_nb_records
|
20
|
-
|
21
|
-
refunds.each do |refund|
|
22
|
-
json[:aaData] << [
|
23
|
-
view_context.link_to(refund.refund_id, view_context.url_for(:controller => :refunds, :action => :show, :id => refund.refund_id)),
|
24
|
-
view_context.format_date(refund.effective_date),
|
25
|
-
view_context.humanized_money_with_symbol(Kaui::Base.to_money(refund.amount, refund.currency)),
|
26
|
-
refund.adjusted,
|
27
|
-
refund.status
|
28
|
-
]
|
29
|
-
end
|
30
|
-
|
31
|
-
respond_to do |format|
|
32
|
-
format.json { render :json => json }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def show
|
37
|
-
if params[:id].present?
|
38
|
-
begin
|
39
|
-
data = Kaui::KillbillHelper::get_refund(params[:id], options_for_klient)
|
40
|
-
rescue => e
|
41
|
-
flash.now[:error] = "Error while retrieving the refund with id #{params[:id]}: #{as_string(e)}"
|
42
|
-
end
|
43
|
-
if data.present?
|
44
|
-
@refunds = [data]
|
45
|
-
else
|
46
|
-
begin
|
47
|
-
@refunds = Kaui::KillbillHelper::get_refunds_for_payment(params[:id], options_for_klient)
|
48
|
-
unless @refunds.present?
|
49
|
-
flash.now[:error] = "Refund for id or payment id #{params[:id]} couldn't be found"
|
50
|
-
render :action => :index and return
|
51
|
-
end
|
52
|
-
rescue => e
|
53
|
-
flash.now[:error] = "Error while retrieving the refunds for the payment: #{as_string(e)}"
|
54
|
-
render :action => :index and return
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
if @refunds.size > 0
|
59
|
-
begin
|
60
|
-
# Retrieve the account via the payment
|
61
|
-
payment = Kaui::KillbillHelper::get_payment(@refunds[0].payment_id, options_for_klient)
|
62
|
-
unless payment.present?
|
63
|
-
flash.now[:error] = "Account for payment id #{@refunds[0].payment_id} couldn't be found"
|
64
|
-
render :action => :index
|
65
|
-
end
|
66
|
-
@account = Kaui::KillbillHelper::get_account(payment.account_id, false, false, options_for_klient)
|
67
|
-
rescue => e
|
68
|
-
flash.now[:error] = "Error while retrieving the account for the refund: #{as_string(e)}"
|
69
|
-
render :action => :index
|
70
|
-
end
|
71
|
-
end
|
72
|
-
else
|
73
|
-
flash.now[:error] = "A refund or payment id should be specifed"
|
74
|
-
render :action => :index
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
3
|
def new
|
79
|
-
|
80
|
-
|
81
|
-
|
4
|
+
payment_id = params[:payment_id]
|
5
|
+
invoice_id = params[:invoice_id]
|
6
|
+
account_id = params[:account_id]
|
82
7
|
|
83
|
-
@refund =
|
8
|
+
@refund = KillBillClient::Model::InvoiceItem.new
|
84
9
|
|
85
10
|
begin
|
86
|
-
@account = Kaui::
|
87
|
-
@payment = Kaui::
|
88
|
-
@invoice = Kaui::
|
11
|
+
@account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
|
12
|
+
@payment = Kaui::InvoicePayment::find_by_id(payment_id, false, options_for_klient)
|
13
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
89
14
|
rescue => e
|
90
15
|
flash[:error] = "Error while processing refund: #{as_string(e)}"
|
91
|
-
redirect_to kaui_engine.account_timeline_path(:id =>
|
16
|
+
redirect_to kaui_engine.account_timeline_path(:id => account_id)
|
92
17
|
end
|
93
18
|
end
|
94
19
|
|
95
20
|
def create
|
96
|
-
invoice = Kaui::
|
97
|
-
|
98
|
-
|
99
|
-
|
21
|
+
invoice = Kaui::Invoice.find_by_id_or_number(params[:invoice_id], true, 'NONE', options_for_klient)
|
22
|
+
|
23
|
+
items = []
|
24
|
+
if params[:adjustment_type] == 'invoiceItemAdjustment'
|
25
|
+
(params[:adjustments] || []).each do |ii|
|
26
|
+
original_item = find_original_item(invoice.items, ii[0])
|
100
27
|
|
101
|
-
|
102
|
-
|
103
|
-
params[:adjustments].each_with_index do |ii, idx|
|
104
|
-
original_item = find_original_item(invoice.items, ii[0])
|
105
|
-
h = Hash.new
|
106
|
-
h[:invoice_item_id] = ii[0]
|
28
|
+
item = KillBillClient::Model::InvoiceItem.new
|
29
|
+
item.invoice_item_id = ii[0]
|
107
30
|
# If we tried to do a partial item adjustment, we pass the value, if not we don't send any value and let the system
|
108
|
-
# decide what is the
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
refund["adjustments"][idx] = kaui_ii
|
31
|
+
# decide what is the maximum amount we can have on that item
|
32
|
+
item.amount = (ii[1].to_f == original_item.amount) ? nil : ii[1]
|
33
|
+
|
34
|
+
items << item
|
113
35
|
end
|
114
36
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
else
|
123
|
-
flash[:error] = "No refund to process"
|
37
|
+
|
38
|
+
begin
|
39
|
+
KillBillClient::Model::InvoicePayment.refund(params[:payment_id], params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
40
|
+
flash[:notice] = 'Refund created'
|
41
|
+
rescue => e
|
42
|
+
flash[:error] = "Error while processing refund: #{as_string(e)}"
|
124
43
|
end
|
44
|
+
|
125
45
|
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
|
126
46
|
end
|
127
47
|
|
@@ -1,121 +1,73 @@
|
|
1
|
-
require 'kaui/product'
|
2
|
-
|
3
1
|
class Kaui::SubscriptionsController < Kaui::EngineController
|
4
|
-
def index
|
5
|
-
if params[:subscription_id].present?
|
6
|
-
redirect_to kaui_engine.subscription_path(params[:subscription_id])
|
7
|
-
end
|
8
|
-
end
|
9
2
|
|
10
|
-
def
|
11
|
-
begin
|
12
|
-
@subscription = Kaui::KillbillHelper.get_subscription(params[:id], options_for_klient)
|
13
|
-
unless @subscription.present?
|
14
|
-
flash[:error] = "No subscription id given or subscription not found"
|
15
|
-
redirect_to :back
|
16
|
-
end
|
17
|
-
|
18
|
-
@account = Kaui::KillbillHelper::get_account_by_bundle_id(@subscription.bundle_id, options_for_klient)
|
19
|
-
unless @account.present?
|
20
|
-
flash[:error] = "Unable to retrieve account for bundle #{@subscription.bundle_id}"
|
21
|
-
redirect_to :back
|
22
|
-
end
|
23
|
-
rescue => e
|
24
|
-
flash.now[:error] = "Error while getting subscription information: #{as_string(e)}"
|
25
|
-
end
|
3
|
+
def index
|
26
4
|
end
|
27
5
|
|
28
6
|
def new
|
29
|
-
@
|
30
|
-
bundle_id
|
31
|
-
|
32
|
-
|
33
|
-
begin
|
7
|
+
@base_product_name = params[:base_product_name]
|
8
|
+
@subscription = Kaui::Subscription.new(:bundle_id => params[:bundle_id],
|
9
|
+
:account_id => params[:account_id],
|
10
|
+
:product_category => params[:product_category] || 'BASE')
|
34
11
|
|
35
|
-
|
36
|
-
|
37
|
-
@
|
38
|
-
|
39
|
-
|
12
|
+
begin
|
13
|
+
if @subscription.product_category == 'ADD_ON'
|
14
|
+
@bundle = Kaui::Bundle::find_by_id(@subscription.bundle_id, options_for_klient)
|
15
|
+
plans_details = Kaui::Catalog::available_addons(@base_product_name, options_for_klient)
|
16
|
+
else
|
17
|
+
plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
|
40
18
|
end
|
19
|
+
@plans = plans_details.map { |p| p.plan }
|
41
20
|
rescue => e
|
42
21
|
flash.now[:error] = "Error while trying to start new subscription creation: #{as_string(e)}"
|
22
|
+
render :action => :index
|
43
23
|
end
|
44
|
-
@subscription = Kaui::Subscription.new("bundleId" => bundle_id, "accountId" => @account_id, "product_category" => @product_category)
|
45
24
|
end
|
46
25
|
|
47
26
|
def create
|
48
|
-
|
49
|
-
@subscription = Kaui::Subscription.new(params[:subscription])
|
50
|
-
|
51
|
-
@plan_name = params[:plan_name]
|
27
|
+
@subscription = Kaui::Subscription.new(params[:subscription].delete_if { |key, value| value.blank? })
|
52
28
|
|
53
29
|
begin
|
54
|
-
if @subscription.product_category ==
|
55
|
-
@
|
56
|
-
|
57
|
-
@catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription, options_for_klient)
|
58
|
-
@subscription.account_id = @bundle.account_id
|
30
|
+
if @subscription.product_category == 'ADD_ON'
|
31
|
+
@bundle = Kaui::Bundle::find_by_id(@subscription.bundle_id, options_for_klient)
|
32
|
+
plans_details = Kaui::Catalog::available_addons(params[:base_product_name], options_for_klient)
|
59
33
|
else
|
60
|
-
|
61
|
-
@subscription.external_key = params[:external_key]
|
34
|
+
plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
|
62
35
|
end
|
63
36
|
|
64
|
-
plan
|
65
|
-
@subscription.billing_period =
|
66
|
-
@subscription.product_name
|
67
|
-
@subscription.price_list
|
68
|
-
|
69
|
-
res = Kaui::KillbillHelper::create_subscription(@subscription, current_user, params[:reason], params[:comment], options_for_klient)
|
37
|
+
plan_details = plans_details.find { |p| p.plan == params[:plan_name] }
|
38
|
+
@subscription.billing_period = plan_details.final_phase_billing_period
|
39
|
+
@subscription.product_name = plan_details.product
|
40
|
+
@subscription.price_list = plan_details.price_list
|
70
41
|
|
71
|
-
|
42
|
+
@subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
43
|
+
redirect_to bundle_path(@subscription.bundle_id), :notice => 'Subscription was successfully created'
|
72
44
|
rescue => e
|
73
|
-
|
45
|
+
@plans = plans_details.nil? ? [] : plans_details.map { |p| p.plan }
|
46
|
+
flash.now[:error] = "Error while creating the subscription: #{as_string(e)}"
|
74
47
|
render :new
|
75
48
|
end
|
76
49
|
end
|
77
50
|
|
78
|
-
def
|
79
|
-
@base_product_name = params[:base_product_name]
|
80
|
-
|
81
|
-
@account_id = params[:account_id]
|
82
|
-
@bundle_id = params[:bundle_id]
|
83
|
-
@product_name = params[:product_name]
|
84
|
-
@product_category = params[:product_category]
|
85
|
-
@billing_period = params[:billing_period]
|
86
|
-
@price_list = params[:price_list]
|
87
|
-
|
51
|
+
def show
|
88
52
|
begin
|
89
|
-
@subscription = Kaui::Subscription.
|
90
|
-
|
91
|
-
|
92
|
-
:product_category => @product_category,
|
93
|
-
:billing_period => @billing_period,
|
94
|
-
:price_list => @price_list)
|
95
|
-
|
96
|
-
@bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id, options_for_klient)
|
97
|
-
@available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name], options_for_klient)
|
53
|
+
@subscription = Kaui::Subscription.find_by_id(params[:id], options_for_klient)
|
54
|
+
# Need to retrieve the account for the timezone
|
55
|
+
@account = Kaui::Account::find_by_id(@subscription.account_id, false, false, options_for_klient)
|
98
56
|
rescue => e
|
99
|
-
flash.now[:error] = "Error while
|
57
|
+
flash.now[:error] = "Error while getting subscription information: #{as_string(e)}"
|
58
|
+
render :action => :index
|
100
59
|
end
|
101
60
|
end
|
102
61
|
|
103
62
|
def edit
|
104
63
|
begin
|
105
|
-
@subscription = Kaui::
|
106
|
-
|
107
|
-
|
108
|
-
@account = Kaui::KillbillHelper::get_account(@bundle.account_id, false, false, options_for_klient)
|
109
|
-
@catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
|
64
|
+
@subscription = Kaui::Subscription.find_by_id(params[:id], options_for_klient)
|
65
|
+
plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
|
66
|
+
@plans = plans_details.map { |p| p.plan }
|
110
67
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
@current_plan += " (price list #{@subscription.price_list})"
|
115
|
-
end
|
116
|
-
else
|
117
|
-
flash[:error] = "No subscription id given or subscription not found"
|
118
|
-
redirect_to :back
|
68
|
+
@current_plan = "#{@subscription.product_name} #{@subscription.billing_period}".humanize
|
69
|
+
if @subscription.price_list != 'DEFAULT'
|
70
|
+
@current_plan += " (price list #{@subscription.price_list})"
|
119
71
|
end
|
120
72
|
rescue => e
|
121
73
|
flash.now[:error] = "Error while editing subscription: #{as_string(e)}"
|
@@ -123,61 +75,65 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
123
75
|
end
|
124
76
|
|
125
77
|
def update
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
flash[:
|
78
|
+
requested_date = params[:requested_date] unless params[:requested_date].blank?
|
79
|
+
billing_policy = params[:policy] unless params[:policy].blank?
|
80
|
+
wait_for_completion = params[:wait_for_completion] == '1'
|
81
|
+
|
82
|
+
subscription = Kaui::Subscription.new(:subscription_id => params[:id])
|
83
|
+
|
84
|
+
begin
|
85
|
+
plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
|
86
|
+
new_plan_details = plans_details.find { |p| p.plan == params[:plan_name] }
|
87
|
+
|
88
|
+
subscription.change_plan({
|
89
|
+
:productName => new_plan_details.product,
|
90
|
+
:billingPeriod => new_plan_details.final_phase_billing_period,
|
91
|
+
:priceList => new_plan_details.price_list
|
92
|
+
},
|
93
|
+
current_user.kb_username,
|
94
|
+
params[:reason],
|
95
|
+
params[:comment],
|
96
|
+
requested_date,
|
97
|
+
billing_policy,
|
98
|
+
wait_for_completion,
|
99
|
+
options_for_klient)
|
100
|
+
flash[:notice] = 'Subscription plan successfully changed'
|
101
|
+
rescue => e
|
102
|
+
flash[:error] = "Error while changing subscription plan: #{as_string(e)}"
|
149
103
|
end
|
150
|
-
|
104
|
+
|
105
|
+
redirect_to subscription_path(subscription.subscription_id)
|
151
106
|
end
|
152
107
|
|
153
108
|
def destroy
|
154
|
-
|
109
|
+
requested_date = params[:requested_date] unless params[:requested_date].blank?
|
110
|
+
entitlement_policy = params[:policy] unless params[:policy].blank?
|
111
|
+
billing_policy = entitlement_policy
|
112
|
+
# true by default
|
113
|
+
use_requested_date_for_billing = (params[:use_requested_date_for_billing] || '1') == '1'
|
155
114
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
flash[:error] = "No subscription id given"
|
115
|
+
subscription = Kaui::Subscription.new(:subscription_id => params[:id])
|
116
|
+
|
117
|
+
begin
|
118
|
+
subscription.cancel(current_user.kb_username, params[:reason], params[:comment], requested_date, entitlement_policy, billing_policy, use_requested_date_for_billing, options_for_klient)
|
119
|
+
flash[:notice] = 'Subscription was successfully cancelled'
|
120
|
+
rescue => e
|
121
|
+
flash[:error] = "Error while canceling subscription: #{as_string(e)}"
|
164
122
|
end
|
165
|
-
|
123
|
+
|
124
|
+
redirect_to subscription_path(subscription.subscription_id)
|
166
125
|
end
|
167
126
|
|
168
127
|
def reinstate
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
else
|
178
|
-
flash[:error] = "No subscription id given"
|
128
|
+
subscription = Kaui::Subscription.new(:subscription_id => params[:id])
|
129
|
+
|
130
|
+
begin
|
131
|
+
subscription.uncancel(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
132
|
+
flash[:notice] = 'Subscription was successfully reinstated'
|
133
|
+
rescue => e
|
134
|
+
flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
|
179
135
|
end
|
180
|
-
redirect_to :back
|
181
|
-
end
|
182
136
|
|
137
|
+
redirect_to subscription_path(subscription.subscription_id)
|
138
|
+
end
|
183
139
|
end
|
@@ -1,90 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
flash.now[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
|
10
|
-
@tag_definitions = []
|
11
|
-
end
|
12
|
-
|
13
|
-
respond_to do |format|
|
14
|
-
format.html # index.html.erb
|
15
|
-
format.json { render :json => @tag_definitions }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# GET /tag_definitions/1
|
20
|
-
# GET /tag_definitions/1.json
|
21
|
-
def show
|
22
|
-
@tag_definition = TagDefinition.find(params[:id], options_for_klient)
|
23
|
-
|
24
|
-
respond_to do |format|
|
25
|
-
format.html # show.html.erb
|
26
|
-
format.json { render :json => @tag_definition }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# GET /tag_definitions/new
|
31
|
-
# GET /tag_definitions/new.json
|
32
|
-
def new
|
33
|
-
@tag_definition = TagDefinition.new
|
34
|
-
|
35
|
-
respond_to do |format|
|
36
|
-
format.html # new.html.erb
|
37
|
-
format.json { render :json => @tag_definition }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# GET /tag_definitions/1/edit
|
42
|
-
def edit
|
43
|
-
@tag_definition = TagDefinition.find(params[:id], options_for_klient)
|
1
|
+
class Kaui::TagDefinitionsController < Kaui::EngineController
|
2
|
+
|
3
|
+
def index
|
4
|
+
begin
|
5
|
+
@tag_definitions = Kaui::TagDefinition.all('NONE', options_for_klient)
|
6
|
+
rescue => e
|
7
|
+
flash.now[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
|
8
|
+
@tag_definitions = []
|
44
9
|
end
|
10
|
+
end
|
45
11
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@tag_definition = TagDefinition.new(params[:tag_definition])
|
12
|
+
def show
|
13
|
+
@tag_definition = Kaui::TagDefinition.find_by_id(params[:id], 'NONE', options_for_klient)
|
14
|
+
end
|
50
15
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
format.json { render :json => @tag_definition, :status => :created, :location => @tag_definition }
|
55
|
-
else
|
56
|
-
format.html { render :action => "new" }
|
57
|
-
format.json { render :json => @tag_definition.errors, :status => :unprocessable_entity }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
16
|
+
def new
|
17
|
+
@tag_definition = Kaui::TagDefinition.new
|
18
|
+
end
|
61
19
|
|
62
|
-
|
63
|
-
|
64
|
-
def update
|
65
|
-
@tag_definition = TagDefinition.find(params[:id], options_for_klient)
|
20
|
+
def create
|
21
|
+
@tag_definition = Kaui::TagDefinition.new(params[:tag_definition])
|
66
22
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
format.json { render :json => @tag_definition.errors, :status => :unprocessable_entity }
|
74
|
-
end
|
75
|
-
end
|
23
|
+
begin
|
24
|
+
@tag_definition = @tag_definition.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
25
|
+
redirect_to kaui_engine.tag_definition_path(@tag_definition.id), :notice => 'Tag definition successfully created'
|
26
|
+
rescue => e
|
27
|
+
flash.now[:error] = "Error while creating tag definition: #{as_string(e)}"
|
28
|
+
render :action => :new
|
76
29
|
end
|
30
|
+
end
|
77
31
|
|
78
|
-
|
79
|
-
|
80
|
-
def destroy
|
81
|
-
@tag_definition = TagDefinition.find(params[:id], options_for_klient)
|
82
|
-
@tag_definition.destroy(current_user, params[:reason], params[:comment], options_for_klient)
|
32
|
+
def destroy
|
33
|
+
@tag_definition = Kaui::TagDefinition.find_by_id(params[:id], 'NONE', options_for_klient)
|
83
34
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
35
|
+
begin
|
36
|
+
@tag_definition.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
37
|
+
redirect_to kaui_engine.tag_definitions_path, :notice => 'Tag definition successfully deleted'
|
38
|
+
rescue => e
|
39
|
+
flash.now[:error] = "Error while deleting tag definition: #{as_string(e)}"
|
40
|
+
render :action => :index
|
88
41
|
end
|
89
42
|
end
|
90
43
|
end
|
@@ -4,27 +4,29 @@ class Kaui::TagsController < Kaui::EngineController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def pagination
|
7
|
-
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
8
|
-
|
9
7
|
search_key = params[:sSearch]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
json
|
16
|
-
|
8
|
+
offset = params[:iDisplayStart] || 0
|
9
|
+
limit = params[:iDisplayLength] || 10
|
10
|
+
|
11
|
+
tags = Kaui::Tag.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
|
13
|
+
json = {
|
14
|
+
:sEcho => params[:sEcho],
|
15
|
+
:iTotalRecords => tags.pagination_max_nb_records,
|
16
|
+
:iTotalDisplayRecords => tags.pagination_total_nb_records,
|
17
|
+
:aaData => []
|
18
|
+
}
|
17
19
|
|
18
20
|
tags.each do |tag|
|
19
21
|
json[:aaData] << [
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
tag.tag_id,
|
23
|
+
tag.object_type,
|
24
|
+
tag.tag_definition_name,
|
25
|
+
]
|
24
26
|
end
|
25
27
|
|
26
28
|
respond_to do |format|
|
27
29
|
format.json { render :json => json }
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Kaui::TransactionsController < Kaui::EngineController
|
2
|
+
|
3
|
+
def new
|
4
|
+
@account_id = params[:account_id]
|
5
|
+
@payment_method_id = params[:payment_method_id]
|
6
|
+
@transaction = Kaui::Transaction.new(:payment_id => params[:payment_id],
|
7
|
+
:amount => params[:amount],
|
8
|
+
:currency => params[:currency],
|
9
|
+
:transaction_type => params[:transaction_type])
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@account_id = params[:account_id]
|
14
|
+
@payment_method_id = params[:payment_method_id]
|
15
|
+
@transaction = Kaui::Transaction.new(params[:transaction].delete_if { |key, value| value.blank? })
|
16
|
+
|
17
|
+
begin
|
18
|
+
payment = @transaction.create(@account_id, @payment_method_id, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
19
|
+
redirect_to kaui_engine.account_timeline_path(:id => payment.account_id), :notice => 'Transaction successfully created'
|
20
|
+
rescue => e
|
21
|
+
flash.now[:error] = "Error while creating a new transaction: #{as_string(e)}"
|
22
|
+
render :action => :new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|