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,51 +1,37 @@
|
|
1
1
|
class Kaui::CreditsController < Kaui::EngineController
|
2
|
-
def show
|
3
|
-
@account_id = params[:account_id]
|
4
|
-
@invoice_id = params[:invoice_id]
|
5
2
|
|
6
|
-
|
3
|
+
def new
|
4
|
+
invoice_id = params[:invoice_id]
|
5
|
+
account_id = params[:account_id]
|
6
|
+
amount = params[:amount]
|
7
|
+
currency = params[:currency] || 'USD'
|
8
|
+
|
9
|
+
if invoice_id.present?
|
7
10
|
begin
|
8
|
-
|
9
|
-
|
11
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
12
|
+
account_id = @invoice.account_id
|
13
|
+
amount ||= @invoice.balance
|
14
|
+
currency = @invoice.currency
|
10
15
|
rescue => e
|
11
|
-
flash.now[:error] = "
|
12
|
-
end
|
13
|
-
if data.present?
|
14
|
-
@credit = Kaui::Credit.new(data)
|
15
|
-
else
|
16
|
-
Rails.logger.warn("Did not get back external payments #{response_body}")
|
16
|
+
flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
|
17
17
|
end
|
18
|
-
else
|
19
|
-
flash.now[:notice] = "No id given"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def new
|
24
|
-
@account_id = params[:account_id]
|
25
|
-
@invoice_id = params[:invoice_id]
|
26
|
-
|
27
|
-
begin
|
28
|
-
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
29
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient) unless @invoice_id.nil?
|
30
|
-
rescue => e
|
31
|
-
flash.now[:error] = "Error while starting to create credit: #{as_string(e)}"
|
32
18
|
end
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
20
|
+
# TODO Specifying a custom currency is not supported yet
|
21
|
+
@credit = Kaui::Credit.new(:invoice_id => invoice_id,
|
22
|
+
:account_id => account_id,
|
23
|
+
:credit_amount => amount)
|
38
24
|
end
|
39
25
|
|
40
26
|
def create
|
41
|
-
credit = params[:credit]
|
27
|
+
@credit = Kaui::Credit.new(params[:credit].delete_if { |key, value| value.blank? })
|
28
|
+
|
42
29
|
begin
|
43
|
-
|
44
|
-
|
45
|
-
flash[:notice] = "Credit created"
|
30
|
+
@credit = @credit.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
31
|
+
redirect_to kaui_engine.invoice_path(:id => @credit.invoice_id), :notice => 'Credit was successfully created'
|
46
32
|
rescue => e
|
47
|
-
flash[:error] = "Error while
|
33
|
+
flash.now[:error] = "Error while creating a credit: #{as_string(e)}"
|
34
|
+
render :action => :new
|
48
35
|
end
|
49
|
-
redirect_to Kaui.account_home_path.call(credit['account_id'])
|
50
36
|
end
|
51
37
|
end
|
@@ -4,26 +4,28 @@ class Kaui::CustomFieldsController < 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
|
+
custom_fields = Kaui::CustomField.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
|
13
|
+
json = {
|
14
|
+
:sEcho => params[:sEcho],
|
15
|
+
:iTotalRecords => custom_fields.pagination_max_nb_records,
|
16
|
+
:iTotalDisplayRecords => custom_fields.pagination_total_nb_records,
|
17
|
+
:aaData => []
|
18
|
+
}
|
17
19
|
|
18
20
|
custom_fields.each do |custom_field|
|
19
21
|
json[:aaData] << [
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
custom_field.name,
|
23
|
+
custom_field.value
|
24
|
+
]
|
23
25
|
end
|
24
26
|
|
25
27
|
respond_to do |format|
|
26
28
|
format.json { render :json => json }
|
27
29
|
end
|
28
30
|
end
|
29
|
-
end
|
31
|
+
end
|
@@ -6,18 +6,18 @@ class Kaui::EngineController < ApplicationController
|
|
6
6
|
# Common options for the Kill Bill client
|
7
7
|
def options_for_klient(options = {})
|
8
8
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
# TODO Kaui doesn't support multi-tenancy yet
|
10
|
+
:api_key => KillBillClient.api_key,
|
11
|
+
:api_secret => KillBillClient.api_secret,
|
12
|
+
:username => current_user.kb_username || KillBillClient.username,
|
13
|
+
:password => current_user.password || KillBillClient.password,
|
14
|
+
:session_id => current_user.kb_session_id
|
15
15
|
}.merge(options)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Used for auditing purposes
|
19
19
|
def current_user
|
20
|
-
super
|
20
|
+
super
|
21
21
|
end
|
22
22
|
|
23
23
|
def current_ability
|
@@ -28,9 +28,7 @@ class Kaui::EngineController < ApplicationController
|
|
28
28
|
protected
|
29
29
|
|
30
30
|
def as_string(e)
|
31
|
-
if e.is_a?(
|
32
|
-
"#{e.message}, server response: #{as_string_from_response(e.response)}".split(/\n/).take(5).join("\n")
|
33
|
-
elsif e.is_a?(KillBillClient::API::ResponseError)
|
31
|
+
if e.is_a?(KillBillClient::API::ResponseError)
|
34
32
|
"Error #{e.response.code}: #{as_string_from_response(e.response.body)}"
|
35
33
|
else
|
36
34
|
e.message
|
@@ -1,59 +1,42 @@
|
|
1
1
|
class Kaui::InvoiceItemsController < Kaui::EngineController
|
2
|
-
def index
|
3
|
-
if params[:invoice_item_id].present? and params[:invoice_id].present?
|
4
|
-
redirect_to kaui_engine.invoice_item_path(params[:invoice_item_id], :invoice_id => params[:invoice_id])
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def show
|
9
|
-
find_invoice_item
|
10
|
-
end
|
11
2
|
|
12
3
|
def edit
|
13
|
-
|
14
|
-
|
4
|
+
invoice_item_id = params[:id]
|
5
|
+
invoice_id = params[:invoice_id]
|
15
6
|
|
16
|
-
def update
|
17
|
-
@invoice_item = Kaui::KillbillHelper.new_invoice_item(params[:kill_bill_client_model_invoice_item])
|
18
7
|
begin
|
19
|
-
Kaui::
|
20
|
-
flash[:notice] = "Adjustment item created"
|
21
|
-
redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id)
|
8
|
+
invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
22
9
|
rescue => e
|
23
|
-
flash
|
24
|
-
|
10
|
+
flash[:error] = "Error while getting information for invoice #{invoice_id}: #{as_string(e)}"
|
11
|
+
redirect_to :back
|
25
12
|
end
|
13
|
+
|
14
|
+
@invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }
|
26
15
|
end
|
27
16
|
|
28
|
-
def
|
17
|
+
def update
|
18
|
+
@invoice_item = Kaui::InvoiceItem.new(params[:invoice_item])
|
19
|
+
|
29
20
|
begin
|
30
|
-
|
31
|
-
|
32
|
-
redirect_to kaui_engine.invoice_path(params[:invoice_id])
|
21
|
+
invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
22
|
+
redirect_to kaui_engine.invoice_path(invoice.invoice_id), :notice => 'Adjustment item was successfully created'
|
33
23
|
rescue => e
|
34
|
-
flash[:error] = "Error while
|
35
|
-
|
24
|
+
flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
|
25
|
+
render :action => :edit
|
36
26
|
end
|
37
27
|
end
|
38
28
|
|
39
|
-
|
29
|
+
def destroy
|
30
|
+
@invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params[:id],
|
31
|
+
:invoice_id => params[:invoice_id],
|
32
|
+
:account_id => params[:account_id])
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
rescue => e
|
48
|
-
flash[:error] = "Error while trying to find the invoice item: #{as_string(e)}"
|
49
|
-
end
|
50
|
-
unless @invoice_item.present?
|
51
|
-
flash[:error] = "Invoice for id #{invoice_id} and invoice item id #{invoice_item_id} not found"
|
52
|
-
render :action => :index
|
53
|
-
end
|
54
|
-
else
|
55
|
-
flash[:error] = "Both invoice item and invoice ids should be specified"
|
56
|
-
render :action => :index
|
34
|
+
begin
|
35
|
+
@invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
36
|
+
redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
|
37
|
+
rescue => e
|
38
|
+
flash.now[:error] = "Error while deleting CBA item: #{as_string(e)}"
|
39
|
+
render :action => :edit
|
57
40
|
end
|
58
41
|
end
|
59
42
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Kaui::InvoicesController < Kaui::EngineController
|
2
|
+
|
2
3
|
def index
|
3
4
|
if params[:invoice_id].present?
|
4
5
|
redirect_to kaui_engine.invoice_path(params[:invoice_id])
|
@@ -6,25 +7,25 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
6
7
|
end
|
7
8
|
|
8
9
|
def pagination
|
9
|
-
json = {
|
10
|
+
json = {:sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => []}
|
10
11
|
|
11
12
|
search_key = params[:sSearch]
|
12
13
|
if search_key.present?
|
13
|
-
invoices = Kaui::
|
14
|
+
invoices = Kaui::Invoice.find_in_batches_by_search_key(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
14
15
|
else
|
15
|
-
invoices = Kaui::
|
16
|
+
invoices = Kaui::Invoice.find_in_batches(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
16
17
|
end
|
17
18
|
json[:iTotalDisplayRecords] = invoices.pagination_total_nb_records
|
18
|
-
json[:iTotalRecords]
|
19
|
+
json[:iTotalRecords] = invoices.pagination_max_nb_records
|
19
20
|
|
20
21
|
invoices.each do |invoice|
|
21
22
|
json[:aaData] << [
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
view_context.link_to(view_context.truncate_uuid(invoice.invoice_id), view_context.url_for(:controller => :invoices, :action => :show, :id => invoice.invoice_id)),
|
24
|
+
invoice.invoice_number,
|
25
|
+
view_context.format_date(invoice.invoice_date),
|
26
|
+
view_context.humanized_money_with_symbol(invoice.amount_to_money),
|
27
|
+
view_context.humanized_money_with_symbol(invoice.balance_to_money)
|
28
|
+
]
|
28
29
|
end
|
29
30
|
|
30
31
|
respond_to do |format|
|
@@ -34,54 +35,43 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
34
35
|
|
35
36
|
def show
|
36
37
|
invoice_id_or_number = params[:id]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@invoice_id = @invoice.invoice_id
|
42
|
-
@account = Kaui::KillbillHelper.get_account(@invoice.account_id, false, false, options_for_klient)
|
43
|
-
@payments = Kaui::KillbillHelper.get_payments_for_invoice(@invoice_id, options_for_klient)
|
44
|
-
@payment_methods = {}
|
45
|
-
@payments.each do |payment|
|
46
|
-
# The payment method may have been deleted
|
47
|
-
@payment_methods[payment.payment_id] = Kaui::KillbillHelper::get_payment_method(payment.payment_method_id, options_for_klient) rescue nil
|
38
|
+
unless invoice_id_or_number.present?
|
39
|
+
flash.now[:error] = 'No id given'
|
40
|
+
render :index and return
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
begin
|
44
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id_or_number, true, 'FULL', options_for_klient)
|
45
|
+
@invoice_id = @invoice.invoice_id
|
46
|
+
@account = Kaui::Account.find_by_id(@invoice.account_id, false, false, options_for_klient)
|
47
|
+
@payments = Kaui::Invoice.new(:invoice_id => @invoice_id).payments(false, 'FULL', options_for_klient)
|
48
|
+
@payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, options_for_klient)
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
@subscriptions = {}
|
51
|
+
@bundles = {}
|
52
|
+
@cba_items_not_deleteable = []
|
53
|
+
if @invoice.items.present?
|
54
|
+
@invoice.items.each do |item|
|
55
|
+
@cba_items_not_deleteable << item.linked_invoice_item_id if item.description =~ /account credit/ and item.amount < 0
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
|
64
|
-
@bundles[item.bundle_id] = Kaui::KillbillHelper.get_bundle(item.bundle_id, options_for_klient)
|
65
|
-
end
|
57
|
+
unless item.subscription_id.nil? || @subscriptions.has_key?(item.subscription_id)
|
58
|
+
@subscriptions[item.subscription_id] = Kaui::Subscription::find_by_id(item.subscription_id, options_for_klient)
|
66
59
|
end
|
67
|
-
|
68
|
-
|
60
|
+
unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
|
61
|
+
@bundles[item.bundle_id] = Kaui::Bundle::find_by_id(item.bundle_id, options_for_klient)
|
69
62
|
end
|
70
|
-
else
|
71
|
-
flash.now[:error] = "Invoice #{invoice_id_or_number} not found"
|
72
|
-
render :action => :index
|
73
63
|
end
|
74
|
-
|
75
|
-
flash.now[:error] = "
|
64
|
+
else
|
65
|
+
flash.now[:error] = "Invoice items for #{@invoice_id} not found"
|
76
66
|
end
|
77
|
-
|
78
|
-
flash.now[:error] = "
|
67
|
+
rescue => e
|
68
|
+
flash.now[:error] = "Error while getting information for invoice #{invoice_id_or_number}: #{as_string(e)}"
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
82
72
|
def show_html
|
83
73
|
begin
|
84
|
-
render :text => Kaui::
|
74
|
+
render :text => Kaui::Invoice.as_html(params[:id], options_for_klient)
|
85
75
|
rescue => e
|
86
76
|
flash.now[:error] = "Error rendering invoice html #{params[:id]}: #{as_string(e)}"
|
87
77
|
render :action => :index
|
@@ -1,30 +1,31 @@
|
|
1
|
-
require 'kaui/killbill_helper'
|
2
|
-
|
3
1
|
class Kaui::PaymentMethodsController < Kaui::EngineController
|
2
|
+
|
4
3
|
def index
|
5
4
|
end
|
6
5
|
|
7
6
|
def pagination
|
8
|
-
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
9
|
-
|
10
7
|
search_key = params[:sSearch]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
json
|
17
|
-
|
8
|
+
offset = params[:iDisplayStart] || 0
|
9
|
+
limit = params[:iDisplayLength] || 10
|
10
|
+
|
11
|
+
payment_methods = Kaui::PaymentMethod.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
|
13
|
+
json = {
|
14
|
+
:sEcho => params[:sEcho],
|
15
|
+
:iTotalRecords => payment_methods.pagination_max_nb_records,
|
16
|
+
:iTotalDisplayRecords => payment_methods.pagination_total_nb_records,
|
17
|
+
:aaData => []
|
18
|
+
}
|
18
19
|
|
19
20
|
payment_methods.each do |payment_method|
|
20
21
|
info_plugin = payment_method.plugin_info || OpenStruct.new
|
21
22
|
json[:aaData] << [
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
view_context.link_to(view_context.truncate_uuid(payment_method.payment_method_id), view_context.url_for(:controller => :payment_methods, :action => :show, :id => payment_method.payment_method_id)),
|
24
|
+
view_context.link_to(view_context.truncate_uuid(payment_method.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => payment_method.account_id)),
|
25
|
+
info_plugin.external_payment_id,
|
26
|
+
find_value_from_properties(info_plugin.properties, 'ccName'),
|
27
|
+
find_value_from_properties(info_plugin.properties, 'ccLast4'),
|
28
|
+
]
|
28
29
|
end
|
29
30
|
|
30
31
|
respond_to do |format|
|
@@ -32,26 +33,81 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
36
|
+
def new
|
37
|
+
@payment_method = Kaui::PaymentMethod.new(:account_id => params[:account_id],
|
38
|
+
:plugin_name => params[:plugin_name] || Kaui.creditcard_plugin_name.call)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
@payment_method = Kaui::PaymentMethod.new(params[:payment_method].delete_if { |key, value| value.blank? })
|
43
|
+
# Transform "1" into boolean
|
44
|
+
@payment_method.is_default = @payment_method.is_default == '1'
|
45
|
+
# Sensible default
|
46
|
+
@payment_method.plugin_name ||= Kaui.creditcard_plugin_name.call
|
47
|
+
|
48
|
+
# Instance variables needed in case of failure
|
49
|
+
@card_type = params[:card_type]
|
50
|
+
@card_holder_name = params[:card_holder_name]
|
51
|
+
@expiration_year = params[:expiration_year]
|
52
|
+
@expiration_month = params[:expiration_month]
|
53
|
+
@credit_card_number = params[:credit_card_number]
|
54
|
+
@address1 = params[:address1]
|
55
|
+
@address2 = params[:address2]
|
56
|
+
@city = params[:city]
|
57
|
+
@postal_code = params[:postal_code]
|
58
|
+
@state = params[:state]
|
59
|
+
@country = params[:country]
|
60
|
+
|
61
|
+
@payment_method.plugin_info = {
|
62
|
+
'type' => 'CreditCard',
|
63
|
+
'ccType' => @card_type,
|
64
|
+
'ccName' => @card_holder_name,
|
65
|
+
'ccExpirationMonth' => @expiration_month,
|
66
|
+
'ccExpirationYear' => @expiration_year,
|
67
|
+
'ccLast4' => @credit_card_number[-4, 4],
|
68
|
+
'address1' => @address1,
|
69
|
+
'address2' => @address2,
|
70
|
+
'city' => @city,
|
71
|
+
'country' => @country,
|
72
|
+
'zip' => @postal_code,
|
73
|
+
'state' => @state
|
74
|
+
}
|
75
|
+
|
76
|
+
begin
|
77
|
+
@payment_method = @payment_method.create(current_user.kb_username, @reason, @comment, options_for_klient)
|
78
|
+
redirect_to payment_method_path(@payment_method.payment_method_id), :notice => 'Payment method was successfully created'
|
79
|
+
rescue => e
|
80
|
+
flash.now[:error] = "Error while creating payment method: #{as_string(e)}"
|
81
|
+
render :action => :new
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
35
85
|
def show
|
36
|
-
@payment_methods = []
|
37
86
|
begin
|
38
|
-
@payment_methods
|
87
|
+
@payment_methods = [Kaui::PaymentMethod.find_by_id(params[:id], true, options_for_klient)]
|
39
88
|
rescue => e
|
40
89
|
flash.now[:error] = "Error while retrieving payment method #{params[:id]}: #{as_string(e)}"
|
90
|
+
render :action => :index
|
41
91
|
end
|
42
92
|
end
|
43
93
|
|
44
94
|
def destroy
|
45
95
|
payment_method_id = params[:id]
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
flash[:notice] = 'Did not get the payment method id'
|
96
|
+
|
97
|
+
begin
|
98
|
+
Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
99
|
+
redirect_to payment_methods_path, :notice => "Payment method #{payment_method_id} successfully deleted"
|
100
|
+
rescue => e
|
101
|
+
flash.now[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}"
|
102
|
+
render :action => :index
|
54
103
|
end
|
55
|
-
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def find_value_from_properties(properties, key)
|
109
|
+
return nil if key.nil? or properties.nil?
|
110
|
+
prop = (properties.find { |kv| kv.key.to_s == key.to_s })
|
111
|
+
prop.nil? ? nil : prop.value
|
56
112
|
end
|
57
113
|
end
|
@@ -4,25 +4,33 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def pagination
|
7
|
-
json = {
|
7
|
+
json = {:sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => []}
|
8
8
|
|
9
9
|
search_key = params[:sSearch]
|
10
10
|
if search_key.present?
|
11
|
-
payments = Kaui::
|
11
|
+
payments = Kaui::Payment::find_in_batches_by_search_key(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
12
12
|
else
|
13
|
-
payments = Kaui::
|
13
|
+
payments = Kaui::Payment::find_in_batches(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
14
14
|
end
|
15
15
|
json[:iTotalDisplayRecords] = payments.pagination_total_nb_records
|
16
|
-
json[:iTotalRecords]
|
16
|
+
json[:iTotalRecords] = payments.pagination_max_nb_records
|
17
17
|
|
18
18
|
payments.each do |payment|
|
19
|
+
created_date = nil
|
20
|
+
payment.transactions.each do |transaction|
|
21
|
+
transaction_date = Date.parse(transaction.effective_date)
|
22
|
+
if created_date.nil? or transaction_date < created_date
|
23
|
+
created_date = transaction_date
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
json[:aaData] << [
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
view_context.link_to(view_context.truncate_uuid(payment.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => payment.account_id)),
|
29
|
+
payment.payment_number,
|
30
|
+
view_context.format_date(created_date),
|
31
|
+
view_context.humanized_money_with_symbol(payment.paid_amount_to_money),
|
32
|
+
view_context.humanized_money_with_symbol(payment.returned_amount_to_money)
|
33
|
+
]
|
26
34
|
end
|
27
35
|
|
28
36
|
respond_to do |format|
|
@@ -31,30 +39,60 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
31
39
|
end
|
32
40
|
|
33
41
|
def new
|
34
|
-
|
35
|
-
|
42
|
+
account_id = params[:account_id]
|
43
|
+
invoice_id = params[:invoice_id]
|
44
|
+
amount = 0
|
45
|
+
|
46
|
+
if invoice_id.nil?
|
47
|
+
flash[:error] = 'No invoice id specified'
|
48
|
+
render :action => :index and return
|
49
|
+
end
|
50
|
+
|
51
|
+
if account_id.nil?
|
52
|
+
flash[:error] = 'No account id specified'
|
53
|
+
render :action => :index and return
|
54
|
+
end
|
55
|
+
|
36
56
|
begin
|
37
|
-
@invoice = Kaui::
|
38
|
-
|
57
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
58
|
+
amount = @invoice.balance
|
39
59
|
rescue => e
|
40
|
-
flash[:error] = "
|
41
|
-
|
60
|
+
flash[:error] = "Unable to retrieve invoice: #{as_string(e)}"
|
61
|
+
render :action => :index and return
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
@account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
|
66
|
+
rescue => e
|
67
|
+
flash[:error] = "Unable to retrieve account: #{as_string(e)}"
|
68
|
+
render :action => :index and return
|
42
69
|
end
|
43
70
|
|
44
|
-
@payment = Kaui::
|
71
|
+
@payment = Kaui::InvoicePayment.new('accountId' => account_id, 'targetInvoiceId' => invoice_id, 'purchasedAmount' => amount)
|
45
72
|
end
|
46
73
|
|
47
74
|
def create
|
48
|
-
payment = Kaui::
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
75
|
+
payment = Kaui::InvoicePayment.new(params[:invoice_payment])
|
76
|
+
|
77
|
+
begin
|
78
|
+
payment = payment.create(params[:external] == '1', current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
79
|
+
flash[:notice] = 'Payment created'
|
80
|
+
rescue => e
|
81
|
+
flash[:error] = "Error while creating a new payment: #{as_string(e)}"
|
82
|
+
render :action => :index and return
|
57
83
|
end
|
84
|
+
|
58
85
|
redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
|
59
86
|
end
|
87
|
+
|
88
|
+
def show
|
89
|
+
begin
|
90
|
+
@payments = [Kaui::InvoicePayment.find_by_id(params[:id], true, options_for_klient)]
|
91
|
+
@account = Kaui::Account.find_by_id(@payments.first.account_id, false, false, options_for_klient)
|
92
|
+
@payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, options_for_klient)
|
93
|
+
rescue => e
|
94
|
+
flash.now[:error] = "Error while looking up payment: #{as_string(e)}"
|
95
|
+
render :action => :index
|
96
|
+
end
|
97
|
+
end
|
60
98
|
end
|