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,31 +1,31 @@
|
|
1
1
|
class Kaui::AccountsController < Kaui::EngineController
|
2
|
+
|
2
3
|
def index
|
3
|
-
if params[:account_id].present?
|
4
|
-
redirect_to kaui_engine.account_path(params[:account_id])
|
5
|
-
end
|
6
4
|
end
|
7
5
|
|
8
6
|
def pagination
|
9
|
-
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
10
|
-
|
11
7
|
search_key = params[:sSearch]
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
json
|
18
|
-
|
8
|
+
offset = params[:iDisplayStart] || 0
|
9
|
+
limit = params[:iDisplayLength] || 10
|
10
|
+
|
11
|
+
accounts = Kaui::Account.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
|
13
|
+
json = {
|
14
|
+
:sEcho => params[:sEcho],
|
15
|
+
:iTotalRecords => accounts.pagination_max_nb_records,
|
16
|
+
:iTotalDisplayRecords => accounts.pagination_total_nb_records,
|
17
|
+
:aaData => []
|
18
|
+
}
|
19
19
|
|
20
20
|
accounts.each do |account|
|
21
21
|
json[:aaData] << [
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
view_context.link_to(view_context.truncate_uuid(account.account_id), view_context.url_for(:action => :show, :id => account.account_id)),
|
23
|
+
account.name,
|
24
|
+
account.external_key,
|
25
|
+
account.currency,
|
26
|
+
account.city,
|
27
|
+
account.country
|
28
|
+
]
|
29
29
|
end
|
30
30
|
|
31
31
|
respond_to do |format|
|
@@ -33,163 +33,83 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
if @key.present?
|
39
|
-
# Remove extra whitespaces
|
40
|
-
@key.strip!
|
41
|
-
|
42
|
-
begin
|
43
|
-
@account = Kaui::KillbillHelper::get_account_by_key_with_balance_and_cba(@key, options_for_klient)
|
44
|
-
rescue URI::InvalidURIError => e
|
45
|
-
flash.now[:error] = "Error while retrieving the account for #{@key}: #{e.message}"
|
46
|
-
render :action => :index and return
|
47
|
-
rescue => e
|
48
|
-
flash.now[:error] = "Error while retrieving the account for #{@key}: #{as_string(e)}"
|
49
|
-
render :action => :index and return
|
50
|
-
end
|
51
|
-
|
52
|
-
if @account.present? and @account.is_a? Kaui::Account
|
53
|
-
begin
|
54
|
-
@tags = Kaui::KillbillHelper::get_tags_for_account(@account.account_id, false, "NONE", options_for_klient).sort { |tag_a, tag_b| tag_a.tag_definition_name.downcase <=> tag_b.tag_definition_name.downcase }
|
55
|
-
@account_emails = Kaui::AccountEmail.where({ :account_id => @account.account_id }, options_for_klient)
|
56
|
-
@overdue_state = Kaui::KillbillHelper::get_overdue_state_for_account(@account.account_id, options_for_klient)
|
57
|
-
@payment_methods = Kaui::KillbillHelper::get_non_external_payment_methods(@account.account_id, options_for_klient)
|
58
|
-
@bundles = Kaui::KillbillHelper::get_bundles_for_account(@account.account_id, options_for_klient)
|
59
|
-
|
60
|
-
@subscriptions_by_bundle_id = {}
|
61
|
-
|
62
|
-
@bundles.each do |bundle|
|
63
|
-
@subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + bundle.subscriptions
|
64
|
-
end
|
65
|
-
rescue => e
|
66
|
-
flash.now[:error] = "Error while retrieving account information for account: #{as_string(e)}"
|
67
|
-
render :action => :index
|
68
|
-
end
|
69
|
-
else
|
70
|
-
flash.now[:error] = "Account #{@account_id} not found: #{@account}"
|
71
|
-
render :action => :index
|
72
|
-
end
|
73
|
-
else
|
74
|
-
flash.now[:error] = "No id given"
|
75
|
-
end
|
36
|
+
def new
|
37
|
+
@account = Kaui::Account.new
|
76
38
|
end
|
77
39
|
|
78
|
-
def
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
else
|
92
|
-
flash.now[:notice] = "No account_id given"
|
40
|
+
def create
|
41
|
+
@account = Kaui::Account.new(params[:account].delete_if { |key, value| value.blank? })
|
42
|
+
|
43
|
+
# Transform "1" into boolean
|
44
|
+
@account.is_migrated = @account.is_migrated == '1'
|
45
|
+
@account.is_notified_for_invoices = @account.is_notified_for_invoices == '1'
|
46
|
+
|
47
|
+
begin
|
48
|
+
@account = @account.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
49
|
+
redirect_to account_path(@account.account_id), :notice => 'Account was successfully created'
|
50
|
+
rescue => e
|
51
|
+
flash.now[:error] = "Error while creating account: #{as_string(e)}"
|
52
|
+
render :action => :new
|
93
53
|
end
|
94
54
|
end
|
95
55
|
|
96
|
-
def
|
97
|
-
account_id = params[:id]
|
56
|
+
def show
|
98
57
|
begin
|
99
|
-
@account
|
58
|
+
@account = Kaui::Account::find_by_id_or_key(params[:id], true, true, options_for_klient)
|
59
|
+
@overdue_state = @account.overdue(options_for_klient)
|
60
|
+
@bundles = @account.bundles(options_for_klient)
|
61
|
+
@tags = @account.tags(false, 'NONE', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
|
62
|
+
|
63
|
+
@account_emails = Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', options_for_klient)
|
64
|
+
@payment_methods = Kaui::PaymentMethod.find_non_external_by_account_id(@account.account_id, true, options_for_klient)
|
100
65
|
rescue => e
|
101
|
-
flash.now[:error] = "Error while
|
66
|
+
flash.now[:error] = "Error while retrieving account information: #{as_string(e)}"
|
67
|
+
render :action => :index and return
|
102
68
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
render "kaui/payment_methods/new"
|
69
|
+
|
70
|
+
@subscriptions_by_bundle_id = {}
|
71
|
+
@bundles.each do |bundle|
|
72
|
+
@subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + bundle.subscriptions
|
108
73
|
end
|
109
74
|
end
|
110
75
|
|
111
|
-
def
|
112
|
-
account_id
|
113
|
-
|
114
|
-
@account = Kaui::KillbillHelper::get_account(account_id, false, false, options_for_klient)
|
115
|
-
|
116
|
-
# Implementation example using standard credit card fields
|
117
|
-
@card_type = params[:card_type]
|
118
|
-
@card_holder_name = params[:card_holder_name]
|
119
|
-
@expiration_year = params[:expiration_year]
|
120
|
-
@expiration_month = params[:expiration_month]
|
121
|
-
@credit_card_number = params[:credit_card_number]
|
122
|
-
@address1 = params[:address1]
|
123
|
-
@address2 = params[:address2]
|
124
|
-
@city = params[:city]
|
125
|
-
@country = params[:country]
|
126
|
-
@postal_code = params[:postal_code]
|
127
|
-
@state = params[:state]
|
128
|
-
@is_default = params[:is_default]
|
129
|
-
@reason = params[:reason]
|
130
|
-
@comment = params[:comment]
|
131
|
-
|
132
|
-
payment_method = KillBillClient::Model::PaymentMethod.new
|
133
|
-
payment_method.account_id = account_id
|
134
|
-
payment_method.plugin_name = params[:plugin_name] || Kaui.creditcard_plugin_name.call
|
135
|
-
|
136
|
-
payment_method.plugin_info = {
|
137
|
-
'type' => 'CreditCard',
|
138
|
-
'ccType' => @card_type,
|
139
|
-
'ccName' => @card_holder_name,
|
140
|
-
'ccExpirationMonth' => @expiration_month,
|
141
|
-
'ccExpirationYear' => @expiration_year,
|
142
|
-
'ccLast4' => @credit_card_number[-4,4],
|
143
|
-
'address1' => @address1,
|
144
|
-
'address2' => @address2,
|
145
|
-
'city' => @city,
|
146
|
-
'country' => @country,
|
147
|
-
'zip' => @postal_code,
|
148
|
-
'state' => @state
|
149
|
-
}
|
76
|
+
def set_default_payment_method
|
77
|
+
account_id = params[:id]
|
78
|
+
payment_method_id = params[:payment_method_id]
|
150
79
|
|
151
80
|
begin
|
152
|
-
Kaui::
|
153
|
-
flash[:notice] =
|
154
|
-
redirect_to kaui_engine.account_timeline_path(account_id)
|
81
|
+
Kaui::PaymentMethod.set_default(payment_method_id, account_id, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
82
|
+
flash[:notice] = "Successfully set #{payment_method_id} as default"
|
155
83
|
rescue => e
|
156
|
-
flash
|
157
|
-
render "kaui/payment_methods/new"
|
84
|
+
flash[:error] = "Error while setting payment method #{payment_method_id} as default: #{as_string(e)}"
|
158
85
|
end
|
159
|
-
end
|
160
86
|
|
161
|
-
|
162
|
-
@account_id = params[:id]
|
163
|
-
@payment_method_id = params[:payment_method_id]
|
164
|
-
if @account_id.present? && @payment_method_id.present?
|
165
|
-
begin
|
166
|
-
@payment_methods = Kaui::KillbillHelper::set_payment_method_as_default(@account_id, @payment_method_id, current_user, params[:reason], params[:comment], options_for_klient)
|
167
|
-
rescue => e
|
168
|
-
flash[:error] = "Error while setting payment method as default #{@payment_method_id}: #{as_string(e)}"
|
169
|
-
end
|
170
|
-
else
|
171
|
-
flash[:notice] = 'No account_id or payment_method_id given'
|
172
|
-
end
|
173
|
-
redirect_to :back
|
87
|
+
redirect_to account_path(account_id)
|
174
88
|
end
|
175
89
|
|
176
90
|
def toggle_email_notifications
|
91
|
+
account = Kaui::Account.new(:account_id => params[:id], :is_notified_for_invoices => params[:is_notified])
|
92
|
+
|
177
93
|
begin
|
178
|
-
|
179
|
-
flash[:notice] =
|
94
|
+
account.update_email_notifications(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
95
|
+
flash[:notice] = 'Email preferences updated'
|
180
96
|
rescue => e
|
181
|
-
flash[:error] = "Error while
|
97
|
+
flash[:error] = "Error while setting email notifications: #{as_string(e)}"
|
182
98
|
end
|
183
|
-
|
99
|
+
|
100
|
+
redirect_to account_path(account.account_id)
|
184
101
|
end
|
185
102
|
|
186
103
|
def pay_all_invoices
|
104
|
+
payment = Kaui::InvoicePayment.new(:account_id => params[:id])
|
105
|
+
|
187
106
|
begin
|
188
|
-
|
189
|
-
flash[:notice] =
|
107
|
+
payment.bulk_create(params[:is_external_payment], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
108
|
+
flash[:notice] = 'Successfully triggered a payment for all unpaid invoices'
|
190
109
|
rescue => e
|
191
110
|
flash[:error] = "Error while triggering payments: #{as_string(e)}"
|
192
111
|
end
|
193
|
-
|
112
|
+
|
113
|
+
redirect_to account_path(payment.account_id)
|
194
114
|
end
|
195
115
|
end
|
@@ -1,39 +1,50 @@
|
|
1
1
|
class Kaui::BundleTagsController < Kaui::EngineController
|
2
2
|
|
3
3
|
def show
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
flash
|
4
|
+
bundle_id_or_key = params[:bundle_id]
|
5
|
+
account_id = params[:account_id]
|
6
|
+
|
7
|
+
begin
|
8
|
+
@bundle = Kaui::Bundle::find_by_id_or_key(bundle_id_or_key, account_id, options_for_klient)
|
9
|
+
@account = Kaui::Account::find_by_id_or_key(@bundle.account_id, false, false, options_for_klient)
|
10
|
+
@tags = @bundle.tags(true, 'FULL', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
|
11
|
+
rescue => e
|
12
|
+
flash[:error] = "Error while getting tags: #{as_string(e)}"
|
13
|
+
redirect_to :back
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def edit
|
17
|
-
|
18
|
-
|
19
|
-
@available_tags = Kaui::KillbillHelper::get_tag_definitions(options_for_klient).sort {|tag_a, tag_b| tag_a.name.downcase <=> tag_b.name.downcase }
|
18
|
+
bundle_id_or_key = params[:bundle_id]
|
19
|
+
account_id = params[:account_id]
|
20
20
|
|
21
|
-
|
22
|
-
@
|
21
|
+
begin
|
22
|
+
@bundle = Kaui::Bundle::find_by_id_or_key(bundle_id_or_key, account_id, options_for_klient)
|
23
|
+
@tag_names = (@bundle.tags(false, 'NONE', options_for_klient).map { |tag| tag.tag_definition_name }).sort
|
24
|
+
@available_tags = Kaui::TagDefinition.all_for_bundle(options_for_klient)
|
23
25
|
rescue => e
|
24
|
-
flash
|
26
|
+
flash[:error] = "Error while editing tags: #{as_string(e)}"
|
27
|
+
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id_or_key)
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def update
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
bundle_id = params[:bundle_id]
|
33
|
+
|
34
|
+
tags = []
|
35
|
+
params.each do |tag, tag_name|
|
36
|
+
tag_info = tag.split('_')
|
37
|
+
next if tag_info.size != 2 or tag_info[0] != 'tag'
|
38
|
+
tags << tag_info[1]
|
39
|
+
end
|
32
40
|
|
33
|
-
|
34
|
-
|
41
|
+
begin
|
42
|
+
bundle = Kaui::Bundle.new(:bundle_id => bundle_id)
|
43
|
+
bundle.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
44
|
+
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id), :notice => 'Bundle tags successfully set'
|
35
45
|
rescue => e
|
36
|
-
flash
|
46
|
+
flash[:error] = "Error while updating tags: #{as_string(e)}"
|
47
|
+
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id)
|
37
48
|
end
|
38
49
|
end
|
39
50
|
end
|
@@ -1,30 +1,29 @@
|
|
1
1
|
class Kaui::BundlesController < Kaui::EngineController
|
2
2
|
|
3
3
|
def index
|
4
|
-
if params[:bundle_id].present?
|
5
|
-
redirect_to kaui_engine.bundle_path(params[:bundle_id])
|
6
|
-
end
|
7
4
|
end
|
8
5
|
|
9
6
|
def pagination
|
10
|
-
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
11
|
-
|
12
7
|
search_key = params[:sSearch]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
json
|
19
|
-
|
8
|
+
offset = params[:iDisplayStart] || 0
|
9
|
+
limit = params[:iDisplayLength] || 10
|
10
|
+
|
11
|
+
bundles = Kaui::Bundle.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
|
13
|
+
json = {
|
14
|
+
:sEcho => params[:sEcho],
|
15
|
+
:iTotalRecords => bundles.pagination_max_nb_records,
|
16
|
+
:iTotalDisplayRecords => bundles.pagination_total_nb_records,
|
17
|
+
:aaData => []
|
18
|
+
}
|
20
19
|
|
21
20
|
bundles.each do |bundle|
|
22
21
|
json[:aaData] << [
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
view_context.link_to(view_context.truncate_uuid(bundle.bundle_id), view_context.url_for(:action => :show, :id => bundle.bundle_id)),
|
23
|
+
view_context.link_to(view_context.truncate_uuid(bundle.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => bundle.account_id)),
|
24
|
+
bundle.external_key,
|
25
|
+
bundle.subscriptions.nil? ? '' : (bundle.subscriptions.map { |s| s.product_name }).join(', ')
|
26
|
+
]
|
28
27
|
end
|
29
28
|
|
30
29
|
respond_to do |format|
|
@@ -33,75 +32,51 @@ class Kaui::BundlesController < Kaui::EngineController
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def show
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@account = Kaui::KillbillHelper::get_account(@bundle.account_id, false, false, options_for_klient)
|
43
|
-
@subscriptions = @bundle.subscriptions
|
44
|
-
else
|
45
|
-
flash.now[:error] = "Bundle #{key} not found"
|
46
|
-
render :action => :index
|
47
|
-
end
|
48
|
-
rescue => e
|
49
|
-
flash.now[:error] = "Error while retrieving bundle information for #{key}: #{as_string(e)}"
|
50
|
-
render :action => :index
|
51
|
-
end
|
52
|
-
else
|
53
|
-
flash.now[:error] = "No id given"
|
35
|
+
begin
|
36
|
+
@bundle = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
|
37
|
+
@account = Kaui::Account::find_by_id(@bundle.account_id, false, false, options_for_klient)
|
38
|
+
@tags = @bundle.tags(false, 'NONE', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
|
39
|
+
rescue => e
|
40
|
+
flash.now[:error] = "Error while retrieving bundle information: #{as_string(e)}"
|
54
41
|
render :action => :index
|
55
42
|
end
|
56
43
|
end
|
57
44
|
|
58
45
|
def transfer
|
59
|
-
bundle_id = params[:id]
|
60
46
|
begin
|
61
|
-
@bundle
|
62
|
-
@account = Kaui::
|
47
|
+
@bundle = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
|
48
|
+
@account = Kaui::Account::find_by_id(@bundle.account_id, false, false, options_for_klient)
|
63
49
|
rescue => e
|
64
50
|
flash.now[:error] = "Error while preparing to transfer bundle: #{as_string(e)}"
|
65
|
-
|
66
|
-
if @account.nil?
|
67
|
-
flash.now[:error] = "Account not found for bundle id #{bundle_id}"
|
51
|
+
render :action => :index
|
68
52
|
end
|
69
53
|
end
|
70
54
|
|
71
55
|
def do_transfer
|
72
|
-
bundle_id = params[:id]
|
73
56
|
key = params[:new_account_key]
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.account_id, false, true, current_user, params[:reason], params[:comment], options_for_klient)
|
86
|
-
flash[:notice] = "Bundle transfered successfully"
|
87
|
-
rescue => e
|
88
|
-
flash[:error] = "Error transfering bundle #{as_string(e)}"
|
89
|
-
end
|
90
|
-
redirect_to Kaui.account_home_path.call(@new_account.external_key)
|
91
|
-
return
|
92
|
-
else
|
93
|
-
flash.now[:error] = "Could not retrieve account #{result}"
|
94
|
-
end
|
95
|
-
else
|
96
|
-
flash.now[:error] = "No account key given"
|
57
|
+
unless key.present?
|
58
|
+
flash.now[:error] = 'No new account key given'
|
59
|
+
render :action => :index and return
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
# Retrieve the new account to get the account id
|
64
|
+
new_account = Kaui::Account::find_by_id_or_key(params[:new_account_key], false, false, options_for_klient)
|
65
|
+
rescue => e
|
66
|
+
flash.now[:error] = "Error while retrieving new account: #{as_string(e)}"
|
67
|
+
render :action => :index and return
|
97
68
|
end
|
98
69
|
|
99
70
|
begin
|
100
|
-
|
101
|
-
|
71
|
+
billing_policy = params[:billing_policy]
|
72
|
+
|
73
|
+
bundle = Kaui::Bundle::new(:bundle_id => params[:id], :account_id => new_account.account_id)
|
74
|
+
bundle.transfer(nil, billing_policy, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
75
|
+
|
76
|
+
redirect_to account_path(new_account.account_id), :notice => 'Bundle was successfully transferred'
|
102
77
|
rescue => e
|
103
|
-
flash.now[:error] = "Error while
|
104
|
-
render :
|
78
|
+
flash.now[:error] = "Error while transferring bundle: #{as_string(e)}"
|
79
|
+
render :action => :index
|
105
80
|
end
|
106
81
|
end
|
107
82
|
end
|
@@ -1,79 +1,49 @@
|
|
1
1
|
class Kaui::ChargebacksController < Kaui::EngineController
|
2
2
|
|
3
|
-
def show
|
4
|
-
@payment_id = params[:id]
|
5
|
-
if @payment_id.present?
|
6
|
-
begin
|
7
|
-
data = Kaui::KillbillHelper::get_chargebacks_for_payment(@payment_id, options_for_klient)
|
8
|
-
rescue => e
|
9
|
-
flash.now[:error] = "Error while getting chargeback information: #{as_string(e)}"
|
10
|
-
end
|
11
|
-
if data.present?
|
12
|
-
@chargeback = Kaui::Chargeback.new(data)
|
13
|
-
else
|
14
|
-
Rails.logger.warn("Did not get back chargebacks #{response_body}")
|
15
|
-
end
|
16
|
-
else
|
17
|
-
flash.now[:notice] = "No id given"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
3
|
def new
|
22
|
-
@payment_id = params[:payment_id]
|
23
|
-
@account_id = params[:account_id]
|
24
|
-
@invoice_id = params[:invoice_id]
|
25
|
-
|
26
4
|
begin
|
27
|
-
|
28
|
-
@payment = Kaui::KillbillHelper::get_payment(@payment_id, options_for_klient)
|
29
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
|
5
|
+
payment = Kaui::Payment::find_by_id(params[:payment_id], options_for_klient)
|
30
6
|
rescue => e
|
31
|
-
flash[:error] = "Error while
|
32
|
-
redirect_to
|
7
|
+
flash[:error] = "Error while retrieving payment: #{as_string(e)}"
|
8
|
+
redirect_to :back
|
33
9
|
end
|
34
10
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@chargeback = Kaui::Chargeback.new("paymentId" => @payment_id,
|
39
|
-
"chargebackAmount" => @payment.amount)
|
11
|
+
@chargeback = Kaui::Chargeback.new(:payment_id => payment.payment_id,
|
12
|
+
:amount => payment.paid_amount_to_money.to_f,
|
13
|
+
:currency => payment.currency)
|
40
14
|
end
|
41
15
|
|
42
16
|
def create
|
43
|
-
chargeback
|
44
|
-
should_cancel_subs = (params[:cancel_all_subs] ==
|
45
|
-
|
46
|
-
if chargeback.present?
|
47
|
-
begin
|
48
|
-
Kaui::KillbillHelper::create_chargeback(chargeback, current_user, params[:reason], params[:comment], options_for_klient)
|
49
|
-
rescue => e
|
50
|
-
flash[:error] = "Error while creating a new chargeback: #{as_string(e)}"
|
51
|
-
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id]) and return
|
52
|
-
end
|
17
|
+
@chargeback = Kaui::Chargeback.new(params[:chargeback])
|
18
|
+
should_cancel_subs = (params[:cancel_all_subs] == '1')
|
53
19
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
# Already cancelled?
|
61
|
-
next unless subscription.billing_end_date.blank?
|
20
|
+
begin
|
21
|
+
payment = @chargeback.chargeback(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
22
|
+
rescue => e
|
23
|
+
flash.now[:error] = "Error while creating a new chargeback: #{as_string(e)}"
|
24
|
+
render :action => :new and return
|
25
|
+
end
|
62
26
|
|
63
|
-
|
64
|
-
|
65
|
-
|
27
|
+
# Cancel all subscriptions on the account, if required
|
28
|
+
if should_cancel_subs
|
29
|
+
begin
|
30
|
+
account = Kaui::Account.find_by_id(payment.account_id, false, false, options_for_klient)
|
31
|
+
account.bundles(options_for_klient).each do |bundle|
|
32
|
+
bundle.subscriptions.each do |subscription|
|
33
|
+
# Already cancelled?
|
34
|
+
next unless subscription.billing_end_date.blank?
|
35
|
+
|
36
|
+
# Cancel the entitlement immediately but use the default billing policy
|
37
|
+
entitlement = Kaui::Subscription.new(:subscription_id => subscription.subscription_id)
|
38
|
+
entitlement.cancel_entitlement_immediately(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
66
39
|
end
|
67
|
-
rescue => e
|
68
|
-
flash[:error] = "Error while cancelling subscriptions: #{as_string(e)}"
|
69
|
-
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id]) and return
|
70
40
|
end
|
41
|
+
rescue => e
|
42
|
+
flash[:error] = "Error while cancelling subscriptions: #{as_string(e)}"
|
43
|
+
render :action => :new and return
|
71
44
|
end
|
72
|
-
|
73
|
-
flash[:notice] = "Chargeback created"
|
74
|
-
else
|
75
|
-
flash[:error] = "No chargeback to process"
|
76
45
|
end
|
77
|
-
|
46
|
+
|
47
|
+
redirect_to kaui_engine.account_timeline_path(:id => payment.account_id), :notice => 'Chargeback created'
|
78
48
|
end
|
79
49
|
end
|
@@ -1,34 +1,32 @@
|
|
1
1
|
class Kaui::ChargesController < Kaui::EngineController
|
2
2
|
|
3
3
|
def new
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
4
|
+
invoice_id = params[:invoice_id]
|
5
|
+
account_id = params[:account_id]
|
6
|
+
currency = params[:currency] || 'USD'
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
|
8
|
+
if invoice_id.present?
|
9
|
+
begin
|
10
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
11
|
+
account_id = @invoice.account_id
|
12
|
+
currency = @invoice.currency
|
13
|
+
rescue => e
|
14
|
+
flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
|
14
15
|
end
|
15
|
-
rescue => e
|
16
|
-
flash.now[:error] = "Error while creating a charge: #{as_string(e)}"
|
17
16
|
end
|
17
|
+
|
18
|
+
@charge = Kaui::InvoiceItem.new(:account_id => account_id, :invoice_id => invoice_id, :currency => currency)
|
18
19
|
end
|
19
20
|
|
20
21
|
def create
|
21
|
-
charge = Kaui::
|
22
|
+
@charge = Kaui::InvoiceItem.new(params[:invoice_item].delete_if { |key, value| value.blank? })
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
flash.now[:error] = "Error while creating a charge: #{as_string(e)}"
|
30
|
-
end
|
24
|
+
begin
|
25
|
+
@charge = @charge.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
26
|
+
redirect_to kaui_engine.invoice_path(:id => @charge.invoice_id), :notice => 'Charge was successfully created'
|
27
|
+
rescue => e
|
28
|
+
flash.now[:error] = "Error while creating a charge: #{as_string(e)}"
|
29
|
+
render :action => :new
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|